redcar 0.6.1 → 0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +26 -0
- data/README.md +17 -31
- data/Rakefile +1 -1
- data/bin/redcar +1 -1
- data/lib/redcar.rb +8 -4
- data/lib/redcar/installer.rb +2 -1
- data/plugins/application/features/step_definitions/dialog_steps.rb +5 -0
- data/plugins/application/features/step_definitions/tree_steps.rb +1 -1
- data/plugins/application/features/support/env.rb +38 -17
- data/plugins/application/lib/application.rb +4 -0
- data/plugins/application/lib/application/command.rb +8 -2
- data/plugins/application/lib/application/command/executor.rb +37 -8
- data/plugins/application/lib/application/command/history.rb +3 -3
- data/plugins/application/lib/application/menu.rb +4 -0
- data/plugins/application/lib/application/menu/item.rb +9 -1
- data/plugins/application/lib/application/tab.rb +11 -0
- data/plugins/application/spec/application/command/executor_spec.rb +3 -3
- data/plugins/application/spec/application/command_spec.rb +24 -0
- data/plugins/application/spec/spec_helper.rb +1 -0
- data/plugins/application_swt/lib/application_swt.rb +27 -24
- data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +4 -33
- data/plugins/application_swt/lib/application_swt/dialogs/input_dialog.rb +46 -0
- data/plugins/application_swt/lib/application_swt/dialogs/text_and_file_dialog.rb +118 -0
- data/plugins/application_swt/lib/application_swt/icon.rb +37 -0
- data/plugins/application_swt/lib/application_swt/menu.rb +8 -3
- data/plugins/application_swt/lib/application_swt/tab.rb +6 -3
- data/plugins/application_swt/lib/application_swt/treebook.rb +29 -31
- data/plugins/application_swt/lib/swt/graphics_utils.rb +170 -0
- data/plugins/application_swt/lib/swt/vtab_folder.rb +125 -0
- data/plugins/application_swt/lib/swt/vtab_item.rb +69 -0
- data/plugins/application_swt/lib/swt/vtab_label.rb +84 -0
- data/plugins/auto_indenter/lib/auto_indenter.rb +4 -2
- data/plugins/core/lib/core/controller.rb +18 -0
- data/plugins/declarations/lib/declarations.rb +1 -1
- data/plugins/document_search/lib/document_search.rb +8 -6
- data/plugins/document_search/lib/document_search/replace.rb +51 -31
- data/plugins/document_search/lib/document_search/search_and_replace.rb +12 -11
- data/plugins/edit_view/features/step_definitions/editing_steps.rb +33 -17
- data/plugins/edit_view/lib/edit_view.rb +100 -21
- data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +34 -11
- data/plugins/edit_view/lib/edit_view/actions/deletion.rb +10 -0
- data/plugins/edit_view/lib/edit_view/command.rb +5 -1
- data/plugins/edit_view/lib/edit_view/document.rb +8 -3
- data/plugins/edit_view/lib/edit_view/document/command.rb +15 -1
- data/plugins/edit_view/lib/edit_view/document/controller.rb +9 -0
- data/plugins/edit_view/lib/edit_view/document/history.rb +41 -0
- data/plugins/edit_view/lib/edit_view/tab_settings.rb +1 -11
- data/plugins/edit_view_swt/lib/edit_view_swt.rb +150 -4
- data/plugins/edit_view_swt/lib/edit_view_swt/document.rb +1 -1
- data/plugins/edit_view_swt/vendor/java-mateview.rb +1 -1
- data/plugins/find-in-project/lib/find_in_project.rb +7 -5
- data/plugins/html_view/features/step_definitions/html_view_steps.rb +2 -2
- data/plugins/line_tools/features/step_definitions/line_tools_steps.rb +0 -1
- data/plugins/line_tools/lib/line_tools.rb +7 -9
- data/plugins/macros/features/block_selection_in_macros.feature +48 -0
- data/plugins/macros/features/predictive_macros.feature +79 -0
- data/plugins/macros/features/record_and_run_macro.feature +87 -0
- data/plugins/macros/features/step_definitions/macro_steps.rb +66 -0
- data/plugins/macros/features/step_definitions/prediction_steps.rb +8 -0
- data/plugins/macros/features/support/env.rb +2 -0
- data/plugins/macros/lib/macros.rb +167 -0
- data/plugins/macros/lib/macros/action_sequence.rb +30 -0
- data/plugins/macros/lib/macros/commands.rb +108 -0
- data/plugins/macros/lib/macros/macro.rb +37 -0
- data/plugins/macros/lib/macros/manager_controller.rb +67 -0
- data/plugins/macros/lib/macros/predictive/document_controller.rb +69 -0
- data/plugins/macros/lib/macros/predictive/sequence_finder.rb +112 -0
- data/plugins/macros/plugin.rb +9 -0
- data/plugins/macros/spec/macros/predictive/sequence_finder_spec.rb +142 -0
- data/plugins/macros/spec/spec_helper.rb +6 -0
- data/plugins/macros/views/macro_manager.html.erb +86 -0
- data/plugins/outline_view/lib/outline_view.rb +1 -1
- data/plugins/project/lib/project/commands.rb +2 -2
- data/plugins/redcar/redcar.rb +37 -46
- data/plugins/repl/lib/repl.rb +4 -4
- data/plugins/runnables/features/command_tree.feature +1 -1
- data/plugins/runnables/features/parameter_input.feature +42 -0
- data/plugins/runnables/features/step_definitions/runnable_steps.rb +6 -0
- data/plugins/runnables/features/support/env.rb +28 -8
- data/plugins/runnables/lib/runnables.rb +35 -206
- data/plugins/runnables/lib/runnables/commands.rb +65 -0
- data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable.rb +62 -0
- data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb +59 -0
- data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_type_group.rb +32 -0
- data/plugins/runnables/lib/runnables/tree_mirror/tree_controller.rb +41 -0
- data/plugins/runnables/lib/runnables/tree_mirror/tree_mirror.rb +61 -0
- data/plugins/scm/lib/scm.rb +78 -45
- data/plugins/scm/lib/scm/commands.rb +18 -4
- data/plugins/scm/lib/scm/model.rb +54 -41
- data/plugins/scm_svn/LICENSE +48 -0
- data/plugins/scm_svn/features/add_and_commit.feature +18 -0
- data/plugins/scm_svn/features/checkout.feature +5 -0
- data/plugins/scm_svn/features/edit_and_index.feature +12 -0
- data/plugins/scm_svn/features/ignore_files.feature +14 -0
- data/plugins/scm_svn/features/merge.feature +34 -0
- data/plugins/scm_svn/features/resolve_conflict.feature +23 -0
- data/plugins/scm_svn/features/revert_and_delete.feature +21 -0
- data/plugins/scm_svn/features/step_definitions/branch_and_merge_steps.rb +27 -0
- data/plugins/scm_svn/features/step_definitions/checkout_steps.rb +25 -0
- data/plugins/scm_svn/features/step_definitions/edit_and_index_steps.rb +50 -0
- data/plugins/scm_svn/features/step_definitions/scm_svn_steps.rb +57 -0
- data/plugins/scm_svn/features/support/env.rb +74 -0
- data/plugins/scm_svn/features/switch_branches.feature +53 -0
- data/plugins/scm_svn/features/update.feature +16 -0
- data/plugins/scm_svn/lib/scm_svn.rb +423 -9
- data/plugins/scm_svn/lib/scm_svn/change.rb +116 -0
- data/plugins/swt/lib/swt.rb +0 -15
- data/plugins/swt/lib/swt/cucumber_patches.rb +2 -37
- data/plugins/swt/lib/swt/cucumber_runner.rb +1 -0
- data/plugins/swt/lib/swt/full_swt.rb +2 -0
- data/plugins/textmate/vendor/redcar-bundles/Bundles/Clojure.tmbundle/Syntaxes/Clojure.tmLanguage +14 -2
- data/plugins/todo_list/lib/todo_list/todo_controller.rb +1 -1
- data/plugins/todo_list/views/default.css +50 -0
- data/plugins/todo_list/views/index.html.erb +5 -16
- data/plugins/todo_list/views/redcar_small_icon.png +0 -0
- data/plugins/tree_view_swt/lib/tree_view_swt.rb +14 -33
- data/plugins/view_shortcuts/views/default.css +31 -0
- data/plugins/view_shortcuts/views/index.html.erb +26 -16
- data/plugins/view_shortcuts/views/redcar_small_icon.png +0 -0
- data/{plugins/runnables → share}/icons/cog.png +0 -0
- data/share/icons/folder-gear-emblem.png +0 -0
- data/share/icons/folder-gear.png +0 -0
- data/share/icons/folder-open-small-gears.png +0 -0
- metadata +59 -5
@@ -7,6 +7,7 @@ require "edit_view/command"
|
|
7
7
|
require "edit_view/document"
|
8
8
|
require "edit_view/document/command"
|
9
9
|
require "edit_view/document/controller"
|
10
|
+
require "edit_view/document/history"
|
10
11
|
require "edit_view/document/indentation"
|
11
12
|
require "edit_view/document/mirror"
|
12
13
|
require "edit_view/grammar"
|
@@ -23,6 +24,45 @@ require "edit_view/commands/align_assignment_command"
|
|
23
24
|
|
24
25
|
module Redcar
|
25
26
|
class EditView
|
27
|
+
ACTIONS = [
|
28
|
+
:LINE_UP,
|
29
|
+
:LINE_DOWN,
|
30
|
+
:LINE_START,
|
31
|
+
:LINE_END,
|
32
|
+
:COLUMN_PREVIOUS,
|
33
|
+
:COLUMN_NEXT,
|
34
|
+
:PAGE_UP,
|
35
|
+
:PAGE_DOWN,
|
36
|
+
:WORD_PREVIOUS,
|
37
|
+
:WORD_NEXT,
|
38
|
+
:TEXT_START,
|
39
|
+
:TEXT_END,
|
40
|
+
:WINDOW_START,
|
41
|
+
:WINDOW_END,
|
42
|
+
:SELECT_ALL,
|
43
|
+
:SELECT_LINE_UP,
|
44
|
+
:SELECT_LINE_DOWN,
|
45
|
+
:SELECT_LINE_START,
|
46
|
+
:SELECT_LINE_END,
|
47
|
+
:SELECT_COLUMN_PREVIOUS,
|
48
|
+
:SELECT_COLUMN_NEXT,
|
49
|
+
:SELECT_PAGE_UP,
|
50
|
+
:SELECT_PAGE_DOWN,
|
51
|
+
:SELECT_WORD_PREVIOUS,
|
52
|
+
:SELECT_WORD_NEXT,
|
53
|
+
:SELECT_TEXT_START,
|
54
|
+
:SELECT_TEXT_END,
|
55
|
+
:SELECT_WINDOW_START,
|
56
|
+
:SELECT_WINDOW_END,
|
57
|
+
:CUT,
|
58
|
+
:COPY,
|
59
|
+
:PASTE,
|
60
|
+
:DELETE_PREVIOUS,
|
61
|
+
:DELETE_NEXT,
|
62
|
+
:DELETE_WORD_PREVIOUS,
|
63
|
+
:DELETE_WORD_NEXT
|
64
|
+
]
|
65
|
+
|
26
66
|
include Redcar::Model
|
27
67
|
extend Redcar::Observable
|
28
68
|
include Redcar::Observable
|
@@ -53,9 +93,9 @@ module Redcar
|
|
53
93
|
def self.menus
|
54
94
|
Menu::Builder.build do
|
55
95
|
sub_menu "Edit" do
|
56
|
-
|
57
|
-
|
58
|
-
sub_menu "Convert Text" do
|
96
|
+
sub_menu "Formatting" do
|
97
|
+
item "Align Assignments", EditView::AlignAssignmentCommand
|
98
|
+
sub_menu "Convert Text", :priority => 40 do
|
59
99
|
item "to Uppercase", EditView::UpcaseTextCommand
|
60
100
|
item "to Lowercase", EditView::DowncaseTextCommand
|
61
101
|
item "to Titlecase", EditView::TitlizeTextCommand
|
@@ -64,8 +104,6 @@ module Redcar
|
|
64
104
|
item "to CamelCase", EditView::CamelCaseTextCommand
|
65
105
|
item "to snake_case", EditView::UnderscoreTextCommand
|
66
106
|
item "Toggle PascalCase-underscore-camelCase", EditView::CamelSnakePascalRotateTextCommand
|
67
|
-
separator
|
68
|
-
item "Align Assignments", EditView::AlignAssignmentCommand
|
69
107
|
end
|
70
108
|
end
|
71
109
|
end
|
@@ -321,12 +359,20 @@ module Redcar
|
|
321
359
|
Redcar.app.windows.map {|w| w.notebooks.map {|n| n.tabs}.flatten }.flatten.select {|t| t.is_a?(EditTab)}.map {|t| t.edit_view}
|
322
360
|
end
|
323
361
|
|
324
|
-
attr_reader :document
|
362
|
+
attr_reader :document, :history
|
325
363
|
|
326
364
|
def initialize
|
327
365
|
create_document
|
328
366
|
@grammar = nil
|
329
367
|
@focussed = nil
|
368
|
+
create_history
|
369
|
+
end
|
370
|
+
|
371
|
+
def create_history
|
372
|
+
@history = Document::History.new(500)
|
373
|
+
@history.subscribe do |action|
|
374
|
+
document.controllers.each {|c| c.after_action(action) }
|
375
|
+
end
|
330
376
|
end
|
331
377
|
|
332
378
|
def create_document
|
@@ -358,7 +404,6 @@ module Redcar
|
|
358
404
|
self.show_margin = EditView.tab_settings.show_margin_for(name)
|
359
405
|
refresh_show_invisibles
|
360
406
|
refresh_show_line_numbers
|
361
|
-
refresh_show_annotations
|
362
407
|
end
|
363
408
|
|
364
409
|
def focus
|
@@ -459,22 +504,13 @@ module Redcar
|
|
459
504
|
notify_listeners(:line_number_visibility_changed, @show_line_numbers)
|
460
505
|
end
|
461
506
|
|
462
|
-
def
|
463
|
-
|
507
|
+
def add_annotation(annotation_name, line, text, start, length)
|
508
|
+
start += document.offset_at_line(line)
|
509
|
+
controller.add_annotation(annotation_name, line, text, start, length)
|
464
510
|
end
|
465
511
|
|
466
|
-
def
|
467
|
-
|
468
|
-
end
|
469
|
-
|
470
|
-
def self.show_annotations=(bool)
|
471
|
-
EditView.tab_settings.set_show_annotations(bool)
|
472
|
-
all_edit_views.each {|ev| ev.refresh_show_annotations }
|
473
|
-
end
|
474
|
-
|
475
|
-
def refresh_show_annotations
|
476
|
-
@show_annotations = EditView.tab_settings.show_annotations?
|
477
|
-
notify_listeners(:annotations_visibility_changed, @show_annotations)
|
512
|
+
def add_annotation_type(name, image, rgb)
|
513
|
+
controller.add_annotation_type(name, File.expand_path("#{image}.png", ICONS_DIRECTORY), rgb)
|
478
514
|
end
|
479
515
|
|
480
516
|
def title=(title)
|
@@ -523,5 +559,48 @@ module Redcar
|
|
523
559
|
end
|
524
560
|
@last_checked = Time.now
|
525
561
|
end
|
562
|
+
|
563
|
+
# This characters have custom Redcar behaviour.
|
564
|
+
OVERRIDDEN_CHARACTERS = {
|
565
|
+
9 => [:tab_pressed, []]
|
566
|
+
}
|
567
|
+
|
568
|
+
def type_character(character)
|
569
|
+
unless custom_character_handle(character)
|
570
|
+
notify_listeners(:type_character, character)
|
571
|
+
end
|
572
|
+
history.record(character)
|
573
|
+
end
|
574
|
+
|
575
|
+
def custom_character_handle(character)
|
576
|
+
if method_call = OVERRIDDEN_CHARACTERS[character]
|
577
|
+
send(*method_call)
|
578
|
+
end
|
579
|
+
end
|
580
|
+
|
581
|
+
# These actions have custom Redcar implementations that
|
582
|
+
# override the default StyledText implementation. (Mainly for
|
583
|
+
# soft tabs purposes.)
|
584
|
+
OVERRIDDEN_ACTIONS = {
|
585
|
+
:COLUMN_PREVIOUS => Actions::ArrowLeftHandler,
|
586
|
+
:COLUMN_NEXT => Actions::ArrowRightHandler,
|
587
|
+
:SELECT_COLUMN_PREVIOUS => Actions::ArrowLeftHandler,
|
588
|
+
:SELECT_COLUMN_NEXT => Actions::ArrowRightHandler,
|
589
|
+
:DELETE_PREVIOUS => Actions::BackspaceHandler,
|
590
|
+
:DELETE_NEXT => Actions::DeleteHandler
|
591
|
+
}
|
592
|
+
|
593
|
+
def invoke_overridden_action(action_symbol)
|
594
|
+
if handler = OVERRIDDEN_ACTIONS[action_symbol]
|
595
|
+
handler.send(action_symbol.to_s.downcase, self)
|
596
|
+
end
|
597
|
+
end
|
598
|
+
|
599
|
+
def invoke_action(action_symbol)
|
600
|
+
unless invoke_overridden_action(action_symbol)
|
601
|
+
notify_listeners(:invoke_action, action_symbol)
|
602
|
+
end
|
603
|
+
history.record(action_symbol)
|
604
|
+
end
|
526
605
|
end
|
527
606
|
end
|
@@ -36,14 +36,26 @@ module Redcar
|
|
36
36
|
class ArrowLeftHandler < ArrowHandler
|
37
37
|
def self.handle(edit_view, modifiers)
|
38
38
|
return if (modifiers & %w(Alt Cmd Ctrl)).any?
|
39
|
-
return if edit_view.document.block_selection_mode?
|
40
|
-
doc = edit_view.document
|
41
39
|
if modifiers.include?("Shift")
|
42
|
-
|
43
|
-
doc.set_selection_range(move_left_offset(edit_view), old_selection_offset)
|
40
|
+
select_column_previous(edit_view)
|
44
41
|
else
|
45
|
-
|
42
|
+
column_previous(edit_view)
|
46
43
|
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def self.column_previous(edit_view)
|
47
|
+
return false if edit_view.document.block_selection_mode?
|
48
|
+
doc = edit_view.document
|
49
|
+
doc.cursor_offset = move_left_offset(edit_view)
|
50
|
+
ArrowHandler.ensure_cursor_in_view(edit_view)
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.select_column_previous(edit_view)
|
55
|
+
return false if edit_view.document.block_selection_mode?
|
56
|
+
doc = edit_view.document
|
57
|
+
old_selection_offset = doc.selection_offset
|
58
|
+
doc.set_selection_range(move_left_offset(edit_view), old_selection_offset)
|
47
59
|
ArrowHandler.ensure_cursor_in_view(edit_view)
|
48
60
|
true
|
49
61
|
end
|
@@ -82,15 +94,26 @@ module Redcar
|
|
82
94
|
class ArrowRightHandler < ArrowHandler
|
83
95
|
def self.handle(edit_view, modifiers)
|
84
96
|
return if (modifiers & %w(Alt Cmd Ctrl)).any?
|
85
|
-
return if edit_view.document.block_selection_mode?
|
86
|
-
doc = edit_view.document
|
87
|
-
|
88
97
|
if modifiers.include?("Shift")
|
89
|
-
|
90
|
-
doc.set_selection_range(move_right_offset(edit_view), old_selection_offset)
|
98
|
+
select_column_next(edit_view)
|
91
99
|
else
|
92
|
-
|
100
|
+
column_next(edit_view)
|
93
101
|
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def self.column_next(edit_view)
|
105
|
+
return false if edit_view.document.block_selection_mode?
|
106
|
+
doc = edit_view.document
|
107
|
+
doc.cursor_offset = move_right_offset(edit_view)
|
108
|
+
ArrowHandler.ensure_cursor_in_view(edit_view)
|
109
|
+
true
|
110
|
+
end
|
111
|
+
|
112
|
+
def self.select_column_next(edit_view)
|
113
|
+
return false if edit_view.document.block_selection_mode?
|
114
|
+
doc = edit_view.document
|
115
|
+
old_selection_offset = doc.selection_offset
|
116
|
+
doc.set_selection_range(move_right_offset(edit_view), old_selection_offset)
|
94
117
|
ArrowHandler.ensure_cursor_in_view(edit_view)
|
95
118
|
true
|
96
119
|
end
|
@@ -5,24 +5,34 @@ module Redcar
|
|
5
5
|
class DeleteHandler
|
6
6
|
def self.handle(edit_view, modifiers)
|
7
7
|
return if modifiers.any?
|
8
|
+
delete_next(edit_view)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.delete_next(edit_view)
|
8
12
|
return if edit_view.document.selection?
|
9
13
|
return if edit_view.document.block_selection_mode?
|
10
14
|
doc = edit_view.document
|
11
15
|
old_offset = doc.cursor_offset
|
12
16
|
new_offset = ArrowRightHandler.move_right_offset(edit_view)
|
13
17
|
doc.delete(old_offset, new_offset - old_offset)
|
18
|
+
true
|
14
19
|
end
|
15
20
|
end
|
16
21
|
|
17
22
|
class BackspaceHandler
|
18
23
|
def self.handle(edit_view, modifiers)
|
19
24
|
return if modifiers.any?
|
25
|
+
delete_previous(edit_view)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.delete_previous(edit_view)
|
20
29
|
return if edit_view.document.selection?
|
21
30
|
return if edit_view.document.block_selection_mode?
|
22
31
|
doc = edit_view.document
|
23
32
|
old_offset = doc.cursor_offset
|
24
33
|
new_offset = ArrowLeftHandler.move_left_offset(edit_view)
|
25
34
|
doc.delete(new_offset, old_offset - new_offset)
|
35
|
+
true
|
26
36
|
end
|
27
37
|
end
|
28
38
|
end
|
@@ -31,7 +31,8 @@ module Redcar
|
|
31
31
|
@controllers = {
|
32
32
|
Controller::ModificationCallbacks => [],
|
33
33
|
Controller::NewlineCallback => [],
|
34
|
-
Controller::CursorCallbacks => []
|
34
|
+
Controller::CursorCallbacks => [],
|
35
|
+
Controller => []
|
35
36
|
}
|
36
37
|
Document.all_document_controller_types.each do |type|
|
37
38
|
controller = type.new
|
@@ -54,8 +55,12 @@ module Redcar
|
|
54
55
|
|
55
56
|
end
|
56
57
|
|
57
|
-
def controllers(klass)
|
58
|
-
|
58
|
+
def controllers(klass=nil)
|
59
|
+
if klass
|
60
|
+
@controllers.values.flatten.uniq.select {|c| c.is_a?(klass) }
|
61
|
+
else
|
62
|
+
@controllers.values.flatten.uniq
|
63
|
+
end
|
59
64
|
end
|
60
65
|
|
61
66
|
def save!
|
@@ -2,10 +2,24 @@ module Redcar
|
|
2
2
|
class DocumentCommand < Command
|
3
3
|
sensitize :edit_view_focussed
|
4
4
|
|
5
|
+
def _finished
|
6
|
+
edit_view.history.record(self)
|
7
|
+
end
|
8
|
+
|
9
|
+
def run_in_focussed_tab_edit_view
|
10
|
+
if edit_view = Redcar::EditView.focussed_tab_edit_view
|
11
|
+
run(:env => {:edit_view => edit_view})
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
private
|
6
16
|
|
17
|
+
def edit_view
|
18
|
+
env[:edit_view] || EditView.focussed_edit_view
|
19
|
+
end
|
20
|
+
|
7
21
|
def doc
|
8
|
-
|
22
|
+
edit_view.document
|
9
23
|
end
|
10
24
|
end
|
11
25
|
end
|
@@ -8,6 +8,15 @@ module Redcar
|
|
8
8
|
"<#{self.class}>"
|
9
9
|
end
|
10
10
|
|
11
|
+
# Called after every user action that modifies the document.
|
12
|
+
# E.g. typing "a", moving up, running a search. NOT included
|
13
|
+
# is modifications made by calling methods on Document, but they
|
14
|
+
# are usually implied by the Commands that make them.
|
15
|
+
#
|
16
|
+
# @param [String|Symbol|DocumentCommand] This is a document action.
|
17
|
+
def after_action(action)
|
18
|
+
end
|
19
|
+
|
11
20
|
module ModificationCallbacks
|
12
21
|
def before_modify(start_offset, end_offset, text)
|
13
22
|
raise "not implemented"
|
@@ -0,0 +1,41 @@
|
|
1
|
+
|
2
|
+
module Redcar
|
3
|
+
class Document
|
4
|
+
class History < Array
|
5
|
+
attr_reader :max
|
6
|
+
|
7
|
+
def initialize(max)
|
8
|
+
@max = max
|
9
|
+
@subscribers = []
|
10
|
+
end
|
11
|
+
|
12
|
+
# Record an action in the History
|
13
|
+
def record(action)
|
14
|
+
self << action
|
15
|
+
notify_subscribers(action)
|
16
|
+
truncate
|
17
|
+
end
|
18
|
+
|
19
|
+
def subscribe(&block)
|
20
|
+
@subscribers << block
|
21
|
+
block
|
22
|
+
end
|
23
|
+
|
24
|
+
def unsubscribe(block)
|
25
|
+
@subscribers.delete(block)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def notify_subscribers(action)
|
31
|
+
@subscribers.each {|subscriber| subscriber.call(action)}
|
32
|
+
end
|
33
|
+
|
34
|
+
def truncate #:nodoc:
|
35
|
+
if length > @max + 100
|
36
|
+
self[0..(length - @max)] = nil
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -11,7 +11,7 @@ module Redcar
|
|
11
11
|
|
12
12
|
attr_reader :tab_widths, :softnesses, :word_wraps, :margin_columns
|
13
13
|
attr_reader :show_margins
|
14
|
-
attr_reader :show_invisibles, :show_line_numbers
|
14
|
+
attr_reader :show_invisibles, :show_line_numbers
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
@tab_widths =
|
@@ -31,7 +31,6 @@ module Redcar
|
|
31
31
|
EditView.storage['show_margins'] || {})
|
32
32
|
@show_invisibles = !!EditView.storage['show_invisibles']
|
33
33
|
@show_line_numbers = !!EditView.storage['show_line_numbers']
|
34
|
-
@show_annotations = !!EditView.storage['show_annotations']
|
35
34
|
end
|
36
35
|
|
37
36
|
def width_for(grammar_name)
|
@@ -123,15 +122,6 @@ module Redcar
|
|
123
122
|
EditView.storage['show_line_numbers'] = bool
|
124
123
|
end
|
125
124
|
|
126
|
-
def show_annotations?
|
127
|
-
show_annotations
|
128
|
-
end
|
129
|
-
|
130
|
-
def set_show_annotations(bool)
|
131
|
-
@show_annotations = bool
|
132
|
-
EditView.storage['show_annotations'] = bool
|
133
|
-
end
|
134
|
-
|
135
125
|
def show_margin?
|
136
126
|
show_margin
|
137
127
|
end
|
@@ -12,7 +12,55 @@ require File.dirname(__FILE__) + '/../vendor/java-mateview'
|
|
12
12
|
|
13
13
|
module Redcar
|
14
14
|
class EditViewSWT
|
15
|
+
NAVIGATION_COMMANDS = {
|
16
|
+
:LINE_UP => 16777217,
|
17
|
+
:LINE_DOWN => 16777218,
|
18
|
+
:LINE_START => 16777223,
|
19
|
+
:LINE_END => 16777224,
|
20
|
+
:COLUMN_PREVIOUS => 16777219,
|
21
|
+
:COLUMN_NEXT => 16777220,
|
22
|
+
:PAGE_UP => 16777221,
|
23
|
+
:PAGE_DOWN => 16777222,
|
24
|
+
:WORD_PREVIOUS => 17039363,
|
25
|
+
:WORD_NEXT => 17039364,
|
26
|
+
:TEXT_START => 17039367,
|
27
|
+
:TEXT_END => 17039368,
|
28
|
+
:WINDOW_START => 17039365,
|
29
|
+
:WINDOW_END => 17039366
|
30
|
+
}
|
31
|
+
|
32
|
+
SELECTION_COMMANDS = {
|
33
|
+
:SELECT_ALL => 262209,
|
34
|
+
:SELECT_LINE_UP => 16908289,
|
35
|
+
:SELECT_LINE_DOWN => 16908290,
|
36
|
+
:SELECT_LINE_START => 16908295,
|
37
|
+
:SELECT_LINE_END => 16908296,
|
38
|
+
:SELECT_COLUMN_PREVIOUS => 16908291,
|
39
|
+
:SELECT_COLUMN_NEXT => 16908292,
|
40
|
+
:SELECT_PAGE_UP => 16908293,
|
41
|
+
:SELECT_PAGE_DOWN => 16908294,
|
42
|
+
:SELECT_WORD_PREVIOUS => 17170435,
|
43
|
+
:SELECT_WORD_NEXT => 17170436,
|
44
|
+
:SELECT_TEXT_START => 17170439,
|
45
|
+
:SELECT_TEXT_END => 17170440,
|
46
|
+
:SELECT_WINDOW_START => 17170437,
|
47
|
+
:SELECT_WINDOW_END => 17170438
|
48
|
+
}
|
49
|
+
|
50
|
+
MODIFICATION_COMMANDS = {
|
51
|
+
:CUT => 131199,
|
52
|
+
:COPY => 17039369,
|
53
|
+
:PASTE => 16908297,
|
54
|
+
:DELETE_PREVIOUS => 8,
|
55
|
+
:DELETE_NEXT => 0x7F,
|
56
|
+
:DELETE_WORD_PREVIOUS => 262152,
|
57
|
+
:DELETE_WORD_NEXT => 262271
|
58
|
+
}
|
59
|
+
|
60
|
+
ALL_ACTIONS = NAVIGATION_COMMANDS.merge(SELECTION_COMMANDS).merge(MODIFICATION_COMMANDS)
|
61
|
+
|
15
62
|
include Redcar::Observable
|
63
|
+
include Redcar::Controller
|
16
64
|
|
17
65
|
def self.start
|
18
66
|
if gui = Redcar.gui
|
@@ -59,6 +107,8 @@ module Redcar
|
|
59
107
|
mate_text.add_grammar_listener do |new_grammar|
|
60
108
|
@model.set_grammar(new_grammar)
|
61
109
|
end
|
110
|
+
|
111
|
+
create_model_listeners
|
62
112
|
end
|
63
113
|
|
64
114
|
def create_mate_text
|
@@ -66,6 +116,82 @@ module Redcar
|
|
66
116
|
@mate_text.set_font(EditView.font, EditView.font_size)
|
67
117
|
|
68
118
|
@model.controller = self
|
119
|
+
|
120
|
+
add_styled_text_command_key_listeners
|
121
|
+
end
|
122
|
+
|
123
|
+
class CommandKeyListener
|
124
|
+
|
125
|
+
attr_reader :st
|
126
|
+
|
127
|
+
def initialize(styled_text, edit_view)
|
128
|
+
@edit_view = edit_view
|
129
|
+
@st = styled_text
|
130
|
+
end
|
131
|
+
|
132
|
+
def key_pressed(event)
|
133
|
+
end
|
134
|
+
|
135
|
+
def key_released(event)
|
136
|
+
record_action(event)
|
137
|
+
end
|
138
|
+
|
139
|
+
# This pile of crap is copied from StyledText#handleKey. Wouldn't
|
140
|
+
# it be great if this logic was accessible on StyledText somehow?
|
141
|
+
def record_action(event)
|
142
|
+
if (event.keyCode != 0)
|
143
|
+
# special key pressed (e.g., F1)
|
144
|
+
action = st.getKeyBinding(event.keyCode | event.stateMask)
|
145
|
+
else
|
146
|
+
# character key pressed
|
147
|
+
action = st.getKeyBinding(event.character | event.stateMask)
|
148
|
+
if (action == Swt::SWT::NULL)
|
149
|
+
# see if we have a control character
|
150
|
+
if ((event.stateMask & SWT.CTRL) != 0 && event.character <= 31)
|
151
|
+
# get the character from the CTRL+char sequence, the control
|
152
|
+
# key subtracts 64 from the value of the key that it modifies
|
153
|
+
c = event.character + 64
|
154
|
+
action = st.getKeyBinding(c | event.stateMask)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
if (action == Swt::SWT::NULL)
|
160
|
+
ignore = false
|
161
|
+
|
162
|
+
if (Redcar.platform == :osx)
|
163
|
+
# Ignore accelerator key combinations (we do not want to
|
164
|
+
# insert a character in the text in this instance). Do not
|
165
|
+
# ignore COMMAND+ALT combinations since that key sequence
|
166
|
+
# produces characters on the mac.
|
167
|
+
ignore = (event.stateMask & Swt::SWT::COMMAND) != 0 ||
|
168
|
+
(event.stateMask & Swt::SWT::CTRL) != 0
|
169
|
+
else
|
170
|
+
# Ignore accelerator key combinations (we do not want to
|
171
|
+
# insert a character in the text in this instance). Don't
|
172
|
+
# ignore CTRL+ALT combinations since that is the Alt Gr
|
173
|
+
# key on some keyboards. See bug 20953.
|
174
|
+
ignore = (event.stateMask ^ Swt::SWT::ALT) == 0 ||
|
175
|
+
(event.stateMask ^ Swt::SWT::CTRL) == 0 ||
|
176
|
+
(event.stateMask ^ (Swt::SWT::ALT | Swt::SWT::SHIFT)) == 0 ||
|
177
|
+
(event.stateMask ^ (Swt::SWT::CTRL | Swt::SWT::SHIFT)) == 0
|
178
|
+
end
|
179
|
+
# -ignore anything below SPACE except for line delimiter keys and tab.
|
180
|
+
# -ignore DEL
|
181
|
+
if (!ignore && event.character > 31 && event.character != Swt::SWT::DEL ||
|
182
|
+
event.character == Swt::SWT::CR || event.character == Swt::SWT::LF ||
|
183
|
+
event.character == Swt::SWT::TAB)
|
184
|
+
@edit_view.history.record(event.character)
|
185
|
+
end
|
186
|
+
else
|
187
|
+
@edit_view.history.record(EditViewSWT::ALL_ACTIONS.invert[action])
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
def add_styled_text_command_key_listeners
|
193
|
+
st = @mate_text.get_text_widget
|
194
|
+
st.add_key_listener(CommandKeyListener.new(st, @model))
|
69
195
|
end
|
70
196
|
|
71
197
|
def create_undo_manager
|
@@ -111,6 +237,15 @@ module Redcar
|
|
111
237
|
@undo_manager.end_compound_change
|
112
238
|
end
|
113
239
|
|
240
|
+
def add_annotation_type(name, image_path, rgb)
|
241
|
+
rgb = Swt::Graphics::RGB.new(rgb[0], rgb[1], rgb[2])
|
242
|
+
@mate_text.addAnnotationType(name, image_path, rgb)
|
243
|
+
end
|
244
|
+
|
245
|
+
def add_annotation(annotation_name, line, text, start, length)
|
246
|
+
@mate_text.addAnnotation(annotation_name, line, text, start, length)
|
247
|
+
end
|
248
|
+
|
114
249
|
def create_document
|
115
250
|
@document = EditViewSWT::Document.new(@model.document, @mate_text.mate_document)
|
116
251
|
@model.document.controller = @document
|
@@ -136,9 +271,6 @@ module Redcar
|
|
136
271
|
h9 = @model.add_listener(:line_number_visibility_changed) do |new_bool|
|
137
272
|
@mate_text.set_line_numbers_visible(new_bool)
|
138
273
|
end
|
139
|
-
h10 = @model.add_listener(:annotations_visibility_changed) do |new_bool|
|
140
|
-
@mate_text.set_annotations_visible(new_bool)
|
141
|
-
end
|
142
274
|
h11 = @model.add_listener(:margin_column_changed) do |new_column|
|
143
275
|
@mate_text.set_margin_column(new_column)
|
144
276
|
end
|
@@ -157,7 +289,7 @@ module Redcar
|
|
157
289
|
@mate_text.get_control.add_key_listener(KeyListener.new(self))
|
158
290
|
@handlers << [@model.document, h1] << [@model, h2] << [@model, h3] << [@model, h4] <<
|
159
291
|
[@model, h5] << [@model, h6] << [@model, h7] << [@model, h8] <<
|
160
|
-
[@model, h9] << [@model,
|
292
|
+
[@model, h9] << [@model, h11]
|
161
293
|
end
|
162
294
|
|
163
295
|
def right_click(mouse_event)
|
@@ -169,6 +301,20 @@ module Redcar
|
|
169
301
|
end
|
170
302
|
end
|
171
303
|
end
|
304
|
+
|
305
|
+
def type_character(character)
|
306
|
+
mate_text.get_text_widget.doContent(character)
|
307
|
+
mate_text.get_text_widget.update
|
308
|
+
end
|
309
|
+
|
310
|
+
model_listener :type_character
|
311
|
+
|
312
|
+
def invoke_action(action_symbol)
|
313
|
+
const = EditViewSWT::ALL_ACTIONS[action_symbol]
|
314
|
+
mate_text.get_text_widget.invokeAction(const)
|
315
|
+
end
|
316
|
+
|
317
|
+
model_listener :invoke_action
|
172
318
|
|
173
319
|
class VerifyKeyListener
|
174
320
|
def initialize(edit_view_swt)
|