提交 d5b8aa75 编写于 作者: S Serge Rider

#6484 Text editors in value pane: find/replace + common actions.


Former-commit-id: da145d77
上级 5b367ca9
......@@ -16,10 +16,7 @@
*/
package org.jkiss.dbeaver.ui.controls;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IMenuManager;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.*;
import org.eclipse.jface.text.IFindReplaceTarget;
import org.eclipse.swt.custom.ST;
import org.eclipse.swt.custom.StyledText;
......@@ -64,7 +61,7 @@ public class StyledTextUtils {
text.addDisposeListener(e -> menuMgr.dispose());
}
public static void fillDefaultStyledTextContextMenu(IMenuManager menu, final StyledText text) {
public static void fillDefaultStyledTextContextMenu(IContributionManager menu, final StyledText text) {
final Point selectionRange = text.getSelectionRange();
menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_COPY, selectionRange.y > 0, text, ST.COPY));
menu.add(new StyledTextAction(IWorkbenchCommandConstants.EDIT_PASTE, text.getEditable(), text, ST.PASTE));
......
/*
* DBeaver - Universal Database Manager
* Copyright (C) 2010-2019 Serge Rider (serge@jkiss.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jkiss.dbeaver.ui.editors;
import org.eclipse.jface.action.IContributionManager;
/**
* Action contributor
*/
public interface IActionContributor {
void contributeActions(IContributionManager manager);
}
......@@ -43,16 +43,15 @@ import org.jkiss.dbeaver.ui.ICommentsSupport;
import org.jkiss.dbeaver.ui.ISingleControlEditor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.dialogs.DialogUtils;
import org.jkiss.dbeaver.ui.editors.EditorUtils;
import org.jkiss.dbeaver.ui.editors.INonPersistentEditorInput;
import org.jkiss.dbeaver.ui.editors.IStatefulEditorInput;
import org.jkiss.dbeaver.ui.editors.SubEditorSite;
import org.jkiss.dbeaver.ui.editors.*;
import org.jkiss.dbeaver.utils.ContentUtils;
import org.jkiss.dbeaver.utils.GeneralUtils;
import org.jkiss.utils.IOUtils;
import java.io.*;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.List;
/**
* Abstract text editor.
......@@ -66,6 +65,12 @@ public abstract class BaseTextEditor extends AbstractDecoratedTextEditor impleme
public static final String GROUP_SQL_ADDITIONS = "sql.additions";
public static final String GROUP_SQL_EXTRAS = "sql.extras";
private List<IActionContributor> actionContributors = new ArrayList<>();
public void addContextMenuContributor(IActionContributor contributor) {
actionContributors.add(contributor);
}
public static BaseTextEditor getTextEditor(IEditorPart editor)
{
if (editor == null) {
......@@ -182,6 +187,10 @@ public abstract class BaseTextEditor extends AbstractDecoratedTextEditor impleme
if (preferencesAction != null) {
menu.appendToGroup(GROUP_SQL_PREFERENCES, preferencesAction);
}
for (IActionContributor ac : actionContributors) {
ac.contributeActions(menu);
}
}
@Nullable
......
......@@ -21,12 +21,13 @@ import org.eclipse.jface.action.IContributionManager;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.jkiss.dbeaver.ui.controls.resultset.IResultSetPresentation;
import org.jkiss.dbeaver.ui.editors.IActionContributor;
/**
* ResultSet panel.
* RSV can embed multiple panels to provide additional visualization functionality
*/
public interface IResultSetPanel {
public interface IResultSetPanel extends IActionContributor {
Control createContents(IResultSetPresentation presentation, Composite parent);
......@@ -38,5 +39,4 @@ public interface IResultSetPanel {
void refresh(boolean force);
void contributeActions(IContributionManager manager);
}
......@@ -18,6 +18,7 @@ package org.jkiss.dbeaver.ui.data.managers;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.dialogs.IDialogSettings;
......@@ -29,6 +30,7 @@ import org.eclipse.swt.custom.StyledText;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.texteditor.ITextEditorActionConstants;
import org.jkiss.code.NotNull;
import org.jkiss.dbeaver.DBException;
import org.jkiss.dbeaver.Log;
......@@ -37,6 +39,7 @@ import org.jkiss.dbeaver.model.data.DBDContent;
import org.jkiss.dbeaver.model.impl.StringContentStorage;
import org.jkiss.dbeaver.model.runtime.DBRProgressMonitor;
import org.jkiss.dbeaver.ui.UIUtils;
import org.jkiss.dbeaver.ui.controls.StyledTextUtils;
import org.jkiss.dbeaver.ui.data.IStreamValueEditor;
import org.jkiss.dbeaver.ui.data.IValueController;
import org.jkiss.dbeaver.ui.editors.StringEditorInput;
......@@ -76,11 +79,26 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
assert editorControl != null;
initEditorSettings(editorControl);
editorControl.addDisposeListener(e -> editor.releaseEditorInput());
return editor.getEditorControl();
editor.addContextMenuContributor(manager -> contributeTextEditorActions(manager, editorControl));
return editorControl;
}
protected abstract EDITOR createEditorParty(IValueController valueController);
protected void contributeTextEditorActions(@NotNull IContributionManager manager, @NotNull final StyledText control) {
manager.removeAll();
StyledTextUtils.fillDefaultStyledTextContextMenu(manager, control);
manager.add(new AutoFormatAction());
IAction preferencesAction = editor.getAction(ITextEditorActionConstants.CONTEXT_PREFERENCES);
if (preferencesAction != null) {
manager.add(new Separator());
manager.add(preferencesAction);
}
}
@Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull final StyledText control) {
......@@ -105,15 +123,7 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
BaseTextEditor textEditor = getTextEditor();
if (textEditor != null) {
final Action afAction = new Action("Auto Format", Action.AS_CHECK_BOX) {
@Override
public void run() {
boolean newAF = !getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT);
setChecked(newAF);
getPanelSettings().put(PREF_TEXT_EDITOR_AUTO_FORMAT, newAF);
applyEditorStyle();
}
};
final Action afAction = new AutoFormatAction();
afAction.setChecked(getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT));
manager.add(afAction);
}
......@@ -233,4 +243,22 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
return viewerSettings;
}
private class AutoFormatAction extends Action {
AutoFormatAction() {
super("Auto Format", Action.AS_CHECK_BOX);
}
@Override
public boolean isChecked() {
return getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT);
}
@Override
public void run() {
boolean newAF = !getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT);
//setChecked(newAF);
getPanelSettings().put(PREF_TEXT_EDITOR_AUTO_FORMAT, newAF);
applyEditorStyle();
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册