Changeset 1056

Show
Ignore:
Timestamp:
10/29/06 23:34:17 (2 years ago)
Author:
arjanmol
Message:

Got some more actions working

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gaphor/branches/new-canvas/TODO

    r1027 r1056  
    11 
    2 !!! Create some example diagrams, 
     2 - Undo functionality 
     3 - Load / save regression testing 
     4   !!! Create some example diagrams, 
     5 
    36 - split DiagramItem in a stereotype support, SubjectSupport and some 
    47   other support classes. 
  • gaphor/branches/new-canvas/gaphor/actions/diagramactions.py

    r1046 r1056  
    1818    _action_dependencies(action, 'TabChange') 
    1919 
     20 
    2021class CloseTabAction(Action): 
    2122    id = 'FileCloseTab' 
     
    4647 
    4748register_action(UndoStackAction) 
     49 
    4850 
    4951class UndoAction(Action): 
     
    9193register_action(RedoAction, 'EditUndoStack') 
    9294 
     95 
    9396class ToolChangeAction(Action): 
    9497    """Dummy, triggered when a new tool is selected. 
     
    196199        # Confirm deletion of last views to model objects 
    197200        # They will be deleted along with their last view 
    198         if not self.mayRemoveFromModel(view): 
     201        if not self.may_remove_from_model(view): 
    199202            return 
    200203 
     
    208211                get_undo_manager().commit_transaction() 
    209212     
    210     def mayRemoveFromModel(self, view): 
    211         ''' Check if there are items which will be deleted from the model (when their last views are deleted). If so request user confirmation before deletion. ''' 
     213    def may_remove_from_model(self, view): 
     214        ''' Check if there are items which will be deleted from the model 
     215            (when their last views are deleted). If so request user 
     216            confirmation before deletion. ''' 
    212217        items = view.selected_items 
    213218        for i in items: 
    214             if self.isLastView(i): 
    215                 return self.requestConfirmation() 
     219            if self.is_last_view(i): 
     220                return self.request_confirmation() 
    216221        return True 
    217222 
    218     def isLastView(self, item): 
     223    def is_last_view(self, item): 
    219224        ''' Check if the current view is the last view to its object ''' 
    220225        if item.subject and len(item.subject.presentation)==1: 
     
    222227        return False 
    223228 
    224     def requestConfirmation(self): 
     229    def request_confirmation(self): 
    225230        ''' Request user confirmation on deleting the item from the model ''' 
    226231        dialog = gtk.MessageDialog( 
     
    311316    def _load_element(self, name, value): 
    312317        """Copy an element, preferbly from the list of new items, 
    313         otherwise from the elementFactory. 
     318        otherwise from the element factory. 
    314319        If it does not exist there, do not copy it! 
    315320        """ 
     
    416421    def execute(self): 
    417422        view = self._window.get_current_diagram_view() 
    418         #view.set_zoom(view.get_zoom() - 0.1) 
    419423        view.zoom(1 / 1.2) 
    420424 
     
    436440 
    437441    def execute(self): 
    438         self._window.get_current_diagram_view().set_zoom(1.0) 
     442        view = self._window.get_current_diagram_view() 
     443        # Fetch zoom factor from transformation matrix: 
     444        zx = view.matrix[0] 
     445        self._window.get_current_diagram_view().zoom(1 / zx) 
    439446 
    440447register_action(Zoom100Action) 
  • gaphor/branches/new-canvas/gaphor/actions/itemactions.py

    r1046 r1056  
    4141    y = y + view.vadjustment.value 
    4242    return x, y 
     43 
     44class ItemActionSupport(object): 
     45 
     46    def init(self, window): 
     47        self._window = window 
     48 
     49    def get_pointer(self): 
     50        view = self._window.get_current_diagram_view() 
     51        x, y = view.get_pointer() 
     52        x = x + view.hadjustment.value 
     53        y = y + view.vadjustment.value 
     54        return x, y 
     55 
     56    pointer = property(get_pointer) 
     57 
     58    def get_focused_item(self): 
     59        """Get the focused item in the current diagram view. 
     60        """ 
     61        view = self._window.get_current_diagram_view() 
     62        if view: 
     63            item = view.focused_item 
     64            if item: 
     65                return item 
     66        raise NoFocusItemError, 'No item has focus.' 
     67 
     68    focused_item = property(get_focused_item) 
     69 
    4370 
    4471class ItemNewSubjectAction(Action): 
     
    12911318 
    12921319 
    1293 class DisconnectConnector(Action): 
     1320class DisconnectConnector(Action, ItemActionSupport): 
    12941321    id = 'DisconnectConnector' 
    12951322    label = '_Disconnect Connector' 
    12961323    tooltip = 'Disconnect connected item' 
    12971324 
    1298     def init(self, window): 
    1299         self._window = window 
    1300  
    1301     def update(self): 
    1302         try: 
    1303             item = get_focused_item(self._window) 
     1325#    def init(self, window): 
     1326#        self._window = window 
     1327 
     1328    def update(self): 
     1329        try: 
     1330            item = self.focused_item 
    13041331        except NoFocusItemError: 
    13051332            pass 
     
    13091336    @undoable 
    13101337    def execute(self): 
    1311         item = get_focused_item(self._window) 
     1338        item = self.focused_item 
    13121339        assembly = item.parent 
    13131340        item.unlink() 
     
    13171344 
    13181345 
    1319 class ApplyInterfaceAction(RadioAction, ObjectAction): 
     1346class ApplyInterfaceAction(RadioAction, ObjectAction, ItemActionSupport): 
    13201347 
    13211348    def __init__(self, interface): 
     
    13301357    def update(self): 
    13311358        try: 
    1332             item = get_focused_item(self._window) 
     1359            item = self.focused_item 
    13331360        except NoFocusItemError: 
    13341361            pass 
     
    13391366    @undoable 
    13401367    def execute(self): 
    1341         item = get_focused_item(self._window) 
     1368        item = self.focused_item 
    13421369        if self.active: 
    13431370            item.subject = self.interface