Changeset 1177
- Timestamp:
- 03/27/07 23:20:07 (2 years ago)
- Files:
-
- gaphor/trunk/TODO (modified) (1 diff)
- gaphor/trunk/gaphor/diagram/tool.py (modified) (9 diffs)
- gaphor/trunk/gaphor/services/undomanager.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
gaphor/trunk/TODO
r1176 r1177 8 8 9 9 - Undo functionality 10 - make canvas events transactional.11 10 12 11 - use easysetup tools, move gaphas to a separate package and use gaphor/trunk/gaphor/diagram/tool.py
r1121 r1177 13 13 import gaphas 14 14 from gaphas.geometry import distance_point_point 15 from gaphas.tool import Tool, HandleTool 15 from gaphas.tool import Tool, HandleTool, ToolChain 16 16 17 17 from gaphor import resource 18 from gaphor. undomanager import get_undo_manager18 from gaphor.services.undomanager import get_undo_manager, transactional 19 19 20 20 from interfaces import IEditor, IConnect … … 22 22 __version__ = '$Revision$' 23 23 24 24 25 class ConnectHandleTool(HandleTool): 25 """Handle Tool (acts on item handles) that uses the IConnect protocol 26 """ 27 Handle Tool (acts on item handles) that uses the IConnect protocol 26 28 to connect items to one-another. 27 29 """ 28 30 29 31 def glue(self, view, item, handle, wx, wy): 30 """Find the nearest item that the handle may connect to. 32 """ 33 Find the nearest item that the handle may connect to. 31 34 32 35 This is done by iterating over all items and query for an IConnect … … 71 74 72 75 def connect(self, view, item, handle, wx, wy): 73 """Find an item near @handle that @item can connect to and connect. 76 """ 77 Find an item near @handle that @item can connect to and connect. 74 78 75 79 This is done by attempting a glue() operation. If there is something … … 92 96 93 97 def disconnect(self, view, item, handle): 94 """Disconnect the handle from the element by removing constraints. 98 """ 99 Disconnect the handle from the element by removing constraints. 95 100 Do not yet release the connection on model level, since the handle 96 101 may be connected to the same item on some other place. … … 102 107 103 108 class TextEditTool(Tool): 104 """Text edit tool. Allows for elements that can adapt to the 109 """ 110 Text edit tool. Allows for elements that can adapt to the 105 111 IEditable interface to be edited. 106 112 """ 107 113 108 114 def create_edit_window(self, view, x, y, text, *args): 109 """Create a popup window with some editable text. 115 """ 116 Create a popup window with some editable text. 110 117 """ 111 118 window = gtk.Window() … … 135 142 #window.focus 136 143 144 @transactional 137 145 def submit_text(self, widget, buffer, editor): 138 """Submit the final text to the edited item. 146 """ 147 Submit the final text to the edited item. 139 148 """ 140 149 text = buffer.get_text(buffer.get_start_iter(), buffer.get_end_iter()) … … 172 181 173 182 class PlacementTool(gaphas.tool.PlacementTool): 174 """PlacementTool is used to place items on the canvas. 183 """ 184 PlacementTool is used to place items on the canvas. 175 185 """ 176 186 177 187 def __init__(self, item_factory, action_id, handle_index=-1): 178 """item_factory is a callable. It is used to create a CanvasItem 188 """ 189 item_factory is a callable. It is used to create a CanvasItem 179 190 that is displayed on the diagram. 180 191 """ … … 186 197 187 198 def on_button_press(self, context, event): 199 get_undo_manager().begin_transaction() 188 200 self.is_released = False 189 view = context.view #resource('MainWindow').get_current_diagram_view()201 view = context.view 190 202 view.unselect_all() 191 get_undo_manager().begin_transaction()192 203 if gaphas.tool.PlacementTool.on_button_press(self, context, event): 193 204 try: … … 205 216 def on_button_release(self, context, event): 206 217 self.is_released = True 207 if resource('reset-tool-after-create', False): 208 pool = resource('MainWindow').get_action_pool() 209 pool.get_action('Pointer').active = True 210 get_undo_manager().commit_transaction() 211 return gaphas.tool.PlacementTool.on_button_release(self, context, event) 218 try: 219 if resource('reset-tool-after-create', False): 220 pool = resource('MainWindow').get_action_pool() 221 pool.get_action('Pointer').active = True 222 return gaphas.tool.PlacementTool.on_button_release(self, context, event) 223 finally: 224 get_undo_manager().commit_transaction() 225 226 227 class TransactionalToolChain(ToolChain): 228 """ 229 In addition to a normal toolchain, this chain begins an undo-transaction 230 at button-press and commits the transaction at button-release. 231 """ 232 233 def on_button_press(self, context, event): 234 get_undo_manager().begin_transaction() 235 return ToolChain.on_button_press(self, context, event) 236 237 def on_button_release(self, context, event): 238 try: 239 return ToolChain.on_button_release(self, context, event) 240 finally: 241 get_undo_manager().commit_transaction() 242 243 def on_double_click(self, context, event): 244 get_undo_manager().begin_transaction() 245 try: 246 return ToolChain.on_double_click(self, context, event) 247 finally: 248 get_undo_manager().commit_transaction() 249 250 def on_triple_click(self, context, event): 251 get_undo_manager().begin_transaction() 252 try: 253 return ToolChain.on_triple_click(self, context, event) 254 finally: 255 get_undo_manager().commit_transaction() 212 256 213 257 214 258 from gaphas.tool import ToolChain, HoverTool, ItemTool, RubberbandTool 215 259 260 216 261 def DefaultTool(): 217 """The default tool chain build from HoverTool, ItemTool and HandleTool. 218 """ 219 chain = ToolChain() 262 """ 263 The default tool chain build from HoverTool, ItemTool and HandleTool. 264 """ 265 chain = TransactionalToolChain() 220 266 chain.append(HoverTool()) 221 267 chain.append(ConnectHandleTool()) gaphor/trunk/gaphor/services/undomanager.py
r1171 r1177 20 20 21 21 def get_undo_manager(): 22 """Return the default undo manager. 22 """ 23 Return the default undo manager. 23 24 """ 24 25 return _default_undo_manager … … 156 157 157 158 self._current_transaction = None 159 component.handle(UndoManagerStateChanged(self)) 158 160 159 161 def rollback_transaction(self):
