have recent files available next to open toolbar item
authorgc <gc>
Thu, 7 Apr 2005 21:24:47 +0000 (21:24 +0000)
committergc <gc>
Thu, 7 Apr 2005 21:24:47 +0000 (21:24 +0000)
bin/booh-gui

index c5a276b7e28b44444f371cd959b9a8ee81904484..658b0b7f8d3058f20481358faa4e90e77c94503c 100755 (executable)
@@ -79,7 +79,19 @@ def read_config
         $xmldoc = REXML::Document.new(File.new($config_file))
         $xmldoc.root.elements.each { |element|
             txt = element.get_text
-            $config[element.name] = txt ? txt.value : nil
+            if txt 
+                if txt.value =~ /~~~/ || element.name == 'last-opens'
+                    $config[element.name] = txt.value.split(/~~~/)
+                else
+                    $config[element.name] = txt.value
+                end
+            else
+                $config[element.name] = {}
+                element.each { |chld|
+                    txt = chld.get_text
+                    $config[element.name][chld.name] = txt ? txt.value : nil
+                }
+            end
         }
     end
     if !FileTest.directory?(File.expand_path('~/.booh-gui-files'))
@@ -88,12 +100,25 @@ def read_config
 end
 
 def write_config
+    if $config['last-opens'].size > 5
+        $config['last-opens'] = $config['last-opens'][-5, 5]
+    end
+
     ios = File.open($config_file, "w")
     $xmldoc = Document.new "<booh-gui-rc version='#{$VERSION}'/>"
     $xmldoc << XMLDecl.new( XMLDecl::DEFAULT_VERSION, $CURRENT_CHARSET )
     $config.each_pair { |key, value|
-    elem = $xmldoc.root.add_element key
-        elem.add_text value.to_s
+        elem = $xmldoc.root.add_element key
+        if value.is_a? Hash
+            $config[key].each_pair { |subkey, subvalue|
+                subelem = elem.add_element subkey
+                subelem.add_text subvalue.to_s
+            }
+        elsif value.is_a? Array
+            elem.add_text value.join('~~~')
+        else
+            elem.add_text value.to_s
+        end
     }
     $xmldoc.write(ios, 0)
     ios.close
@@ -469,7 +494,7 @@ def show_popup(parent, msg)
 
     dialog.transient_for = parent
     dialog.set_default_size(200, 120)
-    dialog.window_position = Gtk::Window::POS_CENTER_ON_PARENT
+    dialog.window_position = Gtk::Window::POS_MOUSE
     dialog.show_all
 
     dialog.run
@@ -520,6 +545,10 @@ def change_dir
     $vbox2textview = {}
     $name2widgets = {}
 
+    if !$current_path
+        return
+    end
+
     $subalbums_vb.children.each { |chld|
         $subalbums_vb.remove(chld)
     }
@@ -727,9 +756,19 @@ def change_dir
 end
 
 def open_file(filename)
+
     $filename = nil
     $current_path = nil   #- invalidate
     $rotated_pixbufs = {}
+    $albums_ts.clear
+    $autotable.clear
+    $subalbums_vb.children.each { |chld|
+        $subalbums_vb.remove(chld)
+    }
+
+    if !File.exists?(filename)
+        return utf8(_("File not found."))
+    end
 
     begin
         $xmldoc = REXML::Document.new File.new(filename)
@@ -768,8 +807,6 @@ def open_file(filename)
         return utf8(_("Corrupted booh file..."))
     end
 
-    $albums_ts.clear
-
     append_dir_elem = Proc.new { |parent_iter, location|
         child_iter = $albums_ts.append(parent_iter)
         child_iter[0] = File.basename(location)
@@ -784,6 +821,8 @@ def open_file(filename)
     $albums_tv.expand_all
     $albums_tv.selection.select_iter($albums_ts.iter_first)
 
+    $config['last-opens'] ||= []
+    $config['last-opens'] << filename
     return nil
 end
 
@@ -839,8 +878,29 @@ end
 def create_toolbar
     tb = Gtk::Toolbar.new
 
-    tb.insert(-1, open = Gtk::ToolButton.new(Gtk::Stock::OPEN))
+    tb.insert(-1, open = Gtk::MenuToolButton.new(Gtk::Stock::OPEN))
     open.label = utf8(_("Open"))  #- to avoid missing gtk2 l10n catalogs
+    open.menu = Gtk::Menu.new
+    open.signal_connect('show-menu') {
+        lastopens = Gtk::Menu.new
+        j = 0
+        if $config['last-opens']
+            $config['last-opens'].reverse.each { |e|
+                lastopens.attach(item = Gtk::ImageMenuItem.new(e), 0, 1, j, j + 1)
+                item.signal_connect('activate') {
+                    set_mousecursor_wait($main_window)
+                    msg = open_file(e)
+                    set_mousecursor_normal($main_window)
+                    if msg
+                        show_popup($main_window, msg)
+                    end
+                }
+                j += 1
+            }
+            lastopens.show_all
+        end
+        open.menu = lastopens
+    }
 
     tb.insert(-1, Gtk::SeparatorToolItem.new)