changeset 38:3efacab12daa

Added :SubtlyFindForward and :SubtlyFindBackward
author unexist
date Sat, 23 Jan 2010 23:22:48 +0100
parents 8215e3fcbb6f
children 6838c7123945
files bin/subtly subtly/browser.rb
diffstat 2 files changed, 84 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/bin/subtly	Sat Jan 23 23:21:52 2010 +0100
+++ b/bin/subtly	Sat Jan 23 23:22:48 2010 +0100
@@ -25,8 +25,11 @@
   "m"   => :SubtlyBrowserForward,
   "r"   => :SubtlyBrowerReloadCache,
   "R"   => :SubtlyBrowerReload,
+  "f"   => :SubtlyBrowerFollow,
   "+"   => :SubtlyBrowserZoomIn,
   "-"   => :SubtlyBrowserZoomOut,
+  "/"   => :SubtlyFindForward,
+  "\\"  => :SubtlyFindBackward,
   "gg"  => :SubtlyScrollTop,
   "G"   => :SubtlyScrollBottom,
   "ZZ"  => :SubtlyQuit,
--- a/subtly/browser.rb	Sat Jan 23 23:21:52 2010 +0100
+++ b/subtly/browser.rb	Sat Jan 23 23:22:48 2010 +0100
@@ -32,15 +32,16 @@
       @mode     = :command
       @keys     = {}
       @keychain = ""
-      @jumpbuf  = ""
+      @buffer   = ""
       @times    = ""
+      @forward  = true
 
       # Create widgets
       @win      = Subtly::Gtk::Window.new
       @scrolled = Subtly::Gtk::Scrolled.new
       @info     = Subtly::Gtk::Label.new(true, true)
       @status   = Subtly::Gtk::Label.new(true, false)
-      @page   = Subtly::Gtk::Label.new(true, false)
+      @page     = Subtly::Gtk::Label.new(true, false)
       @input    = Subtly::Gtk::Entry.new(false)
       #@list     = Subtly::Gtk::List.new
       @vbox1    = Subtly::Gtk::Box.new(:vbox, false, 0)
@@ -58,9 +59,10 @@
       @status.foreground = "#ffffff"
       @input.foreground  = "#000000"
       @input.background  = "#ffffff"
-      @page.foreground = "#ffffff"
-      @page.background = "#0000ff"
+      @page.foreground   = "#ffffff"
+      @page.background   = "#0000ff"
       @webkit.focusable  = false
+      @webkit.highlight  = false
       @input.editable    = false
       @input.focusable   = false
       @input.length      = LIMIT
@@ -99,7 +101,7 @@
     ## uri= {{{
     # Set browser uri
     #
-    # @param  [String, #read]  uri  Uri to load
+    # @param [String, #read]  uri  Uri to load
     ##
 
     def uri=(uri)
@@ -112,7 +114,7 @@
     ## add_keys {{{
     # Add keys hash
     #
-    # @param  [Hash, #read]  hash  Keys hash
+    # @param [Hash, #read]  hash  Keys hash
     ##
 
     def add_keys(hash)
@@ -127,7 +129,7 @@
     ## format_status {{{
     # Set status text
     #
-    # @param  [String, #read]  str  Status text
+    # @param [String, #read]  str  Status text
     ##
 
     def format_status(str)
@@ -137,8 +139,8 @@
     ## format_meter {{{
     # Draw status meter
     #
-    # @param  [Fixnum, #read]  progress  Load progress in percent
-    # @param  [Fixnum, #read]  width     Width of the meter
+    # @param [Fixnum, #read]  progress  Load progress in percent
+    # @param [Fixnum, #read]  width     Width of the meter
     ##
 
     def format_meter(progress, width = 14)
@@ -150,7 +152,7 @@
     ## format_page {{{
     # Draw page meter
     #
-    # @param  [String, #read]  page  Page position in percent
+    # @param [String, #read]  page  Page position in percent
     ##
 
     def format_page(page)
@@ -198,16 +200,26 @@
           @webkit.forward
         when :SubtlyBrowserStop then
           @webkit.stop
-        when :SubtlyBrowerReloadCache then
+        when :SubtlyBrowserReloadCache then
           @webkit.reload(true)
-        when :SubtlyBrowerReload then
+        when :SubtlyBrowserReload then
           @webkit.reload(false)
