Author: tfmorris
Date: 2007-08-31 00:20:13-0700
New Revision: 13466
Modified:
trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java
Log:
Add Model undo capability to Undo menu item - last of Bogdan's merges
Modified: trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java
Url: http://argouml.tigris.org/source/browse/argouml/trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java?view=diff&rev=13466&p1=trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java&p2=trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java&r1=13465&r2=13466
==============================================================================
--- trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java (original)
+++ trunk/src_new/org/argouml/ui/cmd/GenericArgoMenuBar.java 2007-08-31 00:20:13-0700
@@ -1,4 +1,4 @@
-// $Id$
+// $Id:GenericArgoMenuBar.java 13104 2007-07-21 18:29:31Z mvw $
// Copyright (c) 1996-2007 The Regents of the University of California. All
// Rights Reserved. Permission to use, copy, modify, and distribute this
// software and its documentation without fee, and without a written
@@ -24,8 +24,12 @@
package org.argouml.ui.cmd;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.util.Iterator;
import java.util.List;
@@ -41,6 +45,8 @@
import org.argouml.application.helpers.ResourceLoaderWrapper;
import org.argouml.i18n.Translator;
import org.argouml.kernel.UndoEnabler;
+import org.argouml.model.CommandStack;
+import org.argouml.model.Model;
import org.argouml.ui.ActionExportXMI;
import org.argouml.ui.ActionImportXMI;
import org.argouml.ui.ActionProjectSettings;
@@ -386,6 +392,8 @@
edit = add(new JMenu(menuLocalize("Edit")));
setMnemonic(edit, "Edit");
+
+ initCommandStackItems(edit);
JMenuItem undoItem = edit.add(ProjectActions.getInstance()
.getUndoAction());
@@ -470,6 +478,68 @@
.assignAccelerator(settingsItem, ShortcutMgr.ACTION_SETTINGS);
}
+ private void initCommandStackItems(JMenu menu) {
+ if (!Model.getCommandStack().isCommandStackCapabilityAvailable()) {
+ return;
+ }
+
+ final JMenuItem undo = new JMenuItem("Undo");
+ undo.setEnabled(false);
+ menu.add(undo);
+
+ undo.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ Model.getCommandStack().undo();
+ }
+
+ });
+
+ final JMenuItem redo = new JMenuItem("Redo");
+ redo.setEnabled(false);
+ menu.add(redo);
+
+ redo.addActionListener(new ActionListener() {
+
+ public void actionPerformed(ActionEvent e) {
+ Model.getCommandStack().redo();
+ }
+
+ });
+
+ PropertyChangeListener listener = new PropertyChangeListener() {
+
+ public void propertyChange(PropertyChangeEvent evt) {
+ updateUndoRedo(undo, redo);
+ }
+
+ };
+
+ Model.getPump().addClassModelEventListener(listener,
+ Model.getMetaTypes().getModelElement(), (String[]) null);
+ Model.getPump().addModelEventListener(listener,
+ CommandStack.COMMAND_STACK_UPDATE_EVENT, (String[]) null);
+
+ menu.addSeparator();
+ }
+
+ private void updateUndoRedo(JMenuItem undo, JMenuItem redo) {
+ if (!Model.getCommandStack().canUndo()) {
+ undo.setText("Undo");
+ undo.setEnabled(false);
+ } else {
+ undo.setText("Undo: " + Model.getCommandStack().getUndoLabel());
+ undo.setEnabled(true);
+ }
+ if (!Model.getCommandStack().canRedo()) {
+ redo.setText("Redo");
+ redo.setEnabled(false);
+ } else {
+ redo.setText("Redo: " + Model.getCommandStack().getRedoLabel());
+ redo.setEnabled(true);
+ }
+ }
+
/**
* Build the menu "View".
*/
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.