/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/__init__.py

  • Committer: Szilveszter Farkas (Phanatic)
  • Date: 2006-10-09 16:47:57 UTC
  • Revision ID: Szilveszter.Farkas@gmail.com-20061009164757-d24b8e94fd1997bb
Added Merge dialog and fixed some minor glade issues.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 #!/usr/bin/python
2
 
 
3
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
4
2
#
5
3
# This program is free software; you can redistribute it and/or modify
18
16
 
19
17
import os
20
18
import sys
21
 
import time
22
19
 
23
20
# gettext support
24
21
import gettext
30
27
except:
31
28
    pass
32
29
 
33
 
import gobject
34
30
import gtk
35
31
import gtk.gdk
36
32
import gtk.glade
37
33
 
38
34
from bzrlib.branch import Branch
39
 
import bzrlib.errors as bzrerrors
40
 
from bzrlib.lazy_import import lazy_import
41
 
from bzrlib.ui import ui_factory
 
35
import bzrlib.errors as errors
42
36
from bzrlib.workingtree import WorkingTree
43
37
 
44
 
from bzrlib.plugins.gtk import _i18n
45
 
from bzrlib.plugins.gtk.dialog import error_dialog, info_dialog, warning_dialog
46
 
from bzrlib.plugins.gtk.errors import show_bzr_error
47
 
from guifiles import GLADEFILENAME
48
 
 
49
 
from bzrlib.plugins.gtk.diff import DiffWindow
50
 
lazy_import(globals(), """
51
 
from bzrlib.plugins.gtk.viz import branchwin
52
 
""")
53
 
from bzrlib.plugins.gtk.annotate.gannotate import GAnnotateWindow
54
 
from bzrlib.plugins.gtk.annotate.config import GAnnotateConfig
55
 
from bzrlib.plugins.gtk.commit import CommitDialog
56
 
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
57
 
from bzrlib.plugins.gtk.initialize import InitDialog
58
 
from bzrlib.plugins.gtk.push import PushDialog
59
 
from bzrlib.plugins.gtk.revbrowser import RevisionBrowser
60
 
 
61
 
def about():
62
 
    """ Display the AboutDialog. """
63
 
    from bzrlib.plugins.gtk import __version__
64
 
    from bzrlib.plugins.gtk.olive.guifiles import GLADEFILENAME
65
 
 
66
 
    # Load AboutDialog description
67
 
    dglade = gtk.glade.XML(GLADEFILENAME, 'aboutdialog')
68
 
    dialog = dglade.get_widget('aboutdialog')
69
 
 
70
 
    # Set version
71
 
    dialog.set_version(__version__)
72
 
    dialog.set_authors([ _i18n("Lead Developer:"),
73
 
                         "Szilveszter Farkas <szilveszter.farkas@gmail.com>",
74
 
                         _i18n("Contributors:"),
75
 
                         "Jelmer Vernooij <jelmer@samba.org>",
76
 
                         "Mateusz Korniak <mateusz.korniak@ant.gliwice.pl>",
77
 
                         "Gary van der Merwe <garyvdm@gmail.com>" ])
78
 
    dialog.set_artists([ "Simon Pascal Klein <klepas@klepas.org>",
79
 
                         "Jakub Steiner <jimmac@novell.com>" ])
80
 
 
81
 
    dialog.run()
82
 
    # Destroy the dialog
83
 
    dialog.destroy()
 
38
# Olive GTK UI version
 
39
__version__ = '0.11.0'
 
40
 
 
41
# Load the glade file
 
42
if sys.platform == 'win32':
 
43
    gladefile = os.path.dirname(sys.executable) + "/share/olive/olive.glade"
 
44
else:
 
45
    gladefile = "/usr/share/olive/olive.glade"
 
46
 
 
47
if not os.path.exists(gladefile):
 
48
    # Load from current directory if not installed
 
49
    gladefile = "olive.glade"
 
50
    # Check again
 
51
    if not os.path.exists(gladefile):
 
52
        # Fail
 
53
        print _('Glade file cannot be found.')
 
54
        sys.exit(1)
 
55
 
 
56
from dialog import error_dialog, info_dialog
84
57
 
85
58
class OliveGtk:
86
59
    """ The main Olive GTK frontend class. This is called when launching the
87
60
    program. """
88
61
    
89
62
    def __init__(self):
90
 
        self.toplevel = gtk.glade.XML(GLADEFILENAME, 'window_main', 'olive-gtk')
 
63
        self.toplevel = gtk.glade.XML(gladefile, 'window_main', 'olive-gtk')
 
64
        
91
65
        self.window = self.toplevel.get_widget('window_main')
92
 
        self.pref = Preferences()
93
 
        self.path = None
 
66
        
 
67
        self.pref = OlivePreferences()
94
68
 
95
69
        # Initialize the statusbar
96
70
        self.statusbar = self.toplevel.get_widget('statusbar')
106
80
        # Get some important menu items
107
81
        self.menuitem_add_files = self.toplevel.get_widget('menuitem_add_files')
108
82
        self.menuitem_remove_files = self.toplevel.get_widget('menuitem_remove_file')
109
 
        self.menuitem_file_bookmark = self.toplevel.get_widget('menuitem_file_bookmark')
110
83
        self.menuitem_file_make_directory = self.toplevel.get_widget('menuitem_file_make_directory')
111
84
        self.menuitem_file_rename = self.toplevel.get_widget('menuitem_file_rename')
112
85
        self.menuitem_file_move = self.toplevel.get_widget('menuitem_file_move')
113
 
        self.menuitem_file_annotate = self.toplevel.get_widget('menuitem_file_annotate')
114
86
        self.menuitem_view_show_hidden_files = self.toplevel.get_widget('menuitem_view_show_hidden_files')
115
 
        self.menuitem_view_show_ignored_files = self.toplevel.get_widget('menuitem_view_show_ignored_files')
116
87
        self.menuitem_branch = self.toplevel.get_widget('menuitem_branch')
117
88
        self.menuitem_branch_init = self.toplevel.get_widget('menuitem_branch_initialize')
118
89
        self.menuitem_branch_get = self.toplevel.get_widget('menuitem_branch_get')
119
90
        self.menuitem_branch_checkout = self.toplevel.get_widget('menuitem_branch_checkout')
120
91
        self.menuitem_branch_pull = self.toplevel.get_widget('menuitem_branch_pull')
121
92
        self.menuitem_branch_push = self.toplevel.get_widget('menuitem_branch_push')
122
 
        self.menuitem_branch_update = self.toplevel.get_widget('menuitem_branch_update')
123
 
        self.menuitem_branch_revert = self.toplevel.get_widget('menuitem_branch_revert')
124
 
        self.menuitem_branch_merge = self.toplevel.get_widget('menuitem_branch_merge')
125
93
        self.menuitem_branch_commit = self.toplevel.get_widget('menuitem_branch_commit')
126
 
        self.menuitem_branch_tags = self.toplevel.get_widget('menuitem_branch_tags')
127
94
        self.menuitem_branch_status = self.toplevel.get_widget('menuitem_branch_status')
128
95
        self.menuitem_branch_missing = self.toplevel.get_widget('menuitem_branch_missing_revisions')
129
 
        self.menuitem_branch_conflicts = self.toplevel.get_widget('menuitem_branch_conflicts')
130
96
        self.menuitem_stats = self.toplevel.get_widget('menuitem_stats')
131
97
        self.menuitem_stats_diff = self.toplevel.get_widget('menuitem_stats_diff')
132
98
        self.menuitem_stats_log = self.toplevel.get_widget('menuitem_stats_log')
137
103
        self.toolbutton_commit = self.toplevel.get_widget('toolbutton_commit')
138
104
        self.toolbutton_pull = self.toplevel.get_widget('toolbutton_pull')
139
105
        self.toolbutton_push = self.toplevel.get_widget('toolbutton_push')
140
 
        self.toolbutton_update = self.toplevel.get_widget('toolbutton_update')
141
106
        # Get the drive selector
142
107
        self.combobox_drive = gtk.combo_box_new_text()
143
108
        self.combobox_drive.connect("changed", self._refresh_drives)
144
109
        
145
 
        # Get the navigation widgets
146
 
        self.hbox_location = self.toplevel.get_widget('hbox_location')
147
 
        self.button_location_up = self.toplevel.get_widget('button_location_up')
148
 
        self.button_location_jump = self.toplevel.get_widget('button_location_jump')
149
 
        self.entry_location = self.toplevel.get_widget('entry_location')
150
 
        self.image_location_error = self.toplevel.get_widget('image_location_error')
151
 
        
152
 
        # Get the History widgets
153
 
        self.check_history = self.toplevel.get_widget('checkbutton_history')
154
 
        self.entry_history = self.toplevel.get_widget('entry_history_revno')
155
 
        self.button_history = self.toplevel.get_widget('button_history_browse')
156
 
        
157
110
        self.vbox_main_right = self.toplevel.get_widget('vbox_main_right')
 
111
 
158
112
        
159
113
        # Dictionary for signal_autoconnect
