提交 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;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.IContributionManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.text.IUndoManager;
import org.eclipse.jface.text.source.ISourceViewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.StyledText;
......@@ -56,7 +57,7 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
private IValueController valueController;
private IEditorSite subSite;
private BaseTextEditor editor;
private EDITOR editor;
@Override
public StyledText createControl(IValueController valueController) {
......@@ -77,7 +78,7 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
return editor.getEditorControl();
}
protected abstract BaseTextEditor createEditorParty(IValueController valueController);
protected abstract EDITOR createEditorParty(IValueController valueController);
@Override
public void contributeActions(@NotNull IContributionManager manager, @NotNull final StyledText control) throws DBCException {
......@@ -117,18 +118,18 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
}
}
protected BaseTextEditor getTextEditor() {
protected EDITOR getTextEditor() {
return editor;
}
protected void initEditorSettings(StyledText control) {
private void initEditorSettings(StyledText control) {
boolean wwEnabled = ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_WORD_WRAP);
if (wwEnabled != control.getWordWrap()) {
control.setWordWrap(wwEnabled);
}
}
protected void applyEditorStyle() {
private void applyEditorStyle() {
BaseTextEditor textEditor = getTextEditor();
if (textEditor != null && ValueViewerPanel.getPanelSettings().getBoolean(PREF_TEXT_EDITOR_AUTO_FORMAT)) {
try {
......@@ -146,6 +147,9 @@ public abstract class AbstractTextPanelEditor<EDITOR extends BaseTextEditor> imp
if (adapter.isAssignableFrom(textEditor.getClass())) {
return adapter.cast(textEditor);
}
if (adapter == IUndoManager.class) {
return adapter.cast(textEditor.getTextViewer().getUndoManager());
}
return textEditor.getAdapter(adapter);
}
return null;
......
......@@ -22,10 +22,10 @@ import org.jkiss.dbeaver.ui.editors.text.BaseTextEditor;
/**
* TextPanelEditor
*/
public class TextPanelEditor extends AbstractTextPanelEditor<BaseTextEditor> {
public class TextPanelEditor extends AbstractTextPanelEditor<TextEditorPart> {
@Override
protected BaseTextEditor createEditorParty(IValueController valueController) {
protected TextEditorPart createEditorParty(IValueController valueController) {
return new TextEditorPart();
}
}
......@@ -26,7 +26,7 @@ import org.jkiss.dbeaver.ui.editors.xml.XMLEditor;
public class XMLPanelEditor extends AbstractTextPanelEditor<XMLEditor> {
@Override
protected BaseTextEditor createEditorParty(IValueController valueController) {
protected XMLEditor createEditorParty(IValueController valueController) {
return new XMLEditor();
}
}
......@@ -20,6 +20,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.text.IUndoManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
......@@ -371,33 +372,42 @@ public class EntityEditor extends MultiPageDatabaseEditor
public void undoChanges()
{
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getUndoCommand() != null) {
if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) {
//getSite().getPage().closeEditor(this, true);
//return;
// Undo of last command in command context will close editor
// Let's ask user about it
if (ConfirmationDialog.showConfirmDialog(
null,
DBeaverPreferences.CONFIRM_ENTITY_REJECT,
ConfirmationDialog.QUESTION,
getDatabaseObject().getName()) != IDialogConstants.YES_ID)
{
return;
IUndoManager undoManager = getAdapter(IUndoManager.class);
if (undoManager != null) {
undoManager.undo();
} else {
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getUndoCommand() != null) {
if (!getDatabaseObject().isPersisted() && commandContext.getUndoCommands().size() == 1) {
//getSite().getPage().closeEditor(this, true);
//return;
// Undo of last command in command context will close editor
// Let's ask user about it
if (ConfirmationDialog.showConfirmDialog(
null,
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()
{
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getRedoCommand() != null) {
commandContext.redoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY);
IUndoManager undoManager = getAdapter(IUndoManager.class);
if (undoManager != null) {
undoManager.redo();
} else {
DBECommandContext commandContext = getCommandContext();
if (commandContext != null && commandContext.getRedoCommand() != null) {
commandContext.redoCommand();
firePropertyChange(IEditorPart.PROP_DIRTY);
}
}
}
......
......@@ -17,6 +17,7 @@
package org.jkiss.dbeaver.ui.editors.entity;
import org.eclipse.core.expressions.PropertyTester;
import org.eclipse.jface.text.IUndoManager;
import org.jkiss.dbeaver.Log;
import org.jkiss.dbeaver.model.edit.DBECommandContext;
import org.jkiss.dbeaver.ui.ActionUtils;
......@@ -43,15 +44,27 @@ public class EntityEditorPropertyTester extends PropertyTester
return false;
}
EntityEditor editor = (EntityEditor)receiver;
DBECommandContext commandContext = editor.getEditorInput().getCommandContext();
if (commandContext != null) {
if (PROP_DIRTY.equals(property)) {
return editor.isDirty();
}
IUndoManager undoManager = editor.getAdapter(IUndoManager.class);
if (undoManager != null) {
switch (property) {
case PROP_CAN_UNDO:
return commandContext.getUndoCommand() != null;
return undoManager.undoable();
case PROP_CAN_REDO:
return commandContext.getRedoCommand() != null;
case PROP_DIRTY:
return editor.isDirty();
return undoManager.redoable();
}
} 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.
先完成此消息的编辑!
想要评论请 注册