changeset 18:ccd7fc8f1cb5

Added jump implementation
author unexist
date Fri, 22 Jan 2010 13:09:09 +0100
parents d8bc17ad2c63
children f1a454f3411d
files subtly/browser.rb
diffstat 1 files changed, 24 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/subtly/browser.rb	Fri Jan 22 13:08:51 2010 +0100
+++ b/subtly/browser.rb	Fri Jan 22 13:09:09 2010 +0100
@@ -15,9 +15,6 @@
 
 module Subtly
   class Browser < Subtly::Gtk::Runner
-    attr_accessor :mode, :win, :scrolled, :info, :status, :input, :vbox, :hbox, :webkit
-    attr_accessor :keys, :keychain
-
     LIMIT = 80 #< Limit url length in bar
 
     ## initialize {{{
@@ -33,6 +30,7 @@
       @mode     = :command
       @keys     = {}
       @keychain = ""
+      @jumpbuf  = ""
 
       # Create widgets
       @win      = Subtly::Gtk::Window.new
@@ -116,7 +114,7 @@
     def add_keys(hash)
       hash.each do |v, k|
         # Just make a symbol from keys an store it
-        keys[v.to_sym] = k
+        @keys[v.to_sym] = k
       end
     end # }}}
 
@@ -232,6 +230,16 @@
               @info.text      = uri[0..LIMIT]
               @input.editable = false
               @input.text     = ""
+            when :jump then
+              uri         = @keys[@keychain.to_sym]
+              uri         = "http://" + uri unless(uri.include?("http://"))
+              uri         = uri.gsub("%s", @jumpbuf)
+
+              @webkit.uri = uri
+              @info.text  = uri[0..LIMIT]
+              @jumpbuf    = ""
+              @keychain   = ""
+              @mode       = :command
           end
         when Subtly::Gdk::Keys[:backspace] then
           case @mode
@@ -244,12 +252,22 @@
           case @mode
             when :uri then
               @input << event[:string]
+            when :jump then
+              @jumpbuf << event[:string]
+
+              @input.text = ":open %s" % [ @keys[@keychain.to_sym].gsub("%s", @jumpbuf) ]
             else
               @keychain << event[:string]
 
               if(@keys.include?(@keychain.to_sym))
-                commands(@keys[@keychain.to_sym])
-                @keychain = ""
+                # Check if command is a jump
+                if("_" == event[:string])
+                  @mode = :jump
+                  @input.text = ":open %s" % [ @keys[@keychain.to_sym].gsub("%s", @jumpbuf) ]
+                else
+                  commands(@keys[@keychain.to_sym])
+                  @keychain = ""
+                end
               end
           end 
       end