160
114
        dic = { "on_window_main_destroy": gtk.main_quit,
163
117
                "on_about_activate": self.on_about_activate,
164
118
                "on_menuitem_add_files_activate": self.on_menuitem_add_files_activate,
165
119
                "on_menuitem_remove_file_activate": self.on_menuitem_remove_file_activate,
166
 
                "on_menuitem_file_bookmark_activate": self.on_menuitem_file_bookmark_activate,
167
120
                "on_menuitem_file_make_directory_activate": self.on_menuitem_file_make_directory_activate,
168
121
                "on_menuitem_file_move_activate": self.on_menuitem_file_move_activate,
169
122
                "on_menuitem_file_rename_activate": self.on_menuitem_file_rename_activate,
170
 
                "on_menuitem_file_annotate_activate": self.on_menuitem_file_annotate_activate,
171
123
                "on_menuitem_view_show_hidden_files_activate": self.on_menuitem_view_show_hidden_files_activate,
172
 
                "on_menuitem_view_show_ignored_files_activate": self.on_menuitem_view_show_ignored_files_activate,
173
124
                "on_menuitem_view_refresh_activate": self.on_menuitem_view_refresh_activate,
174
125
                "on_menuitem_branch_initialize_activate": self.on_menuitem_branch_initialize_activate,
175
126
                "on_menuitem_branch_get_activate": self.on_menuitem_branch_get_activate,
176
127
                "on_menuitem_branch_checkout_activate": self.on_menuitem_branch_checkout_activate,
177
 
                "on_menuitem_branch_revert_activate": self.on_menuitem_branch_revert_activate,
178
 
                "on_menuitem_branch_merge_activate": self.on_menuitem_branch_merge_activate,
179
128
                "on_menuitem_branch_commit_activate": self.on_menuitem_branch_commit_activate,
180
129
                "on_menuitem_branch_push_activate": self.on_menuitem_branch_push_activate,
181
130
                "on_menuitem_branch_pull_activate": self.on_menuitem_branch_pull_activate,
182
 
                "on_menuitem_branch_update_activate": self.on_menuitem_branch_update_activate,                
183
 
                "on_menuitem_branch_tags_activate": self.on_menuitem_branch_tags_activate,
184
131
                "on_menuitem_branch_status_activate": self.on_menuitem_branch_status_activate,
185
132
                "on_menuitem_branch_missing_revisions_activate": self.on_menuitem_branch_missing_revisions_activate,
186
 
                "on_menuitem_branch_conflicts_activate": self.on_menuitem_branch_conflicts_activate,
187
133
                "on_menuitem_stats_diff_activate": self.on_menuitem_stats_diff_activate,
188
134
                "on_menuitem_stats_log_activate": self.on_menuitem_stats_log_activate,
189
135
                "on_menuitem_stats_infos_activate": self.on_menuitem_stats_infos_activate,
194
140
                "on_toolbutton_commit_clicked": self.on_menuitem_branch_commit_activate,
195
141
                "on_toolbutton_pull_clicked": self.on_menuitem_branch_pull_activate,
196
142
                "on_toolbutton_push_clicked": self.on_menuitem_branch_push_activate,
197
 
                "on_toolbutton_update_clicked": self.on_menuitem_branch_update_activate,
198
143
                "on_treeview_right_button_press_event": self.on_treeview_right_button_press_event,
199
144
                "on_treeview_right_row_activated": self.on_treeview_right_row_activated,
200
145
                "on_treeview_left_button_press_event": self.on_treeview_left_button_press_event,
201
 
                "on_treeview_left_button_release_event": self.on_treeview_left_button_release_event,
202
 
                "on_treeview_left_row_activated": self.on_treeview_left_row_activated,
203
 
                "on_button_location_up_clicked": self.on_button_location_up_clicked,
204
 
                "on_button_location_jump_clicked": self.on_button_location_jump_clicked,
205
 
                "on_entry_location_key_press_event": self.on_entry_location_key_press_event,
206
 
                "on_checkbutton_history_toggled": self.on_checkbutton_history_toggled,
207
 
                "on_entry_history_revno_key_press_event": self.on_entry_history_revno_key_press_event,
208
 
                "on_button_history_browse_clicked": self.on_button_history_browse_clicked
209
 
            }
 
146
                "on_treeview_left_row_activated": self.on_treeview_left_row_activated }
210
147
        
211
148
        # Connect the signals to the handlers
212
149
        self.toplevel.signal_autoconnect(dic)
213
150
        
214
 
        self._just_started = True
215
 
        
216
151
        # Apply window size and position
217
152
        width = self.pref.get_preference('window_width', 'int')
218
153
        height = self.pref.get_preference('window_height', 'int')
233
168
        
234
169
        # Show drive selector if under Win32
235
170
        if sys.platform == 'win32':
236
 
            self.hbox_location.pack_start(self.combobox_drive, False, False, 0)
237
 
            self.hbox_location.reorder_child(self.combobox_drive, 1)
 
171
            self.vbox_main_right.pack_start(self.combobox_drive, False, True, 0)
 
172
            self.vbox_main_right.reorder_child(self.combobox_drive, 0)
238
173
            self.combobox_drive.show()
239
174
            self.gen_hard_selector()
240
175
        
242
177
 
243
178
        # Apply menu state
244
179
        self.menuitem_view_show_hidden_files.set_active(self.pref.get_preference('dotted_files', 'bool'))
245
 
        self.menuitem_view_show_ignored_files.set_active(self.pref.get_preference('ignored_files', 'bool'))
246
180
 
247
 
        # We're starting local
248
 
        self.remote = False
249
 
        self.remote_branch = None
250
 
        self.remote_path = None
251
 
        self.remote_revision = None
252
 
        
253
181
        self.set_path(os.getcwd())
254
182
        self._load_right()
255
 
        
256
 
        self._just_started = False
257
183
 
258
 
    def set_path(self, path, force_remote=False):
 
184
    def set_path(self, path):
 
185
        self.path = path
259
186
        self.notbranch = False
260
 
        
261
 
        if force_remote:
262
 
            # Forcing remote mode (reading data from inventory)
263
 
            self._show_stock_image(gtk.STOCK_DISCONNECT)
264
 
            try:
265
 
                br = Branch.open_containing(path)[0]
266
 
            except bzrerrors.NotBranchError:
267
 
                self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
268
 
                self.check_history.set_active(False)
269
 
                self.check_history.set_sensitive(False)
270
 
                return False
271
 
            except bzrerrors.UnsupportedProtocol:
272
 
                self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
273
 
                self.check_history.set_active(False)
274
 
                self.check_history.set_sensitive(False)
275
 
                return False
276
 
            
277
 
            self._show_stock_image(gtk.STOCK_CONNECT)
278
 
            
279
 
            self.remote = True
280
 
           
281
 
            # We're remote
282
 
            self.remote_branch, self.remote_path = Branch.open_containing(path)
283
 
            
284
 
            if self.remote_revision is None:
285
 
                self.remote_revision = self.remote_branch.last_revision()
286
 
            
287
 
            self.remote_entries = self.remote_branch.repository.get_inventory(self.remote_revision).entries()
288
 
            
289
 
            if len(self.remote_path) == 0:
290
 
                self.remote_parent = self.remote_branch.repository.get_inventory(self.remote_branch.last_revision()).iter_entries_by_dir().next()[1].file_id
291
 
            else:
292
 
                for (name, type) in self.remote_entries:
293
 
                    if name == self.remote_path:
294
 
                        self.remote_parent = type.file_id
295
 
                        break
296
 
            
297
 
            if not path.endswith('/'):
298
 
                path += '/'
299
 
            
300
 
            if self.remote_branch.base == path:
301
 
                self.button_location_up.set_sensitive(False)
302
 
            else:
303
 
                self.button_location_up.set_sensitive(True)
304
 
        else:
305
 
            if os.path.isdir(path):
306
 
                self.image_location_error.destroy()
307
 
                self.remote = False
308
 
                
309
 
                # We're local
310
 
                try:
311
 
                    self.wt, self.wtpath = WorkingTree.open_containing(path)
312
 
                except (bzrerrors.NotBranchError, bzrerrors.NoWorkingTree):
313
 
                    self.notbranch = True
314
 
                
315
 
                # If we're in the root, we cannot go up anymore
316
 
                if sys.platform == 'win32':
317
 
                    drive, tail = os.path.splitdrive(path)
318
 
                    if tail in ('', '/', '\\'):
319
 
                        self.button_location_up.set_sensitive(False)
320
 
                    else:
321
 
                        self.button_location_up.set_sensitive(True)
322
 
                else:
323
 
                    if self.path == '/':
324
 
                        self.button_location_up.set_sensitive(False)
325
 
                    else:
326
 
                        self.button_location_up.set_sensitive(True)
327
 
            elif not os.path.isfile(path):
328
 
                # Doesn't seem to be a file nor a directory, trying to open a
329
 
                # remote location
330
 
                self._show_stock_image(gtk.STOCK_DISCONNECT)
331
 
                try:
332
 
                    br = Branch.open_containing(path)[0]
333
 
                except bzrerrors.NotBranchError:
334
 
                    self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
335
 
                    self.check_history.set_active(False)
336
 
                    self.check_history.set_sensitive(False)
337
 
                    return False
338
 
                except bzrerrors.UnsupportedProtocol:
339
 
                    self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
340
 
                    self.check_history.set_active(False)
341
 
                    self.check_history.set_sensitive(False)
342
 
                    return False
343
 
                
344
 
                self._show_stock_image(gtk.STOCK_CONNECT)
345
 
                
346
 
                self.remote = True
347
 
               
348
 
                # We're remote
349
 
                self.remote_branch, self.remote_path = Branch.open_containing(path)
350
 
                
351
 
                if self.remote_revision is None:
352
 
                    self.remote_revision = self.remote_branch.last_revision()
353
 
                
354
 
                self.remote_entries = self.remote_branch.repository.get_inventory(self.remote_revision).entries()
355
 
                
356
 
                if len(self.remote_path) == 0:
357
 
                    self.remote_parent = self.remote_branch.repository.get_inventory(self.remote_branch.last_revision()).iter_entries_by_dir().next()[1].file_id
358
 
                else:
359
 
                    for (name, type) in self.remote_entries:
360
 
                        if name == self.remote_path:
361
 
                            self.remote_parent = type.file_id
362
 
                            break
363
 
                
364
 
                if not path.endswith('/'):
365
 
                    path += '/'
366
 
                
367
 
                if self.remote_branch.base == path:
368
 
                    self.button_location_up.set_sensitive(False)
369
 
                else:
370
 
                    self.button_location_up.set_sensitive(True)
371
 
        
372
 
        if self.notbranch:
373
 
            self.check_history.set_active(False)
374
 
            self.check_history.set_sensitive(False)
375
 
        else:
376
 
            self.check_history.set_sensitive(True)
377
 
        
378
 
        self.statusbar.push(self.context_id, path)
379
 
        self.entry_location.set_text(path)
380
 
        self.path = path
381
 
        return True
 
187
        try:
 
188
            self.wt, self.wtpath = WorkingTree.open_containing(self.path)
 
189
        except errors.NotBranchError:
 
190
            self.notbranch = True
382
191
 
383
192
    def get_path(self):
384
 
        if not self.remote:
385
 
            return self.path
386
 
        else:
387
 
            # Remote mode
388
 
            if len(self.remote_path) > 0:
389
 
                return self.remote_branch.base + self.remote_path + '/'
390
 
            else:
391
 
                return self.remote_branch.base
 
193
        return self.path
392
194
   
393
195
    def on_about_activate(self, widget):
 
196
        from dialog import about
394
197
        about()
395
 
    
396
 
    def on_button_history_browse_clicked(self, widget):
397
 
        """ Browse for revision button handler. """
398
 
        if self.remote:
399
 
            br = self.remote_branch
400
 
        else:
401
 
            br = self.wt.branch
402
 
            
403
 
        revb = RevisionBrowser(br, self.window)
404
 
        response = revb.run()
405
 
        if response != gtk.RESPONSE_NONE:
406
 
            revb.hide()
407
 
        
408
 
            if response == gtk.RESPONSE_OK:
409
 
                if revb.selected_revno is not None:
410
 
                    self.entry_history.set_text(revb.selected_revno)
411
 
            
412
 
            revb.destroy()
413
 
    
414
 
    def on_button_location_jump_clicked(self, widget):
415
 
        """ Location Jump button handler. """
416
 
        location = self.entry_location.get_text()
417
 
        
418
 
        if self.set_path(location):
419
 
            self.refresh_right()
420
 
    
421
 
    def on_button_location_up_clicked(self, widget):
422
 
        """ Location Up button handler. """
423
 
        if not self.remote:
424
 
            # Local mode
