Skip to content

Commit

Permalink
overcome merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
rdp committed Feb 14, 2010
2 parents b5eb668 + ee6e29c commit 50b33ca
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 67 deletions.
27 changes: 17 additions & 10 deletions lib/redcar.rb
Expand Up @@ -17,32 +17,27 @@
# ## Loading and Initialization
#
# Every feature in Redcar is written as a plugin. This module contains a few

# methods to bootstrap the plugins by loading the PluginManager.
#
# Once loaded, bin/redcar will start the gui pump, which will run

# Redcar.gui.start. This starts the GUI library's event loop and hands over

# control to the GUI.
#
# ## Application
#
# The top class of Redcar is a {Redcar::Application}, which handles the creation

# of Redcar::Windows. {Redcar::Application} is a good place to start
# to see how the Redcar models are created.

#
# {Redcar::ApplicationSWT} is the start point for the SWT GUI, which listens
# for events from the Redcar::Application model and reflects them in the GUI.
# for events from the {Redcar::Application} model and reflects them in the GUI.
#
# This structure of a model and a controller that listens to it is repeated for
# each part of Redcar reflected in the GUI.
#
# * Redcar::Window has Redcar::ApplicationSWT::Window
# * Redcar::Notebook has Redcar::ApplicationSWT::Notebook
# * Redcar::EditTab has Redcar::EditViewSWT::EditTab
# * {Redcar::Window} has {Redcar::ApplicationSWT::Window}
# * {Redcar::Notebook} has {Redcar::ApplicationSWT::Notebook}
# * {Redcar::EditTab} has {Redcar::EditViewSWT::EditTab}
#
# and so on.
module Redcar
Expand Down Expand Up @@ -102,6 +97,7 @@ def self.plugin_manager
end
end

# Tells the plugin manager to load plugins, and prints debug output.
def self.load
plugin_manager.load
if plugin_manager.unreadable_definitions.any?
Expand All @@ -122,8 +118,8 @@ def self.load
end
end

# Starts the GUI.
def self.pump

Redcar.gui.start
end

Expand Down Expand Up @@ -156,6 +152,17 @@ def self.user_dir
end
File.expand_path(userdir)
end

class << self
attr_accessor :app
attr_reader :gui
end

# Set the application GUI.
def self.gui=(gui)
raise "can't set gui twice" if @gui
@gui = gui
end
end

usage = Redcar::Usage.new
Expand Down
88 changes: 48 additions & 40 deletions plugins/application/lib/application.rb
Expand Up @@ -21,26 +21,23 @@
require 'application/window'

module Redcar
class << self
attr_accessor :app, :history
attr_reader :gui
end

# Set the application GUI.
def self.gui=(gui)
raise "can't set gui twice" if @gui
@gui = gui
end

# A Redcar process contains one Application instance. The application instance
# (the app) contains:
#
# * an array of {Redcar::Window} objects and handles creating new Windows.
# * a {Redcar::Clipboard}
#  * a {Redcar::Command::History}
#
# A lot of events in Redcar bubble up through the app, which gives plugins
# one place to hook into Redcar events.
class Application
NAME = "Redcar"

include Redcar::Model
include Redcar::Observable

def self.start
Redcar.app = Application.new
Redcar.history = Command::History.new
Redcar.app = Application.new
end

def self.sensitivities
Expand Down Expand Up @@ -69,25 +66,24 @@ def self.sensitivities
]
end

attr_reader :clipboard, :keymap, :menu
attr_reader :clipboard, :keymap, :menu, :history

# Create an application instance with a Redcar::Clipboard and a Redcar::History.
def initialize
@windows = []
@window_handlers = Hash.new {|h,k| h[k] = []}
create_clipboard
create_history
end

def create_clipboard
@clipboard = Clipboard.new("application")
@clipboard.add_listener(:added) { notify_listeners(:clipboard_added) }
end

# Immediatley halts the gui event loop.
# Immediately halts the gui event loop.
def quit
Redcar.gui.stop
end

# Return a list of all open windows
# All open windows
#
# @return [Array<Redcar::Window>]
def windows
@windows
end
Expand All @@ -112,8 +108,8 @@ def make_sure_at_least_one_window_open
end
end

# Removes a window from this Application. Should not be called by user
# code, use Window#close instead.
# Removes a window from this Application. Should not be called by plugins,
# use Window#close instead.
def window_closed(window)
windows.delete(window)
if focussed_window == window
Expand All @@ -136,48 +132,45 @@ def self.storage
@storage ||= Plugin::Storage.new('application_plugin')
end

# All Redcar::Notebooks in all Windows.
def all_notebooks
windows.inject([]) { |arr, window| arr << window.notebooks }.flatten
end

# All Redcar::Tabs in all Notebooks in all Windows.
def all_tabs
all_notebooks.inject([]) { |arr, notebook| arr << notebook.tabs }.flatten
end

# The focussed Redcar::Notebook in the focussed window, or nil.
def focussed_window_notebook
focussed_window.focussed_notebook if focussed_window
end

# The focussed Redcar::Tab in the focussed notebook in the focussed window.
def focussed_notebook_tab
focussed_window_notebook.focussed_tab if focussed_window_notebook
end

def focussed_tab_edit_view
focussed_notebook_tab.edit_view if focussed_notebook_tab and focussed_notebook_tab.edit_tab?
end

def focussed_edit_view_document
focussed_tab_edit_view.document if focussed_tab_edit_view
end

def focussed_document_mirror
focussed_edit_view_document.mirror if focussed_edit_view_document
end


# The focussed Redcar::Window.
def focussed_window
@focussed_window
end

