Skip to content

Commit

Permalink
DocumentCommands now operate on the focussed EditView.
Browse files Browse the repository at this point in the history
  • Loading branch information
danlucraft committed Feb 9, 2010
1 parent 079c51a commit 01a9baa
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
10 changes: 9 additions & 1 deletion plugins/application/features/support/env.rb
Expand Up @@ -59,7 +59,7 @@ def save_file(*args)

World(SwtHelper)

After do
def close_everything
Redcar.app.windows.each do |win|
while tree = win.treebook.trees.first
Redcar::ApplicationSWT.sync_exec do
Expand All @@ -86,6 +86,14 @@ def save_file(*args)
end
end

Before do
close_everything
end

After do
close_everything
end




Expand Down
14 changes: 10 additions & 4 deletions plugins/edit_view/lib/edit_view.rb
Expand Up @@ -16,18 +16,24 @@ class EditView

class << self
attr_reader :undo_sensitivity, :redo_sensitivity
attr_reader :focussed_edit_view
end

def self.focussed_mate_text=(mate_text)
@focussed_mate_text = mate_text
notify_listeners(:focussed_mate_text, mate_text)
# Called by the GUI whenever an EditView is focussed or
# loses focus. Sends :focussed_edit_view event.
def self.focussed_edit_view=(edit_view)
@focussed_edit_view = edit_view
notify_listeners(:focussed_edit_view, edit_view)
end

def self.sensitivities
[
Sensitivity.new(:edit_tab_focussed, Redcar.app, false, [:tab_focussed]) do |tab|
tab and tab.is_a?(EditTab)
end,
Sensitivity.new(:edit_view_focussed, EditView, false, [:focussed_edit_view]) do |edit_view|
edit_view
end,
Sensitivity.new(:selected_text, Redcar.app, false, [:focussed_tab_selection_changed, :tab_focussed]) do
if win = Redcar.app.focussed_window
tab = win.focussed_notebook.focussed_tab
Expand Down Expand Up @@ -108,7 +114,7 @@ def set_grammar(name)
@grammar = name
end

def gained_focus
def focus
notify_listeners(:focussed)
end

Expand Down
6 changes: 6 additions & 0 deletions plugins/edit_view/lib/edit_view/document.rb
Expand Up @@ -100,6 +100,10 @@ def selection_range_changed(start_offset, end_offset)
notify_listeners(:selection_range_changed, start_offset..end_offset)
end

def single_line?
controller.single_line?
end

# The line index the cursor is on (zero-based)
#
# @return [Integer]
Expand Down Expand Up @@ -137,6 +141,7 @@ def selection?
# @param [Integer] offset character offset from the start of the document
# @param [String] text text to insert
def insert(offset, text)
text = text.gsub("\n", "") if single_line?
replace(offset, 0, text)
end

Expand All @@ -154,6 +159,7 @@ def delete(offset, length)
# @param [Integer] length length of text to replace
# @param [String] text replacement text
def replace(offset, length, text)
text = text.gsub("\n", "") if single_line?
controller.replace(offset, length, text)
end

Expand Down
2 changes: 1 addition & 1 deletion plugins/edit_view/lib/edit_view/document/command.rb
Expand Up @@ -5,7 +5,7 @@ class DocumentCommand < Command
private

def doc
tab.edit_view.document
EditView.focussed_edit_view.document
end
end
end
11 changes: 5 additions & 6 deletions plugins/edit_view_swt/lib/edit_view_swt.rb
Expand Up @@ -77,27 +77,26 @@ def reset_undo
@undo_manager.reset
end


def create_document
@document = EditViewSWT::Document.new(@model.document, @mate_text.mate_document)
@model.document.controller = @document
h1 = @model.document.add_listener(:before => :new_mirror,
&method(:update_grammar))
h2 = @model.add_listener(:grammar_changed, &method(:model_grammar_changed))
h3 = @model.add_listener(:focussed, &method(:focus))
@mate_text.getTextWidget.addFocusListener(FocusListener.new(self))
@mate_text.getTextWidget.addVerifyListener(VerifyListener.new(@model.document, self))
@mate_text.getTextWidget.addModifyListener(ModifyListener.new(@model.document, self))
@handlers << [@model.document, h1] << [@model, h2]
end

def swt_focus_gained
p :focus_gained
EditView.focussed_mate_text = self
EditView.focussed_edit_view = @model
@model.focus
end

def swt_focus_lost
p :focus_lost
EditView.focussed_mate_text = nil
EditView.focussed_edit_view = nil
end

def focus
Expand All @@ -106,7 +105,7 @@ def focus

def has_focus?
focus_control = ApplicationSWT.display.get_focus_control
focus_control.parent.parent == @mate_text
focus_control == @mate_text.get_control
end

def attach_listeners
Expand Down
4 changes: 4 additions & 0 deletions plugins/edit_view_swt/lib/edit_view_swt/document.rb
Expand Up @@ -16,6 +16,10 @@ def attach_modification_listeners
styledText.add_selection_listener(SelectionListener.new(@model))
end

def single_line?
@swt_mate_document.mateText.isSingleLine
end

def to_s
jface_document.get
end
Expand Down

0 comments on commit 01a9baa

Please sign in to comment.