425
 
            self.set_path(os.path.split(self.get_path())[0])
426
 
        else:
427
 
            # Remote mode
428
 
            delim = '/'
429
 
            newpath = delim.join(self.get_path().split(delim)[:-2])
430
 
            newpath += '/'
431
 
            self.set_path(newpath)
432
 
 
433
 
        self.refresh_right()
434
 
    
435
 
    def on_checkbutton_history_toggled(self, widget):
436
 
        """ History Mode toggle handler. """
437
 
        if self.check_history.get_active():
438
 
            # History Mode activated
439
 
            self.entry_history.set_sensitive(True)
440
 
            self.button_history.set_sensitive(True)
441
 
        else:
442
 
            # History Mode deactivated
443
 
            self.entry_history.set_sensitive(False)
444
 
            self.button_history.set_sensitive(False)
445
 
    
446
 
    @show_bzr_error
447
 
    def on_entry_history_revno_key_press_event(self, widget, event):
448
 
        """ Key pressed handler for the history entry. """
449
 
        if event.keyval == gtk.gdk.keyval_from_name('Return') or event.keyval == gtk.gdk.keyval_from_name('KP_Enter'):
450
 
            # Return was hit, so we have to load that specific revision
451
 
            # Emulate being remote, so inventory should be used
452
 
            path = self.get_path()
453
 
            if not self.remote:
454
 
                self.remote = True
455
 
                self.remote_branch = self.wt.branch
456
 
            
457
 
            revno = int(self.entry_history.get_text())
458
 
            self.remote_revision = self.remote_branch.get_rev_id(revno)
459
 
            if self.set_path(path, True):
460
 
                self.refresh_right()
461
 
    
462
 
    def on_entry_location_key_press_event(self, widget, event):
463
 
        """ Key pressed handler for the location entry. """
464
 
        if event.keyval == gtk.gdk.keyval_from_name('Return') or event.keyval == gtk.gdk.keyval_from_name('KP_Enter'):
465
 
            # Return was hit, so we have to jump
466
 
            self.on_button_location_jump_clicked(widget)
467
 
    
 
198
        
468
199
    def on_menuitem_add_files_activate(self, widget):
469
200
        """ Add file(s)... menu handler. """
470
201
        from add import OliveAdd
473
204
    
474
205
    def on_menuitem_branch_get_activate(self, widget):
475
206
        """ Branch/Get... menu handler. """
476
 
        from bzrlib.plugins.gtk.branch import BranchDialog
477
 
        
478
 
        if self.remote:
479
 
            branch = BranchDialog(os.getcwd(), self.window, self.remote_branch.base)
480
 
        else:
481
 
            branch = BranchDialog(self.get_path(), self.window)
482
 
        response = branch.run()
483
 
        if response != gtk.RESPONSE_NONE:
484
 
            branch.hide()
485
 
            
486
 
            if response == gtk.RESPONSE_OK:
487
 
                self.refresh_right()
488
 
            
489
 
            branch.destroy()
 
207
        from branch import BranchDialog
 
208
        branch = BranchDialog(self.get_path())
 
209
        branch.display()
490
210
    
491
211
    def on_menuitem_branch_checkout_activate(self, widget):
492
212
        """ Branch/Checkout... menu handler. """
493
 
        from bzrlib.plugins.gtk.checkout import CheckoutDialog
494
 
        
495
 
        if self.remote:
496
 
            checkout = CheckoutDialog(os.getcwd(), self.window, self.remote_branch.base)
497
 
        else:
498
 
            checkout = CheckoutDialog(self.get_path(), self.window)
499
 
        response = checkout.run()
500
 
        if response != gtk.RESPONSE_NONE:
501
 
            checkout.hide()
502
 
        
503
 
            if response == gtk.RESPONSE_OK:
504
 
                self.refresh_right()
505
 
            
506
 
            checkout.destroy()
 
213
        from checkout import OliveCheckout
 
214
        checkout = OliveCheckout(self.get_path())
 
215
        checkout.display()
507
216
    
508
 
    @show_bzr_error
509
217
    def on_menuitem_branch_commit_activate(self, widget):
510
218
        """ Branch/Commit... menu handler. """
511
 
#     def __init__(self, wt, wtpath, notbranch, selected=None, parent=None):
512
 
        selected = self.get_selected_right()
513
 
        if selected:
514
 
            selected = os.path.join(self.wtpath, selected)
515
 
        commit = CommitDialog(wt=self.wt,
516
 
                              parent=self.window,
517
 
                              selected=selected,
518
 
                             )
519
 
        response = commit.run()
520
 
        if response != gtk.RESPONSE_NONE:
521
 
            commit.hide()
522
 
        
523
 
            if response == gtk.RESPONSE_OK:
524
 
                self.refresh_right()
525
 
            
526
 
            commit.destroy()
527
 
    
528
 
    def on_menuitem_branch_conflicts_activate(self, widget):
529
 
        """ Branch/Conflicts... menu handler. """
530
 
        conflicts = ConflictsDialog(self.wt, self.window)
531
 
        response = conflicts.run()
532
 
        if response != gtk.RESPONSE_NONE:
533
 
            conflicts.destroy()
534
 
    
535
 
    def on_menuitem_branch_merge_activate(self, widget):
536
 
        """ Branch/Merge... menu handler. """
537
 
        from bzrlib.plugins.gtk.merge import MergeDialog
538
 
        
539
 
        if self.check_for_changes():
540
 
            error_dialog(_i18n('There are local changes in the branch'),
541
 
                         _i18n('Please commit or revert the changes before merging.'))
542
 
        else:
543
 
            parent_branch_path = self.wt.branch.get_parent()
544
 
            merge = MergeDialog(self.wt, self.wtpath,default_branch_path=parent_branch_path )
545
 
            merge.display()
546
 
 
547
 
    @show_bzr_error
 
219
        from commit import CommitDialog
 
220
        commit = CommitDialog(self.wt, self.wtpath)
 
221
        commit.display()
 
222
    
548
223
    def on_menuitem_branch_missing_revisions_activate(self, widget):
549
224
        """ Branch/Missing revisions menu handler. """
550
 
        
551
 
        from bzrlib.missing import find_unmerged, iter_log_revisions
552
 
        
553
225
        local_branch = self.wt.branch
554
 
        parent_branch_path = local_branch.get_parent()
555
 
        if parent_branch_path is None:
556
 
            error_dialog(_i18n('Parent location is unknown'),
557
 
                         _i18n('Cannot determine missing revisions if no parent location is known.'))
 
226
        
 
227
        other_branch = local_branch.get_parent()
 
228
        if other_branch is None:
 
229
            error_dialog(_('Parent location is unknown'),
 
230
                         _('Cannot determine missing revisions if no parent location is known.'))
558
231
            return
559
232
        
560
 
        parent_branch = Branch.open(parent_branch_path)
561
 
        
562
 
        if parent_branch.base == local_branch.base:
563
 
            parent_branch = local_branch
564
 
        
565
 
        local_extra, remote_extra = find_unmerged(local_branch,parent_branch)
566
 
 
567
 
        if local_extra or remote_extra:
568
 
            
569
 
            ## def log_revision_one_line_text(log_revision):
570
 
            ##    """ Generates one line description of log_revison ended with end of line."""
571
 
            ##    revision = log_revision.rev
572
 
            ##    txt =  "- %s (%s)\n" % (revision.get_summary(), revision.committer, )
573
 
            ##    txt = txt.replace("<"," ") # Seems < > chars are expected to be xml tags ...
574
 
            ##    txt = txt.replace(">"," ")
575
 
            ##    return txt
576
 
            
577
 
            dlg_txt = ""
578
 
            if local_extra:
579
 
                dlg_txt += _i18n('%d local extra revision(s). \n') % (len(local_extra),) 
580
 
                ## NOTE: We do not want such ugly info about missing revisions
581
 
                ##       Revision Browser should be used there
582
 
                ## max_revisions = 10
583
 
                ## for log_revision in iter_log_revisions(local_extra, local_branch.repository, verbose=1):
584
 
                ##    dlg_txt += log_revision_one_line_text(log_revision)
585
 
                ##    if max_revisions <= 0:
586
 
                ##        dlg_txt += _i18n("more ... \n")
587
 
                ##        break
588
 
                ## max_revisions -= 1
589
 
            ## dlg_txt += "\n"
590
 
            if remote_extra:
591
 
                dlg_txt += _i18n('%d local missing revision(s).\n') % (len(remote_extra),) 
592
 
                ## max_revisions = 10
593
 
                ## for log_revision in iter_log_revisions(remote_extra, parent_branch.repository, verbose=1):
594
 
                ##    dlg_txt += log_revision_one_line_text(log_revision)
595
 
                ##    if max_revisions <= 0:
596
 
                ##        dlg_txt += _i18n("more ... \n")
597
 
                ##        break
598
 
                ##    max_revisions -= 1
599
 
                
600
 
            info_dialog(_i18n('There are missing revisions'),
601
 
                        dlg_txt)
 
233
        remote_branch = Branch.open(other_branch)
 
234
        
 
235
        if remote_branch.base == local_branch.base:
 
236
            remote_branch = local_branch
 
237
 
 
238
        ret = len(local_branch.missing_revisions(remote_branch))
 
239
 
 
240
        if ret > 0:
 
241
            info_dialog(_('There are missing revisions'),
 
242
                        _('%d revision(s) missing.') % ret)
602
243
        else:
603
 
            info_dialog(_i18n('Local branch up to date'),
604
 
                        _i18n('There are no missing revisions.'))
 
244
            info_dialog(_('Local branch up to date'),
 
245
                        _('There are no missing revisions.'))
605
246
 
606
 
    @show_bzr_error
607
247
    def on_menuitem_branch_pull_activate(self, widget):
608
248
        """ Branch/Pull menu handler. """
609
249
        branch_to = self.wt.branch
610
250
 
611
251
        location = branch_to.get_parent()
612
252
        if location is None:
613
 
            error_dialog(_i18n('Parent location is unknown'),
614
 
                                     _i18n('Pulling is not possible until there is a parent location.'))
 
253
            error_dialog(_('Parent location is unknown'),
 
254
                                     _('Pulling is not possible until there is a parent location.'))
615
255
            return
616
256
 
617
 
        branch_from = Branch.open(location)
 
257
        try:
 
258
            branch_from = Branch.open(location)
 
259
        except errors.NotBranchError:
 
260
            error_dialog(_('Directory is not a branch'),
 
261
                                     _('You can perform this action only in a branch.'))
618
262
 
619
263
        if branch_to.get_parent() is None:
620
264
            branch_to.set_parent(branch_from.base)
621
265
 
622
 
        ret = branch_to.pull(branch_from)
623
 
        
624
 
        info_dialog(_i18n('Pull successful'), _i18n('%d revision(s) pulled.') % ret)
625
 
        
626
 
    @show_bzr_error
