various fixes
authorgc <gc>
Mon, 4 Jul 2005 20:41:28 +0000 (20:41 +0000)
committergc <gc>
Mon, 4 Jul 2005 20:41:28 +0000 (20:41 +0000)
bin/booh

index 4050cfb0590aa009f15a43215fc2b5988e4d56ea..531031cd4839fb4a9199a697252a7569258f1621 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -1088,10 +1088,12 @@ def save_current_file
 end
 
 def save_current_file_user
+    save_tempfilename = $filename
     $filename = $orig_filename
     save_current_file
     $modified = false
     $generated_outofline = false
+    $filename = save_tempfilename
 end
 
 #- ret: true => ok  false => cancel
@@ -1135,6 +1137,7 @@ def ask_save_modifications(msg1, msg2, *options)
                         $xmldoc.write(ios, 0)
                         ios.close
                     rescue Exception
+                        puts "exception: #{$!}"
                     end
                 end
             end
@@ -1259,6 +1262,7 @@ def backend_wait_message(parent, msg, infopipe_path, mode)
     w.signal_connect('delete-event') { w.destroy }
     w.signal_connect('destroy') {
         Thread.kill(refresh_thread)
+        gtk_thread_abandon  #- needed because we're about to destroy widgets in w, for which they may be some pending gtk calls
         if infopipe_path
             infopipe.close
             system("rm -f #{infopipe_path}")
@@ -1312,16 +1316,40 @@ def save_changes(*forced)
 
     $xmldir.delete_attribute('already-generated')
 
+    propagate_children = Proc.new { |xmldir|
+        if xmldir.attributes['subdirs-caption']
+            xmldir.delete_attribute('already-generated')
+        end
+        xmldir.elements.each('dir') { |element|
+            propagate_children.call(element)
+        }
+    }
+
     if $xmldir.child_byname_notattr('dir', 'deleted')
-        $xmldir.add_attribute('subdirs-caption', $subalbums_title.buffer.text)
+        new_title = $subalbums_title.buffer.text
+        if new_title != $xmldir.attributes['subdirs-caption']
+            parent = $xmldir.parent
+            if parent.name == 'dir'
+                parent.delete_attribute('already-generated')
+            end
+            propagate_children.call($xmldir)
+        end
+        $xmldir.add_attribute('subdirs-caption', new_title)
         $xmldir.elements.each('dir') { |element|
             if !element.attributes['deleted']
                 path = element.attributes['path']
+                newtext = $subalbums_edits[path][:editzone].buffer.text
                 if element.attributes['subdirs-caption']
-                    element.add_attribute('subdirs-caption',     $subalbums_edits[path][:editzone].buffer.text)
+                    if element.attributes['subdirs-caption'] != newtext
+                        propagate_children.call(element)
+                    end
+                    element.add_attribute('subdirs-caption',     newtext)
                     element.add_attribute('subdirs-captionfile', utf8($subalbums_edits[path][:captionfile]))
                 else
-                    element.add_attribute('thumbnails-caption',     $subalbums_edits[path][:editzone].buffer.text)
+                    if element.attributes['thumbnails-caption'] != newtext
+                        element.delete_attribute('already-generated')
+                    end
+                    element.add_attribute('thumbnails-caption',     newtext)
                     element.add_attribute('thumbnails-captionfile', utf8($subalbums_edits[path][:captionfile]))
                 end
             end
@@ -2113,10 +2141,11 @@ def new_album
     configskel = File.expand_path(from_utf8(conf.text))
     theme = theme_button.label
     sizes = theme_sizes.find_all { |e| e[:widget].active? }.collect { |e| e[:value] }.join(',')
-    dialog.destroy
     if src_nb_thread
         Thread.kill(src_nb_thread)
+        gtk_thread_abandon  #- needed because we're about to destroy widgets in dialog, for which they may be some pending gtk calls
     end
+    dialog.destroy
     Gtk.timeout_remove(timeout_src_nb)
 
     if ok
@@ -2154,7 +2183,7 @@ def properties
                1, 2, 2, 3, Gtk::FILL, Gtk::SHRINK, 2, 2)
     tbl.attach(Gtk::Label.new(utf8(_("Filename where this album's properties are stored: "))),
                0, 1, 3, 4, Gtk::SHRINK, Gtk::SHRINK, 2, 2)
-    tbl.attach(Gtk::Alignment.new(0, 0.5, 0, 0).add(Gtk::Label.new.set_markup('<i>' + $filename + '</i>')),
+    tbl.attach(Gtk::Alignment.new(0, 0.5, 0, 0).add(Gtk::Label.new.set_markup('<i>' + $orig_filename + '</i>')),
                1, 2, 3, 4, Gtk::FILL, Gtk::SHRINK, 2, 2)
 
     frame2 = Gtk::Frame.new(utf8(_("Configuration"))).add(tbl = Gtk::Table.new(0, 0, false))
@@ -2283,7 +2312,7 @@ def save_as_do
     fc.transient_for = $main_window
     fc.add_shortcut_folder(File.expand_path("~/.booh"))
     fc.set_current_folder(File.expand_path("~/.booh"))
-    fc.filename = $filename
+    fc.filename = $orig_filename
     if fc.run == Gtk::Dialog::RESPONSE_ACCEPT
         $orig_filename = fc.filename
         save_current_file_user
@@ -2669,6 +2698,12 @@ def gtk_thread_protect(&proc)
     end
 end
 
+def gtk_thread_abandon
+    $protect_gtk_pending_calls.try_lock
+    $gtk_pending_calls = []
+    $protect_gtk_pending_calls.unlock
+end
+
 def create_main_window
 
     mb, tb = create_menu_and_toolbar
@@ -2765,6 +2800,7 @@ def create_main_window
             $gtk_pending_calls.each { |c| c.call }
             $gtk_pending_calls = []
         }
+        true
     }
 
     $statusbar.push(0, utf8(_("Ready.")))