ruber 0.0.1.1

Sign up to get free protection for your applications and to get access to all the features.
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,193 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>RSpecProjectWidget</class>
4
+ <widget class="QWidget" name="RSpecProjectWidget">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>447</width>
10
+ <height>315</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Form</string>
15
+ </property>
16
+ <layout class="QGridLayout" name="gridLayout_3">
17
+ <item row="0" column="0">
18
+ <spacer name="verticalSpacer">
19
+ <property name="orientation">
20
+ <enum>Qt::Vertical</enum>
21
+ </property>
22
+ <property name="sizeHint" stdset="0">
23
+ <size>
24
+ <width>20</width>
25
+ <height>10</height>
26
+ </size>
27
+ </property>
28
+ </spacer>
29
+ </item>
30
+ <item row="2" column="0" colspan="2">
31
+ <widget class="QGroupBox" name="groupBox_2">
32
+ <property name="title">
33
+ <string>RSpec</string>
34
+ </property>
35
+ <layout class="QGridLayout" name="gridLayout_2">
36
+ <item row="1" column="0">
37
+ <widget class="QLabel" name="label_5">
38
+ <property name="text">
39
+ <string>&amp;RSpec options</string>
40
+ </property>
41
+ <property name="buddy">
42
+ <cstring>_rspec__options</cstring>
43
+ </property>
44
+ </widget>
45
+ </item>
46
+ <item row="1" column="2">
47
+ <widget class="KLineEdit" name="_rspec__options">
48
+ <property name="access" stdset="0">
49
+ <string>$spec_options</string>
50
+ </property>
51
+ </widget>
52
+ </item>
53
+ <item row="0" column="0">
54
+ <widget class="QLabel" name="label_6">
55
+ <property name="text">
56
+ <string>&amp;RSpec executable</string>
57
+ </property>
58
+ <property name="buddy">
59
+ <cstring>_rspec__executable</cstring>
60
+ </property>
61
+ </widget>
62
+ </item>
63
+ <item row="0" column="2">
64
+ <widget class="KLineEdit" name="_rspec__executable"/>
65
+ </item>
66
+ <item row="2" column="0">
67
+ <widget class="QCheckBox" name="_rspec__full_backtraces">
68
+ <property name="text">
69
+ <string>&amp;Generate full backtraces</string>
70
+ </property>
71
+ </widget>
72
+ </item>
73
+ </layout>
74
+ </widget>
75
+ </item>
76
+ <item row="3" column="1">
77
+ <spacer name="verticalSpacer_3">
78
+ <property name="orientation">
79
+ <enum>Qt::Vertical</enum>
80
+ </property>
81
+ <property name="sizeHint" stdset="0">
82
+ <size>
83
+ <width>20</width>
84
+ <height>0</height>
85
+ </size>
86
+ </property>
87
+ </spacer>
88
+ </item>
89
+ <item row="4" column="0" colspan="2">
90
+ <widget class="QGroupBox" name="groupBox">
91
+ <property name="title">
92
+ <string>Spec files</string>
93
+ </property>
94
+ <layout class="QGridLayout" name="gridLayout">
95
+ <item row="0" column="0">
96
+ <widget class="QLabel" name="label">
97
+ <property name="text">
98
+ <string>Spec &amp;directory</string>
99
+ </property>
100
+ <property name="buddy">
101
+ <cstring>_rspec__spec_directory</cstring>
102
+ </property>
103
+ </widget>
104
+ </item>
105
+ <item row="0" column="1">
106
+ <widget class="KUrlRequester" name="_rspec__spec_directory"/>
107
+ </item>
108
+ <item row="1" column="0">
109
+ <widget class="QLabel" name="label_2">
110
+ <property name="text">
111
+ <string>&amp;Filter</string>
112
+ </property>
113
+ <property name="buddy">
114
+ <cstring>_rspec__spec_files</cstring>
115
+ </property>
116
+ </widget>
117
+ </item>
118
+ <item row="1" column="1">
119
+ <widget class="KLineEdit" name="_rspec__spec_files">
120
+ <property name="text">
121
+ <string>*_spec.rb</string>
122
+ </property>
123
+ </widget>
124
+ </item>
125
+ <item row="2" column="0">
126
+ <widget class="QLabel" name="label_3">
127
+ <property name="text">
128
+ <string>&amp;Pattern</string>
129
+ </property>
130
+ <property name="buddy">
131
+ <cstring>_rspec__spec_pattern</cstring>
132
+ </property>
133
+ </widget>
134
+ </item>
135
+ <item row="2" column="1">
136
+ <widget class="KLineEdit" name="_rspec__spec_pattern">
137
+ <property name="text">
138
+ <string>%f_spec.rb</string>
139
+ </property>
140
+ <property name="access" stdset="0">
141
+ <string>$pattern</string>
142
+ </property>
143
+ </widget>
144
+ </item>
145
+ </layout>
146
+ </widget>
147
+ </item>
148
+ <item row="5" column="0" colspan="2">
149
+ <spacer name="verticalSpacer_2">
150
+ <property name="orientation">
151
+ <enum>Qt::Vertical</enum>
152
+ </property>
153
+ <property name="sizeHint" stdset="0">
154
+ <size>
155
+ <width>20</width>
156
+ <height>0</height>
157
+ </size>
158
+ </property>
159
+ </spacer>
160
+ </item>
161
+ <item row="1" column="0">
162
+ <widget class="RubyOptionsWidget" name="_rspec__ruby_options" native="true"/>
163
+ </item>
164
+ </layout>
165
+ </widget>
166
+ <customwidgets>
167
+ <customwidget>
168
+ <class>KUrlRequester</class>
169
+ <extends>QFrame</extends>
170
+ <header>kurlrequester.h</header>
171
+ </customwidget>
172
+ <customwidget>
173
+ <class>KLineEdit</class>
174
+ <extends>QLineEdit</extends>
175
+ <header>klineedit.h</header>
176
+ </customwidget>
177
+ <customwidget>
178
+ <class>RubyOptionsWidget</class>
179
+ <extends>QWidget</extends>
180
+ <header>rubyoptionswidget.h</header>
181
+ <container>1</container>
182
+ </customwidget>
183
+ </customwidgets>
184
+ <tabstops>
185
+ <tabstop>_rspec__executable</tabstop>
186
+ <tabstop>_rspec__options</tabstop>
187
+ <tabstop>_rspec__spec_directory</tabstop>
188
+ <tabstop>_rspec__spec_files</tabstop>
189
+ <tabstop>_rspec__spec_pattern</tabstop>
190
+ </tabstops>
191
+ <resources/>
192
+ <connections/>
193
+ </ui>
@@ -0,0 +1,27 @@
1
+ name: ruby_development
2
+ version: 0.0.1
3
+ about:
4
+ authors: [Stefano Crocco, stefano.crocco@alice.it]
5
+ license: gpl
6
+ description: Allows to run ruby programs being developed in Ruber
7
+ bug_address: http://github.com/stcrocco/ruber/issues
8
+ icon: ruby_development.png
9
+ deps: [ruby_runner, autosave]
10
+ class: Ruber::FilesRunner::Plugin
11
+ require: ruby_development
12
+ ui_file: ruby_developmentui.rc
13
+ tool_widgets: {:class: Ruber::FilesRunner::OutputWidget, :caption: Ruby output, :position: :bottom, :name: ruby_output_widget, pixmap: ruby_development.png}
14
+ project_options:
15
+ ruby:
16
+ main_program: {default: "''", relative_path: true}
17
+ options: {default: [], scope: [document, global]}
18
+ working_dir: {default: '.', relative_path: true}
19
+ run_in_terminal: {default: false, scope: [document, global]}
20
+ project_widgets:
21
+ - {caption: Ruby, class: Ruber::FilesRunner::ProjectWidget, scope: [document, global]}
22
+ actions:
23
+ ruby_runner-run: {text: '&Run', icon: ruby_development.png, shortcut: F8, slot: run(), states: [active_project_exists, current_document, ruby_running]}
24
+ ruby_runner-run_current_file: {text: Run &Current File, icon: ruby_development.png, shortcut: Ctrl+F8, slot: run_current_document(), states: [current_document, ruby_running]}
25
+ ruby_runner-run_file: {text: Run &File..., icon: ruby_development.png, shortcut: Shift+F8, slot: run_file(), state: '!ruby_running'}
26
+ ruby_runner-stop: {text: '&Stop', icon: process-stop, shortcut: ESC, slot: stop_process(), state: ruby_running}
27
+ ruby_runner-run_in_terminal: {text: Run Programs in &Terminal, class: KDE::ToggleAction}
@@ -0,0 +1,453 @@
1
+ require 'ruber/filtered_output_widget'
2
+
3
+ require 'ruby_runner/ruby_runner'
4
+
5
+ require_relative 'ui/project_widget'
6
+
7
+ module Ruber
8
+
9
+ =begin rdoc
10
+ Plugin which allows the user to run the current project or file he's wokring on
11
+ in ruby
12
+
13
+ This plugin allows to run in ruby the main file specified by the current project,
14
+ the file corresponding to the current document or another file specified by the
15
+ user. The output of the program (both standard output and standard error) are
16
+ displayied in a tool widget.
17
+
18
+ The interpreter to use can be set document- or project-wise using the Ruby runner
19
+ plugin.
20
+
21
+ An action and an option are provided to decide whether the program should or
22
+ not be run in a terminal. The action, if checked, has precedence over the option,
23
+ so the user can force a program to be run in a terminal.
24
+
25
+ For a program to be run in terminal, the @Konsole@ program must be installed.
26
+
27
+ @todo Allow for other programs to be used as terminals
28
+ @todo Allow to run unsaved documents in ruby by saving them to temporary files
29
+
30
+ @api feature ruby_development
31
+ @plugin Plugin
32
+ =end
33
+ module FilesRunner
34
+
35
+ =begin rdoc
36
+ Plugin object for the Files runner plugn
37
+ @api_method #run_document
38
+ @api_method #run_project
39
+ @api_method #run_file
40
+ @api_method #run_ruby
41
+ @api_method #run_in_terminal?
42
+ =end
43
+ class Plugin < RubyRunner::RubyRunnerPlugin
44
+
45
+ slots :load_settings
46
+
47
+ =begin rdoc
48
+ @param [PluginSpecification] the {PluginSpecification} describing the plugin
49
+ =end
50
+ def initialize psf
51
+ super psf, :ruby, :scope => [:document, :global], :file_extension => %w[*.rb Rakefile rakefile],
52
+ :mimetype => ['application/x-ruby']
53
+ process.next_open_mode = Qt::IODevice::ReadOnly | Qt::IODevice::Unbuffered
54
+ Ruber[:autosave].register_plugin self, true
55
+ connect self, SIGNAL('process_finished(int, QString)'), self, SLOT('ruby_exited(int, QString)')
56
+ self.connect(SIGNAL(:process_failed_to_start)){@gui.action_collection.action('ruby_runner-stop').enabled = false}
57
+ Ruber[:main_window].change_state 'ruby_running', false
58
+ register_action_handler('ruby_runner-run') do |states|
59
+ (states['current_document'] or states['active_project_exists']) and
60
+ !states['ruby_running']
61
+ end
62
+ register_action_handler('ruby_runner-run_current_file') do |states|
63
+ states['current_document'] and ! states['ruby_running']
64
+ end
65
+ Ruber[:components].connect(SIGNAL('feature_loaded(QString, QObject*)')) do |f, o|
66
+ o.register_plugin self, true if f == 'autosave'
67
+ end
68
+ @output_widget = @widget
69
+ end
70
+
71
+ =begin rdoc
72
+ Runs ruby the given script in ruby
73
+
74
+ The output of ruby is displayed in the associated output widget. If desired,
75
+ files are autosaved before running it.
76
+
77
+ If ruby is already running, or if autosaving fails, noting is done.
78
+
79
+ @param [String] script the ruby script to execute (either absolute path or relative
80
+ to the @:dir@ entry of _opts_)
81
+ @param [Hash] opts options to fine-tune the behaviour of ruby
82
+ @param [Hash] autosave_opts options telling whether and how autosave files
83
+ @param [Proc] blk a block to pass to autosave. If not given, no block will be
84
+ passed to autosave
85
+
86
+ @option opts [String] :ruby (Ruber[:config][:ruby, :ruby]) the ruby interpreter
87
+ to use
88
+ @option opts [Array<String>] :ruby_options (Ruber[:config][:ruby, :ruby_options])
89
+ an array with the options to pass to the ruby interpreter
90
+ @option opts [Array<String>] :options ([]) an array with the options to pass
91
+ to the script
92
+ @option opts [String] :dir (Dir.pwd) the directory to run ruby from
93
+
94
+ @option autosave_opts [Array<Document>,Symbol] :files (nil) the documents to autosave.
95
+ It can be anything which can be passed as second parameter to {Autosave::AutosavePlugin#autosave}.
96
+ If it's *nil*, autosave won't be used
97
+ @option autosave_opts [Symbol, Plugin] :plugin (Ruber[:ruby_development]) the value to pass
98
+ as first argument to {Autosave::AutosavePlugin#autosave}
99
+ @option autosave_opts [Boolean] :stop_on_failure (nil) as in {Autosave::AutosavePlugin#autosave}
100
+ @option autosave_opts [Symbol] :on_failure (nil) as in {Autosave::AutosavePlugin#autosave}
101
+ @option autosave_opts [String] :message (nil) as in {Autosave::AutosavePlugin#autosave}
102
+
103
+ @return [Boolean] *true* if the process is started and *false* otherwise
104
+ (including the case when the process was already running or autosaving failed)
105
+
106
+ @see Autosave::AutosavePlugin#autosave
107
+ =end
108
+ def run_ruby script, opts, autosave_opts = {}, &blk
109
+ default = {
110
+ :ruby => Ruber[:config][:ruby, :ruby],
111
+ :ruby_options => Ruber[:config][:ruby, :ruby_options],
112
+ :dir => Dir.pwd,
113
+ :options => []
114
+ }
115
+ opts = default.merge opts
116
+ return false unless process.state == Qt::Process::NotRunning
117
+ if autosave_opts[:files]
118
+ plug = autosave_opts[:plugin] || self
119
+ what = autosave_opts[:files]
120
+ return false unless Ruber[:autosave].autosave plug,
121
+ what, autosave_opts, &blk
122
+ end
123
+ @widget.working_directory = opts[:dir]
124
+ @widget.clear_output
125
+ cmd = opts[:ruby_options] + [script] + opts[:options]
126
+ Ruber[:main_window].show_tool @widget
127
+ Ruber[:main_window].change_state 'ruby_running', true
128
+ if opts[:run_in_terminal]
129
+ run_process 'konsole', opts[:dir], ['--workdir', opts[:dir], '--hold',
130
+ '-e', opts[:ruby]] + cmd
131
+ else run_process opts[:ruby], opts[:dir], cmd
132
+ end
133
+ true
134
+ end
135
+
136
+ =begin rdoc
137
+ Runs either the project main program or the file in the current view in ruby,
138
+ displaying the output in the output tool widget
139
+
140
+ This method calls {#run_project} or {#run_document} (with the current document)
141
+ if theere's a global project or an active document. If there isn't either a global
142
+ project nor a document, then {#run_file} is used.
143
+
144
+ @return [Boolean] *true* or *false* depending on whether the ruby process was
145
+ started correctly or not.
146
+
147
+ @see #run_project
148
+ @see #run_document
149
+ @see #run_file
150
+ =end
151
+ def run
152
+ if Ruber[:projects].current then run_project
153
+ elsif (doc = Ruber[:main_window].current_document) then run_document doc
154
+ else run_file
155
+ end
156
+ end
157
+ slots :run
158
+
159
+ =begin rdoc
160
+ Runs the main program of the project.
161
+
162
+ It uses the project settings for options, working directory and so on.
163
+
164
+ If the appropriate option is set, it will attempt to save all the documents
165
+ corresponding to files in the project before executing. If it fails, then ruby
166
+ won't be run.
167
+
168
+ This method calls {#run_ruby_for} internally.
169
+ @return [Booelan] *true* or *false* depending on whether the ruby process was
170
+ started successfully.
171
+ @see #run_ruby_for
172
+ =end
173
+ def run_project
174
+ prj = Ruber.current_project
175
+ data = prj[:ruby]
176
+ prog = Pathname.new(data[:main_program, :abs])
177
+ wdir = Pathname.new(data[:working_dir, :abs]||prj.project_dir)
178
+ prog = (prog.relative_path_from(wdir)).to_s
179
+ run_ruby_for prj, prog, wdir.to_s, data[:options], run_in_terminal?(prj),
180
+ :files => :project_files, :on_failure => :ask
181
+ end
182
+
183
+ =begin rdoc
184
+ Runs the file associated with the given document in ruby
185
+
186
+ If the user has enabled autosave for this plugin, the document will be saved before
187
+ ruby is run.
188
+
189
+ Ruby will be executed from the directory where the file is, while the interpreter
190
+ to use, the options to pass to ruby and those to pass to the program are read
191
+ from the {DocumentProject} associated with the document itself.
192
+
193
+ The {#run_in_terminal?} method is used to decide whether the program should be
194
+ run in a terminal window or not.
195
+
196
+ This method uses {#run_ruby_for}.
197
+
198
+ @param [Ruber::Document] doc the document to run in ruby
199
+ @return [Boolean] *true* or *false* depending on whether the ruby process was started
200
+ successfully or not
201
+
202
+ @see #run_ruby_for
203
+ =end
204
+ def run_document doc
205
+ return unless doc.save if !doc.has_file?
206
+ prj = doc.project
207
+ file = File.basename(doc.path)
208
+ dir = File.dirname(doc.path)
209
+ run_ruby_for prj, file, dir, prj[:ruby, :options], run_in_terminal?(doc.project),
210
+ :files => [doc], :on_failure => :ask
211
+ end
212
+
213
+ =begin rdoc
214
+ Runs a file in ruby.
215
+
216
+ If the file is associated with a document, this method will work like {#run_document}.
217
+
218
+ Ruby will be executed from the directory where the file is.
219
+
220
+ The program will be run in a terminal if the corresponding action is checked.
221
+
222
+ This method uses {#run_ruby_for}
223
+
224
+ *Note:* it is not possible to specify command line options to be passed to _file_.
225
+ @param [String, nil] file the path of the file to run. If *nil*, an "Open file"
226
+ dialog is shown to the user
227
+ @return [Boolean, nil] *true* or *false* depending on whether the ruby process
228
+ was started. If the user pressed the Cancel button of the dialog, *nil* is returned.
229
+ @see #run_ruby_for
230
+ =end
231
+ def run_file file = nil
232
+ unless file
233
+ file = KDE::FileDialog.get_open_file_name KDE::Url.new(Ruber[:main_window].scripts_directory),
234
+ "*.rb|Ruby files (*.rb)", nil, "Choose file to run"
235
+ return unless file
236
+ end
237
+
238
+ if doc = Ruber[:docs].document_for_file(file)
239
+ return run_document doc
240
+ end
241
+
242
+ dir = File.dirname(file)
243
+ file = File.basename(file)
244
+ run_ruby_for nil, file, dir, [], run_in_terminal?
245
+ end
246
+ slots :run_file
247
+
248
+ =begin rdoc
249
+ Override of {Ruber::PluginLike#register_with_project Ruber::Plugin#register_with_project}
250
+
251
+ This mehtods sets the @ruby/main_program@ project option to bin/project_name if
252
+ it's empty and sets up a connection with the {AbstractProject#option_changed option_changed}
253
+ signal of the project to do the same whenever this option changes.
254
+
255
+ It works as {Ruber::PluginLike#register_with_project Ruber::Plugin#register_with_project}
256
+ if the project has document scope
257
+
258
+ @param [Ruber::AbstractProject] prj the project to registeer with
259
+ @return [nil]
260
+ =end
261
+ def register_with_project prj
262
+ super
263
+ return unless prj.scope == :global
264
+ if prj[:ruby, :main_program].empty?
265
+ prj[:ruby, :main_program] = File.join('bin',prj.project_name.gsub(/\W/,'_').downcase)
266
+ end
267
+ prj.connect(SIGNAL('option_changed(QString, QString)')) do |g, n|
268
+ if g == 'ruby' and n == 'main_program' && prj[:ruby, :main_program].empty?
269
+ prj[:ruby, :main_program] = File.join 'bin',prj.project_name.gsub(/\W/,'_').downcase
270
+ end
271
+ end
272
+ nil
273
+ end
274
+
275
+ private
276
+
277
+ =begin rdoc
278
+ Starts executing a given ruby program and displays the tool widget
279
+
280
+ This method uses {RubyRunner::RubyRunnerPluginInternal#ruby_command_for RubyRunner::RubyRunnerPlugin#ruby_command_for} to retrieve the first part
281
+ of the command line to use and {#run_ruby} to actually start the ruby process.
282
+
283
+ @param [Ruber::AbstractProject, Ruber::Document, String, nil] what has the same
284
+ meaning as in {RubyRunner::RubyRunnerPluginInternal#ruby_command_for RubyRunner::RubyRunnerPlugin#ruby_command_for}
285
+ @param [String] file the filename of the script to run
286
+ @param [String] dir has the same meaning as in {RubyRunner::RubyRunnerPluginInternal#ruby_command_for RubyRunner::RubyRunnerPlugin#ruby_command_for}
287
+ @param [<String>] prog_options a list of the command line options to pass to the
288
+ program (not to ruby itself)
289
+ @param [Boolean] run_in_terminal whether to run the program in a terminal window
290
+ or not
291
+ @param [Hash] autosave_opts has the same meaning as in {#run_ruby}
292
+ @param [Proc] blk has the same meaning as in {#run_ruby}
293
+ @return [Boolean] *true* or *false* depending on whether the ruby process was
294
+ started correctly
295
+ @see #run_ruby
296
+ @see RubyRunner::RubyRunnerPluginInternal#ruby_command_for
297
+ =end
298
+ def run_ruby_for what, file, dir, prog_options, run_in_terminal, autosave_opts, &blk
299
+ ruby, *ruby_opts = ruby_command_for what, dir
300
+ opts = {
301
+ :dir => dir,
302
+ :options => prog_options,
303
+ :run_in_terminal => run_in_terminal,
304
+ :ruby => ruby,
305
+ :ruby_options => ruby_opts
306
+ }
307
+ run_ruby file, opts, autosave_opts, &blk
308
+ end
309
+
310
+ =begin rdoc
311
+ Runs the current document in ruby
312
+
313
+ If there's an open document, it works like {#run_document}, otherwise it does
314
+ nothing
315
+ @return [Boolean, nil] *true* or *false* depending on whether the ruby process
316
+ was started correctly and *nil* if no document exists
317
+ @see {#run_document}
318
+ =end
319
+ def run_current_document
320
+ doc = Ruber[:main_window].current_document
321
+ run_document doc if doc
322
+ end
323
+ slots :run_current_document
324
+
325
+ =begin rdoc
326
+ Whether a given ruby program should be run in terminal or not
327
+
328
+ This method takes into account the @ruby/run_in_terminal@ option stored in the
329
+ given project (if any) and the state of the @ruby_runner-run_in_terminal@ action
330
+ (which, if checked, overrides the option).
331
+
332
+ *Note:* while the user can, by checking the action, force a program to be run in terminal
333
+ even if the project doesn't say so, there's no way in which he can force a program
334
+ to be run without a terminal if the project says it should be run in a terminal
335
+ (because if the action is unchecked, only the project option is taken into account).
336
+
337
+ @param [Ruber::AbstractProject,nil] prj the project from which to retrieve the
338
+ settings. If *nil*, only the action will be taken into account
339
+ @return [Boolean] *true* if the program should be run in terminal and *false*
340
+ otherwise.
341
+ =end
342
+ def run_in_terminal? prj = nil
343
+ action_collection.action('ruby_runner-run_in_terminal').checked? ||
344
+ (prj and prj[:ruby, :run_in_terminal])
345
+ end
346
+
347
+ =begin rdoc
348
+ Slot called when the ruby process exited
349
+
350
+ Resets the UI, scrolls the tool widget at the end and gives focus to the editor
351
+ @return [nil]
352
+ =end
353
+ def ruby_exited code, reason
354
+ Ruber[:main_window].change_state 'ruby_running', false
355
+ @widget.scroll_to -1
356
+ Ruber[:main_window].focus_on_editor
357
+ nil
358
+ end
359
+ slots 'ruby_exited(int, QString)'
360
+
361
+ end
362
+
363
+ =begin rdoc
364
+ The class used by the Files runner tool widget
365
+
366
+ It's a normal {Ruber::FilteredOutputWidget} which overrides the {#find_filename_in_index}
367
+ method
368
+ =end
369
+ class OutputWidget < FilteredOutputWidget
370
+
371
+ private
372
+
373
+ =begin rdoc
374
+ Override of {OutputWidget#find_filename_in_index}
375
+
376
+ It differs from the
377
+ original implementation in that it attempts to work around the situation where
378
+ there's a syntax error in a file loaded using require. In this case, the error message takes the form:
379
+
380
+ @requiring_file:line: in `require': file_with_syntax_error:line: syntax error...@
381
+
382
+ Most often, the user will want to open the file with the syntax error, not the
383
+ one requiring it, so this method attempts to remove the first part of the string
384
+ before passing it to *super*. It also works with rubygems in ruby 1.8, when
385
+ require is replaced by @gem_original_require@
386
+ @param [Qt::ModelIndex] idx the index to search for a filename
387
+ @return [<String,Integer>,String,nil] see {Ruber::OutputWidget#find_filename_in_index}
388
+ =end
389
+ def find_filename_in_index idx
390
+ str = idx.data.to_string
391
+ if idx.row == 0 then super
392
+ else
393
+ super str.sub( %r<^[^\s:]+:\d+:in\s+`(?:gem_original_require|require):\s+'>, '')
394
+ end
395
+ end
396
+
397
+ end
398
+
399
+ =begin rdoc
400
+ Project configuration widget for the Files runner plugin
401
+ =end
402
+ class ProjectWidget < Ruber::ProjectConfigWidget
403
+
404
+ =begin rdoc
405
+ @param [Ruber::AbstractProject] prj the project the configuration widget refers to
406
+ =end
407
+ def initialize prj
408
+ super
409
+ @ui = Ui::FilesRunnerProjectWidget.new
410
+ @ui.setupUi self
411
+ hide_global_only_widgets if prj.scope == :document
412
+ end
413
+
414
+ =begin rdoc
415
+ Sets the contents of the program options widget
416
+ @param [<String>] value a list of the command line options to be passed to the
417
+ script to execute
418
+ =end
419
+ def program_options= value
420
+ @ui._ruby__options.text = value.join " "
421
+ end
422
+
423
+ =begin rdoc
424
+ Splits the content of the program options widget into an array
425
+
426
+ @return [<String>] an array containing the options to pass to the ruby script to
427
+ execute. Quotes are preserved.
428
+ =end
429
+ def program_options
430
+ Shellwords.split_with_quotes @ui._ruby__options.text
431
+ end
432
+
433
+ private
434
+
435
+ =begin rdoc
436
+ Hides the widgets corresponding to global options
437
+
438
+ This method is called by the constructor when the widget is associated with a
439
+ project with document scope.
440
+ @return [nil]
441
+ =end
442
+ def hide_global_only_widgets
443
+ @ui.main_program_label.hide
444
+ @ui._ruby__main_program.hide
445
+ @ui.working_dir_label.hide
446
+ @ui._ruby__working_dir.hide
447
+ end
448
+
449
+ end
450
+
451
+ end
452
+
453
+ end