[Pkg-bazaar-commits] ./bzr-gtk/unstable r120: Use OliveRemoveDialog class instead of OliveRemove.

Szilveszter Farkas (Phanatic) Szilveszter.Farkas at gmail.com
Fri Apr 10 07:49:44 UTC 2009


------------------------------------------------------------
revno: 120
committer: Szilveszter Farkas (Phanatic) <Szilveszter.Farkas at gmail.com>
branch nick: bzr-gtk
timestamp: Sat 2006-12-16 16:44:16 +0100
message:
  Use OliveRemoveDialog class instead of OliveRemove.
  
  Fixed: #73766 and #73767.
modified:
  olive/__init__.py
  olive/menu.py
  olive/remove.py
-------------- next part --------------
=== modified file 'olive/__init__.py'
--- a/olive/__init__.py	2006-12-15 18:10:16 +0000
+++ b/olive/__init__.py	2006-12-16 15:44:16 +0000
@@ -348,9 +348,21 @@
 
     def on_menuitem_remove_file_activate(self, widget):
         """ Remove (unversion) selected file. """
-        from remove import OliveRemove
-        remove = OliveRemove(self.wt, self.wtpath, self.get_selected_right())
-        remove.display()
+        from remove import OliveRemoveDialog
+        remove = OliveRemoveDialog(self.wt, self.wtpath,
+                                   selected=self.get_selected_right(),
+                                   parent=self.window,
+                                   single=False)
+        response = remove.run()
+        
+        if response != gtk.RESPONSE_NONE:
+            remove.hide()
+        
+            if response == gtk.RESPONSE_OK:
+                self.set_path(self.path)
+                self.refresh_right()
+            
+            remove.destroy()
     
     def on_menuitem_stats_diff_activate(self, widget):
         """ Statistics/Differences... menu handler. """
@@ -414,7 +426,9 @@
         if event.button == 3:
             # Create a menu
             from menu import OliveMenu
-            menu = OliveMenu(self.get_path(), self.get_selected_right())
+            menu = OliveMenu(path=self.get_path(),
+                             selected=self.get_selected_right(),
+                             app=self)
             # get the menu items
             m_add = menu.ui.get_widget('/context_right/add')
             m_remove = menu.ui.get_widget('/context_right/remove')

=== modified file 'olive/menu.py'
--- a/olive/menu.py	2006-12-13 13:06:49 +0000
+++ b/olive/menu.py	2006-12-16 15:44:16 +0000
@@ -34,7 +34,7 @@
 
 class OliveMenu:
     """ This class is responsible for building the context menus. """
-    def __init__(self, path, selected):
+    def __init__(self, path, selected, app=None):
         # Load the UI file
         from guifiles import UIFILENAME
 
@@ -46,6 +46,7 @@
         # Set default values
         self.path = path
         self.selected = selected
+        self.app = app
         
         # Create the file list context menu
         self.ui = gtk.UIManager()
@@ -161,7 +162,7 @@
             return
         
         try:
-            wt, path = WorkingTree.open_containing(directory + os.sep + filename)
+            wt, path = WorkingTree.open_containing(os.path.join(directory, filename))
             wt.remove(path)
 
         except errors.NotBranchError:
@@ -173,6 +174,9 @@
                          _('The selected file is not versioned.'))
             return
 
+        self.app.set_path(self.path)
+        self.app.refresh_right()
+
     def rename_file(self, action):
         """ Right context menu -> Rename """
         from rename import OliveRename

=== modified file 'olive/remove.py'
--- a/olive/remove.py	2006-10-25 16:29:18 +0000
+++ b/olive/remove.py	2006-12-16 15:44:16 +0000
@@ -93,3 +93,69 @@
     
     def close(self, widget=None):
         self.window.destroy()
+
+class OliveRemoveDialog(gtk.Dialog):
+    """ This class wraps the old Remove window into a gtk.Dialog. """
+    
+    def __init__(self, wt, wtpath, selected=[], parent=None, single=False):
+        """ Initialize the Remove file(s) dialog. """
+        gtk.Dialog.__init__(self, title="Remove files - Olive",
+                                  parent=parent,
+                                  flags=0,
+                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
+        
+        # Get arguments
+        self.wt = wt
+        self.wtpath = wtpath
+        self.selected = selected
+        self.single = single
+        
+        # Create widgets
+        self._label = gtk.Label(_("Which file(s) do you want to remove?"))
+        self._radio_selected = gtk.RadioButton(None, _("Selected only"), False)
+        self._radio_added = gtk.RadioButton(self._radio_selected, _("All files with status 'added'"), False)
+        self._button_remove = gtk.Button(_("_Remove"), use_underline=True)
+        
+        self._button_remove.connect('clicked', self._on_remove_clicked)
+        
+        self.vbox.pack_start(self._label)
+        self.vbox.pack_end(self._radio_added)
+        self.vbox.pack_end(self._radio_selected)
+        
+        self.action_area.pack_end(self._button_remove)
+        
+        self.vbox.set_spacing(3)
+        self.vbox.show_all()
+        
+    def _on_remove_clicked(self, button):
+        """ Remove button clicked handler. """
+        if self._radio_selected.get_active():
+            # Remove only the selected file
+            filename = self.selected
+            
+            if filename is None:
+                error_dialog(_('No file was selected'),
+                             _('Please select a file from the list,\nor choose the other option.'))
+                return
+            
+            try:
+                self.wt.remove(os.path.join(self.wtpath, filename))
+            except errors.NotBranchError:
+                error_dialog(_('Directory is not a branch'),
+                             _('You can perform this action only in a branch.'))
+                return
+            except errors.NotVersionedError:
+                error_dialog(_('File not versioned'),
+                             _('The selected file is not versioned.'))
+                return
+        elif self._radio_added.get_active():
+            # Remove added files recursively
+            added = self.wt.changes_from(self.wt.basis_tree()).added
+            file_list = sorted([f[0] for f in added], reverse=True)
+            if len(file_list) == 0:
+                warning_dialog(_('No matching files'),
+                               _('No added files were found in the working tree.'))
+                return
+            self.wt.remove(file_list)
+        
+        self.response(gtk.RESPONSE_OK)



More information about the Pkg-bazaar-commits mailing list