use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by dbeaver.
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);
}
}
}
}
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;
}
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;
}
use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by serge-rider.
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;
}
use of org.jkiss.dbeaver.ui.editors.text.BaseTextEditor in project dbeaver by serge-rider.
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);
}
}
Aggregations