Search in sources :

Example 1 with BaseTextEditor

use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by serge-rider.

the class UIUtils method enableHostEditorKeyBindings.

/**
     * Eclipse hack. Disables/enabled all key bindings in specified site's part. Works only if host editor is extender of
     * AbstractTextEditor Uses reflection because setActionActivation is private method
     * TODO: find better way to disable key bindings or prioritize event handling to widgets
     * 
     * @param partSite workbench part site
     * @param enable enable or disable
     */
@Deprecated
public static void enableHostEditorKeyBindings(IWorkbenchPartSite partSite, boolean enable) {
    IWorkbenchPart part = partSite.getPart();
    if (part instanceof AbstractTextEditor) {
        AbstractTextEditor hostEditor = (AbstractTextEditor) part;
        if (hostEditor instanceof BaseTextEditor) {
            StyledText textWidget = ((BaseTextEditor) hostEditor).getTextViewer().getTextWidget();
            if (textWidget == null || textWidget.isDisposed()) {
                return;
            }
        }
        try {
            Method activatorMethod = AbstractTextEditor.class.getDeclaredMethod("setActionActivation", Boolean.TYPE);
            activatorMethod.setAccessible(true);
            activatorMethod.invoke(hostEditor, enable);
        } catch (Throwable e) {
            if (e instanceof InvocationTargetException) {
                e = ((InvocationTargetException) e).getTargetException();
            }
            log.warn("Can't disable text editor action activations", e);
        }
    //hostEditor.getEditorSite().getActionBarContributor().setActiveEditor(hostEditor);
    }
}
Also used : AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) Method(java.lang.reflect.Method) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 2 with BaseTextEditor

use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by serge-rider.

the class AbstractCommentHandler method execute.

public final Object execute(ExecutionEvent event) throws ExecutionException {
    BaseTextEditor textEditor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
    if (textEditor != null) {
        ICommentsSupport commentsSupport = textEditor.getCommentsSupport();
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        if (document != null && commentsSupport != null) {
            // get current text selection
            ISelectionProvider provider = textEditor.getSelectionProvider();
            if (provider != null) {
                ISelection selection = provider.getSelection();
                if (selection instanceof ITextSelection) {
                    ITextSelection textSelection = (ITextSelection) selection;
                    if (!textSelection.isEmpty()) {
                        try {
                            processAction(textEditor.getSelectionProvider(), commentsSupport, document, textSelection);
                        } catch (BadLocationException e) {
                            log.warn(e);
                        }
                    }
                }
            }
        }
    }
    return null;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) ICommentsSupport(org.jkiss.dbeaver.ui.ICommentsSupport) ISelection(org.eclipse.jface.viewers.ISelection) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor) IDocument(org.eclipse.jface.text.IDocument) ITextSelection(org.eclipse.jface.text.ITextSelection) BadLocationException(org.eclipse.jface.text.BadLocationException)

Example 3 with BaseTextEditor

use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by serge-rider.

the class LoadTextFileHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    BaseTextEditor editor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
    if (editor == null) {
        return null;
    }
    editor.loadFromExternalFile();
    return null;
}
Also used : BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor)

Example 4 with BaseTextEditor

use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by dbeaver.

the class ToggleWordWrapHandler method execute.

@Override
public Object execute(ExecutionEvent event) {
    // get active editor where word wrap will be toggled
    BaseTextEditor textEditor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
    if (textEditor != null) {
        // editor (ITextEditor) adapter returns StyledText
        Object text = textEditor.getAdapter(Control.class);
        if (text instanceof StyledText) {
            StyledText styledText = (StyledText) text;
            // toggle wrapping
            styledText.setWordWrap(!styledText.getWordWrap());
        }
    }
    return null;
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor)

Example 5 with BaseTextEditor

use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by dbeaver.

the class SaveTextFileHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    BaseTextEditor editor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(event));
    if (editor == null) {
        return null;
    }
    editor.saveToExternalFile();
    return null;
}
Also used : BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor)

Aggregations

BaseTextEditor (org.jkiss.dbeaver.ui.editors.text.BaseTextEditor)12 BadLocationException (org.eclipse.jface.text.BadLocationException)3 IDocument (org.eclipse.jface.text.IDocument)3 ITextSelection (org.eclipse.jface.text.ITextSelection)3 ISelection (org.eclipse.jface.viewers.ISelection)3 ISelectionProvider (org.eclipse.jface.viewers.ISelectionProvider)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 StyledText (org.eclipse.swt.custom.StyledText)2 AbstractTextEditor (org.eclipse.ui.texteditor.AbstractTextEditor)2 ICommentsSupport (org.jkiss.dbeaver.ui.ICommentsSupport)2 Action (org.eclipse.jface.action.Action)1 Separator (org.eclipse.jface.action.Separator)1