627
 
    def on_menuitem_branch_update_activate(self, widget):
628
 
        """ Brranch/checkout update menu handler. """
629
 
        
630
 
        ret = self.wt.update()
631
 
        conflicts = self.wt.conflicts()
632
 
        if conflicts:
633
 
            info_dialog(_i18n('Update successful but conflicts generated'), _i18n('Number of conflicts generated: %d.') % (len(conflicts),) )
634
 
        else:
635
 
            info_dialog(_i18n('Update successful'), _i18n('No conflicts generated.') )
 
266
        #old_rh = branch_to.revision_history()
 
267
        #if tree_to is not None:
 
268
        #    tree_to.pull(branch_from)
 
269
        #else:
 
270
        #    branch_to.pull(branch_from)
 
271
        branch_to.pull(branch_from)
 
272
        
 
273
        # TODO: get the number of pulled revisions
 
274
        ret = 0
 
275
        
 
276
        info_dialog(_('Pull successful'), _('%d revision(s) pulled.') % ret)
636
277
    
637
278
    def on_menuitem_branch_push_activate(self, widget):
638
279
        """ Branch/Push... menu handler. """
639
 
        push = PushDialog(repository=None,revid=None,branch=self.wt.branch, parent=self.window)
640
 
        response = push.run()
641
 
        if response != gtk.RESPONSE_NONE:
642
 
            push.destroy()
643
 
    
644
 
    @show_bzr_error
645
 
    def on_menuitem_branch_revert_activate(self, widget):
646
 
        """ Branch/Revert all changes menu handler. """
647
 
        ret = self.wt.revert([])
648
 
        if ret:
649
 
            warning_dialog(_i18n('Conflicts detected'),
650
 
                           _i18n('Please have a look at the working tree before continuing.'))
651
 
        else:
652
 
            info_dialog(_i18n('Revert successful'),
653
 
                        _i18n('All files reverted to last revision.'))
654
 
        self.refresh_right()
 
280
        from push import OlivePush
 
281
        push = OlivePush(self.wt.branch)
 
282
        push.display()
655
283
    
656
284
    def on_menuitem_branch_status_activate(self, widget):
657
285
        """ Branch/Status... menu handler. """
658
 
        from bzrlib.plugins.gtk.status import StatusDialog
659
 
        status = StatusDialog(self.wt, self.wtpath)
660
 
        response = status.run()
661
 
        if response != gtk.RESPONSE_NONE:
662
 
            status.destroy()
 
286
        from status import OliveStatus
 
287
        status = OliveStatus(self.wt, self.wtpath)
 
288
        status.display()
663
289
    
664
290
    def on_menuitem_branch_initialize_activate(self, widget):
665
291
        """ Initialize current directory. """
666
 
        init = InitDialog(self.path, self.window)
667
 
        response = init.run()
668
 
        if response != gtk.RESPONSE_NONE:
669
 
            init.hide()
670
 
        
671
 
            if response == gtk.RESPONSE_OK:
672
 
                self.refresh_right()
673
 
            
674
 
            init.destroy()
675
 
        
676
 
    def on_menuitem_branch_tags_activate(self, widget):
677
 
        """ Branch/Tags... menu handler. """
678
 
        from bzrlib.plugins.gtk.tags import TagsWindow
679
 
        if not self.remote:
680
 
            window = TagsWindow(self.wt.branch, self.window)
681
 
        else:
682
 
            window = TagsWindow(self.remote_branch, self.window)
683
 
        window.show()
684
 
    
685
 
    def on_menuitem_file_annotate_activate(self, widget):
686
 
        """ File/Annotate... menu handler. """
687
 
        if self.get_selected_right() is None:
688
 
            error_dialog(_i18n('No file was selected'),
689
 
                         _i18n('Please select a file from the list.'))
690
 
            return
691
 
        
692
 
        branch = self.wt.branch
693
 
        file_id = self.wt.path2id(self.wt.relpath(os.path.join(self.path, self.get_selected_right())))
694
 
        
695
 
        window = GAnnotateWindow(all=False, plain=False, parent=self.window)
696
 
        window.set_title(os.path.join(self.path, self.get_selected_right()) + " - Annotate")
697
 
        config = GAnnotateConfig(window)
698
 
        window.show()
699
 
        branch.lock_read()
 
292
        import bzrlib.bzrdir as bzrdir
 
293
        
700
294
        try:
701
 
            window.annotate(self.wt, branch, file_id)
702
 
        finally:
703
 
            branch.unlock()
704
 
    
705
 
    def on_menuitem_file_bookmark_activate(self, widget):
706
 
        """ File/Bookmark current directory menu handler. """
707
 
        if self.pref.add_bookmark(self.path):
708
 
            info_dialog(_i18n('Bookmark successfully added'),
709
 
                        _i18n('The current directory was bookmarked. You can reach\nit by selecting it from the left panel.'))
710
 
            self.pref.write()
 
295
            if not os.path.exists(self.path):
 
296
                os.mkdir(self.path)
 
297
     
 
298
            try:
 
299
                existing_bzrdir = bzrdir.BzrDir.open(self.path)
 
300
            except errors.NotBranchError:
 
301
                bzrdir.BzrDir.create_branch_convenience(self.path)
 
302
            else:
 
303
                if existing_bzrdir.has_branch():
 
304
                    if existing_bzrdir.has_workingtree():
 
305
                        raise errors.AlreadyBranchError(self.path)
 
306
                    else:
 
307
                        raise errors.BranchExistsWithoutWorkingTree(self.path)
 
308
                else:
 
309
                    existing_bzrdir.create_branch()
 
310
                    existing_bzrdir.create_workingtree()
 
311
        except errors.AlreadyBranchError, errmsg:
 
312
            error_dialog(_('Directory is already a branch'),
 
313
                                     _('The current directory (%s) is already a branch.\nYou can start using it, or initialize another directory.') % errmsg)
 
314
        except errors.BranchExistsWithoutWorkingTree, errmsg:
 
315
            error_dialog(_('Branch without a working tree'),
 
316
                                     _('The current directory (%s)\nis a branch without a working tree.') % errmsg)
711
317
        else:
712
 
            warning_dialog(_i18n('Location already bookmarked'),
713
 
                           _i18n('The current directory is already bookmarked.\nSee the left panel for reference.'))
 
318
            info_dialog(_('Initialize successful'),
 
319
                                    _('Directory successfully initialized.'))
 
320
            self.refresh_right()
714
321
        
715
 
        self.refresh_left()
716
 
    
717
322
    def on_menuitem_file_make_directory_activate(self, widget):
718
323
        """ File/Make directory... menu handler. """
719
324
        from mkdir import OliveMkdir
734
339
 
735
340
    def on_menuitem_remove_file_activate(self, widget):
736
341
        """ Remove (unversion) selected file. """
737
 
        from remove import OliveRemoveDialog
738
 
        remove = OliveRemoveDialog(self.wt, self.wtpath,
739
 
                                   selected=self.get_selected_right(),
740
 
                                   parent=self.window)
741
 
        response = remove.run()
742
 
        
743
 
        if response != gtk.RESPONSE_NONE:
744
 
            remove.hide()
745
 
        
746
 
            if response == gtk.RESPONSE_OK:
747
 
                self.set_path(self.path)
748
 
                self.refresh_right()
749
 
            
750
 
            remove.destroy()
 
342
        from remove import OliveRemove
 
343
        remove = OliveRemove(self.wt, self.wtpath, self.get_selected_right())
 
344
        remove.display()
751
345
    
752
346
    def on_menuitem_stats_diff_activate(self, widget):
753
347
        """ Statistics/Differences... menu handler. """
754
 
        window = DiffWindow(parent=self.window)
 
348
        from bzrlib.plugins.gtk.viz.diffwin import DiffWindow
 
349
        window = DiffWindow()
755
350
        parent_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
756
351
        window.set_diff(self.wt.branch.nick, self.wt, parent_tree)
757
352
        window.show()
759
354
    def on_menuitem_stats_infos_activate(self, widget):
760
355
        """ Statistics/Informations... menu handler. """
761
356
        from info import OliveInfo
762
 
        if self.remote:
763
 
            info = OliveInfo(self.remote_branch)
764
 
        else:
765
 
            info = OliveInfo(self.wt.branch)
 
357
        info = OliveInfo(self.wt)
766
358
        info.display()
767
359
    
768
360
    def on_menuitem_stats_log_activate(self, widget):
769
361
        """ Statistics/Log... menu handler. """
770
 
 
771
 
        if not self.remote:
772
 
            branch = self.wt.branch
773
 
        else:
774
 
            branch = self.remote_branch
775
 
 
776
 
        window = branchwin.BranchWindow(branch, branch.last_revision(), None, parent=self.window)
 
362
        from bzrlib.plugins.gtk.viz.branchwin import BranchWindow
 
363
        window = BranchWindow()
 
364
        window.set_branch(self.wt.branch, self.wt.branch.last_revision(), None)
777
365
        window.show()
778
366
    
779
367
    def on_menuitem_view_refresh_activate(self, widget):
786
374
    def on_menuitem_view_show_hidden_files_activate(self, widget):
787
375
        """ View/Show hidden files menu handler. """
788
376
        self.pref.set_preference('dotted_files', widget.get_active())
789
 
        if self.path is not None:
790
 
            self.refresh_right()
791
377
 
792
 
    def on_menuitem_view_show_ignored_files_activate(self, widget):
793
 
        """ Hide/Show ignored files menu handler. """
794
 
        self.pref.set_preference('ignored_files', widget.get_active())
795
 
        if self.path is not None:
796
 
            self.refresh_right()
797
 
            
798
378
    def on_treeview_left_button_press_event(self, widget, event):
799
379
        """ Occurs when somebody right-clicks in the bookmark list. """
800
380
        if event.button == 3:
804
384
 
805
385
            # Create a menu
806
386
            from menu import OliveMenu
807
 
            menu = OliveMenu(path=self.get_path(),
808
 
                             selected=self.get_selected_left(),
809
 
                             app=self)
 
387
            menu = OliveMenu(self.get_path(), self.get_selected_left())
810
388
            
811
389
            menu.left_context_menu().popup(None, None, None, 0,
812
390
                                           event.time)
813
391
 
814
 
    def on_treeview_left_button_release_event(self, widget, event):
815
 
        """ Occurs when somebody just clicks a bookmark. """
816
 
        if event.button != 3:
817
 
            # Allow one-click bookmark opening
818
 
            if self.get_selected_left() == None:
819
 
                return
820
 
            
821
 
            newdir = self.get_selected_left()
822
 
            if newdir == None:
823
 
                return
824
 
 
825
 
            if self.set_path(newdir):
826
 
                self.refresh_right()
827
 
 
828
392
    def on_treeview_left_row_activated(self, treeview, path, view_column):
829
393
        """ Occurs when somebody double-clicks or enters an item in the
830
394
        bookmark list. """
