allow to change thumbnails and subalbums position in the popup menu
authorgc <gc>
Sun, 22 May 2005 17:21:47 +0000 (17:21 +0000)
committergc <gc>
Sun, 22 May 2005 17:21:47 +0000 (17:21 +0000)
bin/booh
data/booh/images/stock-move-down.png [new file with mode: 0644]
data/booh/images/stock-move-left.png [new file with mode: 0644]
data/booh/images/stock-move-right.png [new file with mode: 0644]
data/booh/images/stock-move-up.png [new file with mode: 0644]

index 4dc62671ea59f577db93e4af2041ba256ae5ebc9..7a4a14290c60436f96484c23fb1e6cfec3931097 100755 (executable)
--- a/bin/booh
+++ b/bin/booh
@@ -543,7 +543,7 @@ def gen_real_thumbnail(type, origfile, destfile, xmldir, size, img, infotype)
     }
 end
 
-def popup_thumbnail_menu(event, optionals, type, xmldir, attributes_prefix, closures)
+def popup_thumbnail_menu(event, optionals, type, xmldir, attributes_prefix, possible_moves, closures)
     menu = Gtk::Menu.new
     if optionals.include?('change_image')
         menu.append(changeimg = Gtk::ImageMenuItem.new(utf8(_("Change image"))))
@@ -557,9 +557,35 @@ def popup_thumbnail_menu(event, optionals, type, xmldir, attributes_prefix, clos
     menu.append(r270 = Gtk::ImageMenuItem.new(utf8(_("Rotate counter-clockwise"))))
     r270.image = Gtk::Image.new("#{$FPATH}/images/stock-rotate-270-16.png")
     r270.signal_connect('activate') { closures[:rotate].call(-90) }
-    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 }
+    menu.append(               Gtk::SeparatorMenuItem.new)
+    if !possible_moves[:forbid_left]
+        menu.append(moveleft = Gtk::ImageMenuItem.new(utf8(_("Move left"))))
+        moveleft.image = Gtk::Image.new("#{$FPATH}/images/stock-move-left.png")
+        moveleft.signal_connect('activate') { closures[:move].call('left') }
+        if !possible_moves[:can_left]
+            moveleft.sensitive = false
+        end
+    end
+    if !possible_moves[:forbid_right]
+        menu.append(moveright = Gtk::ImageMenuItem.new(utf8(_("Move right"))))
+        moveright.image = Gtk::Image.new("#{$FPATH}/images/stock-move-right.png")
+        moveright.signal_connect('activate') { closures[:move].call('right') }
+        if !possible_moves[:can_right]
+            moveright.sensitive = false
+        end
+    end
+    menu.append(moveup = Gtk::ImageMenuItem.new(utf8(_("Move up"))))
+    moveup.image = Gtk::Image.new("#{$FPATH}/images/stock-move-up.png")
+    moveup.signal_connect('activate') { closures[:move].call('up') }
+    if !possible_moves[:can_up]
+        moveup.sensitive = false
+    end
+    menu.append(movedown = Gtk::ImageMenuItem.new(utf8(_("Move down"))))
+    movedown.image = Gtk::Image.new("#{$FPATH}/images/stock-move-down.png")
+    movedown.signal_connect('activate') { closures[:move].call('down') }
+    if !possible_moves[:can_down]
+        movedown.sensitive = false
+    end
     if type == 'video'
         menu.append(               Gtk::SeparatorMenuItem.new)
         menu.append(  color_swap = Gtk::ImageMenuItem.new(utf8(_("Red/blue color swap"))))
@@ -573,6 +599,9 @@ def popup_thumbnail_menu(event, optionals, type, xmldir, attributes_prefix, clos
         frame_offset.signal_connect('activate') { closures[:frame_offset].call }
     end
     menu.append(               Gtk::SeparatorMenuItem.new)
+    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 }
     menu.append(enhance      = Gtk::ImageMenuItem.new(utf8(xmldir.attributes["#{attributes_prefix}enhance"] ? _("Original contrast") :
                                                                                                               _("Enhance constrast"))))
     enhance.image = Gtk::Image.new("#{$FPATH}/images/stock-channels-16.png")
@@ -637,6 +666,27 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
         cleanup_all_thumbnails.call
     }
 
