redcar 0.6.1 → 0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (124) hide show
  1. data/CHANGES +26 -0
  2. data/README.md +17 -31
  3. data/Rakefile +1 -1
  4. data/bin/redcar +1 -1
  5. data/lib/redcar.rb +8 -4
  6. data/lib/redcar/installer.rb +2 -1
  7. data/plugins/application/features/step_definitions/dialog_steps.rb +5 -0
  8. data/plugins/application/features/step_definitions/tree_steps.rb +1 -1
  9. data/plugins/application/features/support/env.rb +38 -17
  10. data/plugins/application/lib/application.rb +4 -0
  11. data/plugins/application/lib/application/command.rb +8 -2
  12. data/plugins/application/lib/application/command/executor.rb +37 -8
  13. data/plugins/application/lib/application/command/history.rb +3 -3
  14. data/plugins/application/lib/application/menu.rb +4 -0
  15. data/plugins/application/lib/application/menu/item.rb +9 -1
  16. data/plugins/application/lib/application/tab.rb +11 -0
  17. data/plugins/application/spec/application/command/executor_spec.rb +3 -3
  18. data/plugins/application/spec/application/command_spec.rb +24 -0
  19. data/plugins/application/spec/spec_helper.rb +1 -0
  20. data/plugins/application_swt/lib/application_swt.rb +27 -24
  21. data/plugins/application_swt/lib/application_swt/dialog_adapter.rb +4 -33
  22. data/plugins/application_swt/lib/application_swt/dialogs/input_dialog.rb +46 -0
  23. data/plugins/application_swt/lib/application_swt/dialogs/text_and_file_dialog.rb +118 -0
  24. data/plugins/application_swt/lib/application_swt/icon.rb +37 -0
  25. data/plugins/application_swt/lib/application_swt/menu.rb +8 -3
  26. data/plugins/application_swt/lib/application_swt/tab.rb +6 -3
  27. data/plugins/application_swt/lib/application_swt/treebook.rb +29 -31
  28. data/plugins/application_swt/lib/swt/graphics_utils.rb +170 -0
  29. data/plugins/application_swt/lib/swt/vtab_folder.rb +125 -0
  30. data/plugins/application_swt/lib/swt/vtab_item.rb +69 -0
  31. data/plugins/application_swt/lib/swt/vtab_label.rb +84 -0
  32. data/plugins/auto_indenter/lib/auto_indenter.rb +4 -2
  33. data/plugins/core/lib/core/controller.rb +18 -0
  34. data/plugins/declarations/lib/declarations.rb +1 -1
  35. data/plugins/document_search/lib/document_search.rb +8 -6
  36. data/plugins/document_search/lib/document_search/replace.rb +51 -31
  37. data/plugins/document_search/lib/document_search/search_and_replace.rb +12 -11
  38. data/plugins/edit_view/features/step_definitions/editing_steps.rb +33 -17
  39. data/plugins/edit_view/lib/edit_view.rb +100 -21
  40. data/plugins/edit_view/lib/edit_view/actions/arrow_keys.rb +34 -11
  41. data/plugins/edit_view/lib/edit_view/actions/deletion.rb +10 -0
  42. data/plugins/edit_view/lib/edit_view/command.rb +5 -1
  43. data/plugins/edit_view/lib/edit_view/document.rb +8 -3
  44. data/plugins/edit_view/lib/edit_view/document/command.rb +15 -1
  45. data/plugins/edit_view/lib/edit_view/document/controller.rb +9 -0
  46. data/plugins/edit_view/lib/edit_view/document/history.rb +41 -0
  47. data/plugins/edit_view/lib/edit_view/tab_settings.rb +1 -11
  48. data/plugins/edit_view_swt/lib/edit_view_swt.rb +150 -4
  49. data/plugins/edit_view_swt/lib/edit_view_swt/document.rb +1 -1
  50. data/plugins/edit_view_swt/vendor/java-mateview.rb +1 -1
  51. data/plugins/find-in-project/lib/find_in_project.rb +7 -5
  52. data/plugins/html_view/features/step_definitions/html_view_steps.rb +2 -2
  53. data/plugins/line_tools/features/step_definitions/line_tools_steps.rb +0 -1
  54. data/plugins/line_tools/lib/line_tools.rb +7 -9
  55. data/plugins/macros/features/block_selection_in_macros.feature +48 -0
  56. data/plugins/macros/features/predictive_macros.feature +79 -0
  57. data/plugins/macros/features/record_and_run_macro.feature +87 -0
  58. data/plugins/macros/features/step_definitions/macro_steps.rb +66 -0
  59. data/plugins/macros/features/step_definitions/prediction_steps.rb +8 -0
  60. data/plugins/macros/features/support/env.rb +2 -0
  61. data/plugins/macros/lib/macros.rb +167 -0
  62. data/plugins/macros/lib/macros/action_sequence.rb +30 -0
  63. data/plugins/macros/lib/macros/commands.rb +108 -0
  64. data/plugins/macros/lib/macros/macro.rb +37 -0
  65. data/plugins/macros/lib/macros/manager_controller.rb +67 -0
  66. data/plugins/macros/lib/macros/predictive/document_controller.rb +69 -0
  67. data/plugins/macros/lib/macros/predictive/sequence_finder.rb +112 -0
  68. data/plugins/macros/plugin.rb +9 -0
  69. data/plugins/macros/spec/macros/predictive/sequence_finder_spec.rb +142 -0
  70. data/plugins/macros/spec/spec_helper.rb +6 -0
  71. data/plugins/macros/views/macro_manager.html.erb +86 -0
  72. data/plugins/outline_view/lib/outline_view.rb +1 -1
  73. data/plugins/project/lib/project/commands.rb +2 -2
  74. data/plugins/redcar/redcar.rb +37 -46
  75. data/plugins/repl/lib/repl.rb +4 -4
  76. data/plugins/runnables/features/command_tree.feature +1 -1
  77. data/plugins/runnables/features/parameter_input.feature +42 -0
  78. data/plugins/runnables/features/step_definitions/runnable_steps.rb +6 -0
  79. data/plugins/runnables/features/support/env.rb +28 -8
  80. data/plugins/runnables/lib/runnables.rb +35 -206
  81. data/plugins/runnables/lib/runnables/commands.rb +65 -0
  82. data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable.rb +62 -0
  83. data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_group.rb +59 -0
  84. data/plugins/runnables/lib/runnables/tree_mirror/nodes/runnable_type_group.rb +32 -0
  85. data/plugins/runnables/lib/runnables/tree_mirror/tree_controller.rb +41 -0
  86. data/plugins/runnables/lib/runnables/tree_mirror/tree_mirror.rb +61 -0
  87. data/plugins/scm/lib/scm.rb +78 -45
  88. data/plugins/scm/lib/scm/commands.rb +18 -4
  89. data/plugins/scm/lib/scm/model.rb +54 -41
  90. data/plugins/scm_svn/LICENSE +48 -0
  91. data/plugins/scm_svn/features/add_and_commit.feature +18 -0
  92. data/plugins/scm_svn/features/checkout.feature +5 -0
  93. data/plugins/scm_svn/features/edit_and_index.feature +12 -0
  94. data/plugins/scm_svn/features/ignore_files.feature +14 -0
  95. data/plugins/scm_svn/features/merge.feature +34 -0
  96. data/plugins/scm_svn/features/resolve_conflict.feature +23 -0
  97. data/plugins/scm_svn/features/revert_and_delete.feature +21 -0
  98. data/plugins/scm_svn/features/step_definitions/branch_and_merge_steps.rb +27 -0
  99. data/plugins/scm_svn/features/step_definitions/checkout_steps.rb +25 -0
  100. data/plugins/scm_svn/features/step_definitions/edit_and_index_steps.rb +50 -0
  101. data/plugins/scm_svn/features/step_definitions/scm_svn_steps.rb +57 -0
  102. data/plugins/scm_svn/features/support/env.rb +74 -0
  103. data/plugins/scm_svn/features/switch_branches.feature +53 -0
  104. data/plugins/scm_svn/features/update.feature +16 -0
  105. data/plugins/scm_svn/lib/scm_svn.rb +423 -9
  106. data/plugins/scm_svn/lib/scm_svn/change.rb +116 -0
  107. data/plugins/swt/lib/swt.rb +0 -15
  108. data/plugins/swt/lib/swt/cucumber_patches.rb +2 -37
  109. data/plugins/swt/lib/swt/cucumber_runner.rb +1 -0
  110. data/plugins/swt/lib/swt/full_swt.rb +2 -0
  111. data/plugins/textmate/vendor/redcar-bundles/Bundles/Clojure.tmbundle/Syntaxes/Clojure.tmLanguage +14 -2
  112. data/plugins/todo_list/lib/todo_list/todo_controller.rb +1 -1
  113. data/plugins/todo_list/views/default.css +50 -0
  114. data/plugins/todo_list/views/index.html.erb +5 -16
  115. data/plugins/todo_list/views/redcar_small_icon.png +0 -0
  116. data/plugins/tree_view_swt/lib/tree_view_swt.rb +14 -33
  117. data/plugins/view_shortcuts/views/default.css +31 -0
  118. data/plugins/view_shortcuts/views/index.html.erb +26 -16
  119. data/plugins/view_shortcuts/views/redcar_small_icon.png +0 -0
  120. data/{plugins/runnables → share}/icons/cog.png +0 -0
  121. data/share/icons/folder-gear-emblem.png +0 -0
  122. data/share/icons/folder-gear.png +0 -0
  123. data/share/icons/folder-open-small-gears.png +0 -0
  124. metadata +59 -5
