fix multiple calls
authorgc <gc>
Tue, 15 Nov 2005 21:28:32 +0000 (21:28 +0000)
committergc <gc>
Tue, 15 Nov 2005 21:28:32 +0000 (21:28 +0000)
bin/booh

index 64378bd97dd543f2b05d44ef2d8409028df02bac..747a53e0c08252129c9f96df7a5c437e25e9c426 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -550,7 +550,7 @@ def ask_new_pano_amount(xmldir, attributes_prefix)
     if xmldir
         value = xmldir.attributes["#{attributes_prefix}pano-amount"]
     else
-        value = ''
+        value = nil
     end
 
     dialog = Gtk::Dialog.new(utf8(_("Specify panorama amount")),
@@ -631,7 +631,7 @@ def ask_whitebalance(orig, thumbnail_img, img_, xmlelem, attributes_prefix, desi
     #- init $modified_pixbufs correctly
 #    update_shown_pixbuf(thumbnail_img, img_, desired_x, desired_y)
 
-    value = xmlelem.attributes["#{attributes_prefix}white-balance"] || "0"
+    value = xmlelem ? (xmlelem.attributes["#{attributes_prefix}white-balance"] || "0") : "0"
 
     dialog = Gtk::Dialog.new(utf8(_("Fix white balance")),
                              $main_window,
@@ -646,7 +646,9 @@ or too yellow because your camera didn't detect the light correctly. Drag the
 slider below the image to the left for more blue, to the right for more yellow.
 "))
     dialog.vbox.add(lbl)
-    dialog.vbox.add(evt = Gtk::EventBox.new.add(img = Gtk::Image.new(img_.pixbuf)))
+    if img_
+        dialog.vbox.add(evt = Gtk::EventBox.new.add(img = Gtk::Image.new(img_.pixbuf)))
+    end
     dialog.vbox.add(hs = Gtk::HScale.new(-200, 200, 1).set_value(value.to_i))
     
     dialog.window_position = Gtk::Window::POS_MOUSE
@@ -656,7 +658,9 @@ slider below the image to the left for more blue, to the right for more yellow.
     timeout = Gtk.timeout_add(100) {
         if hs.value != lastval
             lastval = hs.value
-            recalc_whitebalance(lastval, orig, thumbnail_img, img, xmlelem, attributes_prefix, desired_x, desired_y, infotype)
+            if img_
+                recalc_whitebalance(lastval, orig, thumbnail_img, img, xmlelem, attributes_prefix, desired_x, desired_y, infotype)
+            end
         end
         true
     }
@@ -670,9 +674,11 @@ slider below the image to the left for more blue, to the right for more yellow.
             dialog.destroy
             return { :old => value, :new => newval }
         else
-            $modified_pixbufs[thumbnail_img] ||= {}
-            $modified_pixbufs[thumbnail_img][:whitebalance] = value.to_f
-            $modified_pixbufs[thumbnail_img][:pixbuf] = img_.pixbuf
+            if thumbnail_img
+                $modified_pixbufs[thumbnail_img] ||= {}
+                $modified_pixbufs[thumbnail_img][:whitebalance] = value.to_f
+                $modified_pixbufs[thumbnail_img][:pixbuf] = img_.pixbuf
+            end
             dialog.destroy
             return nil
         end
@@ -721,27 +727,29 @@ def popup_thumbnail_menu(event, optionals, fullpath, type, xmldir, attributes_pr
         menu.append(changeimg = Gtk::ImageMenuItem.new(utf8(_("Change image"))))
         changeimg.image = Gtk::Image.new("#{$FPATH}/images/stock-images-16.png")
         changeimg.signal_connect('activate') { closures[:change].call }
-        menu.append(            Gtk::SeparatorMenuItem.new)
+        menu.append(Gtk::SeparatorMenuItem.new)
     end
-    if closures[:view]
-        if type == 'image'
-            menu.append(view = Gtk::ImageMenuItem.new(utf8(_("View larger"))))
-            view.image = Gtk::Image.new("#{$FPATH}/images/stock-view-16.png")
-            view.signal_connect('activate') { closures[:view].call }
-        else
-            menu.append(view = Gtk::ImageMenuItem.new(utf8(_("Play video"))))
-            view.image = Gtk::Image.new("#{$FPATH}/images/stock-video-16.png")
-            view.signal_connect('activate') { closures[:view].call }
-            menu.append(               Gtk::SeparatorMenuItem.new)
-        end
-    end
-    if type == 'image'
-        menu.append(exif = Gtk::ImageMenuItem.new(utf8(_("View EXIF data"))))
-        exif.image = Gtk::Image.new("#{$FPATH}/images/stock-list-16.png")
-        exif.signal_connect('activate') { show_popup($main_window,
-                                                     utf8(`identify -format "%[EXIF:*]" #{fullpath}`.sub(/MakerNote.*\n/, '')),
-                                                     { :title => utf8(_("EXIF data of %s") % File.basename(fullpath)), :nomarkup => true, :scrolled => true }) }
-        menu.append(               Gtk::SeparatorMenuItem.new)
+    if !possible_actions[:can_multiple] || $selected_elements.length == 0
+        if closures[:view]
+            if type == 'image'
+                menu.append(view = Gtk::ImageMenuItem.new(utf8(_("View larger"))))
+                view.image = Gtk::Image.new("#{$FPATH}/images/stock-view-16.png")
+                view.signal_connect('activate') { closures[:view].call }
+            else
+                menu.append(view = Gtk::ImageMenuItem.new(utf8(_("Play video"))))
+                view.image = Gtk::Image.new("#{$FPATH}/images/stock-video-16.png")
+                view.signal_connect('activate') { closures[:view].call }
+                menu.append(Gtk::SeparatorMenuItem.new)
+            end
+        end
+        if type == 'image' && (!possible_actions[:can_multiple] || $selected_elements.length == 0)
+            menu.append(exif = Gtk::ImageMenuItem.new(utf8(_("View EXIF data"))))
+            exif.image = Gtk::Image.new("#{$FPATH}/images/stock-list-16.png")
+            exif.signal_connect('activate') { show_popup($main_window,
+                                                         utf8(`identify -format "%[EXIF:*]" #{fullpath}`.sub(/MakerNote.*\n/, '')),
+                                                         { :title => utf8(_("EXIF data of %s") % File.basename(fullpath)), :nomarkup => true, :scrolled => true }) }
+            menu.append(Gtk::SeparatorMenuItem.new)
+        end
     end
     menu.append(r90 = Gtk::ImageMenuItem.new(utf8(_("Rotate clockwise"))))
     r90.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-90-16.png")
@@ -750,7 +758,7 @@ def popup_thumbnail_menu(event, optionals, fullpath, type, xmldir, attributes_pr
     r270.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-270-16.png")
     r270.signal_connect('activate') { distribute_multiple_call.call(:rotate, -90) }
     if !possible_actions[:can_multiple] || $selected_elements.length == 0
-        menu.append(               Gtk::SeparatorMenuItem.new)
+        menu.append(Gtk::SeparatorMenuItem.new)
         if !possible_actions[:forbid_left]
             menu.append(moveleft = Gtk::ImageMenuItem.new(utf8(_("Move left"))))
             moveleft.image = Gtk::Image.new("#{$FPATH}/images/stock-move-left.png")
@@ -782,11 +790,11 @@ def popup_thumbnail_menu(event, optionals, fullpath, type, xmldir, attributes_pr
     end
     if type == 'video'
         if !possible_actions[:can_multiple] || $selected_elements.length == 0 || $selected_elements.reject { |k,v| $name2widgets[k][:type] == 'video' }.empty?
-            menu.append(               Gtk::SeparatorMenuItem.new)
-            menu.append(  color_swap = Gtk::ImageMenuItem.new(utf8(_("Red/blue color swap"))))
+            menu.append(Gtk::SeparatorMenuItem.new)
+            menu.append(color_swap = Gtk::ImageMenuItem.new(utf8(_("Red/blue color swap"))))
             color_swap.image = Gtk::Image.new("#{$FPATH}/images/stock-color-triangle-16.png")
             color_swap.signal_connect('activate') { distribute_multiple_call.call(:color_swap) }
-            menu.append(        flip = Gtk::ImageMenuItem.new(utf8(_("Flip upside-down"))))
+            menu.append(flip = Gtk::ImageMenuItem.new(utf8(_("Flip upside-down"))))
             flip.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-180-16.png")
             flip.signal_connect('activate') { distribute_multiple_call.call(:rotate, 180) }
             menu.append(frame_offset = Gtk::ImageMenuItem.new(utf8(_("Specify frame offset"))))
@@ -803,11 +811,17 @@ def popup_thumbnail_menu(event, optionals, fullpath, type, xmldir, attributes_pr
         end
     end
     menu.append(               Gtk::SeparatorMenuItem.new)
-    if !possible_actions[:can_multiple] || $selected_elements.length == 0
-        menu.append(whitebalance = Gtk::ImageMenuItem.new(utf8(_("Fix white-balance"))))
-        whitebalance.image = Gtk::Image.new("#{$FPATH}/images/stock-tool-color-balance-16.png")
-        whitebalance.signal_connect('activate') { closures[:whitebalance].call }
-    end
+    menu.append(whitebalance = Gtk::ImageMenuItem.new(utf8(_("Fix white-balance"))))
+    whitebalance.image = Gtk::Image.new("#{$FPATH}/images/stock-tool-color-balance-16.png")
+    whitebalance.signal_connect('activate') { 
+        if possible_actions[:can_multiple] && $selected_elements.length > 0
+            if values = ask_whitebalance(nil, nil, nil, nil, '', nil, nil, '')
+                distribute_multiple_call.call(:whitebalance, values)
+            end
+        else
+            closures[:whitebalance].call
+        end
+    }
     if !possible_actions[:can_multiple] || $selected_elements.length == 0
         menu.append(enhance = Gtk::ImageMenuItem.new(utf8(xmldir.attributes["#{attributes_prefix}enhance"] ? _("Original contrast") :
                                                                                                              _("Enhance constrast"))))
@@ -819,7 +833,15 @@ def popup_thumbnail_menu(event, optionals, fullpath, type, xmldir, attributes_pr
     if type == 'image' && possible_actions[:can_panorama]
         menu.append(panorama = Gtk::ImageMenuItem.new(utf8(_("Set as panorama"))))
         panorama.image = Gtk::Image.new("#{$FPATH}/images/stock-images-16.png")
-        panorama.signal_connect('activate') { closures[:pano].call }
+        panorama.signal_connect('activate') {
+            if possible_actions[:can_multiple] && $selected_elements.length > 0
+                if values = ask_new_pano_amount(nil, '')
+                    distribute_multiple_call.call(:pano, values)
+                end
+            else
+                distribute_multiple_call.call(:pano)
+            end
+       }
     end
     if optionals.include?('delete')
         menu.append(               Gtk::SeparatorMenuItem.new)
@@ -998,30 +1020,34 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
         end
     }
 
-    whitebalance_and_cleanup = Proc.new {
-        if values = ask_whitebalance(fullpath, thumbnail_img, img,
-                                     $xmldir.elements["*[@filename='#{filename}']"], '', $default_thumbnails[:x], $default_thumbnails[:y], '')
-            perform_change_whitebalance_and_cleanup = Proc.new { |val|
-                change_whitebalance($xmldir.elements["*[@filename='#{filename}']"], '', val)
-                recalc_whitebalance(val, fullpath, thumbnail_img, img,
-                                    $xmldir.elements["*[@filename='#{filename}']"], '', $default_thumbnails[:x], $default_thumbnails[:y], '')
-                cleanup_all_thumbnails.call
-            }
-            perform_change_whitebalance_and_cleanup.call(values[:new])
+    whitebalance_and_cleanup_real = Proc.new { |values|
+        perform_change_whitebalance_and_cleanup = Proc.new { |val|
+            change_whitebalance($xmldir.elements["*[@filename='#{filename}']"], '', val)
+            recalc_whitebalance(val, fullpath, thumbnail_img, img,
+                                $xmldir.elements["*[@filename='#{filename}']"], '', $default_thumbnails[:x], $default_thumbnails[:y], '')
+            cleanup_all_thumbnails.call
+        }
+        perform_change_whitebalance_and_cleanup.call(values[:new])
 
-            save_undo(_("fix white balance"),
+        save_undo(_("fix white balance"),
+                  Proc.new {
+                      perform_change_whitebalance_and_cleanup.call(values[:old])
+                      textview.grab_focus
+                      autoscroll_if_needed($autotable_sw, img, textview)
+                      $notebook.set_page(1)
                       Proc.new {
-                          perform_change_whitebalance_and_cleanup.call(values[:old])
+                          perform_change_whitebalance_and_cleanup.call(values[:new])
                           textview.grab_focus
                           autoscroll_if_needed($autotable_sw, img, textview)
                           $notebook.set_page(1)
-                          Proc.new {
-                              perform_change_whitebalance_and_cleanup.call(values[:new])
-                              textview.grab_focus
-                              autoscroll_if_needed($autotable_sw, img, textview)
-                              $notebook.set_page(1)
-                          }
-                      })
+                      }
+                  })
+    }
+
+    whitebalance_and_cleanup = Proc.new {
+        if values = ask_whitebalance(fullpath, thumbnail_img, img,
+                                     $xmldir.elements["*[@filename='#{filename}']"], '', $default_thumbnails[:x], $default_thumbnails[:y], '')
+            whitebalance_and_cleanup_real.call(values)
         end
     }
 
@@ -1141,7 +1167,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
 
     $name2closures[filename] = { :rotate => rotate_and_cleanup, :enhance => enhance_and_cleanup, :delete => delete, :cut => cut,
                                  :color_swap => color_swap_and_cleanup, :frame_offset => change_frame_offset_and_cleanup_real,
-                                 :pano => change_pano_amount_and_cleanup }
+                                 :whitebalance => whitebalance_and_cleanup_real, :pano => change_pano_amount_and_cleanup_real }
 
     textview.signal_connect('key-press-event') { |w, event|
         propagate = true