+    move = Proc.new { |direction|
+        do_method = "move_#{direction}"
+        undo_method = "move_" + case direction; when 'left'; 'right'; when 'right'; 'left'; when 'up'; 'down'; when 'down'; 'up' end
+        perform = Proc.new {
+            done = autotable.method(do_method).call(vbox)
+            textview.grab_focus  #- because if moving, focus is stolen
+            done
+        }
+        if perform.call
+            save_undo(_("move %s") % direction,
+                      Proc.new {
+                          autotable.method(undo_method).call(vbox)
+                          $notebook.set_page(1)
+                          Proc.new {
+                              autotable.method(do_method).call(vbox)
+                              $notebook.set_page(1)
+                          }
+                      })
+        end
+    }
+
     color_swap_and_cleanup = Proc.new {
         perform_color_swap_and_cleanup = Proc.new {
             color_swap($xmldir.elements["[@filename='#{filename}']"], '')
@@ -772,8 +822,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                     $vbox2textview[autotable.get_widget_at_pos(x, y - 1)].grab_focus
                 end
                 if shift_pressed
-                    autotable.move_up(vbox)
-                    textview.grab_focus  #- because if moving, focus is stolen
+                    move.call('up')
                 end
             end
             if event.keyval == Gdk::Keyval::GDK_Down && y < autotable.get_max_y
@@ -781,19 +830,16 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                     $vbox2textview[autotable.get_widget_at_pos(x, y + 1)].grab_focus
                 end
                 if shift_pressed
-                    autotable.move_down(vbox)
-                    textview.grab_focus  #- because if moving, focus is stolen
+                    move.call('down')
                 end
             end
             if event.keyval == Gdk::Keyval::GDK_Left
-                previous = autotable.get_previous_widget(vbox)
-                if previous && autotable.get_current_pos(previous)[0] < x
+                if x > 0
                     if control_pressed
                         $vbox2textview[previous].grab_focus
                     end
                     if shift_pressed
-                        autotable.move_left(vbox)
-                        textview.grab_focus  #- because if moving, focus is stolen
+                        move.call('left')
                     end
                 end
                 if alt_pressed
@@ -807,8 +853,7 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
                         $vbox2textview[next_].grab_focus
                     end
                     if shift_pressed
-                        autotable.move_right(vbox)
-                        textview.grab_focus  #- because if moving, focus is stolen
+                        move.call('right')
                     end
                 end
                 if alt_pressed
@@ -843,8 +888,12 @@ def add_thumbnail(autotable, filename, type, thumbnail_img, caption)
             end
         end
         if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 3
+            x, y = autotable.get_current_pos(vbox)
+            next_ = autotable.get_next_widget(vbox)
             popup_thumbnail_menu(event, ['delete'], type, $xmldir.elements["[@filename='#{filename}']"], '',
-                                 { :rotate => rotate_and_cleanup, :color_swap => color_swap_and_cleanup, :enhance => enhance_and_cleanup,
+                                 { :can_left => x > 0, :can_right => next_ && autotable.get_current_pos(next_)[0] > x,
+                                   :can_up => y > 0, :can_down => y < autotable.get_max_y },
+                                 { :rotate => rotate_and_cleanup, :move => move, :color_swap => color_swap_and_cleanup, :enhance => enhance_and_cleanup,
                                    :frame_offset => change_frame_offset_and_cleanup, :delete => delete, :whitebalance => whitebalance_and_cleanup })
         end
         if event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 1
@@ -1168,8 +1217,12 @@ def change_dir
 
     $xmldir = $xmldoc.elements["//dir[@path='#{$current_path}']"]
     $subalbums_edits = {}
+    subalbums_counter = 0
+    subalbums_edits_bypos = {}
 
-    add_subalbum = Proc.new { |xmldir|
+    add_subalbum = Proc.new { |xmldir, counter|
+        $subalbums_edits[xmldir.attributes['path']] = { :position => counter }
+        subalbums_edits_bypos[counter] = $subalbums_edits[xmldir.attributes['path']]
         if xmldir == $xmldir
             thumbnail_file = "#{current_dest_dir}/thumbnails-thumbnail.jpg"
             caption = xmldir.attributes['thumbnails-caption']
@@ -1201,6 +1254,11 @@ def change_dir
         $subalbums.attach(hbox,
                           0, 1, current_y_sub_albums, current_y_sub_albums + 1, Gtk::FILL, Gtk::FILL, 2, 2)
 
+        frame, textview = create_editzone($subalbums_sw, 0, img)
+        textview.buffer.text = caption
+        $subalbums.attach(Gtk::Alignment.new(0, 0.5, 0.5, 0).add(frame),
+                          1, 2, current_y_sub_albums, current_y_sub_albums + 1, Gtk::FILL, Gtk::FILL, 2, 2)
+
         change_image = Proc.new {
             fc = Gtk::FileChooserDialog.new(utf8(_("Select image for caption")),
                                             nil,
@@ -1266,6 +1324,27 @@ def change_dir
             system("rm -f '#{thumbnail_file}'")
         }
 
+        move = Proc.new { |direction|
+            save_changes
+            if direction == 'up'
+                oldpos = $subalbums_edits[xmldir.attributes['path']][:position]
+                $subalbums_edits[xmldir.attributes['path']][:position] -= 1
+                subalbums_edits_bypos[oldpos - 1][:position] += 1
+            else
+                oldpos = $subalbums_edits[xmldir.attributes['path']][:position]
+                $subalbums_edits[xmldir.attributes['path']][:position] += 1
+                subalbums_edits_bypos[oldpos + 1][:position] -= 1
+            end
+
+            elems = []
+            $xmldir.elements.each('dir') { |element|
+                elems << [ element.attributes['path'], element.remove ]
+            }
+            elems.sort { |a,b| $subalbums_edits[a[0]][:position] <=> $subalbums_edits[b[0]][:position] }.
+                  each { |e| $xmldir.add_element(e[1]) }
+            change_dir
+        }
+
         color_swap_and_cleanup = Proc.new {
             perform_color_swap_and_cleanup = Proc.new {
                 color_swap(xmldir, "#{infotype}-")
@@ -1358,7 +1437,9 @@ def change_dir
             end
             if event.event_type == Gdk::Event::BUTTON_PRESS && event.button == 3
                 popup_thumbnail_menu(event, ['change_image'], entry2type(captionfile), xmldir, "#{infotype}-",
-                                     { :change => change_image, :rotate => rotate_and_cleanup, :enhance => enhance_and_cleanup,
+                                     { :forbid_left => true, :forbid_right => true,
+                                       :can_up => counter > 1, :can_down => counter > 0 && counter < subalbums_counter },
+                                     { :change => change_image, :move => move, :rotate => rotate_and_cleanup, :enhance => enhance_and_cleanup,
                                        :color_swap => color_swap_and_cleanup, :frame_offset => change_frame_offset_and_cleanup, :whitebalance => whitebalance_and_cleanup })
             end
             if event.event_type == Gdk::Event::BUTTON2_PRESS && event.button == 1
@@ -1382,13 +1463,9 @@ def change_dir
             end
             $gesture_press = nil
         }
-        
-        frame, textview = create_editzone($subalbums_sw, 0, img)
-        textview.buffer.text = caption
-        $subalbums.attach(Gtk::Alignment.new(0, 0.5, 0.5, 0).add(frame),
-                          1, 2, current_y_sub_albums, current_y_sub_albums + 1, Gtk::FILL, Gtk::FILL, 2, 2)
-        
-        $subalbums_edits[xmldir.attributes['path']] = { :editzone => textview, :captionfile => captionfile }
+                
+        $subalbums_edits[xmldir.attributes['path']][:editzone] = textview
+        $subalbums_edits[xmldir.attributes['path']][:captionfile] = captionfile
         current_y_sub_albums += 1
     }
 
@@ -1400,7 +1477,7 @@ def change_dir
         $subalbums_vb.pack_start(Gtk::Alignment.new(0.5, 0.5, 0.5, 0).add(frame), false, false)
         #- this album image/caption
         if $xmldir.attributes['thumbnails-caption']
-            add_subalbum.call($xmldir)
+            add_subalbum.call($xmldir, 0)
         end
     end
     $xmldir.elements.each { |element|
@@ -1412,7 +1489,7 @@ def change_dir
         end
         if element.name == 'dir'
             #- sub-album image/caption
-            add_subalbum.call(element)
+            add_subalbum.call(element, subalbums_counter += 1)
         end
     }
     $subalbums_vb.add($subalbums)
diff --git a/data/booh/images/stock-move-down.png b/data/booh/images/stock-move-down.png
new file mode 100644 (file)
index 0000000..d6317fc
Binary files /dev/null and b/data/booh/images/stock-move-down.png differ
diff --git a/data/booh/images/stock-move-left.png b/data/booh/images/stock-move-left.png
new file mode 100644 (file)
index 0000000..3a77ad9
Binary files /dev/null and b/data/booh/images/stock-move-left.png differ
diff --git a/data/booh/images/stock-move-right.png b/data/booh/images/stock-move-right.png
new file mode 100644 (file)
index 0000000..f7c61b4
Binary files /dev/null and b/data/booh/images/stock-move-right.png differ
diff --git a/data/booh/images/stock-move-up.png b/data/booh/images/stock-move-up.png
new file mode 100644 (file)
index 0000000..b526845
Binary files /dev/null and b/data/booh/images/stock-move-up.png differ