@@ -25,7 +25,7 @@ module Redcar
25
25
  end
26
26
  Application::Dialog.popup_menu(menu, :pointer)
27
27
  end
28
-
28
+
29
29
  def attach_modification_listeners
30
30
  jface_document.add_document_listener(DocumentListener.new(@model))
31
31
  styledText.add_selection_listener(SelectionListener.new(@model))
@@ -32,4 +32,4 @@ module JavaMateView
32
32
  end
33
33
  end
34
34
 
35
-
35
+
@@ -5,10 +5,12 @@ module Redcar
5
5
  class FindInProject
6
6
  def self.menus
7
7
  Redcar::Menu::Builder.build do
8
- sub_menu "Plugins" do
9
- sub_menu "Find In Project", :priority => 64 do
10
- item "Find In Project!", Redcar::FindInProject::OpenSearch
11
- item "Edit Preferences", Redcar::FindInProject::EditPreferences
8
+ sub_menu "Edit" do
9
+ sub_menu "Search" do
10
+ sub_menu "Find In Project", :priority => 64 do
11
+ item "Find In Project!", Redcar::FindInProject::OpenSearch
12
+ item "Edit Preferences", Redcar::FindInProject::EditPreferences
13
+ end
12
14
  end
13
15
  end
14
16
  end
