Sha256: 5f3e3177f5d214d7d56793ddcf0f5025863465f23d21d2fa138ae609bc5844c8

Contents?: true

Size: 1.87 KB

Versions: 13

Compression:

Stored size: 1.87 KB

Contents

module Redcar
  class ApplicationSWT
    class HtmlTab < Tab
      attr_reader :browser
      
      def initialize(model, notebook)
        super
        @model.add_listener(:changed_title) { |title| @item.text = title }
      end
      
      def create_tab_widget
        Swt::Graphics::Device.DEBUG = true
        if Redcar.platform == :windows
          java.lang.System.setProperty('org.eclipse.swt.browser.XULRunnerPath',
                                      (Redcar.asset_dir + "/xulrunner").gsub("/", "\\"))
          @browser = Swt::Browser.new(notebook.tab_folder, Swt::SWT::MOZILLA)
        else
          @browser = Swt::Browser.new(notebook.tab_folder, Swt::SWT::NONE)
        end
        @widget = @browser
        @item.control = @widget
        add_listeners
      end
      
      # Focuses the Browser tab within the CTabFolder, and gives the keyboard
      # focus to the EditViewSWT.
      def focus
        super
        browser.set_focus
      end
      
      # Close the HtmlTab, disposing of any resources along the way.
      def close
        @browser.remove_location_listener(@location_listener)
        @browser.dispose
        @location_listener = nil
        super
      end
      
      def go_to_location(url)
        @browser.set_url(url)
      end
      
      class LocationListener
        def initialize(html_tab)
          @html_tab = html_tab
        end
        
        def changing(event)
          uri = URI.parse(event.location)
          if uri.path =~ %r{/controller/([^/]*)}
            event.doit = false
            params = uri.query ? CGI.parse(uri.query) : nil
            @html_tab.controller_action($1, params)
          end
        end

        def changed(*_); end
      end
      
      def add_listeners
        @location_listener = LocationListener.new(@model)
        @browser.add_location_listener(@location_listener)
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
redcar-dev-0.12.14dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.13dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.12dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.11dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.10dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.9dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.8dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.7dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.6dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.4dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.3dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.1dev-java plugins/application_swt/lib/application_swt/html_tab.rb
redcar-dev-0.12.0dev-java plugins/application_swt/lib/application_swt/html_tab.rb