Class: TT::WebDialogPatch

Inherits:
UI::WebDialog
  • Object
show all
Defined in:
TT_Lib2/webdialog_patch.rb

Overview

Custom WebDialog wrapper that works around problems with WebDialog#set_html under OSX after Safari 5.0.6 is installed.

Example is bare bone without any error checking. Expand as you find fit.

Since:

  • 2.5.5

Direct Known Subclasses

GUI::Window

Instance Method Summary collapse

Instance Method Details

#set_file(filename) ⇒ Nil

Parameters:

  • filename (String)

Returns:

  • (Nil)

Since:

  • 2.5.5



77
78
79
80
# File 'TT_Lib2/webdialog_patch.rb', line 77

def set_file( filename )
  cleanup_temp_file()
  set_file_original( filename )
end

#set_html(html_string) ⇒ Nil

Note:

Safari 5.0.6 made .set_html unusable under OSX because any links to resources ( Images, CSS, JS ) on the local computer failed to load. Previously it would work when you spesified file:/// but now it is denied.

Parameters:

  • html_string (String)

Returns:

  • (Nil)

Since:

  • 2.5.5



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
# File 'TT_Lib2/webdialog_patch.rb', line 38

def set_html( html_string )
  # Clean up any old temp file.
  cleanup_temp_file()
  # Finalizer is attached to the webdialog so when it gets garbage collected
  # temp file is erased.
  # 
  # The temp filename needs to be different from the last on in order for the
  # html to be loaded. If the name is the same the content is not refreshed.
  #
  # For both the temp directory and temp file handling with better error
  # handling it'd probably best to port `tmpdir.rb` and `tempfile.rb` from
  # the Standard Ruby Library.
  #
  # http://www.ruby-doc.org/stdlib-1.8.6/
  unique_seed = "#{self.object_id}#{Time.now.to_i}".hash.abs
  filename = "webdialog_#{unique_seed}.html"
  @tempfile = File.join( TT::System.temp_path, filename )
  cleanup_proc = self.class.cleanup_temp_file( @tempfile.dup )
  ObjectSpace.define_finalizer( self, cleanup_proc )
  # Write the HTML content out to the temp file.
  File.open( @tempfile, 'w' ) { |file|
    file.write( html_string )
  }
  set_file_original( @tempfile )
  nil
end

#set_url(url) ⇒ Nil

Parameters:

  • url (String)

Returns:

  • (Nil)

Since:

  • 2.5.5



85
86
87
88
# File 'TT_Lib2/webdialog_patch.rb', line 85

def set_url( url )
  cleanup_temp_file()
  super
end