~matthias-mueller-reineke/bzr-gtk/development-env

« back to all changes in this revision

Viewing changes to olive/menu.py

  • Committer: Matthias Mueller-Reineke
  • Date: 2007-08-23 10:08:55 UTC
  • mfrom: (222.1.3 refactor_olive)
  • Revision ID: matthias.mueller-reineke@grundvers.de-20070823100855-scgw4nssb6otygfl
merge refactor_olive

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 
19
19
import os.path
20
 
import sys
 
20
from os.path import join
 
21
from sys import stdout
21
22
 
22
23
try:
23
24
    import pygtk
40
41
 
41
42
class OliveMenu:
42
43
    """ This class is responsible for building the context menus. """
43
 
    def __init__(self, path, knows_selected, app=None):
 
44
    def __init__(self, path, knows_selected, app):
44
45
        # Load the UI file
45
46
        from guifiles import UIFILENAME
46
47
 
90
91
                                       _('Diff'), None,
91
92
                                       _('Show the diff of the file'),
92
93
                                       self.diff),
 
94
                                      ('log', None,
 
95
                                       _('Log'), None,
 
96
                                       _('Show log of the file'),
 
97
                                       self.log),
93
98
                                      ('bookmark', None,
94
99
                                       _('Bookmark'), None,
95
100
                                       _('Bookmark current location'),
286
291
    @show_bzr_error
287
292
    def diff(self, action):
288
293
        """ Right context menu -> Diff """
289
 
        wt = WorkingTree.open_containing(self.path)[0]
 
294
        wt = self.wt()
290
295
        window = DiffWindow()
291
296
        parent_tree = wt.branch.repository.revision_tree(wt.branch.last_revision())
292
297
        window.set_diff(wt.branch.nick, wt, parent_tree)
293
298
        window.set_file(wt.relpath(self.path + os.sep + self.selected()))
294
299
        window.show()
295
300
    
 
301
    @show_bzr_error
 
302
    def log(self, action):
 
303
        """ Right context menu -> Log """
 
304
        wt = self.wt()
 
305
        b = wt.branch
 
306
        from bzrlib import log
 
307
        log_format = log.log_formatter_registry.get_default(b)
 
308
        lf = log_format(to_file=stdout)
 
309
        from bzrlib.log import show_log
 
310
        show_log(b, lf, self.file_id())
 
311
 
296
312
    def bookmark(self, action):
297
313
        """ Right context menu -> Bookmark """
298
314
        if self.pref.add_bookmark(self.path):
349
365
    
350
366
    def view_remote(self, action):
351
367
        """ Remote context menu -> View contents """
352
 
        print "DEBUG: view contents."
353
 
    
 
368
        rev_tree = self.app.branch()\
 
369
                   .repository.revision_tree(self.app.remote_revision)
 
370
        file_name = self.selected()
 
371
        import tempfile
 
372
        tmp_file_name = join(tempfile.mkdtemp(), file_name)
 
373
        tmp_file = file(tmp_file_name, 'w')
 
374
        tmp_file.write(rev_tree.get_file_text(rev_tree.path2id(
 
375
                 join(self.app.remote_path, file_name))))
 
376
        tmp_file.close()
 
377
        launch(tmp_file_name)
 
378
        """ Consequence of this implementation is that the temporary file
 
379
        exists until next boot (or longer on less Fhs conform systems).
 
380
        Who knows when to delete such files?
 
381
        Even when the application is launched like described in
 
382
        http://therning.org/magnus/archives/date/2007/01
 
383
        it may terminate imediately, because it tells another running
 
384
        instance to open the file. """
 
385
 
354
386
    def diff_remote(self, action):
355
387
        """ Remote context menu -> Show differences """
356
388
        print "DEBUG: show differences."
358
390
    def revert_remote(self, action):
359
391
        """ Remote context menu -> Revert to this revision """
360
392
        print "DEBUG: revert to this revision."
 
393
 
 
394
    # Functions for internal use:
 
395
 
 
396
    def wt(self):
 
397
       return WorkingTree.open_containing(self.path)[0]
 
398
 
 
399
    def file_id(self):
 
400
        directory = self.path
 
401
        filename = self.selected()
 
402
        
 
403
        wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
 
404
        return wt.path2id(wt.relpath(os.path.join(directory, filename)))