add the toolbar
authorgc <gc>
Fri, 1 Apr 2005 22:43:56 +0000 (22:43 +0000)
committergc <gc>
Fri, 1 Apr 2005 22:43:56 +0000 (22:43 +0000)
bin/booh-gui
data/booh/images/stock-none-16.png [new file with mode: 0644]
data/booh/images/stock-rotate-270-16.png [new file with mode: 0644]
data/booh/images/stock-rotate-90-16.png [new file with mode: 0644]
lib/booh/booh-lib.rb

index c0a1f31ecee89ec9b6b7016d2852da42d21bd149..15133f2e5f2bdca40a28fdcf756c214db010a54c 100755 (executable)
@@ -99,12 +99,15 @@ def write_config
     ios.close
 end
 
+def set_mousecursor(window, what)
+    window.set_cursor(Gdk::Cursor.new(what))
+end
 def set_mousecursor_wait(window)
-    window.set_cursor(Gdk::Cursor.new(Gdk::Cursor::WATCH))
+    set_mousecursor(window, Gdk::Cursor::WATCH)
     Gtk.main_iteration while Gtk.events_pending?
 end
 def set_mousecursor_normal(window)
-    window.set_cursor(Gdk::Cursor.new(Gdk::Cursor::LEFT_PTR))
+    set_mousecursor(window, Gdk::Cursor::LEFT_PTR)
 end
 
 def build_full_dest_filename(filename)
@@ -232,6 +235,17 @@ def add_thumbnail(autotable, name, type, filename, caption)
         end
     }
 
+    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
+    }
+
     textview.signal_connect('key-press-event') { |w, event|
         propagate = true
         textview.set_editable(event.keyval != Gdk::Keyval::GDK_Tab)
@@ -292,14 +306,7 @@ def add_thumbnail(autotable, name, type, filename, caption)
                 end
             end
             if event.keyval == Gdk::Keyval::GDK_Delete && control_pressed
-                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
+                delete.call
             end
             if event.keyval == Gdk::Keyval::GDK_Return && control_pressed
                 view_element(File.basename(name))
@@ -315,13 +322,25 @@ def add_thumbnail(autotable, name, type, filename, caption)
     }
 
     evtbox.signal_connect('button-press-event') { |w, event|
+        retval = true
+        if event.event_type == Gdk::Event::BUTTON_PRESS
+            if $delete.active?
+                delete.call
+            end
+            if $r90.active?
+                rotate.call(90)
+            end
+            if $r270.active?
+                rotate.call(270)
+            end
+        end
         textview.grab_focus
         if event.event_type == Gdk::Event::BUTTON2_PRESS
             view_element(File.basename(name))
-            true
         else
-            false  #- propagate
+            retval = false  #- propagate
         end
+        retval
     }
 
     vbox.signal_connect('button-press-event') { |w, event|
@@ -368,12 +387,16 @@ end
 def show_popup(parent, msg)
     dialog = Gtk::Dialog.new
     dialog.title = utf8(_("Booh message"))
+    lbl = Gtk::Label.new
+    lbl.markup = msg
+    dialog.vbox.add(lbl)
+    dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK)
+
     dialog.transient_for = parent
     dialog.set_default_size(200, 120)
-    dialog.vbox.add(Gtk::Label.new(msg))
-
-    dialog.add_button(Gtk::Stock::OK, Gtk::Dialog::RESPONSE_OK)
+    dialog.window_position = Gtk::Window::POS_CENTER_ON_PARENT
     dialog.show_all
+
     dialog.run
     dialog.destroy
 end
@@ -473,6 +496,34 @@ def open_file(filename)
     return nil
 end
 
+def open_file_popup
+    fc = Gtk::FileChooserDialog.new(utf8(_("Open file")),
+                                    nil,
+                                    Gtk::FileChooser::ACTION_OPEN,
+                                    nil,
+                                    [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL])
+    fc.add_shortcut_folder(File.expand_path("~/.booh-gui-files"))
+    fc.set_current_folder(File.expand_path("~/.booh-gui-files"))
+    fc.transient_for = $main_window
+    ok = false
+    while !ok
+        if fc.run == Gtk::Dialog::RESPONSE_ACCEPT
+            set_mousecursor_wait(fc.window)
+            msg = open_file(fc.filename)
+            set_mousecursor_normal(fc.window)
+            if msg
+                show_popup(fc, msg)
+                ok = false
+            else
+                ok = true
+            end
+        else
+            ok = true
+        end
+    end
+    fc.destroy
+end
+
 def create_menu
     mb = Gtk::MenuBar.new
 
@@ -488,45 +539,96 @@ def create_menu
     filemenu.set_submenu(filesubmenu)
     mb.append(filemenu)
 
