add undo and redo in menubar
[booh] / bin / booh-gui
index 952047469b2baba34fb5c88fbd7cd8d15d64a63e..fda76ca9e574a084cb1e115540df5a27943b31e9 100755 (executable)
@@ -1,4 +1,4 @@
-#!/usr/bin/ruby
+#!/usredo/bin/ruby
 #
 #                         *  BOOH  *
 #
@@ -151,7 +151,7 @@ end
 
 def save_undo(closure, *params)
     UndoHandler.save_undo(closure, [ *params ])
-    $undo.sensitive = true
+    $undo_tb.sensitive = $undo_mb.sensitive = true
 end
 
 def view_element(filename)
@@ -638,8 +638,8 @@ def change_dir
     $vbox2textview = {}
     $name2widgets = {}
     UndoHandler.cleanup
-    $undo.sensitive = false
-    $redo.sensitive = false
+    $undo_tb.sensitive = $undo_mb.sensitive = false
+    $redo_tb.sensitive = $redo_mb.sensitive = false
 
     if !$current_path
         return
@@ -974,7 +974,9 @@ def open_file_popup
     fc.destroy
 end
 
-def create_menu
+def create_menu_and_toolbar
+
+    #- menu
     mb = Gtk::MenuBar.new
 
     filemenu = Gtk::MenuItem.new(utf8(_("_File")))
@@ -992,10 +994,17 @@ def create_menu
     open.signal_connect('activate') { open_file_popup }
     quit.signal_connect('activate') { try_quit }
 
-    return mb
-end
-
-def create_toolbar
+    editmenu = Gtk::MenuItem.new(utf8(_("_Edit")))
+    editsubmenu = Gtk::Menu.new
+    editsubmenu.append($undo_mb = Gtk::ImageMenuItem.new(Gtk::Stock::UNDO))
+    editsubmenu.append($redo_mb = Gtk::ImageMenuItem.new(Gtk::Stock::REDO))
+    editsubmenu.append(           Gtk::SeparatorMenuItem.new)
+    editsubmenu.append(prefs    = Gtk::ImageMenuItem.new(Gtk::Stock::PREFERENCES))
+    editmenu.set_submenu(editsubmenu)
+    mb.append(editmenu)
+
+   
+    #- toolbar
     tb = Gtk::Toolbar.new
 
     tb.insert(-1, open = Gtk::MenuToolButton.new(Gtk::Stock::OPEN))
@@ -1039,21 +1048,27 @@ def create_toolbar
 
     tb.insert(-1, Gtk::SeparatorToolItem.new)
 
-    tb.insert(-1, $undo = Gtk::ToolButton.new(Gtk::Stock::UNDO).set_sensitive(false))
-    tb.insert(-1, $redo = Gtk::ToolButton.new(Gtk::Stock::REDO).set_sensitive(false))
-    $undo.signal_connect('clicked') {
-        $redo.sensitive = true
+    tb.insert(-1, $undo_tb = Gtk::ToolButton.new(Gtk::Stock::UNDO))
+    tb.insert(-1, $redo_tb = Gtk::ToolButton.new(Gtk::Stock::REDO))
+
+    perform_undo = Proc.new {
+        $redo_tb.sensitive = $redo_mb.sensitive = true
         if not more_undoes = UndoHandler.undo
-            $undo.sensitive = false
+            $undo_tb.sensitive = $undo_mb.sensitive = false
         end
     }
-    $redo.signal_connect('clicked') {
-        $undo.sensitive = true
+    perform_redo = Proc.new {
+        $undo_tb.sensitive = $undo_mb.sensitive = true
         if not more_redoes = UndoHandler.redo
-            $redo.sensitive = false
+            $redo_tb.sensitive = $redo_mb.sensitive = false
         end
     }
 
+    $undo_tb.signal_connect('clicked')  { perform_undo.call }
+    $undo_mb.signal_connect('activate') { perform_undo.call }
+    $redo_tb.signal_connect('clicked')  { perform_redo.call }
+    $redo_mb.signal_connect('activate') { perform_redo.call }
+
     one_click_explain_try = Proc.new {
         if !$config['one-click-explained']
             show_popup($main_window, utf8(_("<b>One-Click tools.</b>
@@ -1127,14 +1142,12 @@ Click the <span foreground=\"darkblue\">None</span> icon when you're finished wi
         set_mousecursor_normal($subalbums)
     }
 
-    return tb
+    return [ mb, tb ]
 end
 
 def create_main_window
 
-    mb = create_menu
-
-    tb = create_toolbar
+    mb, tb = create_menu_and_toolbar
 
 #    open_file('/home/gc/booh/foo')