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,15 @@
1
+ ruber.desktop:
2
+ - "<%= `kde4-config --path xdgdata-apps`.strip.split(':').find{|path| !path.start_with?(ENV['HOME'])} %>"
3
+ - "<%= `kde4-config --path xdgdata-apps`.strip.split(':').find{|path| path.start_with?(ENV['HOME'])} %>"
4
+ icons/ruber-48.png:
5
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| !path.start_with?(ENV['HOME'])}, 'hicolor', '48x48', 'apps', 'ruber.png' %>"
6
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| path.start_with?(ENV['HOME'])}, 'hicolor', '48x48', 'apps', 'ruber.png' %>"
7
+ icons/ruber-32.png:
8
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| !path.start_with?(ENV['HOME'])}, 'hicolor', '32x32', 'apps', 'ruber.png' %>"
9
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| path.start_with?(ENV['HOME'])}, 'hicolor', '32x32', 'apps', 'ruber.png' %>"
10
+ icons/ruber-16.png:
11
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| !path.start_with?(ENV['HOME'])}, 'hicolor', '16x16', 'apps', 'ruber.png' %>"
12
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| path.start_with?(ENV['HOME'])}, 'hicolor', '16x16', 'apps', 'ruber.png' %>"
13
+ icons/ruber-8.png:
14
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| !path.start_with?(ENV['HOME'])}, 'hicolor', '8x8', 'apps', 'ruber.png' %>"
15
+ - "<%= File.join `kde4-config --path xdgdata-icon`.strip.split(':').find{|path| path.start_with?(ENV['HOME'])}, 'hicolor', '8x8', 'apps', 'ruber.png' %>"
@@ -0,0 +1,404 @@
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_relative 'ui/autosave_config_widget'
22
+
23
+ =begin rdoc
24
+ Subclass of @Qt::ListView@ which emits a signal whenever the model changes
25
+ @todo Put under the correct namespace
26
+ =end
27
+ class AutosavePluginListView < Qt::ListView
28
+
29
+ =begin rdoc
30
+ Signal emitted whenever some of the indexes in the model change
31
+ =end
32
+ signals :items_changed
33
+
34
+ =begin rdoc
35
+ Override of @Qt::ListView#model=@
36
+
37
+ Besides calling *super*, it also connects to the model's @dataChanged@ signal to
38
+ the view's {#items_changed} signal (and disconnects the old model if necessary).
39
+ =end
40
+ def model= mod
41
+ if model
42
+ model.disconnect SIGNAL('dataChanged(QModelIndex, QModelIndex)'), self, SIGNAL(:items_changed)
43
+ end
44
+ super
45
+ if model
46
+ connect model, SIGNAL('dataChanged(QModelIndex, QModelIndex)'), self, SIGNAL(:items_changed)
47
+ end
48
+ end
49
+
50
+ end
51
+
52
+ module Ruber
53
+
54
+ =begin rdoc
55
+ Plugin providing a common interface to autosaving documents.
56
+
57
+ Plugins which want to autosave some files whenever something happen may register
58
+ with this plugin then call its {AutosavePlugin#autosave autosave} method whenever
59
+ they want to autosave files.
60
+
61
+ The user can choose whether they want autosave globally enabled an turn it off
62
+ plugin-wise if they want. If autosave is disabled for a given plugin (either because
63
+ it's disabled globally or only for that plugin), the {AutosavePlugin#autosave autosave}
64
+ method will behave as if the files were successfully saved, but, of course, will
65
+ not actually save them.
66
+
67
+ <b>Note:</b> in all the documentation of this class, the method parameter _plug_
68
+ can be either a plugin or its name.
69
+
70
+ @api feature autosave
71
+ @plugin AutosavePlugin
72
+ =end
73
+ module Autosave
74
+
75
+ =begin rdoc
76
+ Plugin class for the @autosave@ plugin.
77
+
78
+ @api_method #autosave
79
+ @api_method #register_plugin
80
+ @api_method #remove_plugin
81
+ @api_method #registered_plugins
82
+ =end
83
+ class AutosavePlugin < Plugin
84
+
85
+ =begin rdoc
86
+ @return [Hash] a hash which has the names of registered plugins as keys and whether
87
+ autosaving is enabled for them as keys
88
+ =end
89
+ attr_reader :registered_plugins
90
+
91
+ =begin rdoc
92
+ Creates a new instance
93
+
94
+ @param [PluginSpecification] the plugin specification associated with the plugin
95
+ =end
96
+ def initialize pdf
97
+ @registered_plugins = {}
98
+ @enabled = true
99
+ @settings = {}
100
+ super
101
+ Ruber[:components].connect SIGNAL('unloading_component(QObject*)') do |c|
102
+ @registered_plugins.delete c.component_name
103
+ end
104
+ end
105
+
106
+ =begin rdoc
107
+ Makes another plugin known to @Autosave@.
108
+
109
+ If the configuration file already has an entry for the plugin _plug_ in the
110
+ @autosave/plugins@ setting, autosaving
111
+ will be enabled or not basing on that value. If there's not such an entry,
112
+ then autosaving will be enabled if _default_ is *true* and disabled otherwise.
113
+
114
+ <b>Note:</b> you have to register a plugin before calling the {#autosave} method
115
+ for it.
116
+
117
+ @param [PluginLike, Symbol] plug the plugin to register or its name
118
+ @param [Boolean] default whether or not autosaving should be enabled for _plug_
119
+ if the configuration file doesn't have an entry for it
120
+ =end
121
+ def register_plugin plug, default = true
122
+ plug = plug.plugin_name if plug.is_a? PluginLike
123
+ val = @settings.fetch plug, default
124
+ @registered_plugins[plug] = val
125
+ val
126
+ end
127
+
128
+ =begin rdoc
129
+ Removes a plugin from the list of registered plugins.
130
+
131
+ Usually, there's no need to use this method, as registered plugins are automatically
132
+ removed whenever they're unloaded.
133
+
134
+ <b>Note:</b> you can't call the {#autosave} method for a plugin which has been
135
+ removed using this method.
136
+
137
+ @param [PluginLike, Symbol] plug the name of the plugin to remove from the autosave
138
+ list or its name
139
+ =end
140
+ def remove_plugin plug
141
+ plug = plug.plugin_name if plug.is_a? PluginLike
142
+ @registered_plugins.delete plug
143
+ end
144
+
145
+ =begin rdoc
146
+ Loads the settings
147
+
148
+ @return [void]
149
+ =end
150
+ def load_settings
151
+ @enabled = Ruber[:config][:autosave, :enable]
152
+ @settings = Ruber[:config][:autosave, :plugins]
153
+ nil
154
+ end
155
+
156
+ =begin rdoc
157
+ Autosaves the given documents or files.
158
+
159
+ This is the main method of this class. Whenever a plugin wants some documents to be autosaved,
160
+ it calls this method passing itself as first argument and a list of the documents
161
+ to save (or one of the special symbols listed below) as second argument and, optionally
162
+ some options or a block.
163
+
164
+ If autosaving is enabled both globally and for the plugin, an attempt will
165
+ be made to save all the specified documents. If one or more documents can't be saved, the
166
+ behaviour depends on the third and fourth argument. If autosaving is disabled,
167
+ either globally or for the given plugin, this method does nothing.
168
+
169
+ @param [PluginLike, Symbol] plug the plugin requesting to autosave the documents
170
+ or its name
171
+ @param [<Document>, Symbol] what either an array with the documents to autosave
172
+ or one of the symbols listed below.
173
+
174
+ * @:open_documents@: autosave all the open documents (including those which aren't
175
+ associated with a file)
176
+
177
+ * @:documents_with_file@: autosave all the open documents which are associated with
178
+ a file
179
+
180
+ * @:project_files@: autosave all the open documents corresponding to a file belonging
181
+ to the current project. Note that using this value when there's no active global
182
+ project leads to undefined behaviour.
183
+
184
+ @param [Hash] opts a hash which fine tunes the behaviour in case one of the specified
185
+ documents can't be saved.
186
+
187
+ @param [Proc] blk a block which will be called if some of the documents couldn't
188
+ be saved. If given, it will be given an array containing the unsaved documents as
189
+ argument.
190
+
191
+ @option opts [Boolean] :stop_on_failure (false) whether to stop saving documents
192
+ as soon as one fails to save. By default, this method attempts to save all given
193
+ documents, regardless of whether saving the other documents was successful or not.
194
+ @option opts [Symbol] :on_failure (nil) what to do if some documents can't be saved
195
+ (this option will be ignored if a block has been given).
196
+ It can have the following values:
197
+
198
+ * @:warn@: an information message box describing the error is displayed
199
+
200
+ * @:ask@: a Yes/No message box describing he error is displayed. The return value
201
+ of the method depends on the choice made by the user
202
+
203
+ @option opts [String] message nil custom text to add to the default message in
204
+ the message box displayed if the @:on_failure@ option is @:warn@ or @:ask@. If the
205
+ message box is a Yes/No one, most likely you'll need to specify this option to
206
+ describe what will happen if the user chooses Yes and what happens if he chooses
207
+ No.
208
+
209
+ @return [Boolean] *true* if all the documents were saved successfully or if autosaving
210
+ was disabled either globally or for the specific plugin. If some documents couldn't
211
+ be saved, this method returns *false*, unless
212
+
213
+ * a block was given. In this case, the return value of the block is returned
214
+
215
+ * the @:on_failure@ option is @:ask@. In this case, the returned value is *true*
216
+ if the user chose Yes in the message box and *false* otherwise.
217
+ =end
218
+ def autosave plug, what, opts = {}, &blk
219
+ plug = plug.plugin_name if plug.is_a? PluginLike
220
+ return true unless @enabled and @registered_plugins[plug]
221
+ if what.is_a? Array then save_files what, opts, blk
222
+ else send "save_#{what}", opts, blk
223
+ end
224
+ end
225
+
226
+ private
227
+
228
+ =begin rdoc
229
+ Attempts to save all the open documents corresponding to a file belonging to the current project.
230
+
231
+ This method should only be called if autosaving is enabled because it doesn't take
232
+ into account the enabled option and always attempt to save the documents.
233
+
234
+ @param [Hash] opts see {#autosave}
235
+ @param [Proc] blk see {#autosave}
236
+ @return [Boolean] see {#autosave}
237
+ =end
238
+ def save_project_files opts, blk
239
+ docs = Ruber[:docs].documents_with_file
240
+ prj_files = Ruber[:projects].current.project_files.abs
241
+ docs = docs.select{|d| prj_files.include? d.path}
242
+ save_files docs, opts, blk
243
+ end
244
+
245
+ =begin rdoc
246
+ Attempts to save all the open documents.
247
+
248
+ This method should only be called if autosaving is enabled because it doesn't take
249
+ into account the enabled option and always attempt to save the documents.
250
+
251
+ @param [Hash] opts see {#autosave}
252
+ @param [Proc] blk see {#autosave}
253
+ @return [Boolean] see {#autosave}
254
+ =end
255
+ def save_open_documents opts, blk
256
+ save_files Ruber[:docs].documents, opts, blk
257
+ end
258
+
259
+ =begin rdoc
260
+ Attempts to save all the open documents corresponding to a file.
261
+
262
+ This method should only be called if autosaving is enabled because it doesn't take
263
+ into account the enabled option and always attempt to save the documents.
264
+
265
+ @param [Hash] opts see {#autosave}
266
+ @param [Proc] blk see {#autosave}
267
+ @return [Boolean] see {#autosave}
268
+ =end
269
+ def save_documents_with_file opts, blk
270
+ save_files Ruber[:docs].documents_with_file, opts, blk
271
+ end
272
+
273
+ =begin rdoc
274
+ Attempts to save the documents contained in the array _docs_.
275
+
276
+ This method should only be called if autosaving is enabled because it doesn't take
277
+ into account the enabled option and always attempt to save the documents.
278
+
279
+ @param [<Document>] docs an array with the documents to save
280
+ @param [Hash] opts see {#autosave}
281
+ @param [Proc] blk see {#autosave}
282
+ @return [Boolean] see {#autosave}
283
+ =end
284
+ def save_files docs, opts, blk
285
+ unsaved = []
286
+ docs.each_with_index do |d, i|
287
+ unless d.save
288
+ unsaved << d
289
+ if opts[:stop_on_failure]
290
+ unsaved += docs[(i+1)..-1]
291
+ break
292
+ end
293
+ end
294
+ end
295
+ msg = <<-EOS
296
+ The following documents couldn't be saved:
297
+ #{
298
+ unsaved.map{|d| d.path.empty? ? d.document_name : d.path}
299
+ }
300
+ EOS
301
+ if unsaved.empty? then return true
302
+ elsif blk then return blk.call unsaved
303
+ else
304
+ case opts[:on_failure]
305
+ when :warn
306
+ msg << "\n#{opts[:message]}" if opts[:message]
307
+ KDE::MessageBox.sorry Ruber[:main_window], msg
308
+ when :ask
309
+ msg << "\n#{opts[:message]||'Do you want to go on?'}"
310
+ ans = KDE::MessageBox.question_yes_no Ruber[:main_window], msg
311
+ return true if ans == KDE::MessageBox::Yes
312
+ end
313
+ end
314
+ false
315
+ end
316
+
317
+ end
318
+
319
+ =begin rdoc
320
+ The configuration widget for the Autosave plugin
321
+ =end
322
+ class ConfigWidget < Qt::Widget
323
+
324
+ =begin rdoc
325
+ Creates a new instance
326
+
327
+ @param [Qt::Widget, nil] the parent widget
328
+ =end
329
+ def initialize parent = nil
330
+ super
331
+ @ui = Ui::AutosaveConfigWidget.new
332
+ @ui.setupUi self
333
+ m = Qt::StandardItemModel.new @ui._autosave__plugins
334
+ @ui._autosave__plugins.model = m
335
+ fill_plugin_list
336
+ @ui._autosave__plugins.enabled = false
337
+ @ui._autosave__enable.connect(SIGNAL('toggled(bool)')) do |b|
338
+ @ui._autosave__plugins.enabled = b
339
+ end
340
+ end
341
+
342
+ =begin rdoc
343
+ Changes the status of the Plugins widget according to the given value
344
+
345
+ @param [Hash] val the keys are the names of the plugin, while the values tell whether
346
+ autosave should be enabled or not for the given plugin. Any entries corresponding
347
+ to plugins without a corresponding entry in the wigdet are added
348
+
349
+ @return [void]
350
+ =end
351
+ def plugins= val
352
+ mod = @ui._autosave__plugins.model
353
+ val.each_pair do |k, v|
354
+ name = v.to_s
355
+ it = mod.find{|i| i.data.to_string == name}
356
+ unless it
357
+ it = Qt::StandardItem.new k.to_s
358
+ it.data = Qt::Variant.new k.to_s
359
+ it.flags = Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsUserCheckable
360
+ mod.append_row it
361
+ end
362
+ it.checked = v
363
+ end
364
+ end
365
+
366
+ =begin rdoc
367
+ The plugins for which autsave is enabled and those for which it's disabled
368
+
369
+ @return [Hash] a hash whose keys are the plugin names and whose values tell whether
370
+ autosave is enabled or not for a given plugin
371
+ =end
372
+ def plugins
373
+ mod = @ui._autosave__plugins.model
374
+ mod.inject({}) do |res, it|
375
+ res[it.data.to_string.to_sym] = it.checked?
376
+ res
377
+ end
378
+ end
379
+
380
+ private
381
+
382
+ =begin rdoc
383
+ Fills the list view with the registered plugins
384
+
385
+ @return [nil]
386
+ =end
387
+ def fill_plugin_list
388
+ m = @ui._autosave__plugins.model
389
+ Ruber[:autosave].registered_plugins.each_pair do |pl, val|
390
+ obj = Ruber[pl.to_sym]
391
+ it = Qt::StandardItem.new obj.plugin_description.about.human_name
392
+ it.data = Qt::Variant.new(pl.to_s)
393
+ it.flags = Qt::ItemIsEnabled|Qt::ItemIsSelectable|Qt::ItemIsUserCheckable
394
+ it.checked = val
395
+ m.append_row it
396
+ end
397
+ nil
398
+ end
399
+
400
+ end
401
+
402
+ end
403
+
404
+ end
@@ -0,0 +1,16 @@
1
+ name: autosave
2
+ version: 0.0.1
3
+ about:
4
+ authors: [Stefano Crocco, stefano.crocco@alice.it]
5
+ license: gpl
6
+ description: Provides a central place to manage autosave settings for other plugins
7
+ bug_address: http://github.com/stcrocco/ruber/issues
8
+ icon: document-save.png
9
+ require: autosave
10
+ class: Ruber::Autosave::AutosavePlugin
11
+ config_options:
12
+ autosave:
13
+ enable: {default: true}
14
+ plugins: {default: {}}
15
+ config_widgets:
16
+ - {caption: General, class: Ruber::Autosave::ConfigWidget}
@@ -0,0 +1,83 @@
1
+ =begin
2
+ ** Form generated from reading ui file 'autosave_config_widget.ui'
3
+ **
4
+ ** Created: ven ott 29 17:39:04 2010
5
+ ** by: Qt User Interface Compiler version 4.7.0
6
+ **
7
+ ** WARNING! All changes made in this file will be lost when recompiling ui file!
8
+ =end
9
+
10
+ class Ui_AutosaveConfigWidget
11
+ attr_reader :verticalLayout_2
12
+ attr_reader :groupBox
13
+ attr_reader :verticalLayout_3
14
+ attr_reader :verticalLayout
15
+ attr_reader :_autosave__enable
16
+ attr_reader :label_2
17
+ attr_reader :_autosave__plugins
18
+
19
+ def setupUi(autosaveConfigWidget)
20
+ if autosaveConfigWidget.objectName.nil?
21
+ autosaveConfigWidget.objectName = "autosaveConfigWidget"
22
+ end
23
+ autosaveConfigWidget.resize(279, 300)
24
+ @verticalLayout_2 = Qt::VBoxLayout.new(autosaveConfigWidget)
25
+ @verticalLayout_2.objectName = "verticalLayout_2"
26
+ @groupBox = Qt::GroupBox.new(autosaveConfigWidget)
27
+ @groupBox.objectName = "groupBox"
28
+ @verticalLayout_3 = Qt::VBoxLayout.new(@groupBox)
29
+ @verticalLayout_3.objectName = "verticalLayout_3"
30
+ @verticalLayout = Qt::VBoxLayout.new()
31
+ @verticalLayout.objectName = "verticalLayout"
32
+ @_autosave__enable = Qt::CheckBox.new(@groupBox)
33
+ @_autosave__enable.objectName = "_autosave__enable"
34
+
35
+ @verticalLayout.addWidget(@_autosave__enable)
36
+
37
+ @label_2 = Qt::Label.new(@groupBox)
38
+ @label_2.objectName = "label_2"
39
+
40
+ @verticalLayout.addWidget(@label_2)
41
+
42
+ @_autosave__plugins = AutosavePluginListView.new(@groupBox)
43
+ @_autosave__plugins.objectName = "_autosave__plugins"
44
+
45
+ @verticalLayout.addWidget(@_autosave__plugins)
46
+
47
+
48
+ @verticalLayout_3.addLayout(@verticalLayout)
49
+
50
+
51
+ @verticalLayout_2.addWidget(@groupBox)
52
+
53
+ @label_2.buddy = @_autosave__plugins
54
+
55
+ retranslateUi(autosaveConfigWidget)
56
+
57
+ Qt::MetaObject.connectSlotsByName(autosaveConfigWidget)
58
+ end # setupUi
59
+
60
+ def setup_ui(autosaveConfigWidget)
61
+ setupUi(autosaveConfigWidget)
62
+ end
63
+
64
+ def retranslateUi(autosaveConfigWidget)
65
+ autosaveConfigWidget.windowTitle = Qt::Application.translate("AutosaveConfigWidget", "Form", nil, Qt::Application::UnicodeUTF8)
66
+ @groupBox.title = Qt::Application.translate("AutosaveConfigWidget", "Autosave", nil, Qt::Application::UnicodeUTF8)
67
+ @_autosave__enable.text = Qt::Application.translate("AutosaveConfigWidget", "&Enable autosave", nil, Qt::Application::UnicodeUTF8)
68
+ @label_2.text = Qt::Application.translate("AutosaveConfigWidget", "&Exceptions", nil, Qt::Application::UnicodeUTF8)
69
+ @_autosave__plugins.setProperty("access", Qt::Variant.new(Qt::Application.translate("AutosaveConfigWidget", "$plugins", nil, Qt::Application::UnicodeUTF8)))
70
+ @_autosave__plugins.setProperty("signal", Qt::Variant.new(Qt::Application.translate("AutosaveConfigWidget", "items_changed()", nil, Qt::Application::UnicodeUTF8)))
71
+ end # retranslateUi
72
+
73
+ def retranslate_ui(autosaveConfigWidget)
74
+ retranslateUi(autosaveConfigWidget)
75
+ end
76
+
77
+ end
78
+
79
+ module Ui
80
+ class AutosaveConfigWidget < Ui_AutosaveConfigWidget
81
+ end
82
+ end # module Ui
83
+