提交 d97b1b06 编写于 作者: S serge@jkiss.org

#3596 Undo/redo command handle fix


Former-commit-id: 1c1b21d7
上级 d811ead8
...@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IAdaptable; ...@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.jface.action.Action; import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager; import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator; import org.eclipse.jface.action.Separator;
import org.eclipse.jface.text.IUndoManager;
import org.eclipse.jface.text.source.ISourceViewer; import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText; import org.eclipse.swt.custom.StyledText;
...@@ -56,7 +57,7 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp ...@@ -56,7 +57,7 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
private IValueController valueController; private IValueController valueController;
private IEditorSite subSite; private IEditorSite subSite;
private BaseTextEditor editor; private EDITOR editor;
@Override @Override
public StyledText createControl(IValueController valueController) { public StyledText createControl(IValueController valueController) {
...@@ -77,7 +78,7 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp ...@@ -77,7 +78,7 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
return editor.getEditorControl(); return editor.getEditorControl();
} }
protected abstract BaseTextEditor createEditorParty(IValueController valueController); protected abstract EDITOR createEditorParty(IValueController valueController);
@Override @Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull final StyledText control) throws DBCException { public void contributeActions(@NotNull IContributionManager manager, @NotNull final StyledText control) throws DBCException {
...@@ -117,18 +118,18 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp ...@@ -117,18 +118,18 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
} }
} }
protected BaseTextEditor getTextEditor() { protected EDITOR getTextEditor() {
return editor; return editor;
} }
protected void initEditorSettings(StyledText control) { private void initEditorSettings(StyledText control) {
boolean wwEnabled = ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_WORD_WRAP); boolean wwEnabled = ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_WORD_WRAP);
if (wwEnabled != control.getWordWrap()) { if (wwEnabled != control.getWordWrap()) {
control.setWordWrap(wwEnabled); control.setWordWrap(wwEnabled);
} }
} }
protected void applyEditorStyle() { private void applyEditorStyle() {
BaseTextEditor textEditor = getTextEditor(); BaseTextEditor textEditor = getTextEditor();
if (textEditor != null && ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT)) { if (textEditor != null && ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT)) {
try { try {
...@@ -146,6 +147,9 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp ...@@ -146,6 +147,9 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
if (adapter.isAssignableFrom(textEditor.getClass())) { if (adapter.isAssignableFrom(textEditor.getClass())) {
return adapter.cast(textEditor); return adapter.cast(textEditor);
} }
if (adapter == IUndoManager.class) {
return adapter.cast(textEditor.getTextViewer().getUndoManager());
}
return textEditor.getAdapter(adapter); return textEditor.getAdapter(adapter);
} }
return null; return null;
......
...@@ -22,10 +22,10 @@ import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor; ...@@ -22,10 +22,10 @@ import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor;
/** /**
* TextPanelEditor * TextPanelEditor
*/ */
public class TextPanelEditor extends AbstractTextPanelEditor<BaseTextEditor> { public class TextPanelEditor extends AbstractTextPanelEditor<TextEditorPart> {
@Override @Override
protected BaseTextEditor createEditorParty(IValueController valueController) { protected TextEditorPart createEditorParty(IValueController valueController) {
return new TextEditorPart(); return new TextEditorPart();
} }
} }
...@@ -26,7 +26,7 @@ import org.jkiss.dbeaver.ui.editors.xml.XMLEditor; ...@@ -26,7 +26,7 @@ import org.jkiss.dbeaver.ui.editors.xml.XMLEditor;
public class XMLPanelEditor extends AbstractTextPanelEditor<XMLEditor> { public class XMLPanelEditor extends AbstractTextPanelEditor<XMLEditor> {
@Override @Override
protected BaseTextEditor createEditorParty(IValueController valueController) { protected XMLEditor createEditorParty(IValueController valueController) {
return new XMLEditor(); return new XMLEditor();
} }
} }
...@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IProgressMonitor; ...@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status; import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.text.IUndoManager;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter; import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionEvent;
...@@ -371,6 +372,10 @@ public class EntityEditor extends MultiPageDatabaseEditor ...@@ -371,6 +372,10 @@ public class EntityEditor extends MultiPageDatabaseEditor
public void undoChanges() public void undoChanges()
{ {
IUndoManager undoManager = getAdapter(IUndoManager.class);
if (undoManager != null) {
undoManager.undo();
} else {
DBECommandContext commandContext = getCommandContext(); DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getUndoCommand() != null) { if (commandContext != null && commandContext.getUndoCommand() != null) {
if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) { if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) {
...@@ -382,8 +387,7 @@ public class EntityEditor extends MultiPageDatabaseEditor ...@@ -382,8 +387,7 @@ public class EntityEditor extends MultiPageDatabaseEditor
null, null,
DBeaverPreferences.CONFIRM_ENTITY_REJECT, DBeaverPreferences.CONFIRM_ENTITY_REJECT,
ConfirmationDialog.QUESTION, ConfirmationDialog.QUESTION,
getDatabaseObject().getName()) != IDialogConstants.YES_ID) getDatabaseObject().getName()) != IDialogConstants.YES_ID) {
{
return; return;
} }
} }
...@@ -391,15 +395,21 @@ public class EntityEditor extends MultiPageDatabaseEditor ...@@ -391,15 +395,21 @@ public class EntityEditor extends MultiPageDatabaseEditor
firePropertyChange(IEditorPart.PROP_DIRTY); firePropertyChange(IEditorPart.PROP_DIRTY);
} }
} }
}
public void redoChanges() public void redoChanges()
{ {
IUndoManager undoManager = getAdapter(IUndoManager.class);
if (undoManager != null) {
undoManager.redo();
} else {
DBECommandContext commandContext = getCommandContext(); DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getRedoCommand() != null) { if (commandContext != null && commandContext.getRedoCommand() != null) {
commandContext.redoCommand(); commandContext.redoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY); firePropertyChange(IEditorPart.PROP_DIRTY);
} }
} }
}
public int showChanges(boolean allowSave) public int showChanges(boolean allowSave)
{ {
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
package org.jkiss.dbeaver.ui.editors.entity; package org.jkiss.dbeaver.ui.editors.entity;
import org.eclipse.core.expressions.PropertyTester; import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jface.text.IUndoManager;
import org.jkiss.dbeaver.Log; import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.edit.DBECommandContext; import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.ui.ActionUtils; import org.jkiss.dbeaver.ui.ActionUtils;
...@@ -43,6 +44,19 @@ public class EntityEditorPropertyTester extends PropertyTester ...@@ -43,6 +44,19 @@ public class EntityEditorPropertyTester extends PropertyTester
return false; return false;
} }
EntityEditor editor = (EntityEditor)receiver; EntityEditor editor = (EntityEditor)receiver;
if (PROP_DIRTY.equals(property)) {
return editor.isDirty();
}
IUndoManager undoManager = editor.getAdapter(IUndoManager.class);
if (undoManager != null) {
switch (property) {
case PROP_CAN_UNDO:
return undoManager.undoable();
case PROP_CAN_REDO:
return undoManager.redoable();
}
} else {
DBECommandContext commandContext = editor.getEditorInput().getCommandContext(); DBECommandContext commandContext = editor.getEditorInput().getCommandContext();
if (commandContext != null) { if (commandContext != null) {
switch (property) { switch (property) {
...@@ -50,8 +64,7 @@ public class EntityEditorPropertyTester extends PropertyTester ...@@ -50,8 +64,7 @@ public class EntityEditorPropertyTester extends PropertyTester
return commandContext.getUndoCommand() != null; return commandContext.getUndoCommand() != null;
case PROP_CAN_REDO: case PROP_CAN_REDO:
return commandContext.getRedoCommand() != null; return commandContext.getRedoCommand() != null;
case PROP_DIRTY: }
return editor.isDirty();
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册