SUMO - Simulation of Urban MObility
GNEUndoList.cpp
Go to the documentation of this file.
1 /****************************************************************************/
7 // FXUndoList is pretty dandy but some features are missing:
8 // - we cannot find out wether we have currently begun an undo-group and
9 // thus abort() is hard to use.
10 // - onUpd-methods do not disable undo/redo while in an undo-group
11 //
12 // GNEUndoList inherits from FXUndoList and patches some methods. these are
13 // prefixed with p_
14 /****************************************************************************/
15 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
16 // Copyright (C) 2001-2016 DLR (http://www.dlr.de/) and contributors
17 /****************************************************************************/
18 //
19 // This file is part of SUMO.
20 // SUMO is free software: you can redistribute it and/or modify
21 // it under the terms of the GNU General Public License as published by
22 // the Free Software Foundation, either version 3 of the License, or
23 // (at your option) any later version.
24 //
25 /****************************************************************************/
26 
27 
28 // ===========================================================================
29 // included modules
30 // ===========================================================================
31 #ifdef _MSC_VER
32 #include <windows_config.h>
33 #else
34 #include <config.h>
35 #endif
36 
37 #include <iostream>
39 #include "GNEUndoList.h"
40 #include "GNEChange_Attribute.h"
41 #include "GNEApplicationWindow.h"
42 
43 #ifdef CHECK_MEMORY_LEAKS
44 #include <foreign/nvwa/debug_new.h>
45 #endif
46 
47 
48 // ===========================================================================
49 // FOX callback mapping
50 // ===========================================================================
51 FXDEFMAP(GNEUndoList) GNEUndoListMap[] = {
52  //FXMAPFUNC(SEL_COMMAND, FXUndoList::ID_REVERT, FXUndoList::onCmdRevert),
53  //FXMAPFUNC(SEL_COMMAND, FXUndoList::ID_UNDO, FXUndoList::onCmdUndo),
54  //FXMAPFUNC(SEL_COMMAND, FXUndoList::ID_REDO, FXUndoList::onCmdRedo),
55  //FXMAPFUNC(SEL_COMMAND, FXUndoList::ID_UNDO_ALL, FXUndoList::onCmdUndoAll),
56  //FXMAPFUNC(SEL_COMMAND, FXUndoList::ID_REDO_ALL, FXUndoList::onCmdRedoAll),
57  //
58  //FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_UNDO_COUNT, FXUndoList::onUpdUndoCount),
59  //FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_REDO_COUNT, FXUndoList::onUpdRedoCount),
60  //FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_CLEAR, FXUndoList::onUpdClear),
61  //FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_REVERT, FXUndoList::onUpdRevert),
62  FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_UNDO_ALL, GNEUndoList::p_onUpdUndo),
63  FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_REDO_ALL, GNEUndoList::p_onUpdRedo),
64  FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_UNDO, GNEUndoList::p_onUpdUndo),
65  FXMAPFUNC(SEL_UPDATE, FXUndoList::ID_REDO, GNEUndoList::p_onUpdRedo)
66 };
67 
68 // ===========================================================================
69 // FOX-declarations
70 // ===========================================================================
71 FXIMPLEMENT_ABSTRACT(GNEUndoList, FXUndoList, GNEUndoListMap, ARRAYNUMBER(GNEUndoListMap))
72 
73 
74 void
75 GNEUndoList::p_begin(const std::string& description) {
76  myCommandGroups.push(new CommandGroup(description));
77  begin(myCommandGroups.top());
78 }
79 
80 
81 void
83  myCommandGroups.pop();
84  end();
85 }
86 
87 
88 void
90  p_abort();
91  clear();
92 }
93 
94 
95 void
97  while (hasCommandGroup()) {
98  myCommandGroups.top()->undo();
99  myCommandGroups.pop();
100  abort();
101  }
102 }
103 
104 
105 void
107  FXUndoList::undo();
109 }
110 
111 
112 void
114  FXUndoList::redo();
116 }
117 
118 
119 void
121  if (cmd->trueChange()) {
122  add(cmd, true);
123  } else {
124  delete cmd;
125  }
126 }
127 
128 long
129 GNEUndoList::p_onUpdUndo(FXObject* sender, FXSelector, void*) {
130  bool enable = canUndo() && !hasCommandGroup();
131  sender->handle(this, enable ? FXSEL(SEL_COMMAND, FXWindow::ID_ENABLE) : FXSEL(SEL_COMMAND, FXWindow::ID_DISABLE), 0);
132  FXString caption = undoName();
133  if (hasCommandGroup()) {
134  caption = ("Cannot Undo in the middle of " + myCommandGroups.top()->getDescription()).c_str();
135  } else if (!canUndo()) {
136  caption = "Undo";
137  }
138  // only set caption on menu item
139  if (dynamic_cast<FXMenuCommand*>(sender)) {
140  sender->handle(this, FXSEL(SEL_COMMAND, FXMenuCaption::ID_SETSTRINGVALUE), (void*)&caption);
141  }
142  return 1;
143 }
144 
145 
146 long
147 GNEUndoList::p_onUpdRedo(FXObject* sender, FXSelector, void*) {
148  bool enable = canRedo() && !hasCommandGroup();
149  sender->handle(this, enable ? FXSEL(SEL_COMMAND, FXWindow::ID_ENABLE) : FXSEL(SEL_COMMAND, FXWindow::ID_DISABLE), 0);
150  FXString caption = redoName();
151  if (hasCommandGroup()) {
152  caption = ("Cannot Redo in the middle of " + myCommandGroups.top()->getDescription()).c_str();
153  } else if (!canRedo()) {
154  caption = "Redo";
155  }
156  // only set caption on menu item
157  if (dynamic_cast<FXMenuCommand*>(sender)) {
158  sender->handle(this, FXSEL(SEL_COMMAND, FXMenuCaption::ID_SETSTRINGVALUE), (void*)&caption);
159  }
160  return 1;
161 }
162 
FXDEFMAP(GNEUndoList) GNEUndoListMap[]
void redo()
redo the last command group
void updateControls()
update control contents after undo/redo or recompute
void undo()
undo the last command group
void p_clear()
Definition: GNEUndoList.cpp:89
void p_add(GNEChange_Attribute *cmd)
special method, avoid empty changes, always execute
the function-object for an editing operation (abstract base)
bool trueChange()
wether original and new value differ
void p_end()
Definition: GNEUndoList.cpp:82
std::stack< CommandGroup * > myCommandGroups
Definition: GNEUndoList.h:136
GNEApplicationWindow *const myParent
Definition: GNEUndoList.h:139
void p_abort()
reverts and discards ALL active command groups
Definition: GNEUndoList.cpp:96
long p_onUpdRedo(FXObject *, FXSelector, void *)
bool hasCommandGroup() const
Definition: GNEUndoList.h:111
long p_onUpdUndo(FXObject *, FXSelector, void *)