correctly handle completely removed subalbums
authorgc <gc>
Sun, 8 May 2005 17:44:23 +0000 (17:44 +0000)
committergc <gc>
Sun, 8 May 2005 17:44:23 +0000 (17:44 +0000)
bin/booh

index 8cf429ff79dc7aca9b62df0abb14c06a65fa8bf9..a24de9c65b4913f9b93ef28c3a9c6ae4f4e1aeef 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -579,29 +579,42 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
     }
 
     delete = Proc.new {
-        $modified = true
-        perform_delete = Proc.new {
-            after = autotable.get_next_widget(vbox)
+        if autotable.current_order.size > 1 || show_popup($main_window, utf8(_("Do you confirm this subalbum needs to be completely removed?")), { :okcancel => true })
+            $modified = true
+            after = nil
+            perform_delete = Proc.new {
+                after = autotable.get_next_widget(vbox)
+                if !after
+                    after = autotable.get_previous_widget(vbox)
+                end
+                autotable.remove(vbox)
+                if after
+                    $vbox2textview[after].grab_focus
+                end
+            }
+            
+            perform_delete.call
+
             if !after
-                after = autotable.get_previous_widget(vbox)
-            end
-            autotable.remove(vbox)
-            if after
-                $vbox2textview[after].grab_focus
+                if $xmldir.elements['dir']
+                    $xmldir.delete_attribute('thumbnails-caption')
+                    $xmldir.delete_attribute('thumbnails-captionfile')
+                else
+                    $xmldir.remove
+                end
+                populate_subalbums_treeview
+            else
+                save_undo(_("delete"),
+                          Proc.new { |pos|
+                              autotable.reinsert(pos, vbox, filename)
+                              $notebook.set_page(1)
+                              Proc.new {
+                                  perform_delete.call
+                                  $notebook.set_page(1)
+                              }
+                          }, autotable.get_current_number(vbox))
             end
-        }
-
-        save_undo(_("delete"),
-                  Proc.new { |pos|
-                      autotable.reinsert(pos, vbox, filename)
-                      $notebook.set_page(1)
-                      Proc.new {
-                          perform_delete.call
-                          $notebook.set_page(1)
-                      }
-                  }, autotable.get_current_number(vbox))
-
-        perform_delete.call
+        end
     }
 
     textview.signal_connect('key-press-event') { |w, event|
@@ -1220,6 +1233,37 @@ def theme_choose(current)
     return nil
 end
 
+def populate_subalbums_treeview
+    $albums_ts.clear
+    $autotable.clear
+    $subalbums_vb.children.each { |chld|
+        $subalbums_vb.remove(chld)
+    }
+
+    source = $xmldoc.root.attributes['source']
+    msg 3, "source: #{source}"
+
+    xmldir = $xmldoc.elements["//dir[@path='#{source}']"]
+    if !xmldir
+        msg 1, _("Corrupted booh file...")
+        return
+    end
+
+    append_dir_elem = Proc.new { |parent_iter, location|
+        child_iter = $albums_ts.append(parent_iter)
+        child_iter[0] = File.basename(location)
+        child_iter[1] = location
+        msg 3, "puttin location: #{location}"
+        $xmldoc.elements.each("//dir[@path='#{location}']/dir") { |elem|
+            append_dir_elem.call(child_iter, elem.attributes['path'])
+        }
+    }
+    append_dir_elem.call(nil, source)
+
+    $albums_tv.expand_all
+    $albums_tv.selection.select_iter($albums_ts.iter_first)
+end
+
 def open_file(filename)
 
     $filename = nil
@@ -1271,26 +1315,7 @@ def open_file(filename)
     $albums_thumbnail_size =~ /(.*)x(.*)/
     $default_albums_thumbnails = { :x => $1.to_i, :y => $2.to_i }
 
-    msg 3, "source: #{source}"
-
-    xmldir = $xmldoc.elements["//dir[@path='#{source}']"]
-    if !xmldir
-        return utf8(_("Corrupted booh file..."))
-    end
-
-    append_dir_elem = Proc.new { |parent_iter, location|
-        child_iter = $albums_ts.append(parent_iter)
-        child_iter[0] = File.basename(location)
-        child_iter[1] = location
-        msg 3, "puttin location: #{location}"
-        $xmldoc.elements.each("//dir[@path='#{location}']/dir") { |elem|
-            append_dir_elem.call(child_iter, elem.attributes['path'])
-        }
-    }
-    append_dir_elem.call(nil, source)
-
-    $albums_tv.expand_all
-    $albums_tv.selection.select_iter($albums_ts.iter_first)
+    populate_subalbums_treeview
 
     $config['last-opens'] ||= []
     if $config['last-opens'][-1] != utf8(filename)