Sha256: 27e30d20941c2f86ba7518e3b3ff62328211c62c82189821ef6c7219dcfd59c7

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'repl/internal_mirror'

module Redcar
  class REPL
    def self.start
      Sensitivity.new(:open_repl_tab, Redcar.app, false, [:tab_focussed]) do |tab|
        tab and 
        tab.is_a?(EditTab) and 
        tab.edit_view.document.mirror.is_a?(REPL::InternalMirror)
      end
      
      Redcar.app.menu.sub_menu("Plugins").build do
        sub_menu "REPL" do
          item "Open",    REPL::OpenInternalREPL
          item "Execute", REPL::CommitREPL
        end
      end
      Redcar.app.refresh_menu!
    end
    
    class OpenInternalREPL < Command
      
      def execute
        tab = win.new_tab(Redcar::EditTab)
        edit_view = tab.edit_view
        edit_view.document.mirror = InternalMirror.new
        edit_view.cursor_offset = edit_view.document.length
        tab.focus
      end
    end
    
    class ReplCommand < Command
      sensitize :open_repl_tab
    end
    
    class CommitREPL < ReplCommand
      key :linux   => "Ctrl+M",
          :osx     => "Cmd+M",
          :windows => "Ctrl+M"

      def execute
        edit_view = win.focussed_notebook.focussed_tab.edit_view
        edit_view.document.save!
        edit_view.cursor_offset = edit_view.document.length
        edit_view.scroll_to_line(edit_view.document.line_count)
      end
    end
  end
end


Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
redcar-0.3.1dev plugins/repl/lib/repl.rb