ruber 0.0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. data/COPYING +339 -0
  2. data/INSTALL +137 -0
  3. data/LICENSE +8 -0
  4. data/bin/ruber +65 -0
  5. data/data/share/apps/ruber/core_components.yaml +31 -0
  6. data/data/share/apps/ruber/ruberui.rc +109 -0
  7. data/data/share/icons/ruber.png +0 -0
  8. data/data/share/pixmaps/ruby.png +0 -0
  9. data/icons/ruber-16.png +0 -0
  10. data/icons/ruber-32.png +0 -0
  11. data/icons/ruber-48.png +0 -0
  12. data/icons/ruber-8.png +0 -0
  13. data/lib/ruber/application/application.rb +288 -0
  14. data/lib/ruber/application/plugin.yaml +11 -0
  15. data/lib/ruber/component_manager.rb +899 -0
  16. data/lib/ruber/config/config.rb +82 -0
  17. data/lib/ruber/config/plugin.yaml +3 -0
  18. data/lib/ruber/document_project.rb +209 -0
  19. data/lib/ruber/documents/document_list.rb +416 -0
  20. data/lib/ruber/documents/plugin.yaml +4 -0
  21. data/lib/ruber/editor/document.rb +506 -0
  22. data/lib/ruber/editor/editor_view.rb +167 -0
  23. data/lib/ruber/editor/ktexteditor_wrapper.rb +202 -0
  24. data/lib/ruber/exception_widgets.rb +245 -0
  25. data/lib/ruber/external_program_plugin.rb +397 -0
  26. data/lib/ruber/filtered_output_widget.rb +342 -0
  27. data/lib/ruber/gui_states_handler.rb +231 -0
  28. data/lib/ruber/kde_config_option_backend.rb +167 -0
  29. data/lib/ruber/kde_sugar.rb +249 -0
  30. data/lib/ruber/main_window/choose_plugins_dlg.rb +353 -0
  31. data/lib/ruber/main_window/main_window.rb +524 -0
  32. data/lib/ruber/main_window/main_window_actions.rb +537 -0
  33. data/lib/ruber/main_window/main_window_internal.rb +239 -0
  34. data/lib/ruber/main_window/open_file_in_project_dlg.rb +212 -0
  35. data/lib/ruber/main_window/output_color_widget.rb +35 -0
  36. data/lib/ruber/main_window/plugin.yaml +58 -0
  37. data/lib/ruber/main_window/save_modified_files_dlg.rb +89 -0
  38. data/lib/ruber/main_window/status_bar.rb +156 -0
  39. data/lib/ruber/main_window/ui/choose_plugins_widget.rb +90 -0
  40. data/lib/ruber/main_window/ui/choose_plugins_widget.ui +77 -0
  41. data/lib/ruber/main_window/ui/main_window_settings_widget.rb +108 -0
  42. data/lib/ruber/main_window/ui/main_window_settings_widget.ui +89 -0
  43. data/lib/ruber/main_window/ui/new_project_widget.rb +119 -0
  44. data/lib/ruber/main_window/ui/new_project_widget.ui +178 -0
  45. data/lib/ruber/main_window/ui/open_file_in_project_dlg.rb +109 -0
  46. data/lib/ruber/main_window/ui/open_file_in_project_dlg.ui +168 -0
  47. data/lib/ruber/main_window/ui/output_color_widget.rb +241 -0
  48. data/lib/ruber/main_window/ui/output_color_widget.ui +204 -0
  49. data/lib/ruber/main_window/workspace.rb +442 -0
  50. data/lib/ruber/output_widget.rb +1093 -0
  51. data/lib/ruber/plugin.rb +264 -0
  52. data/lib/ruber/plugin_like.rb +589 -0
  53. data/lib/ruber/plugin_specification.rb +106 -0
  54. data/lib/ruber/plugin_specification_reader.rb +451 -0
  55. data/lib/ruber/project.rb +493 -0
  56. data/lib/ruber/project_backend.rb +105 -0
  57. data/lib/ruber/projects/plugin.yaml +11 -0
  58. data/lib/ruber/projects/project_files_list.rb +314 -0
  59. data/lib/ruber/projects/project_files_widget.rb +301 -0
  60. data/lib/ruber/projects/project_list.rb +314 -0
  61. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.rb +74 -0
  62. data/lib/ruber/projects/ui/project_files_rule_chooser_widget.ui +61 -0
  63. data/lib/ruber/projects/ui/project_files_widget.rb +117 -0
  64. data/lib/ruber/projects/ui/project_files_widget.ui +123 -0
  65. data/lib/ruber/qt_sugar.rb +673 -0
  66. data/lib/ruber/settings_container.rb +515 -0
  67. data/lib/ruber/settings_dialog.rb +244 -0
  68. data/lib/ruber/settings_dialog_manager.rb +503 -0
  69. data/lib/ruber/utils.rb +414 -0
  70. data/lib/ruber/yaml_option_backend.rb +159 -0
  71. data/outsider_files +15 -0
  72. data/plugins/autosave/autosave.rb +404 -0
  73. data/plugins/autosave/plugin.yaml +16 -0
  74. data/plugins/autosave/ui/autosave_config_widget.rb +83 -0
  75. data/plugins/autosave/ui/autosave_config_widget.ui +68 -0
  76. data/plugins/command/command.png +0 -0
  77. data/plugins/command/command.rb +74 -0
  78. data/plugins/command/plugin.yaml +11 -0
  79. data/plugins/find_in_files/find_in_files.rb +337 -0
  80. data/plugins/find_in_files/find_in_files_dlg.rb +411 -0
  81. data/plugins/find_in_files/find_in_files_ui.rc +11 -0
  82. data/plugins/find_in_files/find_in_files_widgets.rb +485 -0
  83. data/plugins/find_in_files/plugin.yaml +23 -0
  84. data/plugins/find_in_files/ui/config_widget.rb +58 -0
  85. data/plugins/find_in_files/ui/config_widget.ui +41 -0
  86. data/plugins/find_in_files/ui/find_in_files_widget.rb +260 -0
  87. data/plugins/find_in_files/ui/find_in_files_widget.ui +324 -0
  88. data/plugins/project_browser/plugin.yaml +10 -0
  89. data/plugins/project_browser/project_browser.rb +245 -0
  90. data/plugins/rake/plugin.yaml +39 -0
  91. data/plugins/rake/rake.png +0 -0
  92. data/plugins/rake/rake.rb +567 -0
  93. data/plugins/rake/rake_extension.rb +153 -0
  94. data/plugins/rake/rake_widgets.rb +615 -0
  95. data/plugins/rake/rakeui.rc +27 -0
  96. data/plugins/rake/ui/add_quick_task_widget.rb +71 -0
  97. data/plugins/rake/ui/add_quick_task_widget.ui +59 -0
  98. data/plugins/rake/ui/choose_task_widget.rb +77 -0
  99. data/plugins/rake/ui/choose_task_widget.ui +72 -0
  100. data/plugins/rake/ui/config_widget.rb +127 -0
  101. data/plugins/rake/ui/config_widget.ui +123 -0
  102. data/plugins/rake/ui/project_widget.rb +217 -0
  103. data/plugins/rake/ui/project_widget.ui +246 -0
  104. data/plugins/rspec/plugin.yaml +30 -0
  105. data/plugins/rspec/rspec.png +0 -0
  106. data/plugins/rspec/rspec.rb +945 -0
  107. data/plugins/rspec/rspec.svg +90 -0
  108. data/plugins/rspec/rspecui.rc +20 -0
  109. data/plugins/rspec/ruber_rspec_formatter.rb +312 -0
  110. data/plugins/rspec/ui/rspec_project_widget.rb +170 -0
  111. data/plugins/rspec/ui/rspec_project_widget.ui +193 -0
  112. data/plugins/ruby_development/plugin.yaml +27 -0
  113. data/plugins/ruby_development/ruby_development.png +0 -0
  114. data/plugins/ruby_development/ruby_development.rb +453 -0
  115. data/plugins/ruby_development/ruby_developmentui.rc +19 -0
  116. data/plugins/ruby_development/ui/project_widget.rb +112 -0
  117. data/plugins/ruby_development/ui/project_widget.ui +108 -0
  118. data/plugins/ruby_runner/config_widget.rb +116 -0
  119. data/plugins/ruby_runner/plugin.yaml +26 -0
  120. data/plugins/ruby_runner/project_widget.rb +62 -0
  121. data/plugins/ruby_runner/ruby.png +0 -0
  122. data/plugins/ruby_runner/ruby_interpretersui.rc +26 -0
  123. data/plugins/ruby_runner/ruby_runner.rb +411 -0
  124. data/plugins/ruby_runner/ui/config_widget.rb +92 -0
  125. data/plugins/ruby_runner/ui/config_widget.ui +91 -0
  126. data/plugins/ruby_runner/ui/project_widget.rb +60 -0
  127. data/plugins/ruby_runner/ui/project_widget.ui +48 -0
  128. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.rb +59 -0
  129. data/plugins/ruby_runner/ui/ruby_runnner_plugin_option_widget.ui +44 -0
  130. data/plugins/state/plugin.yaml +28 -0
  131. data/plugins/state/state.rb +520 -0
  132. data/plugins/state/ui/config_widget.rb +92 -0
  133. data/plugins/state/ui/config_widget.ui +89 -0
  134. data/plugins/syntax_checker/plugin.yaml +18 -0
  135. data/plugins/syntax_checker/syntax_checker.rb +662 -0
  136. data/ruber.desktop +10 -0
  137. data/spec/annotation_model_spec.rb +174 -0
  138. data/spec/common.rb +119 -0
  139. data/spec/component_manager_spec.rb +1259 -0
  140. data/spec/document_list_spec.rb +626 -0
  141. data/spec/document_project_spec.rb +373 -0
  142. data/spec/document_spec.rb +779 -0
  143. data/spec/editor_view_spec.rb +167 -0
  144. data/spec/external_program_plugin_spec.rb +676 -0
  145. data/spec/filtered_output_widget_spec.rb +642 -0
  146. data/spec/gui_states_handler_spec.rb +304 -0
  147. data/spec/kde_config_option_backend_spec.rb +214 -0
  148. data/spec/kde_sugar_spec.rb +101 -0
  149. data/spec/ktexteditor_wrapper_spec.rb +305 -0
  150. data/spec/output_widget_spec.rb +1703 -0
  151. data/spec/plugin_spec.rb +1393 -0
  152. data/spec/plugin_specification_reader_spec.rb +1765 -0
  153. data/spec/plugin_specification_spec.rb +401 -0
  154. data/spec/project_backend_spec.rb +172 -0
  155. data/spec/project_files_list_spec.rb +401 -0
  156. data/spec/project_list_spec.rb +511 -0
  157. data/spec/project_spec.rb +990 -0
  158. data/spec/qt_sugar_spec.rb +328 -0
  159. data/spec/settings_container_spec.rb +617 -0
  160. data/spec/settings_dialog_manager_spec.rb +773 -0
  161. data/spec/settings_dialog_spec.rb +419 -0
  162. data/spec/state_spec.rb +991 -0
  163. data/spec/utils_spec.rb +406 -0
  164. data/spec/workspace_spec.rb +869 -0
  165. data/spec/yaml_option_backend_spec.rb +246 -0
  166. metadata +284 -0