833
397
        if newdir == None:
834
398
            return
835
399
 
836
 
        if self.set_path(newdir):
837
 
            self.refresh_right()
 
400
        self.set_path(newdir)
 
401
        self.refresh_right()
838
402
 
839
403
    def on_treeview_right_button_press_event(self, widget, event):
840
404
        """ Occurs when somebody right-clicks in the file list. """
841
405
        if event.button == 3:
842
406
            # Create a menu
843
407
            from menu import OliveMenu
844
 
            menu = OliveMenu(path=self.get_path(),
845
 
                             selected=self.get_selected_right(),
846
 
                             app=self)
 
408
            menu = OliveMenu(self.get_path(), self.get_selected_right())
847
409
            # get the menu items
848
 
            m_open = menu.ui.get_widget('/context_right/open')
849
410
            m_add = menu.ui.get_widget('/context_right/add')
850
411
            m_remove = menu.ui.get_widget('/context_right/remove')
851
 
            m_rename = menu.ui.get_widget('/context_right/rename')
852
 
            m_revert = menu.ui.get_widget('/context_right/revert')
853
412
            m_commit = menu.ui.get_widget('/context_right/commit')
854
 
            m_annotate = menu.ui.get_widget('/context_right/annotate')
855
413
            m_diff = menu.ui.get_widget('/context_right/diff')
856
414
            # check if we're in a branch
857
415
            try:
858
416
                from bzrlib.branch import Branch
859
417
                Branch.open_containing(self.get_path())
860
 
                if self.remote:
861
 
                    m_open.set_sensitive(False)
862
 
                    m_add.set_sensitive(False)
863
 
                    m_remove.set_sensitive(False)
864
 
                    m_rename.set_sensitive(False)
865
 
                    m_revert.set_sensitive(False)
866
 
                    m_commit.set_sensitive(False)
867
 
                    m_annotate.set_sensitive(False)
868
 
                    m_diff.set_sensitive(False)
869
 
                else:
870
 
                    m_open.set_sensitive(True)
871
 
                    m_add.set_sensitive(True)
872
 
                    m_remove.set_sensitive(True)
873
 
                    m_rename.set_sensitive(True)
874
 
                    m_revert.set_sensitive(True)
875
 
                    m_commit.set_sensitive(True)
876
 
                    m_annotate.set_sensitive(True)
877
 
                    m_diff.set_sensitive(True)
878
 
            except bzrerrors.NotBranchError:
879
 
                m_open.set_sensitive(True)
 
418
                m_add.set_sensitive(True)
 
419
                m_remove.set_sensitive(True)
 
420
                m_commit.set_sensitive(True)
 
421
                m_diff.set_sensitive(True)
 
422
            except errors.NotBranchError:
880
423
                m_add.set_sensitive(False)
881
424
                m_remove.set_sensitive(False)
882
 
                m_rename.set_sensitive(False)
883
 
                m_revert.set_sensitive(False)
884
425
                m_commit.set_sensitive(False)
885
 
                m_annotate.set_sensitive(False)
886
426
                m_diff.set_sensitive(False)
887
 
 
888
 
            if not self.remote:
889
 
                menu.right_context_menu().popup(None, None, None, 0,
890
 
                                                event.time)
891
 
            else:
892
 
                menu.remote_context_menu().popup(None, None, None, 0,
893
 
                                                 event.time)
 
427
            menu.right_context_menu().popup(None, None, None, 0,
 
428
                                            event.time)
894
429
        
895
430
    def on_treeview_right_row_activated(self, treeview, path, view_column):
896
431
        """ Occurs when somebody double-clicks or enters an item in the
897
432
        file list. """
 
433
        import os.path
 
434
        
898
435
        from launch import launch
899
436
        
900
437
        newdir = self.get_selected_right()
901
438
        
902
 
        if not self.remote:
903
 
            # We're local
904
 
            if newdir == '..':
905
 
                self.set_path(os.path.split(self.get_path())[0])
 
439
        if newdir == '..':
 
440
            self.set_path(os.path.split(self.get_path())[0])
 
441
        else:
 
442
            fullpath = self.get_path() + os.sep + newdir
 
443
            if os.path.isdir(fullpath):
 
444
                # selected item is an existant directory
 
445
                self.set_path(fullpath)
906
446
            else:
907
 
                fullpath = os.path.join(self.get_path(), newdir)
908
 
                if os.path.isdir(fullpath):
909
 
                    # selected item is an existant directory
910
 
                    self.set_path(fullpath)
911
 
                else:
912
 
                    launch(fullpath)
913
 
        else:
914
 
            # We're remote
915
 
            if self._is_remote_dir(self.get_path() + newdir):
916
 
                self.set_path(self.get_path() + newdir)
 
447
                launch(fullpath) 
917
448
        
918
449
        self.refresh_right()
919
450
    
926
457
        self.pref.set_preference('window_x', x)
927
458
        self.pref.set_preference('window_y', y)
928
459
        self.pref.set_preference('paned_position',
929
 
                                 self.hpaned_main.get_position())
 
460
                                      self.hpaned_main.get_position())
930
461
        
931
462
        self.pref.write()
932
463
        self.window_main.destroy()
940
471
        bookmarks = self.pref.get_bookmarks()
941
472
        
942
473
        # Add them to the TreeStore
943
 
        titer = treestore.append(None, [_i18n('Bookmarks'), None])
 
474
        titer = treestore.append(None, [_('Bookmarks'), None])
944
475
        for item in bookmarks:
945
476
            title = self.pref.get_bookmark_title(item)
946
477
            treestore.append(titer, [title, item])
947
478
        
948
479
        # Create the column and add it to the TreeView
949
480
        self.treeview_left.set_model(treestore)
950
 
        tvcolumn_bookmark = gtk.TreeViewColumn(_i18n('Bookmark'))
 
481
        tvcolumn_bookmark = gtk.TreeViewColumn(_('Bookmark'))
951
482
        self.treeview_left.append_column(tvcolumn_bookmark)
952
483
        
953
484
        # Set up the cells
961
492
    def _load_right(self):
962
493
        """ Load data into the right panel. (Filelist) """
963
494
        # Create ListStore
964
 
        # Model: [ icon, dir, name, status text, status, size (int), size (human), mtime (int), mtime (local), fileid ]
965
 
        liststore = gtk.ListStore(gobject.TYPE_STRING,
966
 
                                  gobject.TYPE_BOOLEAN,
967
 
                                  gobject.TYPE_STRING,
968
 
                                  gobject.TYPE_STRING,
969
 
                                  gobject.TYPE_STRING,
970
 
                                  gobject.TYPE_STRING,
971
 
                                  gobject.TYPE_STRING,
972
 
                                  gobject.TYPE_INT,
973
 
                                  gobject.TYPE_STRING,
974
 
                                  gobject.TYPE_STRING)
 
495
        liststore = gtk.ListStore(str, str, str)
975
496
        
976
 
        dirs = []
 
497
        dirs = ['..']
977
498
        files = []
978
499
        
979
500
        # Fill the appropriate lists
985
506
                dirs.append(item)
986
507
            else:
987
508
                files.append(item)
 
509
            
 
510
        # Sort'em
 
511
        dirs.sort()
 
512
        files.sort()
988
513
        
989
514
        if not self.notbranch:
990
515
            branch = self.wt.branch
993
518
            delta = self.wt.changes_from(tree2, want_unchanged=True)
994
519
        
995
520
        # Add'em to the ListStore
996
 
        for item in dirs:
997
 
            try:
998
 
                statinfo = os.stat(self.path + os.sep + item)
999
 
            except OSError, e:
1000
 
                if e.errno == 40:
1001
 
                    continue
1002
 
                else:
1003
 
                    raise
1004
 
            liststore.append([ gtk.STOCK_DIRECTORY,
1005
 
                               True,
1006
 
                               item,
1007
 
                               '',
1008
 
                               '',
1009
 
                               "<DIR>",
1010
 
                               "<DIR>",
1011
 
                               statinfo.st_mtime,
1012
 
                               self._format_date(statinfo.st_mtime),
1013
 
                               ''])
 
521
        for item in dirs:    
 
522
            liststore.append([gtk.STOCK_DIRECTORY, item, ''])
1014
523
        for item in files:
1015
524
            status = 'unknown'
1016
 
            fileid = ''
1017
525
            if not self.notbranch:
1018
526
                filename = self.wt.relpath(self.path + os.sep + item)
1019
527
                
1020
 
                try:
1021
 
                    self.wt.lock_read()
1022
 
                    
1023
 
                    for rpath, rpathnew, id, kind, text_modified, meta_modified in delta.renamed:
1024
 
                        if rpathnew == filename:
1025
 
                            status = 'renamed'
1026
 
                            fileid = id
1027
 
                    for rpath, id, kind in delta.added:
1028
 
                        if rpath == filename:
1029
 
                            status = 'added'
1030
 
                            fileid = id
1031
 
                    for rpath, id, kind in delta.removed:
1032
 
                        if rpath == filename:
1033
 
                            status = 'removed'
1034
 
                            fileid = id
1035
 
                    for rpath, id, kind, text_modified, meta_modified in delta.modified:
1036
 
                        if rpath == filename:
1037
 
                            status = 'modified'
1038
 
                            fileid = id
1039
 
                    for rpath, id, kind in delta.unchanged:
1040
 
                        if rpath == filename:
1041
 
                            status = 'unchanged'
1042
 
                            fileid = id
1043
 
                    for rpath, file_class, kind, id, entry in self.wt.list_files():
1044
 
                        if rpath == filename and file_class == 'I':
1045
 
                            status = 'ignored'
1046
 
                finally:
1047
 
                    self.wt.unlock()
 
528
                for rpath, rpathnew, id, kind, text_modified, meta_modified in delta.renamed:
 
529
                    if rpathnew == filename:
 
530
                        status = 'renamed'
 
531
                for rpath, id, kind in delta.added:
 
532
                    if rpath == filename:
 
533
                        status = 'added'
 
534
                for rpath, id, kind in delta.removed:
 
535
                    if rpath == filename:
 
536
                        status = 'removed'
 
537
                for rpath, id, kind, text_modified, meta_modified in delta.modified:
 
538
                    if rpath == filename:
 
539
                        status = 'modified'
 
540
                for rpath, id, kind in delta.unchanged:
 
541
                    if rpath == filename:
 
542
                        status = 'unchanged'
 
543
            
 
544
            #try:
 
545
            #    status = fileops.status(path + os.sep + item)
 
546
            #except errors.PermissionDenied:
 
547
            #    continue
1048
548
            
1049
549
            if status == 'renamed':
1050
 
                st = _i18n('renamed')
 
550
                st = _('renamed')
1051
551
            elif status == 'removed':
1052
 
                st = _i18n('removed')
 
552
                st = _('removed')
1053
553
            elif status == 'added':
1054
 
                st = _i18n('added')
 
554
                st = _('added')
