/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/menu.py

  • Committer: Mateusz Korniak
  • Date: 2007-09-02 15:42:18 UTC
  • mto: This revision was merged to the branch mainline in revision 274.
  • Revision ID: matkor@laptop-hp-20070902154218-nba0woaqjsn20f9n
Ignoring eric3 project files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
 
17
import os
17
18
import os.path
 
19
import shutil
18
20
import sys
19
21
 
20
22
try:
28
30
import bzrlib.errors as errors
29
31
from bzrlib.workingtree import WorkingTree
30
32
 
31
 
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
32
 
from errors import show_bzr_error
 
33
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, question_dialog, warning_dialog
 
34
from bzrlib.plugins.gtk.errors import show_bzr_error
 
35
from bzrlib.plugins.gtk.annotate.gannotate import GAnnotateWindow
 
36
from bzrlib.plugins.gtk.annotate.config import GAnnotateConfig
 
37
from bzrlib.plugins.gtk.diff import DiffWindow
33
38
from launch import launch
34
 
from olive import Preferences, DiffWindow
 
39
from olive import Preferences
35
40
 
36
41
class OliveMenu:
37
42
    """ This class is responsible for building the context menus. """
61
66
                                       _('Remove'), None,
62
67
                                       _('Remove the selected file'),
63
68
                                       self.remove_file),
 
69
                                      ('remove_and_delete', gtk.STOCK_REMOVE,
 
70
                                       _('Remove and delete'), None,
 
71
                                       _('Remove the selected file/dir and delete from disk'),
 
72
                                       self.remove_and_delete_file),
64
73
                                      ('rename', None,
65
74
                                       _('Rename'), None,
66
75
                                       _('Rename the selected file'),
77
86
                                       _('Commit'), None,
78
87
                                       _('Commit the changes'),
79
88
                                       self.commit),
 
89
                                      ('annotate', None,
 
90
                                       _('Annotate'), None,
 
91
                                       _('Annotate the selected file'),
 
92
                                       self.annotate),
80
93
                                      ('diff', None,
81
94
                                       _('Diff'), None,
82
95
                                       _('Show the diff of the file'),
104
117
                                      ('diff_all', None,
105
118
                                       _('All...'), None,
106
119
                                       _('Show the differences of all files'),
107
 
                                       self.diff_all)
 
120
                                       self.diff_all),
 
121
                                      ('view_remote', None,
 
122
                                       _('View contents'), None,
 
123
                                       _('View the contents of the file in a builtin viewer'),
 
124
                                       self.view_remote),
 
125
                                      ('diff_remote', None,
 
126
                                       _('Show differences'), None,
 
127
                                       _('Show the differences between two revisions of the file'),
 
128
                                       self.diff_remote),
 
129
                                      ('revert_remote', None,
 
130
                                       _('Revert to this revision'), None,
 
131
                                       _('Revert the selected file to the selected revision'),
 
132
                                       self.revert_remote)
108
133
                                     ])
109
134
        
110
135
        self.ui.insert_action_group(self.actiongroup, 0)
113
138
        self.cmenu_right = self.ui.get_widget('/context_right')
114
139
        self.cmenu_left = self.ui.get_widget('/context_left')
115
140
        self.toolbar_diff = self.ui.get_widget('/toolbar_diff')
 
141
        self.cmenu_remote = self.ui.get_widget('/context_remote')
116
142
        
117
143
        # Set icons
118
144
        # TODO: do it without using deprecated comm
135
161
    def left_context_menu(self):
136
162
        return self.cmenu_left
137
163
    
 
164
    def remote_context_menu(self):
 
165
        return self.cmenu_remote
 
166
    
138
167
    @show_bzr_error
139
168
    def add_file(self, action):
140
169
        """ Right context menu -> Add """
152
181
        bzrlib.add.smart_add([os.path.join(directory, filename)])
153
182
    
154
183
    @show_bzr_error
155
 
    def remove_file(self, action):
 
184
    def annotate(self, action):
 
185
        """ Right context menu -> Annotate """
 
186
        directory = self.path
 
187
        filename = self.selected
 
188
        
 
189
        if filename is None:
 
190
            error_dialog(_('No file was selected'),
 
191
                         _('Please select a file from the list.'))
 
192
            return
 
193
        
 
194
        wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
 
195
        
 
196
        branch = wt.branch
 
197
        file_id = wt.path2id(wt.relpath(os.path.join(directory, filename)))
 
198
        
 
199
        window = GAnnotateWindow(all=False, plain=False)
 
200
        window.set_title(os.path.join(directory, filename) + " - Annotate")
 
201
        config = GAnnotateConfig(window)
 
202
        window.show()
 
203
        branch.lock_read()
 
204
        try:
 
205
            window.annotate(wt, branch, file_id)
 
206
        finally:
 
207
            branch.unlock()
 
208
    
 
209
    @show_bzr_error
 
210
    def remove_file(self, action,delete_on_disk=0):
156
211
        """ Right context menu -> Remove """
157
212
        # Remove only the selected file
158
213
        directory = self.path
165
220
        
166
221
        wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
167
222
        wt.remove(path)
 
223
        
 
224
        if delete_on_disk:
 
225
            abs_filename = os.path.join(directory,filename)
 
226
            if os.path.isdir(abs_filename):
 
227
                response = question_dialog(_('Delete directory with all directories below ?'), abs_filename )
 
228
                if response == gtk.RESPONSE_YES:
 
229
                    shutil.rmtree(abs_filename)
 
230
            else:
 
231
                os.remove(abs_filename)
 
232
                
168
233
        self.app.set_path(self.path)
169
234
        self.app.refresh_right()
 
235
        
 
236
    def remove_and_delete_file(self, action):
 
237
        """ Right context menu -> Remove and delete"""
 
238
        self.remove_file(action,delete_on_disk=1)
170
239
 
171
240
    def rename_file(self, action):
172
241
        """ Right context menu -> Rename """
292
361
        from diff import OliveDiff
293
362
        diff = OliveDiff(self.comm)
294
363
        diff.display()
 
364
    
 
365
    def view_remote(self, action):
 
366
        """ Remote context menu -> View contents """
 
367
        print "DEBUG: view contents."
 
368
    
 
369
    def diff_remote(self, action):
 
370
        """ Remote context menu -> Show differences """
 
371
        print "DEBUG: show differences."
 
372
    
 
373
    def revert_remote(self, action):
 
374
        """ Remote context menu -> Revert to this revision """
 
375
        print "DEBUG: revert to this revision."