add ability to restore deleted images/videos/subalbums (suggested by JC)
authorgc <gc>
Mon, 26 Dec 2005 16:24:13 +0000 (16:24 +0000)
committergc <gc>
Mon, 26 Dec 2005 16:24:13 +0000 (16:24 +0000)
bin/booh
data/booh/images/restore.png [new file with mode: 0644]

index 38ca520fa15f8d139ff3d80a1fade16993c71228..fbb4cafc506e03d644db0115faac1aa1874c653a 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -864,6 +864,8 @@ def popup_thumbnail_menu(event, optionals, fullpath, type, xmldir, attributes_pr
 end
 
 def delete_current_subalbum
+    $modified = true
+    sel = $albums_tv.selection.selected_rows
     $xmldir.elements.each { |e|
         if e.name == 'image' || e.name == 'video'
             e.add_attribute('deleted', 'true')
@@ -884,9 +886,29 @@ def delete_current_subalbum
                 break
             end
         end
+        sel[0].up!
     end
     save_changes('forced')
-    populate_subalbums_treeview
+    populate_subalbums_treeview(false)
+    $albums_tv.selection.select_path(sel[0])
+end
+
+def restore_deleted
+    $modified = true
+    save_changes
+    $current_path = nil  #- prevent save_changes from being rerun again
+    sel = $albums_tv.selection.selected_rows
+    restore_one = proc { |xmldir|
+        xmldir.elements.each { |e|
+            if e.name == 'dir' && e.attributes['deleted']
+                restore_one.call(e)
+            end
+            e.delete_attribute('deleted')
+        }
+    }
+    restore_one.call($xmldir)
+    populate_subalbums_treeview(false)
+    $albums_tv.selection.select_path(sel[0])
 end
 
 def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
@@ -2294,7 +2316,7 @@ def show_password_protections
     examine_dir_elem.call(nil, $xmldoc.elements['//dir'], false)
 end
 
-def populate_subalbums_treeview
+def populate_subalbums_treeview(select_first)
     $albums_ts.clear
     $autotable.clear
     $albums_iters = {}
@@ -2327,7 +2349,9 @@ def populate_subalbums_treeview
     show_password_protections
 
     $albums_tv.expand_all
-    $albums_tv.selection.select_iter($albums_ts.iter_first)
+    if select_first
+        $albums_tv.selection.select_iter($albums_ts.iter_first)
+    end
 end
 
 def open_file(filename)
@@ -2418,7 +2442,7 @@ def open_file(filename)
     $albums_thumbnail_size =~ /(.*)x(.*)/
     $default_albums_thumbnails = { :x => $1.to_i, :y => $2.to_i }
 
-    populate_subalbums_treeview
+    populate_subalbums_treeview(true)
 
     $save.sensitive = $save_as.sensitive = $merge_current.sensitive = $merge_newsubs.sensitive = $merge.sensitive = $generate.sensitive = $view_wa.sensitive = $properties.sensitive = $remove_all_captions.sensitive = true
     return nil
@@ -3824,6 +3848,9 @@ def create_main_window
             menu.append(passprotect = Gtk::ImageMenuItem.new(utf8(_("Password protect"))))
             passprotect.image = Gtk::Image.new("#{$FPATH}/images/galeon-secure.png")
             passprotect.signal_connect('activate') { ask_password_protect }
+            menu.append(restore = Gtk::ImageMenuItem.new(utf8(_("Restore deleted images/videos/subalbums"))))
+            restore.image = Gtk::Image.new("#{$FPATH}/images/restore.png")
+            restore.signal_connect('activate') { restore_deleted }
             menu.append(Gtk::SeparatorMenuItem.new)
             menu.append(delete = Gtk::ImageMenuItem.new(Gtk::Stock::DELETE))
             delete.signal_connect('activate') {
diff --git a/data/booh/images/restore.png b/data/booh/images/restore.png
new file mode 100644 (file)
index 0000000..cfaea21
Binary files /dev/null and b/data/booh/images/restore.png differ