Sha256: ac7f1893eae96367c2e8078c32e0d3f6aab852540bdb2243da6ccf323533468f

Contents?: true

Size: 1.36 KB

Versions: 41

Compression:

Stored size: 1.36 KB

Contents

module Redcar

  class OpenDefaultApp

    def self.project_context_menus(tree, node, controller)
      Menu::Builder.build do
        if node and node.path
          item ("Open Default App"){OpenDefaultAppCommand.new(node.path).run }
        end
      end
    end

    class OpenDefaultAppCommand < Redcar::Command
      import java.awt.Desktop

      attr_reader :path

      def initialize(path)
        @path = path
      end

      def execute(options=nil)
        @path ||= options[:value]
        begin
          file  = java::io::File.new(path)
          if Desktop.is_desktop_supported()
            desktop = Desktop.get_desktop
            desktop.open(file)
          end
        rescue Object => e
          Application::Dialog.message_box("A default application could not be found for this type of file.")
        end
      end
    end
  end

  class OpenDefaultBrowserCommand < Redcar::Command
    import java.awt.Desktop

    attr_reader :uri

    def self.supported?
      Desktop.is_desktop_supported()
    end

    def initialize(uri)
      @uri = uri
    end

    def execute
      begin
        return unless OpenDefaultBrowserCommand.supported?
        URI::parse(@uri)
        parsed_uri = java.net.URI.new(@uri)
        Desktop.get_desktop.browse(parsed_uri)
      rescue URI::InvalidURIError
        raise ArgumentError, "Invalid URI given"
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
redcar-0.13 plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.13.5dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.13.4dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.13.3dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.13.2dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.13.1dev plugins/open_default_app/lib/open_default_app.rb
redcar-0.12.1 plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.13.0dev plugins/open_default_app/lib/open_default_app.rb
redcar-0.12 plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.27dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.26dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.25dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.24dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.23dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.22dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.21dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.20dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.19dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.18dev plugins/open_default_app/lib/open_default_app.rb
redcar-dev-0.12.17dev plugins/open_default_app/lib/open_default_app.rb