1055
555
            elif status == 'modified':
1056
 
                st = _i18n('modified')
 
556
                st = _('modified')
1057
557
            elif status == 'unchanged':
1058
 
                st = _i18n('unchanged')
1059
 
            elif status == 'ignored':
1060
 
                st = _i18n('ignored')
 
558
                st = _('unchanged')
1061
559
            else:
1062
 
                st = _i18n('unknown')
1063
 
            
1064
 
            try:
1065
 
                statinfo = os.stat(self.path + os.sep + item)
1066
 
            except OSError, e:
1067
 
                if e.errno == 40:
1068
 
                    continue
1069
 
                else:
1070
 
                    raise
1071
 
            liststore.append([gtk.STOCK_FILE,
1072
 
                              False,
1073
 
                              item,
1074
 
                              st,
1075
 
                              status,
1076
 
                              str(statinfo.st_size), # NOTE: if int used there it will fail for large files (size expressed as long int)
1077
 
                              self._format_size(statinfo.st_size),
1078
 
                              statinfo.st_mtime,
1079
 
                              self._format_date(statinfo.st_mtime),
1080
 
                              fileid])
 
560
                st = _('unknown')
 
561
            liststore.append([gtk.STOCK_FILE, item, st])
1081
562
        
1082
563
        # Create the columns and add them to the TreeView
1083
564
        self.treeview_right.set_model(liststore)
1084
 
        self._tvcolumn_filename = gtk.TreeViewColumn(_i18n('Filename'))
1085
 
        self._tvcolumn_status = gtk.TreeViewColumn(_i18n('Status'))
1086
 
        self._tvcolumn_size = gtk.TreeViewColumn(_i18n('Size'))
1087
 
        self._tvcolumn_mtime = gtk.TreeViewColumn(_i18n('Last modified'))
1088
 
        self.treeview_right.append_column(self._tvcolumn_filename)
1089
 
        self.treeview_right.append_column(self._tvcolumn_status)
1090
 
        self.treeview_right.append_column(self._tvcolumn_size)
1091
 
        self.treeview_right.append_column(self._tvcolumn_mtime)
 
565
        tvcolumn_filename = gtk.TreeViewColumn(_('Filename'))
 
566
        tvcolumn_status = gtk.TreeViewColumn(_('Status'))
 
567
        self.treeview_right.append_column(tvcolumn_filename)
 
568
        self.treeview_right.append_column(tvcolumn_status)
1092
569
        
1093
570
        # Set up the cells
1094
571
        cellpb = gtk.CellRendererPixbuf()
1095
572
        cell = gtk.CellRendererText()
1096
 
        self._tvcolumn_filename.pack_start(cellpb, False)
1097
 
        self._tvcolumn_filename.pack_start(cell, True)
1098
 
        self._tvcolumn_filename.set_attributes(cellpb, stock_id=0)
1099
 
        self._tvcolumn_filename.add_attribute(cell, 'text', 2)
1100
 
        self._tvcolumn_status.pack_start(cell, True)
1101
 
        self._tvcolumn_status.add_attribute(cell, 'text', 3)
1102
 
        self._tvcolumn_size.pack_start(cell, True)
1103
 
        self._tvcolumn_size.add_attribute(cell, 'text', 6)
1104
 
        self._tvcolumn_mtime.pack_start(cell, True)
1105
 
        self._tvcolumn_mtime.add_attribute(cell, 'text', 8)
1106
 
        
1107
 
        # Set up the properties of the TreeView
1108
 
        self.treeview_right.set_headers_visible(True)
1109
 
        self.treeview_right.set_headers_clickable(True)
1110
 
        self.treeview_right.set_search_column(1)
1111
 
        self._tvcolumn_filename.set_resizable(True)
1112
 
        self._tvcolumn_status.set_resizable(True)
1113
 
        self._tvcolumn_size.set_resizable(True)
1114
 
        self._tvcolumn_mtime.set_resizable(True)
1115
 
        # Set up sorting
1116
 
        liststore.set_sort_func(13, self._sort_filelist_callback, None)
1117
 
        liststore.set_sort_column_id(13, gtk.SORT_ASCENDING)
1118
 
        self._tvcolumn_filename.set_sort_column_id(13)
1119
 
        self._tvcolumn_status.set_sort_column_id(3)
1120
 
        self._tvcolumn_size.set_sort_column_id(5)
1121
 
        self._tvcolumn_mtime.set_sort_column_id(7)
 
573
        tvcolumn_filename.pack_start(cellpb, False)
 
574
        tvcolumn_filename.pack_start(cell, True)
 
575
        tvcolumn_filename.set_attributes(cellpb, stock_id=0)
 
576
        tvcolumn_filename.add_attribute(cell, 'text', 1)
 
577
        tvcolumn_status.pack_start(cell, True)
 
578
        tvcolumn_status.add_attribute(cell, 'text', 2)
1122
579
        
1123
580
        # Set sensitivity
1124
581
        self.set_sensitivity()
1125
582
        
1126
 
    def get_selected_fileid(self):
1127
 
        """ Get the file_id of the selected file. """
1128
 
        treeselection = self.treeview_right.get_selection()
1129
 
        (model, iter) = treeselection.get_selected()
1130
 
        
1131
 
        if iter is None:
1132
 
            return None
1133
 
        else:
1134
 
            return model.get_value(iter, 9)
1135
 
    
1136
583
    def get_selected_right(self):
1137
584
        """ Get the selected filename. """
1138
585
        treeselection = self.treeview_right.get_selection()
1141
588
        if iter is None:
1142
589
            return None
1143
590
        else:
1144
 
            return model.get_value(iter, 2)
 
591
            return model.get_value(iter, 1)
1145
592
    
1146
593
    def get_selected_left(self):
1147
594
        """ Get the selected bookmark. """
1163
610
    
1164
611
    def set_sensitivity(self):
1165
612
        """ Set menu and toolbar sensitivity. """
1166
 
        if not self.remote:
1167
 
            # We're local
1168
 
            self.menuitem_branch_init.set_sensitive(self.notbranch)
1169
 
            self.menuitem_branch_get.set_sensitive(self.notbranch)
1170
 
            self.menuitem_branch_checkout.set_sensitive(self.notbranch)
1171
 
            self.menuitem_branch_pull.set_sensitive(not self.notbranch)
1172
 
            self.menuitem_branch_push.set_sensitive(not self.notbranch)
1173
 
            self.menuitem_branch_update.set_sensitive(not self.notbranch)
1174
 
            self.menuitem_branch_revert.set_sensitive(not self.notbranch)
1175
 
            self.menuitem_branch_merge.set_sensitive(not self.notbranch)
1176
 
            self.menuitem_branch_commit.set_sensitive(not self.notbranch)
1177
 
            self.menuitem_branch_tags.set_sensitive(not self.notbranch)
1178
 
            self.menuitem_branch_status.set_sensitive(not self.notbranch)
1179
 
            self.menuitem_branch_missing.set_sensitive(not self.notbranch)
1180
 
            self.menuitem_branch_conflicts.set_sensitive(not self.notbranch)
1181
 
            self.menuitem_stats.set_sensitive(not self.notbranch)
1182
 
            self.menuitem_stats_diff.set_sensitive(not self.notbranch)
1183
 
            self.menuitem_add_files.set_sensitive(not self.notbranch)
1184
 
            self.menuitem_remove_files.set_sensitive(not self.notbranch)
1185
 
            self.menuitem_file_make_directory.set_sensitive(not self.notbranch)
1186
 
            self.menuitem_file_rename.set_sensitive(not self.notbranch)
1187
 
            self.menuitem_file_move.set_sensitive(not self.notbranch)
1188
 
            self.menuitem_file_annotate.set_sensitive(not self.notbranch)
1189
 
            #self.menutoolbutton_diff.set_sensitive(True)
1190
 
            self.toolbutton_diff.set_sensitive(not self.notbranch)
1191
 
            self.toolbutton_log.set_sensitive(not self.notbranch)
1192
 
            self.toolbutton_commit.set_sensitive(not self.notbranch)
1193
 
            self.toolbutton_pull.set_sensitive(not self.notbranch)
1194
 
            self.toolbutton_push.set_sensitive(not self.notbranch)
1195
 
            self.toolbutton_update.set_sensitive(not self.notbranch)
1196
 
        else:
1197
 
            # We're remote
1198
 
            self.menuitem_branch_init.set_sensitive(False)
1199
 
            self.menuitem_branch_get.set_sensitive(True)
1200
 
            self.menuitem_branch_checkout.set_sensitive(True)
1201
 
            self.menuitem_branch_pull.set_sensitive(False)
1202
 
            self.menuitem_branch_push.set_sensitive(False)
1203
 
            self.menuitem_branch_update.set_sensitive(False)
1204
 
            self.menuitem_branch_revert.set_sensitive(False)
1205
 
            self.menuitem_branch_merge.set_sensitive(False)
1206
 
            self.menuitem_branch_commit.set_sensitive(False)
1207
 
            self.menuitem_branch_tags.set_sensitive(True)
1208
 
            self.menuitem_branch_status.set_sensitive(False)
1209
 
            self.menuitem_branch_missing.set_sensitive(False)
1210
 
            self.menuitem_branch_conflicts.set_sensitive(False)
1211
 
            self.menuitem_stats.set_sensitive(True)
1212
 
            self.menuitem_stats_diff.set_sensitive(False)
1213
 
            self.menuitem_add_files.set_sensitive(False)
1214
 
            self.menuitem_remove_files.set_sensitive(False)
1215
 
            self.menuitem_file_make_directory.set_sensitive(False)
1216
 
            self.menuitem_file_rename.set_sensitive(False)
1217
 
            self.menuitem_file_move.set_sensitive(False)
1218
 
            self.menuitem_file_annotate.set_sensitive(False)
1219
 
            #self.menutoolbutton_diff.set_sensitive(True)
1220
 
            self.toolbutton_diff.set_sensitive(False)
1221
 
            self.toolbutton_log.set_sensitive(True)
1222
 
            self.toolbutton_commit.set_sensitive(False)
1223
 
            self.toolbutton_pull.set_sensitive(False)
1224
 
            self.toolbutton_push.set_sensitive(False)
1225
 
            self.toolbutton_update.set_sensitive(False)
 
613
        self.menuitem_branch_init.set_sensitive(self.notbranch)
 
614
        self.menuitem_branch_checkout.set_sensitive(self.notbranch)
 
615
        self.menuitem_branch_pull.set_sensitive(not self.notbranch)
 
616
        self.menuitem_branch_push.set_sensitive(not self.notbranch)
 
617
        self.menuitem_branch_commit.set_sensitive(not self.notbranch)
 
618
        self.menuitem_branch_status.set_sensitive(not self.notbranch)
 
619
        self.menuitem_branch_missing.set_sensitive(not self.notbranch)
 
620
        self.menuitem_stats.set_sensitive(not self.notbranch)
 