@@ -0,0 +1,68 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>AutosaveConfigWidget</class>
4
+ <widget class="QWidget" name="AutosaveConfigWidget">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>279</width>
10
+ <height>300</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Form</string>
15
+ </property>
16
+ <layout class="QVBoxLayout" name="verticalLayout_2">
17
+ <item>
18
+ <widget class="QGroupBox" name="groupBox">
19
+ <property name="title">
20
+ <string>Autosave</string>
21
+ </property>
22
+ <layout class="QVBoxLayout" name="verticalLayout_3">
23
+ <item>
24
+ <layout class="QVBoxLayout" name="verticalLayout">
25
+ <item>
26
+ <widget class="QCheckBox" name="_autosave__enable">
27
+ <property name="text">
28
+ <string>&amp;Enable autosave</string>
29
+ </property>
30
+ </widget>
31
+ </item>
32
+ <item>
33
+ <widget class="QLabel" name="label_2">
34
+ <property name="text">
35
+ <string>&amp;Exceptions</string>
36
+ </property>
37
+ <property name="buddy">
38
+ <cstring>_autosave__plugins</cstring>
39
+ </property>
40
+ </widget>
41
+ </item>
42
+ <item>
43
+ <widget class="AutosavePluginListView" name="_autosave__plugins">
44
+ <property name="access" stdset="0">
45
+ <string>$plugins</string>
46
+ </property>
47
+ <property name="signal" stdset="0">
48
+ <string>items_changed()</string>
49
+ </property>
50
+ </widget>
51
+ </item>
52
+ </layout>
53
+ </item>
54
+ </layout>
55
+ </widget>
56
+ </item>
57
+ </layout>
58
+ </widget>
59
+ <customwidgets>
60
+ <customwidget>
61
+ <class>AutosavePluginListView</class>
62
+ <extends>QListView</extends>
63
+ <header>autosavepluginlistview.h</header>
64
+ </customwidget>
65
+ </customwidgets>
66
+ <resources/>
67
+ <connections/>
68
+ </ui>
@@ -0,0 +1,74 @@
1
+ module Ruber
2
+
3
+ =begin rdoc
4
+ Plugin which allows to evaluate some ruby code from within the Ruber environment,
5
+ thus effectively giving Ruber commands (this is different from the Ruby Runner
6
+ plugin, which simply starts a new ruby interpreter and runs a script in it).
7
+
8
+ This plugin doesn't provide a plugin class but just a tool widget where the user
9
+ can enter the code and a button to execute it. It also doesn't provide any
10
+ API for the feature.
11
+
12
+ *Note:* the ruby code is executed in the top level context. Any exception
13
+ raised by the code won't cause Ruber to crash, but will be displayed in a dialog.
14
+ =end
15
+ module CommandPlugin
16
+
17
+ =begin rdoc
18
+ The tool widget where the user can enter the ruby code to execute.
19
+ =end
20
+ class ToolWidget < Qt::Widget
21
+
22
+ slots :execute_command, :load_settings
23
+
24
+ =begin rdoc
25
+ @param [Qt::Widget,nil] parent the parent widget
26
+ =end
27
+ def initialize parent = nil
28
+ super
29
+ self.layout = Qt::VBoxLayout.new self
30
+ @editor = Qt::PlainTextEdit.new
31
+ layout.add_widget @editor
32
+ self.focus_proxy = @editor
33
+ @button = Qt::PushButton.new("Execute")
34
+ connect @button, SIGNAL(:clicked), self, SLOT(:execute_command)
35
+ layout.add_widget @button
36
+ end
37
+
38
+ =begin rdoc
39
+ Executes the text in the tool widget in the ruby interpreter where Ruber is running
40
+ in. If an exception is raised by the code, it won't be propagated to Ruber. Instead,
41
+ it will be displayed on standard error and in a message box.
42
+
43
+ @return [Boolean] *true* if the code was executed successfully and *false* if an exception
44
+ was raised.
45
+ =end
46
+ def execute_command
47
+ code = @editor.to_plain_text
48
+ begin
49
+ eval code, TOPLEVEL_BINDING, 'COMMAND'
50
+ true
51
+ rescue Exception => ex
52
+ dlg = ExceptionDialog.new ex, Ruber[:main_window], false,
53
+ 'The command you issued raised the following exception:'
54
+ dlg.exec
55
+ false
56
+ end
57
+ end
58
+
59
+ =begin rdoc
60
+ Called whenever the global settings change and when the plugin is first loaded
61
+
62
+ Sets the font of the editor to the font chosen by the user as the output font
63
+ @return [nil]
64
+ =end
65
+ def load_settings
66
+ @editor.font = Ruber[:config][:general, :output_font]
67
+ nil
68
+ end
69
+
70
+ end
71
+
72
+ end
73
+
74
+ end
@@ -0,0 +1,11 @@
1
+ name: command
2
+ version: 0.0.1
3
+ about:
4
+ authors: [Stefano Crocco, stefano.crocco@alice.it]
5
+ license: gpl
6
+ description: Allow to give commands to Ruber using ruby
7
+ bug_address: http://github.com/stcrocco/ruber/issues
8
+ icon: command.png
9
+ require: command
10
+ tool_widgets:
11
+ - {class: Ruber::CommandPlugin::ToolWidget, caption: Command}
@@ -0,0 +1,337 @@
1
+ =begin
2
+ Copyright (C) 2010 by Stefano Crocco
3
+ stefano.crocco@alice.it
4
+
5
+ This program is free software; you can redistribute it andor modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation; either version 2 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program; if not, write to the
17
+ Free Software Foundation, Inc.,
18
+ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
+ =end
20
+
21
+ require 'ruber/external_program_plugin'
22
+
23
+ require 'find_in_files/find_in_files_widgets'
24
+ require 'find_in_files/find_in_files_dlg'
25
+
26
+ module Ruber
27
+
28
+ =begin rdoc
29
+ Plugin which allows the user to perform searches and replacements in a range of files
30
+
31
+ This plugin, which is mostly a frontend for the "rak":http://rak.rubyforge.org/ program,
32
+ consists in a dialog and two tool widgets.
33
+
34
+ The dialog is where the user chooses
35
+ the search criteria (the text to search, the directory where to look and filters
36
+ to limit the kind of files to look for) and, optionally, the replacement text.
37
+ Depending on whether the user presses the Find or the Replace button in the dialog,
38
+ a find or a replacement operation is started.
39
+
40
+ The tool widgets display the results of the search and replacement operations. In
41
+ particular, in case of a replacement, nothing is actually replaced when the user
42
+ presses the Replace button in the dialog. Instead, when this happens, the Replace
43
+ tool widgets is filled with a list of potential replacements. The user can uncheck
44
+ the replacements he doesn't like. The replacements are only applied when he presses
45
+ the Replace button on the tool widget. If a file changes before the user presses
46
+ that button, replacements in it won't be carried out.
47
+
48
+ @api feature find_in_files
49
+ @plugin
50
+ =end
51
+ module FindInFiles
52
+
53
+ =begin rdoc
54
+ Plugin class for the find_in_files feature
55
+
56
+ The @output_widget instance variable contains the widget output should by displayed
57
+ by at the time. This varies according to whether a search or a replacement search
58
+ is being performed.
59
+ =end
60
+ class FindInFilesPlugin < ExternalProgramPlugin
61
+
62
+ =begin rdoc
63
+ Encapsulates information about a replacement
64
+ =end
65
+ ReplacementData = Struct.new :regexp, :replacement_text, :options
66
+
67
+ slots :find_replace, 'show_replacements(QString)'
68
+
69
+ =begin rdoc
70
+ Signal emitted when a search is started
71
+ =end
72
+ signals :search_started
73
+
74
+ =begin rdoc
75
+ Signal emitted when a search for replacements is started
76
+ =end
77
+ signals :replace_search_started
78
+
79
+ =begin rdoc
80
+ Signal emitted when a search is finished
81
+ =end
82
+ signals :search_finished
83
+
84
+ =begin rdoc
85
+ Signal emitted when a search for replacements is finished
86
+ =end
87
+ signals :replace_search_finished
88
+
89
+ =begin rdoc
90
+ @param [PluginSpecification] psf the plugin specification object associated with the
91
+ plugin
92
+ =end
93
+ def initialize psf
94
+ super
95
+ Ruber[:autosave].register_plugin self, true
96
+ @rak_path = nil
97
+ @dlg = FindReplaceInFilesDlg.new
98
+ @replace_data = nil
99
+ self.connect SIGNAL('process_finished(int, QString)') do
100
+ Ruber[:main_window].change_state 'find_in_files_running', false
101
+ end
102
+ connect @replace_widget, SIGNAL('file_added(QString)'), self, SLOT('show_replacements(QString)')
103
+ self.connect(SIGNAL(:process_started)) do
104
+ emit @replace_data ? replace_search_started : search_started
105
+ end
106
+ self.connect SIGNAL('process_finished(int, QString)') do
107
+ emit @replace_data ? replace_search_finished : search_finished
108
+ end
109
+ Ruber[:components].connect(SIGNAL('feature_loaded(QString, QObject*)')) do |f, o|
110
+ o.register_plugin self, true if f == 'autosave'
111
+ end
112
+ Ruber[:main_window].change_state 'find_in_files_running', false
113
+ end
114
+
115
+ =begin rdoc
116
+ Override of {ExternalProgramPlugin#process_standard_output}
117
+
118
+ It passes the text to the output widget's @display_output@ method
119
+ @param [<String>] the lines to display, as produced by rak
120
+ =end
121
+ def process_standard_output lines
122
+ @output_widget.display_output lines
123
+ end
124
+
125
+ =begin rdoc
126
+ Override of {ExternalProgramPlugin#process_standard_error}
127
+
128
+ It does nothing, so errors are ignored
129
+ @param [<String>] the error lines, as produced by rak
130
+ =end
131
+ def process_standard_error lines
132
+ end
133
+
134
+ private
135
+
136
+ =begin rdoc
137
+ Override of {ExternalProgramPlugin#display_exit_message}
138
+
139
+ It doesn' display any message if rak exited succesfully
140
+ @return [nil]
141
+ =end
142
+ def display_exit_message code, reason
143
+ super if code != 0
144
+ nil
145
+ end
146
+
147
+ =begin rdoc
148
+ Starts a search or replcement search
149
+
150
+ This method is called when the user closes the dialog pressing the Search or
151
+ Replace button
152
+ @return [nil]
153
+ =end
154
+ def find_replace
155
+ @dlg.clear
156
+ @dlg.allow_project = Ruber[:projects].current
157
+ @dlg.exec
158
+ case @dlg.action
159
+ when :find then find @dlg.find_text, options_from_dialog
160
+ when :replace then replace @dlg.find_text, @dlg.replacement_text, options_from_dialog
161
+ else return
162
+ end
163
+ end
164
+
165
+ =begin rdoc
166
+ Starts a search using the parameters the user entered in the dialog
167
+
168
+ After starting the search (which is an asynchronous process), it activates and
169
+ displays the Search tool widget.
170
+
171
+ @return [nil]
172
+ =end
173
+ def find text, opts
174
+ @replace_data = nil
175
+ @output_widget = @find_widget
176
+ cmd = cmd_line text, opts
177
+ @find_widget.clear_output
178
+ Ruber[:main_window].change_state 'find_in_files_running', true
179
+ @find_widget.working_directory = '/'
180
+ run_process 'rak', '/', cmd, nil
181
+ Ruber[:main_window].activate_tool 'find_in_files_widget'
182
+ nil
183
+ end
184
+
185
+ =begin rdoc
186
+ Starts a replacement search using the parameters the user entered in the dialog
187
+
188
+ After starting the search (which is an asynchronous process), it activates and
189
+ displays the Replace tool widget.
190
+
191
+ @return [nil]
192
+ =end
193
+ def replace find_text, replace_text, opts
194
+ opts[:replace] = true
195
+ regexp = create_regexp find_text, opts
196
+ @replace_data = ReplacementData.new regexp, replace_text, opts
197
+ @output_widget = @replace_widget
198
+ cmd = cmd_line find_text, opts
199
+ do_autosave opts[:places]
200
+ @replace_widget.clear_output
201
+ Ruber[:main_window].change_state 'find_in_files_running', true
202
+ @replace_widget.working_directory = '/'
203
+ run_process 'rak', '/', cmd, nil
204
+ Ruber[:main_window].activate_tool 'replace_in_files_widget'
205
+ end
206
+
207
+ =begin rdoc
208
+ Loads the settings
209
+ =end
210
+ def load_settings
211
+ @rak_path = Ruber[:config][:find_in_files, :rak_path]
212
+ nil
213
+ end
214
+
215
+ private
216
+
217
+ =begin rdoc
218
+ Autosaves documents in preparation for a search
219
+
220
+ @param [String,<String>] places the files to save. If it is a string, then
221
+ its understood as an absolute directory name and all open documents corresponding
222
+ to files in that directory are saved. If it is an array, each element of the array
223
+ is interpreted as an absolute file name. All documents corresponding to such files
224
+ are saved.
225
+ @return [Boolean] as {Autosave::AutosavePlugin#autosave AutosavePlugin#autosave}
226
+ =end
227
+ def do_autosave places
228
+ docs = Ruber[:docs].documents_with_file
229
+ if places.is_a? String then docs = docs.select{|d| d.path.start_with? places}
230
+ else docs = docs.select{|d| places.include? d.path}
231
+ end
232
+ Ruber[:autosave].autosave self, docs, :on_failure => :ask, :message => 'Do you want to go on with replacing?'
233
+ end
234
+
235
+ =begin rdoc
236
+ Creates a regexp to search for the given string with the given options
237
+
238
+ This method is used after the user starts a search from the dialog to create the
239
+ regexp to pass to rak.
240
+
241
+ @param [String] find_text the string to make the regexp for
242
+ @param [Hash] opts the options to use for the search
243
+ @option opts [Boolean] plain (false) whether the _find_text_ parameter should be
244
+ interpreted as a string rather than as a regexp. If *true*, characters which have
245
+ special meaning in a regexp will be escaped)
246
+ @option opts [Boolean] whole_words (false) whether the regexp must match whole words rather
247
+ than be allowed to match in the middle of a word. If *true*, the regexp will be
248
+ enclosed in a pair of \b sequences
249
+ @option opts [Boolean] case_insensitive (false) whether or not the regexp should
250
+ ignore case. If *true*, the regexp will be given the @Regexp::IGNORECASE@ flag
251
+ @return [Regexp] a regexp matching the given text and options
252
+ =end
253
+ def create_regexp find_text, opts
254
+ str = find_text.dup
255
+ str = Regexp.quote str if opts[:plain]
256
+ str = "\\b#{str}\\b" if opts[:whole_words]
257
+ reg_opts = opts[:case_insensitive] ? Regexp::IGNORECASE : 0
258
+ Regexp.new str, reg_opts
259
+ end
260
+
261
+ =begin rdoc
262
+ Gathers the options entered in the find dialog an puts them in a hash
263
+
264
+ @return [Hash] a hash containing the options chosen by the user. It can contain
265
+ the following entries:
266
+ * @:case_insensitive@: whether the search should be case insensitive or not
267
+ * @:plain@: whether the contents of the find widget in the dialog should be interpreted
268
+ as a regexp or a plain string
269
+ * @:whole_words@: whether the search should match full words or not
270
+ * @:places@: an array of files and directory to search
271
+ * @:all_files@: whether all files or only those matching some filter must be searched
272
+ * @:filter@: an array of the standard filters to use
273
+ * @:custom_filter@: a custom filter to use
274
+ =end
275
+ def options_from_dialog
276
+ opts = {}
277
+ opts[:case_insensitive] = !@dlg.case_sensitive?
278
+ opts[:plain] = @dlg.mode == :plain
279
+ opts[:whole_words] = @dlg.whole_words?
280
+ places = case @dlg.places
281
+ when :custom_dir then @dlg.directory
282
+ when :project_dir then Ruber[:projects].current.project_directory
283
+ when :project_files then Ruber[:projects].current.project_files.abs.to_a
284
+ when :open_files then Ruber[:docs].documents_with_file.map{|d| d.path}
285
+ end
286
+ opts[:places] = Array(places)
287
+ opts[:all_files] = @dlg.all_files?
288
+ opts[:filters] = @dlg.filters
289
+ opts[:custom_filter] = @dlg.custom_filter
290
+ opts
291
+ end
292
+
293
+ =begin rdoc
294
+ Creates the command line to pass to rak
295
+ @param [String] text the string to look for
296
+ @param [Hash] opts an hash containing the options to use, as that returned by
297
+ {#options_from_dialog}
298
+ @return [<String>] an array with the arguments and options to pass to rak
299
+ =end
300
+ def cmd_line text, opts
301
+ cmd = []
302
+ cmd << '-i' if opts[:case_insensitive]
303
+ cmd << '-w' if opts[:whole_words]
304
+ cmd << '-Q' if opts[:plain]
305
+ if opts[:filters] then opts[:filters].each{|f| cmd << "--#{f}"}
306
+ else cmd << '-a'
307
+ end
308
+ cmd << '-g' << opts[:custom_filter] if opts[:custom_filter]
309
+ cmd << '-l' if opts[:replace]
310
+ cmd << text
311
+ cmd << opts[:places]
312
+ #opts[:places] may be an array, so with flatten it will be reduced to strings
313
+ cmd.flatten
314
+ end
315
+
316
+ =begin rdoc
317
+ Inserts matches for the given file in the Replace tool widget
318
+
319
+ @param [String] file the name of the file
320
+ @return [nil]
321
+ =end
322
+ def show_replacements file
323
+ lines = File.readlines file
324
+ lines.each_with_index do |l, i|
325
+ l.chomp!
326
+ new = l.dup
327
+ changed = new.gsub! @replace_data.regexp, @replace_data.replacement_text
328
+ @replace_widget.add_line file, i, l, new if changed
329
+ end
330
+ nil
331
+ end
332
+
333
+ end
334
+
335
+ end
336
+
337
+ end