-    open.signal_connect('activate') { |w|
-        fc = Gtk::FileChooserDialog.new(utf8(_("Open file")),
-                                        nil,
-                                        Gtk::FileChooser::ACTION_OPEN,
-                                        nil,
-                                        [Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL])
-        fc.add_shortcut_folder(File.expand_path("~/.booh-gui-files"))
-        fc.set_current_folder(File.expand_path("~/.booh-gui-files"))
-        fc.transient_for = $main_window
-        ok = false
-        while !ok
-            if fc.run == Gtk::Dialog::RESPONSE_ACCEPT
-                set_mousecursor_wait(fc.window)
-                msg = open_file(fc.filename)
-                set_mousecursor_normal(fc.window)
-                if msg
-                    show_popup(fc, msg)
-                    ok = false
-                else
-                    ok = true
-                end
-            else
-                ok = true
-            end
+    open.signal_connect('activate') { open_file_popup }
+    quit.signal_connect('activate') { try_quit }
+
+    return mb
+end
+
+def create_toolbar
+    tb = Gtk::Toolbar.new
+
+    tb.insert(-1, open = Gtk::ToolButton.new(Gtk::Stock::OPEN))
+
+    tb.insert(-1, Gtk::SeparatorToolItem.new)
+
+    tb.insert(-1, $r90 = Gtk::ToggleToolButton.new)
+    $r90.icon_widget = Gtk::Image.new("#{$FPATH}/images/stock-rotate-90-16.png")
+    $r90.label = utf8(_("Rotate"))
+    tb.insert(-1, $r270 = Gtk::ToggleToolButton.new)
+    $r270.icon_widget = Gtk::Image.new("#{$FPATH}/images/stock-rotate-270-16.png")
+    $r270.label = utf8(_("Rotate"))
+    tb.insert(-1, $delete = Gtk::ToggleToolButton.new(Gtk::Stock::DELETE))
+    tb.insert(-1, nothing = Gtk::ToolButton.new(''))
+    nothing.icon_widget = Gtk::Image.new("#{$FPATH}/images/stock-none-16.png")
+    nothing.label = utf8(_("None"))
+
+    open.signal_connect('clicked') { open_file_popup }
+
+    one_click_explain_try = Proc.new {
+        if !$config['one-click-explained']
+            show_popup($main_window, utf8(_("<b>One-Click tools.</b>
+
+You have just clicked on a One-Click tool. When such a tool is activated
+(<span foreground=\"darkblue\">Rotate clockwise</span>, <span foreground=\"darkblue\">Rotate counter-clockwise</span>, or <span foreground=\"darkblue\">Delete</span>), clicking on a
+thumbnail will immediately apply the desired action.
+
+Click the <span foreground=\"darkblue\">None</span> icon when you're finished with One-Click tools.
+")))
+            $config['one-click-explained'] = true
         end
-        fc.destroy
     }
 
-    quit.signal_connect('activate') { |w|
-        try_quit
+    $r90.signal_connect('toggled') {
+        if $r90.active?
+            set_mousecursor($autotable.window, Gdk::Cursor::SB_RIGHT_ARROW)
+            one_click_explain_try.call
+            $r270.active = false
+            $delete.active = false
+        else
+            if !$r270.active? && !$delete.active?
+                set_mousecursor_normal($autotable.window)
+            end
+        end
+    }
+    $r270.signal_connect('toggled') {
+        if $r270.active?
+            set_mousecursor($autotable.window, Gdk::Cursor::SB_LEFT_ARROW)
+            one_click_explain_try.call
+            $r90.active = false
+            $delete.active = false
+        else
+            if !$r90.active? && !$delete.active?
+                set_mousecursor_normal($autotable.window)
+            end
+        end
+    }
+    $delete.signal_connect('toggled') {
+        if $delete.active?
+            set_mousecursor($autotable.window, Gdk::Cursor::PIRATE)
+            one_click_explain_try.call
+            $r90.active = false
+            $r270.active = false
+        else
+            if !$r90.active? && !$r270.active?
+                set_mousecursor_normal($autotable.window)
+            end
+        end
+    }
+    nothing.signal_connect('clicked') {
+        $r90.active = $r270.active = $delete.active = false
+        set_mousecursor_normal($autotable.window)
     }
 
-    return mb
+    return tb
 end
 
 def create_main_window
 
     mb = create_menu
 
+    tb = create_toolbar
+
     tbl = create_auto_table
 #    open_file('/home/gc/booh/foo')
 
@@ -548,13 +650,15 @@ def create_main_window
     }
     $albums_ts = Gtk::TreeStore.new(String, String)
     $albums_tv.set_model($albums_ts)
+    $albums_tv.signal_connect('realize') { $albums_tv.grab_focus }
 
     paned = Gtk::HPaned.new
     paned.pack1($albums_tv, false, false)
     paned.pack2(tbl, true, true)
 
-    main_vbox = Gtk::VBox.new(false, 5)
+    main_vbox = Gtk::VBox.new(false, 0)
     main_vbox.pack_start(mb, false, false)
+    main_vbox.pack_start(tb, false, false)
     main_vbox.pack_start(paned, true, true)
     main_vbox.pack_end($statusbar = Gtk::Statusbar.new, false, false)
 
diff --git a/data/booh/images/stock-none-16.png b/data/booh/images/stock-none-16.png
new file mode 100644 (file)
index 0000000..77a2d18
Binary files /dev/null and b/data/booh/images/stock-none-16.png differ
diff --git a/data/booh/images/stock-rotate-270-16.png b/data/booh/images/stock-rotate-270-16.png
new file mode 100644 (file)
index 0000000..cbe3ef8
Binary files /dev/null and b/data/booh/images/stock-rotate-270-16.png differ
diff --git a/data/booh/images/stock-rotate-90-16.png b/data/booh/images/stock-rotate-90-16.png
new file mode 100644 (file)
index 0000000..cdac3bc
Binary files /dev/null and b/data/booh/images/stock-rotate-90-16.png differ
index 9ca28a29fcc1b297186b61a7dea2db03628064a8..8a5b1cf8b73be48353f7aaff2252cb057a6b3905 100644 (file)
@@ -219,4 +219,11 @@ module Booh
         end
     end
 
+    def invornil(obj, methodname)
+        if obj == nil
+            return nil
+        else
+            return obj.method(methodname).call
+        end
+    end
 end