621
        self.menuitem_add_files.set_sensitive(not self.notbranch)
 
622
        self.menuitem_remove_files.set_sensitive(not self.notbranch)
 
623
        self.menuitem_file_make_directory.set_sensitive(not self.notbranch)
 
624
        self.menuitem_file_rename.set_sensitive(not self.notbranch)
 
625
        self.menuitem_file_move.set_sensitive(not self.notbranch)
 
626
        #self.menutoolbutton_diff.set_sensitive(True)
 
627
        self.toolbutton_diff.set_sensitive(not self.notbranch)
 
628
        self.toolbutton_log.set_sensitive(not self.notbranch)
 
629
        self.toolbutton_commit.set_sensitive(not self.notbranch)
 
630
        self.toolbutton_pull.set_sensitive(not self.notbranch)
 
631
        self.toolbutton_push.set_sensitive(not self.notbranch)
1226
632
    
1227
633
    def refresh_left(self):
1228
634
        """ Refresh the bookmark list. """
1233
639
 
1234
640
        # Re-read preferences
1235
641
        self.pref.read()
1236
 
        
 
642
 
1237
643
        # Get bookmarks
1238
644
        bookmarks = self.pref.get_bookmarks()
1239
645
 
1240
646
        # Add them to the TreeStore
1241
 
        titer = treestore.append(None, [_i18n('Bookmarks'), None])
 
647
        titer = treestore.append(None, [_('Bookmarks'), None])
1242
648
        for item in bookmarks:
1243
649
            title = self.pref.get_bookmark_title(item)
1244
650
            treestore.append(titer, [title, item])
1251
657
 
1252
658
    def refresh_right(self, path=None):
1253
659
        """ Refresh the file list. """
1254
 
        if not self.remote:
1255
 
            # We're local
1256
 
            from bzrlib.workingtree import WorkingTree
1257
 
    
1258
 
            if path is None:
1259
 
                path = self.get_path()
1260
 
    
1261
 
            # A workaround for double-clicking Bookmarks
1262
 
            if not os.path.exists(path):
1263
 
                return
1264
 
    
1265
 
            # Get ListStore and clear it
1266
 
            liststore = self.treeview_right.get_model()
1267
 
            liststore.clear()
1268
 
            
1269
 
            # Show Status column
1270
 
            self._tvcolumn_status.set_visible(True)
1271
 
    
1272
 
            dirs = []
1273
 
            files = []
1274
 
    
1275
 
            # Fill the appropriate lists
1276
 
            dotted_files = self.pref.get_preference('dotted_files', 'bool')
1277
 
            ignored_files = self.pref.get_preference('ignored_files', 'bool')
1278
 
 
1279
 
            for item in os.listdir(path):
1280
 
                if not dotted_files and item[0] == '.':
1281
 
                    continue
1282
 
                if os.path.isdir(path + os.sep + item):
1283
 
                    dirs.append(item)
1284
 
                else:
1285
 
                    files.append(item)
1286
 
            
1287
 
            # Try to open the working tree
1288
 
            notbranch = False
1289
 
            try:
1290
 
                tree1 = WorkingTree.open_containing(path)[0]
1291
 
            except (bzrerrors.NotBranchError, bzrerrors.NoWorkingTree):
1292
 
                notbranch = True
1293
 
            
 
660
        from bzrlib.workingtree import WorkingTree
 
661
 
 
662
        if path is None:
 
663
            path = self.get_path()
 
664
 
 
665
        # A workaround for double-clicking Bookmarks
 
666
        if not os.path.exists(path):
 
667
            return
 
668
 
 
669
        # Get ListStore and clear it
 
670
        liststore = self.treeview_right.get_model()
 
671
        liststore.clear()
 
672
 
 
673
        dirs = ['..']
 
674
        files = []
 
675
 
 
676
        # Fill the appropriate lists
 
677
        dotted_files = self.pref.get_preference('dotted_files', 'bool')
 
678
        for item in os.listdir(path):
 
679
            if not dotted_files and item[0] == '.':
 
680
                continue
 
681
            if os.path.isdir(path + os.sep + item):
 
682
                dirs.append(item)
 
683
            else:
 
684
                files.append(item)
 
685
 
 
686
        # Sort'em
 
687
        dirs.sort()
 
688
        files.sort()
 
689
        
 
690
        # Try to open the working tree
 
691
        notbranch = False
 
692
        try:
 
693
            tree1 = WorkingTree.open_containing(path)[0]
 
694
        except errors.NotBranchError:
 
695
            notbranch = True
 
696
        except errors.PermissionDenied:
 
697
            print "DEBUG: permission denied."
 
698
        
 
699
        if not notbranch:
 
700
            branch = tree1.branch
 
701
            tree2 = tree1.branch.repository.revision_tree(branch.last_revision())
 
702
        
 
703
            delta = tree1.changes_from(tree2, want_unchanged=True)
 
704
 
 
705
        # Add'em to the ListStore
 
706
        for item in dirs:
 
707
            liststore.append([gtk.STOCK_DIRECTORY, item, ''])
 
708
        for item in files:
 
709
            status = 'unknown'
1294
710
            if not notbranch:
1295
 
                branch = tree1.branch
1296
 
                tree2 = tree1.branch.repository.revision_tree(branch.last_revision())
1297
 
            
1298
 
                delta = tree1.changes_from(tree2, want_unchanged=True)
1299
 
                
1300
 
            # Add'em to the ListStore
1301
 
            for item in dirs:
1302
 
                try:
1303
 
                    statinfo = os.stat(self.path + os.sep + item)
1304
 
                except OSError, e:
1305
 
                    if e.errno == 40:
1306
 
                        continue
1307
 
                    else:
1308
 
                        raise
1309
 
                liststore.append([gtk.STOCK_DIRECTORY,
1310
 
                                  True,
1311
 
                                  item,
1312
 
                                  '',
1313
 
                                  '',
1314
 
                                  "<DIR>",
1315
 
                                  "<DIR>",
1316
 
                                  statinfo.st_mtime,
1317
 
                                  self._format_date(statinfo.st_mtime),
1318
 
                                  ''])
1319
 
            for item in files:
1320
 
                status = 'unknown'
1321
 
                fileid = ''
1322
 
                if not notbranch:
1323
 
                    filename = tree1.relpath(path + os.sep + item)
1324
 
                    
1325
 
                    try:
1326
 
                        self.wt.lock_read()
1327
 
                        
1328
 
                        for rpath, rpathnew, id, kind, text_modified, meta_modified in delta.renamed:
1329
 
                            if rpathnew == filename:
1330
 
                                status = 'renamed'
1331
 
                                fileid = id
1332
 
                        for rpath, id, kind in delta.added:
1333
 
                            if rpath == filename:
1334
 
                                status = 'added'
1335
 
                                fileid = id
1336
 
                        for rpath, id, kind in delta.removed:
1337
 
                            if rpath == filename:
1338
 
                                status = 'removed'
1339
 
                                fileid = id
1340
 
                        for rpath, id, kind, text_modified, meta_modified in delta.modified:
1341
 
                            if rpath == filename:
1342
 
                                status = 'modified'
1343
 
                                fileid = id
1344
 
                        for rpath, id, kind in delta.unchanged:
1345
 
                            if rpath == filename:
1346
 
                                status = 'unchanged'
1347
 
                                fileid = id
1348
 
                        for rpath, file_class, kind, id, entry in self.wt.list_files():
1349
 
                            if rpath == filename and file_class == 'I':
1350
 
                                status = 'ignored'
1351
 
                    finally:
1352
 
                        self.wt.unlock()
1353
 
                
1354
 
                if status == 'renamed':
1355
 
                    st = _i18n('renamed')
1356
 
                elif status == 'removed':
1357
 
                    st = _i18n('removed')
1358
 
                elif status == 'added':
1359
 
                    st = _i18n('added')
1360
 
                elif status == 'modified':
1361
 
                    st = _i18n('modified')
1362
 
                elif status == 'unchanged':
1363
 
                    st = _i18n('unchanged')
1364
 
                elif status == 'ignored':
1365
 
                    st = _i18n('ignored')
1366
 
                    if not ignored_files:
1367
 
                        continue
1368
 
                else:
1369
 
                    st = _i18n('unknown')
1370
 
                
1371
 
                try:
1372
 
                    statinfo = os.stat(self.path + os.sep + item)
1373
 
                except OSError, e:
1374
 
                    if e.errno == 40:
1375
 
                        continue
1376
 
                    else:
1377
 
                        raise
1378
 
                liststore.append([gtk.STOCK_FILE,
1379
 
                                  False,
1380
 
                                  item,
1381
 
                                  st,
1382
 
                                  status,
1383
 
                                  str(statinfo.st_size),
1384
 
                                  self._format_size(statinfo.st_size),
1385
 
                                  statinfo.st_mtime,
1386
 
                                  self._format_date(statinfo.st_mtime),
1387
 
                                  fileid])
1388
 
        else:
1389
 
            # We're remote
1390
 
            
1391
 
            # Get ListStore and clear it
1392
 
            liststore = self.treeview_right.get_model()
1393
 
            liststore.clear()
1394
 
            
1395
 
            # Hide Status column
1396
 
            self._tvcolumn_status.set_visible(False)
1397
 
            
1398
 
            dirs = []
1399
 
            files = []
1400
 
            
1401
 
            self._show_stock_image(gtk.STOCK_REFRESH)
1402
 
            
1403
 
            for (name, type) in self.remote_entries:
1404
 
                if type.kind == 'directory':
1405
 
                    dirs.append(type)
1406
 
                elif type.kind == 'file':
1407
 
                    files.append(type)
1408
 
            
1409
 
            class HistoryCache:
1410
 
                """ Cache based on revision history. """
1411
 
                def __init__(self, history):
1412
 
                    self._history = history
1413
 
                
1414
 
                def _lookup_revision(self, revid):
1415
 
                    for r in self._history:
1416
 
                        if r.revision_id == revid:
1417
 
                            return r
1418
 
                    rev = repo.get_revision(revid)
1419
 
                    self._history.append(rev)
1420
 
                    return rev
1421
 
            
1422
 
            repo = self.remote_branch.repository
1423
 
            
1424
 
            revhistory = self.remote_branch.revision_history()
1425
 
            try:
1426
 
                revs = repo.get_revisions(revhistory)
1427
 
                cache = HistoryCache(revs)
1428
 
            except bzrerrors.InvalidHttpResponse:
1429
 
                # Fallback to dummy algorithm, because of LP: #115209
1430
 
                cache = HistoryCache([])
1431
 
            
1432
 
            for item in dirs:
1433
 
                if item.parent_id == self.remote_parent:
1434
 
                    rev = cache._lookup_revision(item.revision)
