use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method validateEditorInputState.
@Override
public boolean validateEditorInputState() {
boolean enabled = false;
synchronized (this) {
enabled = fIsStateValidationEnabled;
}
if (enabled) {
ISourceViewer viewer = fSourceViewer;
if (viewer == null)
return false;
fTextInputListener.inputChanged = false;
viewer.addTextInputListener(fTextInputListener);
try {
final IEditorInput input = getEditorInput();
BusyIndicator.showWhile(getSite().getShell().getDisplay(), new Runnable() {
@Override
public void run() {
validateState(input);
}
});
sanityCheckState(input);
return !isEditorInputReadOnly() && !fTextInputListener.inputChanged;
} finally {
viewer.removeTextInputListener(fTextInputListener);
}
}
return !isEditorInputReadOnly();
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method doSetInput.
/**
* Called directly from <code>setInput</code> and from within a workspace
* runnable from <code>init</code>, this method does the actual setting
* of the editor input. Closes the editor if <code>input</code> is
* <code>null</code>. Disconnects from any previous editor input and its
* document provider and connects to the new one.
* <p>
* Subclasses may extend.
* </p>
*
* @param input the input to be set
* @exception CoreException if input cannot be connected to the document
* provider
*/
protected void doSetInput(IEditorInput input) throws CoreException {
ISaveablesLifecycleListener listener = getSite().getService(ISaveablesLifecycleListener.class);
if (listener == null)
fSavable = null;
if (input == null) {
close(isSaveOnCloseNeeded());
if (fSavable != null) {
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
fSavable.disconnectEditor();
fSavable = null;
}
} else {
boolean mustSendLifeCycleEvent = false;
if (fSavable != null) {
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_CLOSE, getSaveables(), false));
fSavable.disconnectEditor();
fSavable = null;
mustSendLifeCycleEvent = true;
}
IEditorInput oldInput = getEditorInput();
if (oldInput != null)
getDocumentProvider().disconnect(oldInput);
super.setInput(input);
updateDocumentProvider(input);
IDocumentProvider provider = getDocumentProvider();
if (provider == null) {
IStatus s = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, IStatus.OK, EditorMessages.Editor_error_no_provider, null);
throw new CoreException(s);
}
provider.connect(input);
initializeTitle(input);
if (fSourceViewer != null) {
initializeSourceViewer(input);
// Reset the undo context for the undo and redo action handlers
IAction undoAction = getAction(ITextEditorActionConstants.UNDO);
IAction redoAction = getAction(ITextEditorActionConstants.REDO);
boolean areOperationActionHandlersInstalled = undoAction instanceof OperationHistoryActionHandler && redoAction instanceof OperationHistoryActionHandler;
IUndoContext undoContext = getUndoContext();
if (undoContext != null && areOperationActionHandlersInstalled) {
((OperationHistoryActionHandler) undoAction).setContext(undoContext);
((OperationHistoryActionHandler) redoAction).setContext(undoContext);
} else {
createUndoRedoActions();
}
}
if (fIsOverwriting)
toggleOverwriteMode();
setInsertMode(getLegalInsertModes().get(0));
updateCaret();
updateStatusField(ITextEditorActionConstants.STATUS_CATEGORY_ELEMENT_STATE);
if (fSelectionListener != null)
fSelectionListener.setDocument(getDocumentProvider().getDocument(input));
IVerticalRuler ruler = getVerticalRuler();
if (ruler instanceof CompositeRuler)
updateContributedRulerColumns((CompositeRuler) ruler);
// Send savable life-cycle if needed.
if (mustSendLifeCycleEvent && listener != null)
listener.handleLifecycleEvent(new SaveablesLifecycleEvent(this, SaveablesLifecycleEvent.POST_OPEN, getSaveables(), false));
}
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class AbstractTextEditor method handleEditorInputChanged.
/**
* Handles an external change of the editor's input element. Subclasses may
* extend.
*/
protected void handleEditorInputChanged() {
String title;
String msg;
Shell shell = getSite().getShell();
final IDocumentProvider provider = getDocumentProvider();
if (provider == null) {
// fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=15066
close(false);
return;
}
final IEditorInput input = getEditorInput();
final String inputName = input.getToolTipText();
if (provider.isDeleted(input)) {
if (isSaveAsAllowed()) {
title = EditorMessages.Editor_error_activated_deleted_save_title;
msg = NLSUtility.format(EditorMessages.Editor_error_activated_deleted_save_message, inputName);
String[] buttons = { EditorMessages.Editor_error_activated_deleted_save_button_save, EditorMessages.Editor_error_activated_deleted_save_button_close };
MessageDialog dialog = new MessageDialog(shell, title, null, msg, MessageDialog.QUESTION, buttons, 0);
if (dialog.open() == 0) {
IProgressMonitor pm = getProgressMonitor();
try {
performSaveAs(pm);
if (pm.isCanceled())
handleEditorInputChanged();
} finally {
pm.done();
}
} else {
close(false);
}
} else {
title = EditorMessages.Editor_error_activated_deleted_close_title;
msg = NLSUtility.format(EditorMessages.Editor_error_activated_deleted_close_message, inputName);
if (MessageDialog.openConfirm(shell, title, msg))
close(false);
}
} else if (fHasBeenActivated) {
title = EditorMessages.Editor_error_activated_outofsync_title;
msg = NLSUtility.format(EditorMessages.Editor_error_activated_outofsync_message, inputName);
if (MessageDialog.openQuestion(shell, title, msg)) {
try {
if (provider instanceof IDocumentProviderExtension) {
IDocumentProviderExtension extension = (IDocumentProviderExtension) provider;
extension.synchronize(input);
} else {
doSetInput(input);
}
} catch (CoreException x) {
IStatus status = x.getStatus();
if (status == null || status.getSeverity() != IStatus.CANCEL) {
title = EditorMessages.Editor_error_refresh_outofsync_title;
msg = NLSUtility.format(EditorMessages.Editor_error_refresh_outofsync_message, inputName);
ErrorDialog.openError(shell, title, msg, x.getStatus());
}
}
} else if (!isDirty()) {
// Trigger dummy change to dirty the editor, for details see https://bugs.eclipse.org/344101 .
try {
IDocument document = provider.getDocument(input);
if (document != null)
// $NON-NLS-1$
document.replace(0, 0, "");
} catch (BadLocationException e) {
// Ignore as this can't happen
}
}
}
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class HippieProposalProcessor method getSuggestions.
/**
* Create the array of suggestions. It scans all open text editors and prefers suggestions from
* the currently open editor. It also adds the empty suggestion at the end.
*
* @param viewer the viewer
* @param offset the offset
* @param prefix the prefix to search for
* @return the list of all possible suggestions in the currently open editors
* @throws BadLocationException if accessing the current document fails
*/
private List<String> getSuggestions(ITextViewer viewer, int offset, String prefix) throws BadLocationException {
ArrayList<String> suggestions = createSuggestionsFromOpenDocument(viewer, offset, prefix);
IDocument currentDocument = viewer.getDocument();
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
IEditorReference[] editorReferences = window.getActivePage().getEditorReferences();
for (int i = 0; i < editorReferences.length; i++) {
// don't create!
IEditorPart editor = editorReferences[i].getEditor(false);
if (editor instanceof ITextEditor) {
ITextEditor textEditor = (ITextEditor) editor;
IEditorInput input = textEditor.getEditorInput();
IDocument doc = textEditor.getDocumentProvider().getDocument(input);
if (!currentDocument.equals(doc))
suggestions.addAll(fEngine.getCompletionsForward(doc, prefix, 0, false));
}
}
// add the empty suggestion
// $NON-NLS-1$
suggestions.add("");
List<String> uniqueSuggestions = fEngine.makeUnique(suggestions);
return uniqueSuggestions;
}
use of org.eclipse.ui.IEditorInput in project eclipse.platform.text by eclipse.
the class AbstractDecoratedTextEditor method editorContextMenuAboutToShow.
@Override
protected void editorContextMenuAboutToShow(IMenuManager menu) {
super.editorContextMenuAboutToShow(menu);
IAction preferencesAction = getAction(ITextEditorActionConstants.CONTEXT_PREFERENCES);
menu.appendToGroup(IWorkbenchActionConstants.MB_ADDITIONS, new Separator(ITextEditorActionConstants.GROUP_SETTINGS));
menu.appendToGroup(ITextEditorActionConstants.GROUP_SETTINGS, preferencesAction);
menu.appendToGroup(ITextEditorActionConstants.GROUP_SAVE, new Separator(ITextEditorActionConstants.GROUP_OPEN));
IEditorInput editorInput = getEditorInput();
if ((editorInput.getAdapter(IResource.class)) instanceof IFile) {
MenuManager openWithSubMenu = new MenuManager(TextEditorMessages.AbstractDecoratedTextEditor_openWith_menu);
final IWorkbenchPage page = getEditorSite().getPage();
// XXX: Internal reference will get fixed during 3.7, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=307026
openWithSubMenu.add(new OpenWithMenu(page, editorInput) {
@Override
protected void openEditor(IEditorDescriptor editorDescriptor, boolean openUsingDescriptor) {
super.openEditor(editorDescriptor, openUsingDescriptor);
ISelection selection = getSelectionProvider().getSelection();
if (selection instanceof ITextSelection) {
revealInEditor(page.getActiveEditor(), ((ITextSelection) selection).getOffset(), ((ITextSelection) selection).getLength());
}
}
});
menu.appendToGroup(ITextEditorActionConstants.GROUP_OPEN, openWithSubMenu);
}
MenuManager showInSubMenu = new MenuManager(getShowInMenuLabel());
showInSubMenu.add(ContributionItemFactory.VIEWS_SHOW_IN.create(getEditorSite().getWorkbenchWindow()));
menu.appendToGroup(ITextEditorActionConstants.GROUP_OPEN, showInSubMenu);
}
Aggregations