+        when :SubtlyBrowserFollow
+          @webkit.follow
         when :SubtlyBrowserZoomIn then
           @webkit.zoom = 1
           @info.text   = "Zoom: %d%%" % [ (@webkit.zoom * 100).to_i ]
         when :SubtlyBrowserZoomOut then
           @webkit.zoom = -1
           @info.text   = "Zoom: %d%%" % [ (@webkit.zoom * 100).to_i ]
+        when :SubtlyFindForward then
+          @mode       = :find
+          @forward    = true
+          @input.text = "/"
+        when :SubtlyFindBackward then
+          @mode       = :find
+          @forward    = false
+          @input.text = "\\"
         when :SubtlyScrollTop
           @scrolled.vadjust = 0.0
           @page.text        = format_page(0)
@@ -246,42 +258,83 @@
               @webkit.focusable = false
               @input.text       = ""
               @keychain         = ""
+            when :find then
+              @mode             = :command
+              @buffer           = ""
+              @input.text       = ""
+
+              # Disable highlights
+              @webkit.highlight = false
+              @webkit.unmark
           end
         when Subtly::Gdk::Keys[:return]
           case @mode
             when :uri then
-              uri             = @input.text.gsub(":open ", "")
-              uri             = "http://" + uri unless(uri.include?("http://"))
-              @webkit.uri     = uri
-              @info.text      = uri[0..LIMIT]
+              # Sanitize uri and load it
+              uri         = @input.text.gsub(":open ", "")
+              uri         = "http://" + uri unless(uri.include?("http://"))
+              @webkit.uri = uri
+              @info.text  = uri[0..LIMIT]
+
+              # Tidy up
               @input.editable = false
               @input.text     = ""
             when :jump then
+              # Sanitize uri and load it
               uri         = @keys[@keychain.to_sym]
               uri         = "http://" + uri unless(uri.include?("http://"))
-              uri         = uri.gsub("%s", @jumpbuf)
-
+              uri         = uri.gsub("%s", @buffer)
               @webkit.uri = uri
               @info.text  = uri[0..LIMIT]
-              @jumpbuf    = ""
+
+              # Tidy up
+              @buffer     = ""
               @keychain   = ""
               @mode       = :command
+            when :find then
+              @webkit.find(@buffer, @forward) #< Find next
           end
         when Subtly::Gdk::Keys[:backspace] then
           case @mode
-            when :uri
-             if(":open " != @input.text)
-              @input.text = @input.text.chop
-            end
+            when :uri then
+              # Delete char in input
+              if(":open " != @input.text)
+                @input.text.chop!
+              end
+            when :find then
+              # Delete char in buffer
+              if("/" != @input.text || "\\" != @input.text)
+                @buffer.chop!
+                @input.text = "%s%s" % [ @input.text[0], @buffer ]
+                @webkit.find(@buffer, @forward)
+              else
+                @webkit.unmark #< Remove highlight
+                @webkit.highlight = false
+              end
           end
-        else
+        else #< Other keys
           case @mode
             when :uri then
+              # Append char to buffer
               @input << event[:string]
             when :jump then
-              @jumpbuf << event[:string]
+              # Append char to buffer
+              @buffer << event[:string]
 
-              @input.text = ":open %s" % [ @keys[@keychain.to_sym].gsub("%s", @jumpbuf) ]
+              @input.text = ":open %s" % [ @keys[@keychain.to_sym].gsub("%s", @buffer) ]
+            when :find then
+              # Append char to buffer
+              @buffer << event[:string]
+
+              # Start finding
+              @input.text = "/%s" % [ @buffer ]
+
+              @webkit.unmark
+              @webkit.mark(@buffer)
+
+              @webkit.find(@buffer, @forward)
+
+              @webkit.highlight = true
             else
               # Check for numbers
               if(event[:string].match(/[0-9]/))
@@ -295,7 +348,7 @@
                 # Check if command is a jump
                 if("_" == event[:string])
                   @mode       = :jump
-                  @input.text = ":open %s" % [ @keys[@keychain.to_sym].gsub("%s", @jumpbuf) ]
+                  @input.text = ":open %s" % [ @keys[@keychain.to_sym].gsub("%s", @buffer) ]
                 else
                   time = Integer(@times) rescue 1
 
@@ -304,6 +357,7 @@
                     commands(@keys[@keychain.to_sym])
                   end
 
+                  # Tidy up
                   @keychain = ""
                   @times    = ""
                 end