Search in sources :

Example 11 with BaseTextEditor

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

the class AbstractTextPanelEditor method applyEditorStyle.

private void applyEditorStyle() {
    BaseTextEditor textEditor = getTextEditor();
    if (textEditor != null && getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT)) {
        TextViewer textViewer = textEditor.getTextViewer();
        if (textViewer != null) {
            StyledText textWidget = textViewer.getTextWidget();
            if (textWidget == null || textWidget.isDisposed()) {
                return;
            }
            textWidget.setRedraw(false);
            boolean oldEditable = textViewer.isEditable();
            if (!oldEditable) {
                textViewer.setEditable(true);
            }
            try {
                if (textViewer.canDoOperation(ISourceViewer.FORMAT)) {
                    textViewer.doOperation(ISourceViewer.FORMAT);
                }
            } catch (Exception e) {
                log.debug("Error formatting text", e);
            } finally {
                if (!oldEditable) {
                    textViewer.setEditable(false);
                }
                textWidget.setRedraw(true);
            }
        }
    }
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor) PartInitException(org.eclipse.ui.PartInitException) DBException(org.jkiss.dbeaver.DBException) TextViewer(org.eclipse.jface.text.TextViewer)

Example 12 with BaseTextEditor

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

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 13 with BaseTextEditor

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

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)

Example 14 with BaseTextEditor

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

the class AbstractTextPanelEditor method contributeSettings.

@Override
public void contributeSettings(@NotNull IContributionManager manager, @NotNull final StyledText editorControl) {
    manager.add(new Separator());
    {
        Action wwAction = new Action("Word Wrap", Action.AS_CHECK_BOX) {

            @Override
            public void run() {
                boolean newWW = !editorControl.getWordWrap();
                setChecked(newWW);
                editorControl.setWordWrap(newWW);
                getPanelSettings().put(PREF_TEXT_EDITOR_WORD_WRAP, newWW);
            }
        };
        wwAction.setChecked(editorControl.getWordWrap());
        manager.add(wwAction);
    }
    BaseTextEditor textEditor = getTextEditor();
    if (textEditor != null) {
        final Action afAction = new AutoFormatAction();
        afAction.setChecked(getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT));
        manager.add(afAction);
    }
}
Also used : IAction(org.eclipse.jface.action.IAction) Action(org.eclipse.jface.action.Action) Separator(org.eclipse.jface.action.Separator) BaseTextEditor(org.jkiss.dbeaver.ui.editors.text.BaseTextEditor)

Example 15 with BaseTextEditor

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

the class MorphDelimitedListHandler method execute.

@Override
public Object execute(ExecutionEvent executionEvent) throws ExecutionException {
    Shell activeShell = HandlerUtil.getActiveShell(executionEvent);
    BaseTextEditor textEditor = BaseTextEditor.getTextEditor(HandlerUtil.getActiveEditor(executionEvent));
    if (textEditor != null) {
        IDocument document = textEditor.getDocumentProvider().getDocument(textEditor.getEditorInput());
        ISelectionProvider provider = textEditor.getSelectionProvider();
        if (provider != null) {
            ISelection selection = provider.getSelection();
            if (selection instanceof ITextSelection) {
                ITextSelection textSelection = (ITextSelection) selection;
                if (textSelection.getLength() <= 0) {
                    UIUtils.showMessageBox(activeShell, "Morph text", "Text selection is empty. You need to select some text to morph", SWT.ICON_INFORMATION);
                    return null;
                }
                String formattedText = morphText(activeShell, textSelection.getText());
                if (formattedText != null) {
                    try {
                        document.replace(textSelection.getOffset(), textSelection.getLength(), formattedText);
                    } catch (BadLocationException e) {
                        DBWorkbench.getPlatformUI().showError("Morph text", "Error replacing text", e);
                    }
                }
            }
        }
    }
    return null;
}
Also used : ISelectionProvider(org.eclipse.jface.viewers.ISelectionProvider) 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)

Aggregations

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