@@ -16,7 +18,7 @@ module Redcar
16
18
 
17
19
  def self.toolbars
18
20
  ToolBar::Builder.build do
19
- item "Find in Project", :command => OpenSearch, :icon => File.join(Redcar::ICONS_DIRECTORY, "application-search-result.png"), :barname => :search
21
+ item "Find in Project", :command => OpenSearch, :icon => File.join(Redcar::ICONS_DIRECTORY, "application-search-result.png"), :barname => :project
20
22
  end
21
23
  end
22
24
 
@@ -7,7 +7,7 @@ Then /^the HTML tab (should say|says) "([^"]*)"$/ do |_, needle|
7
7
  started = true
8
8
  start = Time.now
9
9
  contents = get_browser_contents
10
- while !contents.match(needle) && Time.now - start < limit
10
+ while !contents or (contents and !contents.match(needle)) && Time.now - start < limit
11
11
  contents = get_browser_contents
12
12
  sleep 0.1
13
13
  end
@@ -19,4 +19,4 @@ Then /^the HTML tab (should say|says) "([^"]*)"$/ do |_, needle|
19
19
  # on current version of SWT and XulRunner. More info at:
20
20
  # https://bugs.eclipse.org/bugs/show_bug.cgi?id=259687
21
21
  contents.should match needle unless Redcar.platform == :windows
