Class: XTabbedWindow
- Inherits:
-
Object
- Object
- XTabbedWindow
- Defined in:
- lib/xtabbedwindow.rb
Instance Attribute Summary collapse
-
#tabs ⇒ Object
readonly
Returns the value of attribute tabs.
-
#window ⇒ Object
readonly
Returns the value of attribute window.
Instance Method Summary collapse
- #goto_tab(pattern) ⇒ Object
-
#initialize(name, new_tab: "Ctrl+t", scan_tabs: true, next_tab: "Ctrl+Tab", location_key: 'Ctrl+l') ⇒ XTabbedWindow
constructor
next_tab values e.g.
- #new_tab ⇒ Object
- #next_tab ⇒ Object
- #read_tabs ⇒ Object
- #tab?(obj) ⇒ Boolean (also: #include?)
- #title ⇒ Object
Constructor Details
#initialize(name, new_tab: "Ctrl+t", scan_tabs: true, next_tab: "Ctrl+Tab", location_key: 'Ctrl+l') ⇒ XTabbedWindow
next_tab values e.g. Ctrl+Tab (default), Ctrl+Alt+Page_Up
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/xtabbedwindow.rb', line 16 def initialize(name, new_tab: "Ctrl+t", scan_tabs: true, next_tab: "Ctrl+Tab", location_key: 'Ctrl+l') @new_tab, @next_tab, @location_key = new_tab, next_tab, location_key a = WMCtrl.instance.windows @window = a.detect {|x| x.title =~ /#{name}/i} if @window sleep 0.3 @window.activate end @tabs = [] read_tabs() if scan_tabs end |
Instance Attribute Details
#tabs ⇒ Object (readonly)
Returns the value of attribute tabs.
12 13 14 |
# File 'lib/xtabbedwindow.rb', line 12 def tabs @tabs end |
#window ⇒ Object (readonly)
Returns the value of attribute window.
12 13 14 |
# File 'lib/xtabbedwindow.rb', line 12 def window @window end |
Instance Method Details
#goto_tab(pattern) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/xtabbedwindow.rb', line 34 def goto_tab(pattern) regex = pattern.is_a?(String) ? /^#{pattern}/i : pattern return true if title() =~ regex read_tabs if @tabs.empty? a = @tabs r = a.grep(regex) if r.empty? and pattern.is_a? String then regex = /#{pattern}/i r = a.grep(regex) end if r.empty? then new_tab() # open the document XDo::Keyboard.char(@location_key) block_given? ? yield : return else i = a.index(r.first) @window.activate sleep 0.1 XDo::Keyboard.char("Alt+1") sleep 0.1 i.times { XDo::Keyboard.char(@next_tab) } true end end |
#new_tab ⇒ Object
76 77 78 79 80 81 |
# File 'lib/xtabbedwindow.rb', line 76 def new_tab() @window.activate sleep 0.05 XDo::Keyboard.char(@new_tab) sleep 0.3 end |
#next_tab ⇒ Object
83 84 85 86 |
# File 'lib/xtabbedwindow.rb', line 83 def next_tab() sleep 0.05 XDo::Keyboard.char(@next_tab) end |
#read_tabs ⇒ Object
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/xtabbedwindow.rb', line 88 def read_tabs() @window.activate XDo::Keyboard.char("Alt+1") start_tab_title = title() @tabs = [start_tab_title] next_tab() window_title = title() while window_title != start_tab_title do @tabs << window_title next_tab() window_title = title() end @tabs end |
#tab?(obj) ⇒ Boolean Also known as: include?
111 112 113 114 115 116 117 |
# File 'lib/xtabbedwindow.rb', line 111 def tab?(obj) read_tabs if @tabs.empty? regex = obj.is_a?(String) ? /^#{obj}|#{obj}/ : obj @tabs.grep(regex).any? end |
#title ⇒ Object
121 122 123 124 |
# File 'lib/xtabbedwindow.rb', line 121 def title() sleep 0.05 XDo::XWindow.from_active.title end |