提交 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,33 +372,42 @@ public class EntityEditor extends MultiPageDatabaseEditor ...@@ -371,33 +372,42 @@ public class EntityEditor extends MultiPageDatabaseEditor
public void undoChanges() public void undoChanges()
{ {
DBECommandContext commandContext = getCommandContext(); IUndoManager undoManager = getAdapter(IUndoManager.class);
if (commandContext != null && commandContext.getUndoCommand() != null) { if (undoManager != null) {
if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) { undoManager.undo();
//getSite().getPage().closeEditor(this, true); } else {
//return; DBECommandContext commandContext = getCommandContext();
// Undo of last command in command context will close editor if (commandContext != null && commandContext.getUndoCommand() != null) {
// Let's ask user about it if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) {
if (ConfirmationDialog.showConfirmDialog( //getSite().getPage().closeEditor(this, true);
null, //return;
DBeaverPreferences.CONFIRM_ENTITY_REJECT, // Undo of last command in command context will close editor
ConfirmationDialog.QUESTION, // Let's ask user about it
getDatabaseObject().getName()) != IDialogConstants.YES_ID) if (ConfirmationDialog.showConfirmDialog(
{ null,
return; DBeaverPreferences.CONFIRM_ENTITY_REJECT,
ConfirmationDialog.QUESTION,
getDatabaseObject().getName()) != IDialogConstants.YES_ID) {
return;
}
} }
commandContext.undoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY);
} }
commandContext.undoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY);
} }
} }
public void redoChanges() public void redoChanges()
{ {
DBECommandContext commandContext = getCommandContext(); IUndoManager undoManager = getAdapter(IUndoManager.class);
if (commandContext != null && commandContext.getRedoCommand() != null) { if (undoManager != null) {
commandContext.redoCommand(); undoManager.redo();
firePropertyChange(IEditorPart.PROP_DIRTY); } else {
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getRedoCommand() != null) {
commandContext.redoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY);
}
} }
} }
......
...@@ -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,15 +44,27 @@ public class EntityEditorPropertyTester extends PropertyTester ...@@ -43,15 +44,27 @@ public class EntityEditorPropertyTester extends PropertyTester
return false; return false;
} }
EntityEditor editor = (EntityEditor)receiver; EntityEditor editor = (EntityEditor)receiver;
DBECommandContext commandContext = editor.getEditorInput().getCommandContext(); if (PROP_DIRTY.equals(property)) {
if (commandContext != null) { return editor.isDirty();
}
IUndoManager undoManager = editor.getAdapter(IUndoManager.class);
if (undoManager != null) {
switch (property) { switch (property) {
case PROP_CAN_UNDO: case PROP_CAN_UNDO:
return commandContext.getUndoCommand() != null; return undoManager.undoable();
case PROP_CAN_REDO: case PROP_CAN_REDO:
return commandContext.getRedoCommand() != null; return undoManager.redoable();
case PROP_DIRTY: }
return editor.isDirty(); } else {
DBECommandContext commandContext = editor.getEditorInput().getCommandContext();
if (commandContext != null) {
switch (property) {
case PROP_CAN_UNDO:
return commandContext.getUndoCommand() != null;
case PROP_CAN_REDO:
return commandContext.getRedoCommand() != null;
}
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册