22
- end
22
+ end
@@ -18,7 +18,6 @@ When /^I replace the line$/ do
18
18
  Redcar::LineTools::ReplaceLineCommand.new.run
19
19
  end
20
20
 
21
-
22
21
  When /^I clear the line$/ do
23
22
  Redcar::LineTools::ClearLineCommand.new.run
24
23
  end
@@ -5,15 +5,13 @@ module Redcar
5
5
  def self.menus
6
6
  Menu::Builder.build do
7
7
  sub_menu "Edit" do
8
- group(:priority => 110) do
9
- sub_menu "Line Tools" do
10
- item "Raise Region", LineTools::RaiseTextCommand
11
- item "Lower Region", LineTools::LowerTextCommand
12
- item "Replace Line", LineTools::ReplaceLineCommand
13
- item "Clear Line" , LineTools::ClearLineCommand
14
- item "Trim Line" , LineTools::TrimLineAfterCursorCommand
15
- item "Kill Line" , LineTools::KillLineCommand
16
- end
8
+ sub_menu "Line Tools" do
9
+ item "Raise Region", LineTools::RaiseTextCommand
10
+ item "Lower Region", LineTools::LowerTextCommand
11
+ item "Replace Line", LineTools::ReplaceLineCommand
12
+ item "Clear Line" , LineTools::ClearLineCommand
13
+ item "Trim Line" , LineTools::TrimLineAfterCursorCommand
14
+ item "Kill Line" , LineTools::KillLineCommand
17
15
  end
18
16
  end
19
17
  end
