/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: 2007-05-18 16:01:10 UTC
  • mto: This revision was merged to the branch mainline in revision 201.
  • Revision ID: szilveszter.farkas@gmail.com-20070518160110-curir2hdf024r2e2
The History feature kinda works now, but still needs some polishing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
53
53
from bzrlib.plugins.gtk.conflicts import ConflictsDialog
54
54
from bzrlib.plugins.gtk.initialize import InitDialog
55
55
from bzrlib.plugins.gtk.push import PushDialog
 
56
from bzrlib.plugins.gtk.revbrowser import RevisionBrowser
56
57
 
57
58
class OliveGtk:
58
59
    """ The main Olive GTK frontend class. This is called when launching the
117
118
        self.entry_location = self.toplevel.get_widget('entry_location')
118
119
        self.image_location_error = self.toplevel.get_widget('image_location_error')
119
120
        
 
121
        # Get the History widgets
 
122
        self.check_history = self.toplevel.get_widget('checkbutton_history')
 
123
        self.entry_history = self.toplevel.get_widget('entry_history_revno')
 
124
        self.button_history = self.toplevel.get_widget('button_history_browse')
 
125
        
120
126
        self.vbox_main_right = self.toplevel.get_widget('vbox_main_right')
121
127
        
122
128
        # Dictionary for signal_autoconnect
160
166
                "on_treeview_left_row_activated": self.on_treeview_left_row_activated,
161
167
                "on_button_location_up_clicked": self.on_button_location_up_clicked,
162
168
                "on_button_location_jump_clicked": self.on_button_location_jump_clicked,
163
 
                "on_entry_location_key_press_event": self.on_entry_location_key_press_event
 
169
                "on_entry_location_key_press_event": self.on_entry_location_key_press_event,
 
170
                "on_checkbutton_history_toggled": self.on_checkbutton_history_toggled,
 
171
                "on_entry_history_revno_key_press_event": self.on_entry_history_revno_key_press_event,
 
172
                "on_button_history_browse_clicked": self.on_button_history_browse_clicked
164
173
            }
165
174
        
166
175
        # Connect the signals to the handlers
202
211
        self.remote = False
203
212
        self.remote_branch = None
204
213
        self.remote_path = None
 
214
        self.remote_revision = None
205
215
        
206
216
        self.set_path(os.getcwd())
207
217
        self._load_right()
208
218
        
209
219
        self._just_started = False
210
220
 
211
 
    def set_path(self, path):
 
221
    def set_path(self, path, force_remote=False):
212
222
        self.notbranch = False
213
223
        
214
 
        if os.path.isdir(path):
215
 
            self.image_location_error.destroy()
216
 
            self.remote = False
217
 
            
218
 
            # We're local
219
 
            try:
220
 
                self.wt, self.wtpath = WorkingTree.open_containing(path)
221
 
            except (bzrerrors.NotBranchError, bzrerrors.NoWorkingTree):
222
 
                self.notbranch = True
223
 
            
224
 
            # If we're in the root, we cannot go up anymore
225
 
            if sys.platform == 'win32':
226
 
                drive, tail = os.path.splitdrive(path)
227
 
                if tail in ('', '/', '\\'):
228
 
                    self.button_location_up.set_sensitive(False)
229
 
                else:
230
 
                    self.button_location_up.set_sensitive(True)
231
 
            else:
232
 
                if self.path == '/':
233
 
                    self.button_location_up.set_sensitive(False)
234
 
                else:
235
 
                    self.button_location_up.set_sensitive(True)
236
 
        elif not os.path.isfile(path):
237
 
            # Doesn't seem to be a file nor a directory, trying to open a
238
 
            # remote location
 
224
        if force_remote:
 
225
            # Forcing remote mode (reading data from inventory)
239
226
            self._show_stock_image(gtk.STOCK_DISCONNECT)
240
227
            try:
241
228
                br = Branch.open_containing(path)[0]
242
229
            except bzrerrors.NotBranchError:
243
230
                self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
 
231
                self.check_history.set_active(False)
 
232
                self.check_history.set_sensitive(False)
244
233
                return False
245
234
            except bzrerrors.UnsupportedProtocol:
246
235
                self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
 
236
                self.check_history.set_active(False)
 
237
                self.check_history.set_sensitive(False)
247
238
                return False
248
239
            
249
240
            self._show_stock_image(gtk.STOCK_CONNECT)
253
244
            # We're remote
254
245
            self.remote_branch, self.remote_path = Branch.open_containing(path)
255
246
            
256
 
            self.remote_entries = self.remote_branch.repository.get_inventory(self.remote_branch.last_revision()).entries()
 
247
            if self.remote_revision is None:
 
248
                self.remote_entries = self.remote_branch.repository.get_inventory(self.remote_branch.last_revision()).entries()
 
249
            else:
 
250
                self.remote_entries = self.remote_branch.repository.get_inventory(self.remote_revision).entries()
257
251
            
258
252
            if len(self.remote_path) == 0:
259
253
                self.remote_parent = self.remote_branch.repository.get_inventory(self.remote_branch.last_revision()).iter_entries_by_dir().next()[1].file_id
270
264
                self.button_location_up.set_sensitive(False)
271
265
            else:
272
266
                self.button_location_up.set_sensitive(True)
 
267
        else:
 
268
            if os.path.isdir(path):
 
269
                self.image_location_error.destroy()
 
270
                self.remote = False
 
271
                
 
272
                # We're local
 
273
                try:
 
274
                    self.wt, self.wtpath = WorkingTree.open_containing(path)
 
275
                except (bzrerrors.NotBranchError, bzrerrors.NoWorkingTree):
 
276
                    self.notbranch = True
 
277
                
 
278
                # If we're in the root, we cannot go up anymore
 
279
                if sys.platform == 'win32':
 
280
                    drive, tail = os.path.splitdrive(path)
 
281
                    if tail in ('', '/', '\\'):
 
282
                        self.button_location_up.set_sensitive(False)
 
283
                    else:
 
284
                        self.button_location_up.set_sensitive(True)
 
285
                else:
 
286
                    if self.path == '/':
 
287
                        self.button_location_up.set_sensitive(False)
 
288
                    else:
 
289
                        self.button_location_up.set_sensitive(True)
 
290
            elif not os.path.isfile(path):
 
291
                # Doesn't seem to be a file nor a directory, trying to open a
 
292
                # remote location
 
293
                self._show_stock_image(gtk.STOCK_DISCONNECT)
 
294
                try:
 
295
                    br = Branch.open_containing(path)[0]
 
296
                except bzrerrors.NotBranchError:
 
297
                    self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
 
298
                    self.check_history.set_active(False)
 
299
                    self.check_history.set_sensitive(False)
 
300
                    return False
 
301
                except bzrerrors.UnsupportedProtocol:
 
302
                    self._show_stock_image(gtk.STOCK_DIALOG_ERROR)
 
303
                    self.check_history.set_active(False)
 
304
                    self.check_history.set_sensitive(False)
 
305
                    return False
 
306
                
 
307
                self._show_stock_image(gtk.STOCK_CONNECT)
 
308
                
 
309
                self.remote = True
 
310
               
 
311
                # We're remote
 
312
                self.remote_branch, self.remote_path = Branch.open_containing(path)
 
313
                
 
314
                if self.remote_revision is None:
 
315
                    self.remote_entries = self.remote_branch.repository.get_inventory(self.remote_branch.last_revision()).entries()
 
316
                else:
 
317
                    self.remote_entries = self.remote_branch.repository.get_inventory(self.remote_revision).entries()
 
318
                
 
319
                if len(self.remote_path) == 0:
 
320
                    self.remote_parent = self.remote_branch.repository.get_inventory(self.remote_branch.last_revision()).iter_entries_by_dir().next()[1].file_id
 
321
                else:
 
322
                    for (name, type) in self.remote_entries:
 
323
                        if name == self.remote_path:
 
324
                            self.remote_parent = type.file_id
 
325
                            break
 
326
                
 
327
                if not path.endswith('/'):
 
328
                    path += '/'
 
329
                
 
330
                if self.remote_branch.base == path:
 
331
                    self.button_location_up.set_sensitive(False)
 
332
                else:
 
333
                    self.button_location_up.set_sensitive(True)
 
334
        
 
335
        if self.notbranch:
 
336
            self.check_history.set_active(False)
 
337
            self.check_history.set_sensitive(False)
 
338
        else:
 
339
            self.check_history.set_sensitive(True)
273
340
        
274
341
        self.statusbar.push(self.context_id, path)
275
342
        self.entry_location.set_text(path)
290
357
        from bzrlib.plugins.gtk.dialog import about
291
358
        about()
292
359
        
 
360
    
 
361
    def on_button_history_browse_clicked(self, widget):
 
362
        """ Browse for revision button handler. """
 
363
        if self.remote:
 
364
            br = self.remote_branch
 
365
        else:
 
366
            br = self.wt.branch
 
367
            
 
368
        revb = RevisionBrowser(br, self.window)
 
369
        response = revb.run()
 
370
        if response != gtk.RESPONSE_NONE:
 
371
            revb.hide()
 
372
        
 
373
            if response == gtk.RESPONSE_OK:
 
374
                if revb.selected_revno is not None:
 
375
                    self.entry_history.set_text(revb.selected_revno)
 
376
            
 
377
            revb.destroy()
 
378
    
 
379
    def on_button_location_jump_clicked(self, widget):
 
380
        """ Location Jump button handler. """
 
381
        location = self.entry_location.get_text()
 
382
        
 
383
        if self.set_path(location):
 
384
            self.refresh_right()
 
385
    
293
386
    def on_button_location_up_clicked(self, widget):
294
387
        """ Location Up button handler. """
295
388
        if not self.remote:
304
397
 
305
398
        self.refresh_right()
306
399
    
307
 
    def on_button_location_jump_clicked(self, widget):
308
 
        """ Location Jump button handler. """
309
 
        location = self.entry_location.get_text()
310
 
        
311
 
        if self.set_path(location):
312
 
            self.refresh_right()
 
400
    def on_checkbutton_history_toggled(self, widget):
 
401
        """ History Mode toggle handler. """
 
402
        if self.check_history.get_active():
 
403
            # History Mode activated
 
404
            self.entry_history.set_sensitive(True)
 
405
            self.button_history.set_sensitive(True)
 
406
        else:
 
407
            # History Mode deactivated
 
408
            self.entry_history.set_sensitive(False)
 
409
            self.button_history.set_sensitive(False)
 
410
    
 
411
    def on_entry_history_revno_key_press_event(self, widget, event):
 
412
        """ Key pressed handler for the history entry. """
 
413
        if event.keyval == 65293:
 
414
            # Return was hit, so we have to load that specific revision
 
415
            # Emulate being remote, so inventory should be used
 
416
            path = self.get_path()
 
417
            if not self.remote:
 
418
                self.remote = True
 
419
                self.remote_branch = self.wt.branch
 
420
            
 
421
            revno = int(self.entry_history.get_text())
 
422
            self.remote_revision = self.remote_branch.get_rev_id(revno)
 
423
            if self.set_path(path, True):
 
424
                self.refresh_right()
313
425
    
314
426
    def on_entry_location_key_press_event(self, widget, event):
315
427
        """ Key pressed handler for the location entry. """
650
762
                m_annotate.set_sensitive(False)
651
763
                m_diff.set_sensitive(False)
652
764
 
653
 
            menu.right_context_menu().popup(None, None, None, 0,
654
 
                                            event.time)
 
765
            if not self.remote:
 
766
                menu.right_context_menu().popup(None, None, None, 0,
 
767
                                                event.time)
 
768
            else:
 
769
                menu.remote_context_menu().popup(None, None, None, 0,
 
770
                                                 event.time)
655
771
        
656
772
    def on_treeview_right_row_activated(self, treeview, path, view_column):
657
773
        """ Occurs when somebody double-clicks or enters an item in the