lib/webconsole/lib/window.rb in webconsole-0.1.12 vs lib/webconsole/lib/window.rb in webconsole-0.1.13
- old
+ new
@@ -6,13 +6,28 @@
def initialize(window_id = nil)
@window_id = window_id
end
+ # Properties
+
def base_url_path=(value)
@base_url = "file://" + value
end
+
+ def window_id
+ if !@window_id
+ if ENV.has_key?(WINDOW_ID_KEY)
+ @window_id = ENV[WINDOW_ID_KEY]
+ else
+ @window_id = WebConsole::create_window
+ end
+ end
+ return @window_id
+ end
+
+ # Web
LOADHTML_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_html.scpt")
LOADHTMLWITHBASEURL_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "load_html_with_base_url.scpt")
def load_html(html)
arguments = [html]
@@ -22,46 +37,53 @@
if @base_url
script = LOADHTMLWITHBASEURL_SCRIPT
arguments.push(@base_url)
end
- if window_id
- arguments.push(window_id)
- end
-
- result = WebConsole::run_applescript(script, arguments)
- if !window_id
- # This allows a window manager created without a window_id and then be assigned the window_id when load_html is called.
- @window_id = self.class.window_id_from_result(result)
- end
+ return run_script(script, arguments)
end
DOJAVASCRIPT_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "do_javascript.scpt")
def do_javascript(javascript)
- WebConsole::run_applescript(DOJAVASCRIPT_SCRIPT, [javascript, window_id])
+ return run_script(DOJAVASCRIPT_SCRIPT, [javascript])
end
READ_FROM_STANDARD_INPUT_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "read_from_standard_input.scpt")
def read_from_standard_input(text)
- WebConsole::run_applescript(READ_FROM_STANDARD_INPUT_SCRIPT, [text, window_id])
+ run_script(READ_FROM_STANDARD_INPUT_SCRIPT, [text])
end
+ # Window
+
CLOSEWINDOW_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "close_window.scpt")
def close
WebConsole::run_applescript(CLOSEWINDOW_SCRIPT, [window_id])
end
-
- def window_id
- if !@window_id && ENV.has_key?(WINDOW_ID_KEY)
- @window_id = ENV[WINDOW_ID_KEY]
+
+ SPLIT_ID_IN_WINDOW_SCRIPT = File.join(APPLESCRIPT_DIRECTORY, "split_id_in_window.scpt")
+ def split_id(pluginName = nil)
+ arguments = [window_id]
+
+ if pluginName
+ arguments.push(pluginName)
end
- return @window_id
+
+ result = WebConsole::run_applescript(SPLIT_ID_IN_WINDOW_SCRIPT, arguments)
+ result.chomp!
+ return result
end
private
-
- def self.window_id_from_result(result)
- return result.split.last.to_i
+
+ def run_script(script, arguments = [])
+ arguments = arguments_with_target(arguments)
+ return WebConsole::run_applescript(script, arguments)
end
+
+ def arguments_with_target(arguments)
+ arguments.push(window_id)
+ return arguments
+ end
+
end
end