@@ -0,0 +1,48 @@
1
+ #Feature: Block selection in macros
2
+ # The macros should behave correctly around block selection mode.
3
+ #
4
+ # Background:
5
+ # When I open a new edit tab
6
+ # Given the content is:
7
+ # """
8
+ # foo
9
+ # bar
10
+ # baz
11
+ # """
12
+ # And I move to the start of the text
13
+ #
14
+ # Scenario: Set the correct block selection mode before running the macro
15
+ # When I turn block selection on
16
+ # And I start recording a macro
17
+ # And I select down
18
+ # And I select down
19
+ # And I type "a"
20
+ # And I stop recording a macro
21
+ # And I turn block selection off
22
+ # And I move to the start of the text
23
+ # And I run the last recorded macro
24
+ # Then the content should be:
25
+ # """
26
+ # aafoo
27
+ # aabar
28
+ # aabaz
29
+ # """
30
+ #
31
+ # Scenario: Change block selection mode during the macro
32
+ # And I start recording a macro
33
+ # When I turn block selection on
34
+ # And I select down
35
+ # And I select down
36
+ # And I type "a"
37
+ # And I stop recording a macro
38
+ # And I turn block selection off
39
+ # And I move to the start of the text
40
+ # And I run the last recorded macro
41
+ # Then the content should be:
42
+ # """
43
+ # aafoo
44
+ # aabar
45
+ # aabaz
46
+ # """
47
+ #
48
+
@@ -0,0 +1,79 @@
1
+ Feature: Predictive macros
2
+ As a user
3
+ I want Redcar to read my mind
4
+ So I don't have to type stuff
5
+
6
+ Background:
7
+ When I open a new edit tab
8
+
9
+ Scenario: Repeat simple command sequence that is fully repeated
10
+ When I type "abab"
11
+ And I press predict
12
+ Then the contents should be "ababab"
13
+
14
+ Scenario: Repeat simple command sequence that is fully repeated twice
15
+ When I type "abab"
16
+ And I press predict
17
+ And I press predict
18
+ Then the contents should be "abababab"
19
+
20
+ Scenario: Repeat simple command sequence that is partially repeated
21
+ When I type "aba"
22
+ And I press predict
23
+ Then the contents should be "abab"
24
+
25
+ Scenario: Should continue repeating same prediction even if a longer pattern is spotted
26
+ When I type "abab"
27
+ And I press predict
28
+ And I press predict
29
+ And I press predict
30
+ Then the contents should be "ababababab"
31
+
32
+ Scenario: Can define a new pattern after repeating
33
+ When I type "abab"
34
+ And I press predict
35
+ When I type "cdcd"
36
+ And I press predict
37
+ Then the contents should be "abababcdcdcd"
38
+
39
+ Scenario: Can change prediction
40
+ When I type "abccabcc"
41
+ And I press predict
42
+ Then the contents should be "abccabccabcc"
43
+ When I press alternate predict
44
+ Then the contents should be "abccabccc"
45
+
46
+ Scenario: Shouldn't raise an error when there are no predictions
47
+ When I type "abc"
48
+ And I press predict
49
+ Then the contents should be "abc"
50
+
51
+ Scenario: Commenting example with full repeat
52
+ Given I replace the contents with "foo\nbar\nbaz\nqux\nquux\ncorge"
53
+ And I move the cursor to 0
54
+ And I type "# "
55
+ And I move down
56
+ And I move left
57
+ And I move left
58
+ And I type "# "
59
+ And I move down
60
+ And I move left
61
+ And I move left
62
+ And I press predict
63
+ And I press predict
64
+ Then the contents should be "# foo\n# bar\n# baz\n# qux\n<c>quux\ncorge"
65
+
66
+ Scenario: Commenting example with partial repeat
67
+ Given I replace the contents with "foo\nbar\nbaz\nqux\nquux\ncorge"
68
+ And I move the cursor to 0
69
+ And I type "# "
70
+ And I move down
71
+ And I move left
72
+ And I move left
73
+ And I type "# "
74
+ And I press predict
75
+ And I press predict
76
+ Then the contents should be "# foo\n# bar\n# baz\n<c>qux\nquux\ncorge"
77
+
78
+
79
+
@@ -0,0 +1,87 @@
1
+ Feature: Clear Line
2
+
3
+ Background:
4
+ When I open a new edit tab
5
+
6
+ Scenario: Macro with typing
7
+ When I start recording a macro
8
+ And I type "hi there "
9
+ And I stop recording a macro
10
+ And I run the last recorded macro
11
+ Then the contents should be "hi there hi there "
12
+
13
+ Scenario: Check type steps move the cursor correctly
14
+ When I type "hello"
15
+ Then the cursor should be at 5
16
+
17
+ Scenario: Check navigation steps work
18
+ When I type "hello"
19
+ And I move left
20
+ And I move left
21
+ And I move left
22
+ Then the cursor should be at 2
23
+
24
+ Scenario: Macro with movement
25
+ When I replace the contents with "foo bar baz"
26
+ And I move the cursor to 0
27
+ And I start recording a macro
28
+ And I move right
29
+ And I move right
30
+ And I move right
31
+ And I move right
32
+ And I stop recording a macro
33
+ And I run the last recorded macro
34
+ Then the cursor should be at 8
35
+
36
+ Scenario: Macro with typing and movement
37
+ When I start recording a macro
38
+ And I type "foo"
39
+ And I move left
40
+ And I type "X"
41
+ And I move right
42
+ And I stop recording a macro
43
+ And I run the last recorded macro
44
+ Then the contents should be "foXofoXo"
45
+
46
+ Scenario: Macro with typing, movement and commands
47
+ When I replace the contents with "foo\nbar\nbaz\n"
48
+ And I move the cursor to 1
49
+ And I start recording a macro
50
+ And I trim the line
51
+ And I move down
52
+ And I stop recording a macro
53
+ And I run the last recorded macro
54
+ Then the contents should be "f\nb\nbaz\n"
55
+ And the cursor should be at 5
56
+
57
+ Scenario: Should be able to run the last macro twice
58
+ When I replace the contents with "foo\nbar\nbaz\nqux\nquux"
59
+ And I move the cursor to 1
60
+ And I start recording a macro
61
+ And I trim the line
62
+ And I move down
63
+ And I stop recording a macro
64
+ And I run the last recorded macro
65
+ And I run the last recorded macro
66
+ Then the contents should be "f\nb\nb\nqux\nquux"
67
+ And the cursor should be at 7
68
+
69
+ Scenario: Tabs should work correctly in macro
70
+ When tabs are soft, 4 spaces
71
+ And I start recording a macro
72
+ And I type "a\tb"
73
+ And I stop recording a macro
74
+ And I run the last recorded macro
75
+ Then the contents should be "a ba b"
76
+
77
+ Scenario: Delete key in macro
78
+ When I replace the contents with "foo"
79
+ And I move the cursor to 0
80
+ And I start recording a macro
81
+ And I delete
82
+ And I stop recording a macro
83
+ And I run the last recorded macro
84
+ Then the contents should be "o"
85
+ And the cursor should be at 0
86
+
87
+
@@ -0,0 +1,66 @@
1
+ When /I start recording a macro/ do
2
+ Redcar::Macros::StartStopRecordingCommand.new.run
3
+ end
4
+
5
+ When /I stop recording a macro/ do
6
+ Redcar::Macros::StartStopRecordingCommand.new.run
7
+ end
8
+
9
+ When /I run the last recorded macro/ do
10
+ Redcar::Macros::RunLastCommand.new.run
11
+ end
12
+
13
+ When /^I type "([^"]*)"$/ do |text|
14
+ text = text.gsub("\\t", "\t").gsub("\\n", "\n")
15
+ text.split(//).each do |letter|
16
+ edit_view = Redcar::EditView.focussed_edit_view
17
+ edit_view.type_character(letter[0])
18
+ end
19
+ end
20
+
21
+ edit_view_action_steps = {
22
+ :LINE_UP => "I move up",
23
+ :LINE_DOWN => "I move down",
24
+ :LINE_START => "I move to the start of the line",
25
+ :LINE_END => "I move to the end of the line",
26
+ :COLUMN_PREVIOUS => "I move left",
27
+ :COLUMN_NEXT => "I move right",
28
+ :PAGE_UP => "I page up",
29
+ :PAGE_DOWN => "I page down",
30
+ :WORD_PREVIOUS => "I move to the previous word",
31
+ :WORD_NEXT => "I move to the next word",
32
+ :TEXT_START => "I move to the start of the text",
33
+ :TEXT_END => "I move to the end of the text",
34
+ :WINDOW_START => "I move to the start of the window",
35
+ :WINDOW_END => "I move to the end of the window",
36
+ :SELECT_ALL => "I select all",
37
+ :SELECT_LINE_UP => "I select up",
38
+ :SELECT_LINE_DOWN => "I select down",
39
+ :SELECT_LINE_START => "I select to the start of the line",
40
+ :SELECT_LINE_END => "I select to the end of the line",
41
+ :SELECT_COLUMN_PREVIOUS => "I select left",
42
+ :SELECT_COLUMN_NEXT => "I select right",
43
+ :SELECT_PAGE_UP => "I select page up",
44
+ :SELECT_PAGE_DOWN => "I select page down",
45
+ :SELECT_WORD_PREVIOUS => "I select to the previous word",
46
+ :SELECT_WORD_NEXT => "I select to the next word",
47
+ :SELECT_TEXT_START => "I select to the start of the text",
48
+ :SELECT_TEXT_END => "I select to the end of the text",
49
+ :SELECT_WINDOW_START => "I select to the start of the window",
50
+ :SELECT_WINDOW_END => "I select to the end of the window",
51
+ :CUT => "dsafjl;fjsadfk",
52
+ :COPY => "asdfkjalsgj",
53
+ :PASTE => "asdfasdfe",
54
+ :DELETE_PREVIOUS => "I backspace",
55
+ :DELETE_NEXT => "I delete",
56
+ :DELETE_WORD_PREVIOUS => "I delete to the previous word",
57
+ :DELETE_WORD_NEXT => "I delete to the next word"
58
+ }
59
+
60
+ edit_view_action_steps.each do |action_symbol, step_text|
61
+ When step_text do
62
+ Redcar::EditView.focussed_edit_view.invoke_action(action_symbol)
63
+ end
64
+ end
65
+
66
+
@@ -0,0 +1,8 @@
1
+ When /^I press predict$/ do
2
+ Redcar::Macros::PredictCommand.new.run
3
+ end
4
+
5
+ When /^I press alternate predict$/ do
6
+ Redcar::Macros::AlternatePredictCommand.new.run
7
+ end
8
+
@@ -0,0 +1,2 @@
1
+ RequireSupportFiles File.dirname(__FILE__) + "/../../../edit_view/features/"
2
+ RequireSupportFiles File.dirname(__FILE__) + "/../../../line_tools/features/"
@@ -0,0 +1,167 @@
1
+
2
+ require 'macros/action_sequence'
3
+ require 'macros/commands'
4
+ require 'macros/macro'
5
+ require 'macros/manager_controller'
6
+
7
+ require 'macros/predictive/sequence_finder'
8
+ require 'macros/predictive/document_controller'
9
+
10
+ module Redcar
11
+ module Macros
12
+ DONT_RECORD_COMMANDS = [StartStopRecordingCommand, RunLastCommand, NameLastMacroCommand]
13
+
14
+ def self.recording
15
+ @recording ||= {}
16
+ end
17
+
18
+ def self.session_macros
19
+ @session_macros ||= []
20
+ end
21
+
22
+ def self.saved_macros
23
+ @saved_macros ||= storage['saved_macros']
24
+ end
25
+
26
+ def self.save_macro(macro)
27
+ saved_macros << macro
28
+ update_storage
29
+ end
30
+
31
+ def self.update_storage
32
+ storage['saved_macros'] = saved_macros
33
+ end
34
+
35
+ class << self
36
+ attr_accessor :last_run
37
+ attr_accessor :last_run_or_recorded
38
+ end
39
+
40
+ def self.storage
41
+ @storage ||= begin
42
+ storage = Plugin::Storage.new('macros')
43
+ storage.set_default('saved_macros', [])
44
+ storage
45
+ end
46
+ end
47
+
48
+ def self.name_macro(macro_name, msg)
49
+ if macro = Macros.session_macros.detect {|m| m.name == macro_name }
50
+ result = Application::Dialog.input("Macro Name",
51
+ msg, macro.name)
52
+ if result[:button] == :ok
53
+ macro.name = result[:value]
54
+ Macros.session_macros.delete(macro)
55
+ Macros.save_macro(macro)
56
+ Redcar.app.repeat_event(:macro_named)
57
+ end
58
+ end
59
+ end
60
+
61
+ def self.rename_macro(macro_name)
62
+ if macro = Macros.saved_macros.detect {|m| m.name == macro_name }
63
+ result = Application::Dialog.input("Macro Name",
64
+ "Rename macro:", macro.name)
65
+ if result[:button] == :ok
66
+ macro.name = result[:value]
67
+ update_storage
68
+ Redcar.app.repeat_event(:macro_named)
69
+ end
70
+ end
71
+ end
72
+
73
+ def self.delete_macro(macro_name)
74
+ if macro = Macros.saved_macros.detect {|m| m.name == macro_name }
75
+ Macros.saved_macros.delete(macro)
76
+ update_storage
77
+ elsif macro = Macros.session_macros.detect {|m| m.name == macro_name }
78
+ Macros.session_macros.delete(macro)
79
+ end
80
+ end
81
+
82
+ def self.menus
83
+ Menu::Builder.build do
84
+ sub_menu "Plugins" do
85
+ sub_menu "Macros" do
86
+ item lambda {
87
+ if Macros.recording[EditView.focussed_edit_view]
88
+ "Stop Recording"
89
+ else
90
+ "Start Recording"
91
+ end
92
+ }, StartStopRecordingCommand
93
+ item "Run Last", RunLastCommand
94
+ item "Name and Save Last Recorded", NameLastMacroCommand
95
+ separator
96
+ item "Macro Manager", MacroManagerCommand
97
+ lazy_sub_menu "New" do
98
+ Macros.session_macros.reverse.each do |macro|
99
+ item(macro.name) { macro.run }
100
+ end
101
+ end
102
+ lazy_sub_menu "Saved" do
103
+ Macros.saved_macros.reverse.each do |macro|
104
+ item(macro.name) { macro.run }
105
+ end
106
+ end
107
+ separator
108
+ item "Predict", PredictCommand
109
+ item "Change Prediction", AlternatePredictCommand
110
+ end
111
+ end
112
+ end
113
+ end
114
+
115
+ def self.keymaps
116
+ osx = Redcar::Keymap.build("main", :osx) do
117
+ link "Cmd+Alt+M", StartStopRecordingCommand
118
+ link "Cmd+Shift+M", RunLastCommand
119
+ link "Cmd+Alt+Shift+M", NameLastMacroCommand
120
+ link "Cmd+P", PredictCommand
121
+ link "Cmd+Alt+P", AlternatePredictCommand
122
+ end
123
+
124
+ linwin = Redcar::Keymap.build("main", [:linux, :windows]) do
125
+ link "Ctrl+Alt+M", StartStopRecordingCommand
126
+ link "Ctrl+Shift+M", RunLastCommand
127
+ link "Ctrl+Alt+Shift+M", NameLastMacroCommand
128
+ link "Ctrl+P", PredictCommand
129
+ link "Ctrl+Alt+P", AlternatePredictCommand
130
+ end
131
+ [osx, linwin]
132
+ end
133
+
134
+ def self.document_controller_types
135
+ [Macros::Predictive::DocumentController]
136
+ end
137
+
138
+ def self.sensitivities
139
+ [
140
+ Sensitivity.new(:not_recording_a_macro, Redcar.app, false, [:tab_focussed, :macro_record_changed]) do
141
+ edit_view = EditView.focussed_edit_view
142
+ !edit_view or !Macros.recording[edit_view]
143
+ end,
144
+ Sensitivity.new(:recording_a_macro, Redcar.app, false, [:tab_focussed, :macro_record_changed]) do
145
+ edit_view = EditView.focussed_edit_view
146
+ edit_view and Macros.recording[edit_view]
147
+ end,
148
+ Sensitivity.new(:is_last_macro, Redcar.app, false, [:macro_record_changed, :macro_ran]) do
149
+ Macros.last_run_or_recorded
150
+ end,
151
+ Sensitivity.new(:any_macros_recorded_this_session, Redcar.app, false, [:macro_record_changed, :macro_named]) do
152
+ Macros.session_macros.any?
153
+ end,
154
+ Sensitivity.new(:in_prediction_mode, Redcar.app, false, [:tab_focussed, :start_prediction_mode, :end_prediction_mode]) do
155
+ edit_view = EditView.focussed_edit_view
156
+ if edit_view
157
+ if controller = edit_view.document.controllers(Macros::Predictive::DocumentController).first
158
+ controller.in_prediction_mode?
159
+ end
160
+ end
161
+ end
162
+ ]
163
+ end
164
+ end
165
+ end
166
+
167
+