1435
 
                    liststore.append([ gtk.STOCK_DIRECTORY,
1436
 
                                       True,
1437
 
                                       item.name,
1438
 
                                       '',
1439
 
                                       '',
1440
 
                                       "<DIR>",
1441
 
                                       "<DIR>",
1442
 
                                       rev.timestamp,
1443
 
                                       self._format_date(rev.timestamp),
1444
 
                                       ''
1445
 
                                   ])
1446
 
                while gtk.events_pending():
1447
 
                    gtk.main_iteration()
1448
 
            
1449
 
            for item in files:
1450
 
                if item.parent_id == self.remote_parent:
1451
 
                    rev = cache._lookup_revision(item.revision)
1452
 
                    liststore.append([ gtk.STOCK_FILE,
1453
 
                                       False,
1454
 
                                       item.name,
1455
 
                                       '',
1456
 
                                       '',
1457
 
                                       str(item.text_size),
1458
 
                                       self._format_size(item.text_size),
1459
 
                                       rev.timestamp,
1460
 
                                       self._format_date(rev.timestamp),
1461
 
                                       item.file_id
1462
 
                                   ])
1463
 
                while gtk.events_pending():
1464
 
                    gtk.main_iteration()
1465
 
            
1466
 
            self.image_location_error.destroy()
1467
 
 
1468
 
        # Columns should auto-size
1469
 
        self.treeview_right.columns_autosize()
 
711
                filename = tree1.relpath(path + os.sep + item)
 
712
                
 
713
                for rpath, rpathnew, id, kind, text_modified, meta_modified in delta.renamed:
 
714
                    if rpathnew == filename:
 
715
                        status = 'renamed'
 
716
                for rpath, id, kind in delta.added:
 
717
                    if rpath == filename:
 
718
                        status = 'added'                
 
719
                for rpath, id, kind in delta.removed:
 
720
                    if rpath == filename:
 
721
                        status = 'removed'
 
722
                for rpath, id, kind, text_modified, meta_modified in delta.modified:
 
723
                    if rpath == filename:
 
724
                        status = 'modified'
 
725
                for rpath, id, kind in delta.unchanged:
 
726
                    if rpath == filename:
 
727
                        status = 'unchanged'
 
728
            
 
729
            #try:
 
730
            #    status = fileops.status(path + os.sep + item)
 
731
            #except errors.PermissionDenied:
 
732
            #    continue
 
733
 
 
734
            if status == 'renamed':
 
735
                st = _('renamed')
 
736
            elif status == 'removed':
 
737
                st = _('removed')
 
738
            elif status == 'added':
 
739
                st = _('added')
 
740
            elif status == 'modified':
 
741
                st = _('modified')
 
742
            elif status == 'unchanged':
 
743
                st = _('unchanged')
 
744
            else:
 
745
                st = _('unknown')
 
746
            liststore.append([gtk.STOCK_FILE, item, st])
 
747
 
 
748
        # Add the ListStore to the TreeView
 
749
        self.treeview_right.set_model(liststore)
1470
750
        
1471
751
        # Set sensitivity
1472
752
        self.set_sensitivity()
1494
774
        drives = self._harddisks()
1495
775
        for drive in drives:
1496
776
            self.combobox_drive.append_text(drive)
1497
 
        self.combobox_drive.set_active(drives.index(os.getcwd()[0:2]))
1498
777
    
1499
778
    def _refresh_drives(self, combobox):
1500
 
        if self._just_started:
1501
 
            return
1502
779
        model = combobox.get_model()
1503
780
        active = combobox.get_active()
1504
781
        if active >= 0:
1505
782
            drive = model[active][0]
1506
 
            self.set_path(drive + '\\')
1507
783
            self.refresh_right(drive + '\\')
1508
 
    
1509
 
    def check_for_changes(self):
1510
 
        """ Check whether there were changes in the current working tree. """
1511
 
        old_tree = self.wt.branch.repository.revision_tree(self.wt.branch.last_revision())
1512
 
        delta = self.wt.changes_from(old_tree)
1513
 
 
1514
 
        changes = False
1515
 
        
1516
 
        if len(delta.added) or len(delta.removed) or len(delta.renamed) or len(delta.modified):
1517
 
            changes = True
1518
 
        
1519
 
        return changes
1520
 
    
1521
 
    def _sort_filelist_callback(self, model, iter1, iter2, data):
1522
 
        """ The sort callback for the file list, return values:
1523
 
        -1: iter1 < iter2
1524
 
        0: iter1 = iter2
1525
 
        1: iter1 > iter2
1526
 
        """
1527
 
        name1 = model.get_value(iter1, 2)
1528
 
        name2 = model.get_value(iter2, 2)
1529
 
        
1530
 
        if model.get_value(iter1, 1):
1531
 
            # item1 is a directory
1532
 
            if not model.get_value(iter2, 1):
1533
 
                # item2 isn't
1534
 
                return -1
1535
 
            else:
1536
 
                # both of them are directories, we compare their names
1537
 
                if name1 < name2:
1538
 
                    return -1
1539
 
                elif name1 == name2:
1540
 
                    return 0
1541
 
                else:
1542
 
                    return 1
1543
 
        else:
1544
 
            # item1 is not a directory
1545
 
            if model.get_value(iter2, 1):
1546
 
                # item2 is
1547
 
                return 1
1548
 
            else:
1549
 
                # both of them are files, compare them
1550
 
                if name1 < name2:
1551
 
                    return -1
1552
 
                elif name1 == name2:
1553
 
                    return 0
1554
 
                else:
1555
 
                    return 1
1556
 
    
1557
 
    def _format_size(self, size):
1558
 
        """ Format size to a human readable format. """
1559
 
        if size < 1000:
1560
 
            return "%d[B]" % (size,)
1561
 
        size = size / 1000.0
1562
 
        
1563
 
        for metric in ["kB","MB","GB","TB"]:
1564
 
            if size < 1000:
1565
 
                break
1566
 
            size = size / 1000.0
1567
 
        return "%.1f[%s]" % (size,metric) 
1568
 
    
1569
 
    def _format_date(self, timestamp):
1570
 
        """ Format the time (given in secs) to a human readable format. """
1571
 
        return time.ctime(timestamp)
1572
 
    
1573
 
    def _is_remote_dir(self, location):
1574
 
        """ Determine whether the given location is a directory or not. """
1575
 
        if not self.remote:
1576
 
            # We're in local mode
1577
 
            return False
1578
 
        else:
1579
 
            branch, path = Branch.open_containing(location)
1580
 
            for (name, type) in self.remote_entries:
1581
 
                if name == path and type.kind == 'directory':
1582
 
                    # We got it
1583
 
                    return True
1584
 
            # Either it's not a directory or not in the inventory
1585
 
            return False
1586
 
    
1587
 
    def _show_stock_image(self, stock_id):
1588
 
        """ Show a stock image next to the location entry. """
1589
 
        self.image_location_error.destroy()
1590
 
        self.image_location_error = gtk.image_new_from_stock(stock_id, gtk.ICON_SIZE_BUTTON)
1591
 
        self.hbox_location.pack_start(self.image_location_error, False, False, 0)
1592
 
        if sys.platform == 'win32':
1593
 
            self.hbox_location.reorder_child(self.image_location_error, 2)
1594
 
        else:
1595
 
            self.hbox_location.reorder_child(self.image_location_error, 1)
1596
 
        self.image_location_error.show()
1597
 
        while gtk.events_pending():
1598
 
            gtk.main_iteration()
1599
784
 
1600
785
import ConfigParser
1601
786
 
1602
 
class Preferences:
 
787
class OlivePreferences:
1603
788
    """ A class which handles Olive's preferences. """
1604
 
    def __init__(self, path=None):
 
789
    def __init__(self):
1605
790
        """ Initialize the Preferences class. """
1606
791
        # Some default options
1607
792
        self.defaults = { 'strict_commit' : False,
1608
793
                          'dotted_files'  : False,
1609
 
                          'ignored_files' : True,
1610
794
                          'window_width'  : 700,
1611
795
                          'window_height' : 400,
1612
796
                          'window_x'      : 40,
1615
799
 
1616
800
        # Create a config parser object
1617
801
        self.config = ConfigParser.RawConfigParser()
1618
 
 
1619
 
        # Set filename
1620
 
        if path is None:
1621
 
            if sys.platform == 'win32':
1622
 
                # Windows - no dotted files
1623
 
                self._filename = os.path.expanduser('~/olive.conf')
1624
 
            else:
1625
 
                self._filename = os.path.expanduser('~/.olive.conf')
1626
 
        else:
1627
 
            self._filename = path
1628
802
        
1629
803
        # Load the configuration
1630
804
        self.read()
1647
821
 
1648
822
    def read(self):
1649
823
        """ Just read the configuration. """
1650
 
        # Re-initialize the config parser object to avoid some bugs
1651
 
        self.config = ConfigParser.RawConfigParser()
1652
 
        self.config.read([self._filename])
 
824
        if sys.platform == 'win32':
 
825
            # Windows - no dotted files
 
826
            self.config.read([os.path.expanduser('~/olive.conf')])
 
827
        else:
 
828
            self.config.read([os.path.expanduser('~/.olive.conf')])
1653
829
    
1654
830
    def write(self):
1655
831
        """ Write the configuration to the appropriate files. """
1656
 
        fp = open(self._filename, 'w')
1657
 
        self.config.write(fp)
1658
 
        fp.close()
 
832
        if sys.platform == 'win32':
 
833
            # Windows - no dotted files
 
834
            fp = open(os.path.expanduser('~/olive.conf'), 'w')
 
835
            self.config.write(fp)
 
836
            fp.close()
 
837
        else:
 
838
            fp = open(os.path.expanduser('~/.olive.conf'), 'w')
 
839
            self.config.write(fp)
 
840
            fp.close()
1659
841
 
1660
842
    def get_bookmarks(self):
1661
843
        """ Return the list of bookmarks. """
1684
866
    
1685
867
    def set_bookmark_title(self, path, title):
1686
868
        """ Set bookmark title. """
1687
 
        # FIXME: What if path isn't listed yet?
1688
 
        # FIXME: Canonicalize paths first?
1689
869
        self.config.set(path, 'title', title)
1690
870
    
1691
871
    def remove_bookmark(self, path):
1694
874
 
1695
875
    def set_preference(self, option, value):
1696
876
        """ Set the value of the given option. """
1697
 
        if value is True:
1698
 
            value = 'yes'
1699
 
        elif value is False:
1700
 
            value = 'no'
1701
 
        
1702
877
        if self.config.has_section('preferences'):
1703
878
            self.config.set('preferences', option, value)
1704
879
        else:
1712
887
        """
1713
888
        if self.config.has_option('preferences', option):
1714
889
            if kind == 'bool':
1715
 
                return self.config.getboolean('preferences', option)
 
890
                #return self.config.getboolean('preferences', option)
 
891
                return True
1716
892
            elif kind == 'int':
1717
893
                return self.config.getint('preferences', option)
1718
894
            elif kind == 'float':