# Set which window the app thinks is focussed.
# Should not be called by plugins, use Window#focus instead.
def focussed_window=(window)
set_focussed_window(window)
notify_listeners(:focussed_window, window)
end

# Set which window the app thinks is focussed.
# Should not be called by plugins, use Window#focus instead.
def set_focussed_window(window)
@focussed_window = window
end

# Redraw the main menu.
# Redraw the main menu, reloading all the Menus and Keymaps from the plugins.
def refresh_menu!
windows.each do |window|
window.menu = load_menu
Expand All @@ -186,6 +179,9 @@ def refresh_menu!
end
end

# Generate the main menu by combining menus from all plugins.
#
# @return [Redcar::Menu]
def load_menu
menu = Menu.new
Redcar.plugin_manager.loaded_plugins.each do |plugin|
Expand All @@ -196,6 +192,9 @@ def load_menu
menu
end

# Generate the main keymap by merging the keymaps from all plugins.
#
# @return [Redcar::Keymap]
def main_keymap
keymap = Keymap.new("main", Redcar.platform)
Redcar.plugin_manager.loaded_plugins.each do |plugin|
Expand All @@ -210,7 +209,7 @@ def main_keymap
keymap
end


# Loads sensitivities from all plugins.
def load_sensitivities
Redcar.plugin_manager.loaded_plugins.each do |plugin|
if plugin.object.respond_to?(:sensitivities)
Expand All @@ -219,6 +218,8 @@ def load_sensitivities
end
end

private

def attach_window_listeners(window)
h1 = window.add_listener(:tab_focussed) do |tab|
notify_listeners(:tab_focussed, tab)
Expand Down Expand Up @@ -251,13 +252,20 @@ def attach_window_listeners(window)
notify_listeners(:focussed_tab_selection_changed, tab)
end
end

h10 = window.add_listener(:about_to_close) do |win|
notify_listeners(:window_about_to_close, win)
end

@window_handlers[window] << h1 << h2 << h3 << h4 << h5 << h6 << h7 << h8 << h9 << h10
end

def create_clipboard
@clipboard = Clipboard.new("application")
@clipboard.add_listener(:added) { notify_listeners(:clipboard_added) }
end

def create_history
@history = Command::History.new
end
end
end

Expand Down
26 changes: 23 additions & 3 deletions plugins/application/lib/application/clipboard.rb
@@ -1,6 +1,13 @@
module Redcar
# A simple array with a maximum length. Models a copy/paste clipboard
# that can contain multiple elements.
# Models a copy/paste clipboard that can contain multiple elements.
#
# Each entry in the Clipboard is an array of Strings, like these:
#
# ["mytext"]
# ["foo", "bar"]
#
# Each entry is an array of Strings in order to support copy/paste in
# block selection mode.
class Clipboard
include Redcar::Model
include Redcar::Observable
Expand All @@ -17,7 +24,9 @@ def initialize(name)
@contents = []
end

# Add text to the clipboard.
# Add an entry to the clipboard.
#
# Events: [:added, Array<String>]
#
# @param [String, Array<String>]
def <<(text)
Expand All @@ -34,26 +43,37 @@ def <<(text)
notify_listeners(:added, text)
end

# The most recent entry added to the Clipboard
#
# @return [Array<String>]
def last
check_for_changes
@contents.last
end

# The number of entries on the Clipboard
def length
check_for_changes
@contents.length
end

# Fetch an entry. 0 is the most recent
#
# @return [Array<String>]
def [](index)
check_for_changes
@contents[-1*index-1]
end

# Iterate over each entry.
def each(&block)
check_for_changes
@contents.each(&block)
end

# Add an entry without raising an event.
#
# @param [String, Array<String>]
def silently_add(text)
@contents << text
end
Expand Down
4 changes: 2 additions & 2 deletions plugins/application/lib/application/command/executor.rb
Expand Up @@ -42,8 +42,8 @@ def log_error
end

def record
if Redcar.history
Redcar.history.record(@command_instance)
if Redcar.app.history
Redcar.app.history.record(@command_instance)
end
end
end
Expand Down
9 changes: 7 additions & 2 deletions plugins/application/spec/application/command/executor_spec.rb
Expand Up @@ -2,9 +2,14 @@

class Redcar::Command
describe Executor do
class FakeApp
attr_accessor :history
end

before do
Executor.stub!(:current_environment).and_return(:current_environment)
Redcar.history = History.new
Redcar.app = FakeApp.new
Redcar.app.history = History.new
end

describe "executing a command" do
Expand Down Expand Up @@ -32,7 +37,7 @@ def execute

it "should add the command to the History" do
@executor.execute
Redcar.history.last.should == @command
Redcar.app.history.last.should == @command
end

it "should set the command environment" do
Expand Down
10 changes: 6 additions & 4 deletions plugins/auto_indenter/lib/auto_indenter.rb
Expand Up @@ -14,14 +14,16 @@ def self.tab_handlers

class IndentTabHandler
def self.handle(edit_view)
return false unless edit_view.soft_tabs?
doc = edit_view.document
line = doc.get_line(doc.cursor_line)
before_line = line[0...doc.cursor_line_offset]
if before_line =~ /^\s*$/
insert_string = " "*edit_view.tab_width
if edit_view.soft_tabs?
next_tab_stop_offset = (doc.cursor_line_offset/edit_view.tab_width + 1)*edit_view.tab_width
insert_string = " "*(next_tab_stop_offset - doc.cursor_line_offset)
doc.insert(doc.cursor_offset, insert_string)
doc.cursor_offset = doc.cursor_offset + insert_string.length
else
doc.insert(doc.cursor_offset, "\t")
doc.cursor_offset += 1
end
end
end
Expand Down

0 comments on commit 50b33ca

Please sign in to comment.