Module: Redcar::Macros

Defined in:
plugins/macros/lib/macros.rb,
plugins/macros/lib/macros/commands.rb,
plugins/macros/lib/macros/action_sequence.rb,
plugins/macros/lib/macros/manager_controller.rb,
plugins/macros/lib/macros/predictive/sequence_finder.rb,
plugins/macros/lib/macros/predictive/document_controller.rb

Defined Under Namespace

Modules: Predictive Classes: ActionSequence, AlternatePredictCommand, MacroManagerCommand, ManagerController, NameLastMacroCommand, PredictCommand, RunLastCommand, StartStopRecordingCommand

Constant Summary

DONT_RECORD_COMMANDS =
[StartStopRecordingCommand, RunLastCommand, NameLastMacroCommand]

Class Attribute Summary (collapse)

Class Method Summary (collapse)

Class Attribute Details

+ (Object) last_run

Returns the value of attribute last_run



36
37
38
# File 'plugins/macros/lib/macros.rb', line 36

def last_run
  @last_run
end

+ (Object) last_run_or_recorded

Returns the value of attribute last_run_or_recorded



37
38
39
# File 'plugins/macros/lib/macros.rb', line 37

def last_run_or_recorded
  @last_run_or_recorded
end

Class Method Details

+ (Object) delete_macro(macro_name)



73
74
75
76
77
78
79
80
# File 'plugins/macros/lib/macros.rb', line 73

def self.delete_macro(macro_name)
  if macro = Macros.saved_macros.detect {|m| m.name == macro_name }
    Macros.saved_macros.delete(macro)
    update_storage
  elsif macro = Macros.session_macros.detect {|m| m.name == macro_name }
    Macros.session_macros.delete(macro)
  end
end

+ (Object) document_controller_types



134
135
136
# File 'plugins/macros/lib/macros.rb', line 134

def self.document_controller_types
  [Macros::Predictive::DocumentController]
end

+ (Object) keymaps



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'plugins/macros/lib/macros.rb', line 115

def self.keymaps
  osx = Redcar::Keymap.build("main", :osx) do
    link "Cmd+Alt+M", StartStopRecordingCommand
    link "Cmd+Shift+M", RunLastCommand
    link "Cmd+Alt+Shift+M", NameLastMacroCommand
    link "Cmd+P", PredictCommand
    link "Cmd+Alt+P", AlternatePredictCommand
  end
  
  linwin = Redcar::Keymap.build("main", [:linux, :windows]) do
    link "Ctrl+Alt+M", StartStopRecordingCommand
    link "Ctrl+Shift+M", RunLastCommand
    link "Ctrl+Alt+Shift+M", NameLastMacroCommand
    link "Ctrl+P", PredictCommand
    link "Ctrl+Alt+P", AlternatePredictCommand
  end
  [osx, linwin]
end


82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'plugins/macros/lib/macros.rb', line 82

def self.menus
  Menu::Builder.build do
    sub_menu "Plugins" do
      sub_menu "Macros" do
        item lambda {
            if Macros.recording[EditView.focussed_edit_view]
              "Stop Recording"
            else
              "Start Recording"
            end
          }, StartStopRecordingCommand
        item "Run Last", RunLastCommand
        item "Name and Save Last Recorded", NameLastMacroCommand
        separator
        item "Macro Manager", MacroManagerCommand
        lazy_sub_menu "New" do
          Macros.session_macros.reverse.each do |macro|
            item(macro.name) { macro.run }
          end
        end
        lazy_sub_menu "Saved" do
          Macros.saved_macros.reverse.each do |macro|
            item(macro.name) { macro.run }
          end
        end
        separator
        item "Predict", PredictCommand
        item "Change Prediction", AlternatePredictCommand
      end
    end
  end
end

+ (Object) name_macro(macro_name, msg)



48
49
50
51
52
53
54
55
56
57
58
59
# File 'plugins/macros/lib/macros.rb', line 48

def self.name_macro(macro_name, msg)
  if macro = Macros.session_macros.detect {|m| m.name == macro_name }
    result = Application::Dialog.input("Macro Name", 
          msg, macro.name)
    if result[:button] == :ok
      macro.name = result[:value]
      Macros.session_macros.delete(macro)
      Macros.save_macro(macro)
      Redcar.app.repeat_event(:macro_named)
    end
  end
end

+ (Object) recording



14
15
16
# File 'plugins/macros/lib/macros.rb', line 14

def self.recording
  @recording ||= {}
end

+ (Object) rename_macro(macro_name)



61
62
63
64
65
66
67
68
69
70
71
# File 'plugins/macros/lib/macros.rb', line 61

def self.rename_macro(macro_name)
  if macro = Macros.saved_macros.detect {|m| m.name == macro_name }
    result = Application::Dialog.input("Macro Name", 
          "Rename macro:", macro.name)
    if result[:button] == :ok
      macro.name = result[:value]
      update_storage
      Redcar.app.repeat_event(:macro_named)
    end
  end
end

+ (Object) save_macro(macro)



26
27
28
29
# File 'plugins/macros/lib/macros.rb', line 26

def self.save_macro(macro)
  saved_macros << macro
  update_storage
end

+ (Object) saved_macros



22
23
24
# File 'plugins/macros/lib/macros.rb', line 22

def self.saved_macros
  @saved_macros ||= storage['saved_macros']
end

+ (Object) sensitivities



138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'plugins/macros/lib/macros.rb', line 138

def self.sensitivities
  [
    Sensitivity.new(:not_recording_a_macro, Redcar.app, false, [:tab_focussed, :macro_record_changed]) do
      edit_view = EditView.focussed_edit_view
      !edit_view or !Macros.recording[edit_view]
    end,
    Sensitivity.new(:recording_a_macro, Redcar.app, false, [:tab_focussed, :macro_record_changed]) do
      edit_view = EditView.focussed_edit_view
      edit_view and Macros.recording[edit_view]
    end,
    Sensitivity.new(:is_last_macro, Redcar.app, false, [:macro_record_changed, :macro_ran]) do
      Macros.last_run_or_recorded
    end,
    Sensitivity.new(:any_macros_recorded_this_session, Redcar.app, false, [:macro_record_changed, :macro_named]) do
      Macros.session_macros.any?
    end,
    Sensitivity.new(:in_prediction_mode, Redcar.app, false, [:tab_focussed, :start_prediction_mode, :end_prediction_mode]) do
      edit_view = EditView.focussed_edit_view
      if edit_view
        if controller = edit_view.document.controllers(Macros::Predictive::DocumentController).first
          controller.in_prediction_mode?
        end
      end
    end
  ]
end

+ (Object) session_macros



18
19
20
# File 'plugins/macros/lib/macros.rb', line 18

def self.session_macros
  @session_macros ||= []
end

+ (Object) storage



40
41
42
43
44
45
46
# File 'plugins/macros/lib/macros.rb', line 40

def self.storage
  @storage ||= begin
    storage = Plugin::Storage.new('macros')
    storage.set_default('saved_macros', [])
    storage
  end
end

+ (Object) update_storage



31
32
33
# File 'plugins/macros/lib/macros.rb', line 31

def self.update_storage
  storage['saved_macros'] = saved_macros
end