/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: Jelmer Vernooij
  • Date: 2007-04-03 17:16:07 UTC
  • mfrom: (187 trunk)
  • mto: This revision was merged to the branch mainline in revision 188.
  • Revision ID: jelmer@samba.org-20070403171607-0zaskazouokrm4cq
Tags: bzr-gtk-0.15.2
PrepareĀ forĀ 0.15.2

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
18
17
import os.path
19
 
import shutil
20
18
import sys
21
19
 
22
20
try:
30
28
import bzrlib.errors as errors
31
29
from bzrlib.workingtree import WorkingTree
32
30
 
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
 
31
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
 
32
from errors import show_bzr_error
38
33
from launch import launch
39
 
from olive import Preferences
 
34
from olive import Preferences, DiffWindow
40
35
 
41
36
class OliveMenu:
42
37
    """ This class is responsible for building the context menus. """
66
61
                                       _('Remove'), None,
67
62
                                       _('Remove the selected file'),
68
63
                                       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),
73
64
                                      ('rename', None,
74
65
                                       _('Rename'), None,
75
66
                                       _('Rename the selected file'),
86
77
                                       _('Commit'), None,
87
78
                                       _('Commit the changes'),
88
79
                                       self.commit),
89
 
                                      ('annotate', None,
90
 
                                       _('Annotate'), None,
91
 
                                       _('Annotate the selected file'),
92
 
                                       self.annotate),
93
80
                                      ('diff', None,
94
81
                                       _('Diff'), None,
95
82
                                       _('Show the diff of the file'),
117
104
                                      ('diff_all', None,
118
105
                                       _('All...'), None,
119
106
                                       _('Show the differences of all files'),
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)
 
107
                                       self.diff_all)
133
108
                                     ])
134
109
        
135
110
        self.ui.insert_action_group(self.actiongroup, 0)
138
113
        self.cmenu_right = self.ui.get_widget('/context_right')
139
114
        self.cmenu_left = self.ui.get_widget('/context_left')
140
115
        self.toolbar_diff = self.ui.get_widget('/toolbar_diff')
141
 
        self.cmenu_remote = self.ui.get_widget('/context_remote')
142
116
        
143
117
        # Set icons
144
118
        # TODO: do it without using deprecated comm
161
135
    def left_context_menu(self):
162
136
        return self.cmenu_left
163
137
    
164
 
    def remote_context_menu(self):
165
 
        return self.cmenu_remote
166
 
    
167
138
    @show_bzr_error
168
139
    def add_file(self, action):
169
140
        """ Right context menu -> Add """
181
152
        bzrlib.add.smart_add([os.path.join(directory, filename)])
182
153
    
183
154
    @show_bzr_error
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, parent=self.app)
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):
 
155
    def remove_file(self, action):
211
156
        """ Right context menu -> Remove """
212
157
        # Remove only the selected file
213
158
        directory = self.path
220
165
        
221
166
        wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
222
167
        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
 
                
233
168
        self.app.set_path(self.path)
234
169
        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)
239
170
 
240
171
    def rename_file(self, action):
241
172
        """ Right context menu -> Rename """
288
219
        except NotBranchError, e:
289
220
            path = e.path
290
221
        
291
 
        if self.selected:
292
 
            selected = os.path.join(path, self.selected)
293
 
        else:
294
 
            selected = None
295
 
        commit = CommitDialog(wt=wt, selected=selected, parent=None)
 
222
        commit = CommitDialog(wt, path, not branch, self.selected)
296
223
        response = commit.run()
297
224
        if response != gtk.RESPONSE_NONE:
298
225
            commit.hide()
306
233
    def diff(self, action):
307
234
        """ Right context menu -> Diff """
308
235
        wt = WorkingTree.open_containing(self.path)[0]
309
 
        window = DiffWindow(self.app)
 
236
        window = DiffWindow()
310
237
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
311
238
        window.set_diff(wt.branch.nick, wt, parent_tree)
312
239
        window.set_file(wt.relpath(self.path + os.sep + self.selected))
365
292
        from diff import OliveDiff
366
293
        diff = OliveDiff(self.comm)
367
294
        diff.display()
368
 
    
369
 
    def view_remote(self, action):
370
 
        """ Remote context menu -> View contents """
371
 
        print "DEBUG: view contents."
372
 
    
373
 
    def diff_remote(self, action):
374
 
        """ Remote context menu -> Show differences """
375
 
        print "DEBUG: show differences."
376
 
    
377
 
    def revert_remote(self, action):
378
 
        """ Remote context menu -> Revert to this revision """
379
 
        print "DEBUG: revert to this revision."