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,91 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>RubyRunnerConfigWidget</class>
4
+ <widget class="QWidget" name="RubyRunnerConfigWidget">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>385</width>
10
+ <height>306</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Form</string>
15
+ </property>
16
+ <layout class="QVBoxLayout" name="verticalLayout">
17
+ <item>
18
+ <widget class="KEditListBox" name="_ruby__interpreters">
19
+ <property name="title">
20
+ <string>&amp;Availlable Interpreters</string>
21
+ </property>
22
+ <property name="signal" stdset="0">
23
+ <string>changed()</string>
24
+ </property>
25
+ <property name="read" stdset="0">
26
+ <string>$fill_interpreters</string>
27
+ </property>
28
+ <property name="store" stdset="0">
29
+ <string>items</string>
30
+ </property>
31
+ </widget>
32
+ </item>
33
+ <item>
34
+ <widget class="QGroupBox" name="groupBox">
35
+ <property name="title">
36
+ <string>Interpreter</string>
37
+ </property>
38
+ <layout class="QVBoxLayout" name="verticalLayout_2">
39
+ <item>
40
+ <layout class="QHBoxLayout" name="horizontalLayout">
41
+ <item>
42
+ <widget class="QLabel" name="label">
43
+ <property name="text">
44
+ <string>&amp;Default interpreter</string>
45
+ </property>
46
+ <property name="buddy">
47
+ <cstring>_ruby__ruby</cstring>
48
+ </property>
49
+ </widget>
50
+ </item>
51
+ <item>
52
+ <widget class="KComboBox" name="_ruby__ruby">
53
+ <property name="read" stdset="0">
54
+ <string>$default_interpreter=</string>
55
+ </property>
56
+ <property name="store" stdset="0">
57
+ <string>current_text</string>
58
+ </property>
59
+ </widget>
60
+ </item>
61
+ </layout>
62
+ </item>
63
+ <item>
64
+ <widget class="RubyOptionsWidget" name="_ruby__ruby_options" native="true"/>
65
+ </item>
66
+ </layout>
67
+ </widget>
68
+ </item>
69
+ </layout>
70
+ </widget>
71
+ <customwidgets>
72
+ <customwidget>
73
+ <class>KEditListBox</class>
74
+ <extends>QGroupBox</extends>
75
+ <header>keditlistbox.h</header>
76
+ </customwidget>
77
+ <customwidget>
78
+ <class>KComboBox</class>
79
+ <extends>QComboBox</extends>
80
+ <header>kcombobox.h</header>
81
+ </customwidget>
82
+ <customwidget>
83
+ <class>RubyOptionsWidget</class>
84
+ <extends>QWidget</extends>
85
+ <header>rubyoptionswidget.h</header>
86
+ <container>1</container>
87
+ </customwidget>
88
+ </customwidgets>
89
+ <resources/>
90
+ <connections/>
91
+ </ui>
@@ -0,0 +1,60 @@
1
+ =begin
2
+ ** Form generated from reading ui file 'project_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_RubyRunnerProjectWidget
11
+ attr_reader :horizontalLayout
12
+ attr_reader :label
13
+ attr_reader :_ruby__ruby
14
+
15
+ def setupUi(rubyRunnerProjectWidget)
16
+ if rubyRunnerProjectWidget.objectName.nil?
17
+ rubyRunnerProjectWidget.objectName = "rubyRunnerProjectWidget"
18
+ end
19
+ rubyRunnerProjectWidget.resize(414, 34)
20
+ @horizontalLayout = Qt::HBoxLayout.new(rubyRunnerProjectWidget)
21
+ @horizontalLayout.objectName = "horizontalLayout"
22
+ @label = Qt::Label.new(rubyRunnerProjectWidget)
23
+ @label.objectName = "label"
24
+
25
+ @horizontalLayout.addWidget(@label)
26
+
27
+ @_ruby__ruby = KDE::ComboBox.new(rubyRunnerProjectWidget)
28
+ @_ruby__ruby.objectName = "_ruby__ruby"
29
+
30
+ @horizontalLayout.addWidget(@_ruby__ruby)
31
+
32
+ @label.buddy = @_ruby__ruby
33
+
34
+ retranslateUi(rubyRunnerProjectWidget)
35
+
36
+ Qt::MetaObject.connectSlotsByName(rubyRunnerProjectWidget)
37
+ end # setupUi
38
+
39
+ def setup_ui(rubyRunnerProjectWidget)
40
+ setupUi(rubyRunnerProjectWidget)
41
+ end
42
+
43
+ def retranslateUi(rubyRunnerProjectWidget)
44
+ rubyRunnerProjectWidget.windowTitle = Qt::Application.translate("RubyRunnerProjectWidget", "Form", nil, Qt::Application::UnicodeUTF8)
45
+ @label.text = Qt::Application.translate("RubyRunnerProjectWidget", "&Ruby interpreter", nil, Qt::Application::UnicodeUTF8)
46
+ @_ruby__ruby.setProperty("read", Qt::Variant.new(Qt::Application.translate("RubyRunnerProjectWidget", "$interpreter=", nil, Qt::Application::UnicodeUTF8)))
47
+ @_ruby__ruby.setProperty("store", Qt::Variant.new(Qt::Application.translate("RubyRunnerProjectWidget", "current_text", nil, Qt::Application::UnicodeUTF8)))
48
+ end # retranslateUi
49
+
50
+ def retranslate_ui(rubyRunnerProjectWidget)
51
+ retranslateUi(rubyRunnerProjectWidget)
52
+ end
53
+
54
+ end
55
+
56
+ module Ui
57
+ class RubyRunnerProjectWidget < Ui_RubyRunnerProjectWidget
58
+ end
59
+ end # module Ui
60
+
@@ -0,0 +1,48 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>RubyRunnerProjectWidget</class>
4
+ <widget class="QWidget" name="RubyRunnerProjectWidget">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>414</width>
10
+ <height>34</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Form</string>
15
+ </property>
16
+ <layout class="QHBoxLayout" name="horizontalLayout">
17
+ <item>
18
+ <widget class="QLabel" name="label">
19
+ <property name="text">
20
+ <string>&amp;Ruby interpreter</string>
21
+ </property>
22
+ <property name="buddy">
23
+ <cstring>_ruby__ruby</cstring>
24
+ </property>
25
+ </widget>
26
+ </item>
27
+ <item>
28
+ <widget class="KComboBox" name="_ruby__ruby">
29
+ <property name="read" stdset="0">
30
+ <string>$interpreter=</string>
31
+ </property>
32
+ <property name="store" stdset="0">
33
+ <string>current_text</string>
34
+ </property>
35
+ </widget>
36
+ </item>
37
+ </layout>
38
+ </widget>
39
+ <customwidgets>
40
+ <customwidget>
41
+ <class>KComboBox</class>
42
+ <extends>QComboBox</extends>
43
+ <header>kcombobox.h</header>
44
+ </customwidget>
45
+ </customwidgets>
46
+ <resources/>
47
+ <connections/>
48
+ </ui>
@@ -0,0 +1,59 @@
1
+ =begin
2
+ ** Form generated from reading ui file 'ruby_runnner_plugin_option_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_RubyRunnerPluginOptionWidget
11
+ attr_reader :horizontalLayout
12
+ attr_reader :label
13
+ attr_reader :text
14
+
15
+ def setupUi(rubyRunnerPluginOptionWidget)
16
+ if rubyRunnerPluginOptionWidget.objectName.nil?
17
+ rubyRunnerPluginOptionWidget.objectName = "rubyRunnerPluginOptionWidget"
18
+ end
19
+ rubyRunnerPluginOptionWidget.resize(400, 36)
20
+ @horizontalLayout = Qt::HBoxLayout.new(rubyRunnerPluginOptionWidget)
21
+ @horizontalLayout.objectName = "horizontalLayout"
22
+ @label = Qt::Label.new(rubyRunnerPluginOptionWidget)
23
+ @label.objectName = "label"
24
+
25
+ @horizontalLayout.addWidget(@label)
26
+
27
+ @text = KDE::LineEdit.new(rubyRunnerPluginOptionWidget)
28
+ @text.objectName = "text"
29
+
30
+ @horizontalLayout.addWidget(@text)
31
+
32
+ @label.buddy = @text
33
+
34
+ retranslateUi(rubyRunnerPluginOptionWidget)
35
+
36
+ Qt::MetaObject.connectSlotsByName(rubyRunnerPluginOptionWidget)
37
+ end # setupUi
38
+
39
+ def setup_ui(rubyRunnerPluginOptionWidget)
40
+ setupUi(rubyRunnerPluginOptionWidget)
41
+ end
42
+
43
+ def retranslateUi(rubyRunnerPluginOptionWidget)
44
+ rubyRunnerPluginOptionWidget.windowTitle = Qt::Application.translate("RubyRunnerPluginOptionWidget", "Form", nil, Qt::Application::UnicodeUTF8)
45
+ rubyRunnerPluginOptionWidget.setProperty("signal", Qt::Variant.new(Qt::Application.translate("RubyRunnerPluginOptionWidget", "text_changed(QString)", nil, Qt::Application::UnicodeUTF8)))
46
+ @label.text = Qt::Application.translate("RubyRunnerPluginOptionWidget", "Ruby &options", nil, Qt::Application::UnicodeUTF8)
47
+ end # retranslateUi
48
+
49
+ def retranslate_ui(rubyRunnerPluginOptionWidget)
50
+ retranslateUi(rubyRunnerPluginOptionWidget)
51
+ end
52
+
53
+ end
54
+
55
+ module Ui
56
+ class RubyRunnerPluginOptionWidget < Ui_RubyRunnerPluginOptionWidget
57
+ end
58
+ end # module Ui
59
+
@@ -0,0 +1,44 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <ui version="4.0">
3
+ <class>RubyRunnerPluginOptionWidget</class>
4
+ <widget class="QWidget" name="RubyRunnerPluginOptionWidget">
5
+ <property name="geometry">
6
+ <rect>
7
+ <x>0</x>
8
+ <y>0</y>
9
+ <width>400</width>
10
+ <height>36</height>
11
+ </rect>
12
+ </property>
13
+ <property name="windowTitle">
14
+ <string>Form</string>
15
+ </property>
16
+ <property name="signal" stdset="0">
17
+ <string>text_changed(QString)</string>
18
+ </property>
19
+ <layout class="QHBoxLayout" name="horizontalLayout">
20
+ <item>
21
+ <widget class="QLabel" name="label">
22
+ <property name="text">
23
+ <string>Ruby &amp;options</string>
24
+ </property>
25
+ <property name="buddy">
26
+ <cstring>text</cstring>
27
+ </property>
28
+ </widget>
29
+ </item>
30
+ <item>
31
+ <widget class="KLineEdit" name="text"/>
32
+ </item>
33
+ </layout>
34
+ </widget>
35
+ <customwidgets>
36
+ <customwidget>
37
+ <class>KLineEdit</class>
38
+ <extends>QLineEdit</extends>
39
+ <header>klineedit.h</header>
40
+ </customwidget>
41
+ </customwidgets>
42
+ <resources/>
43
+ <connections/>
44
+ </ui>
@@ -0,0 +1,28 @@
1
+ name: state
2
+ version: 0.0.1
3
+ about:
4
+ authors: [Stefano Crocco, stefano.crocco@alice.it]
5
+ license: gpl
6
+ description: Saves and restores open windows and projects and cursor positions between sessions
7
+ bug_address: http://github.com/stcrocco/ruber/issues
8
+ class: Ruber::State::Plugin
9
+ require: state
10
+ config_options:
11
+ state:
12
+ open_documents: {default: []}
13
+ open_projects: {default: []}
14
+ active_document: {default: nil}
15
+ restore_cursor_position: {default: true}
16
+ restore_project_files: {default: true}
17
+ startup_behaviour: {default: :restore_all}
18
+ project_options:
19
+ state:
20
+ open_documents: {default: [], type: session, scope: global}
21
+ active_document: {default: ~, type: session, scope: global}
22
+ cursor_position: {default: [0, 0], type: session, scope: document}
23
+ config_widgets:
24
+ - {class: Ruber::State::ConfigWidget, caption: General}
25
+ extensions:
26
+ state:
27
+ - {class: Ruber::State::DocumentExtension, scope: document}
28
+ - {class: Ruber::State::ProjectExtension, scope: global}
@@ -0,0 +1,520 @@
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/plugin'
22
+ require 'yaml'
23
+
24
+ require 'facets/hash/mash'
25
+
26
+ require_relative 'ui/config_widget'
27
+
28
+ module Ruber
29
+
30
+ =begin rdoc
31
+ Plugin which allows Ruber to store and restore back its state.
32
+
33
+ In this context, the term _state_ means the open project and documents, the position
34
+ of the cursor in each document and the active document. All this data is stored
35
+ in the configuration file and in the project or document project files. Using
36
+ the API provided by this plugin, it is possible to restore a single document,
37
+ project or the whole application to the state it was when it was last closed.
38
+
39
+ In addition to providing an API for saving and restoring state, this plugin also
40
+ restores the full Ruber state when restoring a session and (according to the
41
+ user preferences) when the application starts up.
42
+
43
+ @api feature state
44
+ @plugin
45
+ =end
46
+ module State
47
+
48
+ =begin rdoc
49
+ Plugin object for the State plugin
50
+
51
+ @api_method #with
52
+ @api_method #restore
53
+ @api_method #restore_document
54
+ @api_method #restore_project
55
+ =end
56
+ class Plugin < Ruber::Plugin
57
+
58
+ =begin rdoc
59
+ @param [Ruber::PluginSpecification] psf the plugin specification object associated
60
+ with the plugin
61
+ =end
62
+ def initialize psf
63
+ super
64
+ @force_restore_project_files = nil
65
+ @force_restore_cursor_position = nil
66
+ end
67
+
68
+ =begin rdoc
69
+ Override of {PluginLike#delayed_initialize}
70
+
71
+ If the application is starting and there's no open project and a single, pristine
72
+ document, it uses the {#restore_last_state} method to restore the last state Ruber
73
+ was according to the user preferences.
74
+
75
+ @return [nil]
76
+ =end
77
+ def delayed_initialize
78
+ return unless Ruber[:app].starting?
79
+ if Ruber[:projects].to_a.empty? and Ruber[:docs].to_a.size == 1 and
80
+ Ruber[:docs][0].pristine?
81
+ restore_last_state
82
+ end
83
+ nil
84
+ end
85
+
86
+ =begin rdoc
87
+ Tells whether or not the cursor position should be restored.
88
+
89
+ This takes into account user settings and eventual requests made by the programmer
90
+ using the {#with} method
91
+ @return [Boolean] *true* if the cursor position should be restored and *false*
92
+ otherwise
93
+ =end
94
+ def restore_cursor_position?
95
+ if @force_restore_cursor_position.nil?
96
+ Ruber[:config][:state, :restore_cursor_position]
97
+ else @force_restore_cursor_position
98
+ end
99
+ end
100
+
101
+ =begin rdoc
102
+ Tells whether or not the open files in the project should be restored.
103
+
104
+ This takes into account user settings and eventual requests made by the programmer
105
+ using the {#with} method
106
+ @return [Boolean] *true* if the open files in the project should be restored and *false*
107
+ otherwise
108
+ =end
109
+ def restore_project_files?
110
+ if @force_restore_project_files.nil?
111
+ Ruber[:config][:state, :restore_project_files]
112
+ else @force_restore_project_files
113
+ end
114
+ end
115
+
116
+ =begin rdoc
117
+ Executes a block temporarily overriding the user's settings about what should be
118
+ restored and what shouldn't.
119
+
120
+ Nested calls to this method are allowed. By default, the outer call wins over the
121
+ inner, meaning that a value set by the inner call are only used if the outer
122
+ call didn't set that value. You can change this behaviour by passing the @:force@
123
+ option.
124
+ @param [Hash] hash the settings to change. All settings not specified here will
125
+ remain as chosen by the user
126
+ @option hash [Boolean] :force (false) if *true*, in case of a nested call to this
127
+ method, the values specified by the inner call will override values set by the
128
+ outer call.
129
+ @option hash [Boolean] :restore_cursor_position (false) whether or not the cursor position
130
+ in documents should be restored, regardless of what the user chose
131
+ @option hash [Boolean] :restore_project_files (false) whether or not the open
132
+ files in projects should be restored, regardless of what the user chose
133
+ @return [Object] the value returned by the block
134
+ =end
135
+ def with hash
136
+ old_doc = @force_restore_cursor_position
137
+ old_projects = @force_restore_project_files
138
+ if hash.has_key? :restore_cursor_position
139
+ if @force_restore_cursor_position.nil? or hash[:force]
140
+ @force_restore_cursor_position = hash[:restore_cursor_position] || false
141
+ end
142
+ end
143
+ if hash.has_key? :restore_project_files
144
+ if @force_restore_project_files.nil? or hash[:force]
145
+ @force_restore_project_files = hash[:restore_project_files] || false
146
+ end
147
+ end
148
+ begin yield
149
+ ensure
150
+ @force_restore_cursor_position = old_doc
151
+ @force_restore_project_files = old_projects
152
+ end
153
+ end
154
+
155
+ =begin rdoc
156
+ Restores the given document
157
+
158
+ See {DocumentExtension#restore} for more information
159
+
160
+ @param [Ruber::Document] doc the document to restore
161
+ @return [nil]
162
+ =end
163
+ def restore_document doc
164
+ doc.extension(:state).restore
165
+ end
166
+
167
+ =begin rdoc
168
+ Restores the given global project
169
+
170
+ See {ProjectExtension#restore} for more information
171
+
172
+ @param [Ruber::Project] prj the document to restore
173
+ @return [nil]
174
+ =end
175
+ def restore_project prj
176
+ prj.extension(:state).restore
177
+ end
178
+
179
+ =begin rdoc
180
+ Restores the open projects according to a given configuration object
181
+
182
+ This method is called both when the session is restored and when ruber starts
183
+ up (if the user chose so).
184
+
185
+ @param [#[Symbol, Symbol]] conf the object from which to read the state. See {#restore}
186
+ for more information
187
+ @return [nil]
188
+ =end
189
+ def restore_projects conf = Ruber[:config]
190
+ projects = Ruber[:projects]
191
+ projects.to_a.each{|pr| projects.close_project pr}
192
+ file = conf[:state, :open_projects][0]
193
+ if file
194
+ prj = Ruber[:main_window].safe_open_project file
195
+ Ruber[:projects].current_project = prj if prj
196
+ end
197
+ nil
198
+ end
199
+
200
+ =begin rdoc
201
+ Restores the open documents according to a given configuration object
202
+
203
+ This method is called both when the session is restored and when ruber starts
204
+ up (if the user chose so).
205
+
206
+ @param [#[Symbol, Symbol]] conf the object from which to read the state. See {#restore}
207
+ for more information
208
+ @return [nil]
209
+ =end
210
+ def restore_documents config = Ruber[:config]
211
+ Ruber[:docs].close_all
212
+ files = config[:state, :open_documents]
213
+ return if files.empty?
214
+ active_file = config[:state, :active_document]
215
+ active_file = files[-1] unless files.include? active_file
216
+ mw = Ruber[:main_window]
217
+ mw.without_activating do
218
+ files.each{|f| ed = mw.editor_for! f}
219
+ mw.display_document active_file
220
+ end
221
+ nil
222
+ end
223
+
224
+ =begin rdoc
225
+ Restores ruber state according to the user settings and the data stored in the given object
226
+
227
+ The argument can be any object which has a @[]@ method which takes two arguments
228
+ and behaves as the hash returned by {#gather_settings}.
229
+
230
+ @param [#[Symbol, Symbol]] conf the object from which to read the state
231
+ @return [nil]
232
+ =end
233
+ def restore cfg = Ruber[:config]
234
+ if !cfg[:state, :open_projects].empty? then restore_projects cfg
235
+ else restore_documents cfg
236
+ end
237
+ nil
238
+ end
239
+
240
+ =begin rdoc
241
+ Restores Ruber's state according to the user settings so that it matches the state
242
+ it was when it was last shut down
243
+
244
+ The state information is read from the global configuration object.
245
+
246
+ @return [nil]
247
+ =end
248
+ def restore_last_state
249
+ case Ruber[:config][:state, :startup_behaviour]
250
+ when :restore_all then restore
251
+ when :restore_projects_only
252
+ with(:restore_project_files => false){restore_projects}
253
+ when :restore_documents_only then restore_documents
254
+ end
255
+ end
256
+
257
+ =begin rdoc
258
+ Restores Ruber's state as it was in last session
259
+
260
+ Since this method deals with session management, it ignores the user settings
261
+
262
+ @return [nil]
263
+ =end
264
+ def restore_session data
265
+ hash = data['State'] || {:open_projects => [], :open_documents => [], :active_document => nil}
266
+ hash = hash.map_hash{|k, v| [[:state, k], v]}
267
+ def hash.[] k, v
268
+ super [k, v]
269
+ end
270
+ with(:restore_project_files => true, :restore_cursor_position => true, :force => true) do
271
+ restore hash
272
+ end
273
+ nil
274
+ end
275
+
276
+ =begin rdoc
277
+ Saves Ruber's state to the global config object
278
+
279
+ @return [nil]
280
+ =end
281
+ def save_settings
282
+ h = gather_settings
283
+ cfg = Ruber[:config]
284
+ [:open_projects, :open_documents, :active_document].each do |i|
285
+ cfg[:state, i] = h[i]
286
+ end
287
+ nil
288
+ end
289
+
290
+ =begin rdoc
291
+ Override of {PluginLike#session_data}
292
+
293
+ @return [Hash] a hash containing the session information under the @State@ key
294
+ =end
295
+ def session_data
296
+ {'State' => gather_settings}
297
+ end
298
+
299
+ private
300
+
301
+ =begin rdoc
302
+ Creates a hash with all the data needed to restore Ruber's state
303
+
304
+ @return [Hash] a hash with the following keys:
305
+ * @:open_projects@: an array containing the project file of each open project.
306
+ the first entry is the active project
307
+ * @:open_documents@: an array with the name of the file corresponding to each
308
+ open document (documents without an associated file can't be restored and aren't
309
+ included). The order is that of opening
310
+ * @:active_document@: the name of the file associated with the active document or
311
+ *nil* if there's no open document
312
+ =end
313
+ def gather_settings
314
+ res = {}
315
+ projects = Ruber[:projects].projects.map{|pr| pr.project_file}
316
+ unless projects.empty?
317
+ active_prj = Ruber[:projects].current
318
+ projects.unshift projects.delete(active_prj.project_file) if active_prj
319
+ end
320
+ res[:open_projects] = projects
321
+ docs = Ruber[:docs].documents.map{|doc| doc.path}.select{|path| !path.empty?}
322
+ res[:open_documents] = docs
323
+ current_doc = Ruber[:main_window].current_document.path rescue ''
324
+ res[:active_document] = current_doc.empty? ? nil : current_doc
325
+ res
326
+ end
327
+
328
+ end
329
+
330
+ =begin rdoc
331
+ Extension for documents needed by the State plugin
332
+
333
+ The scope of this extension is to save and restore the position of the cursor
334
+ in the document
335
+ =end
336
+ class DocumentExtension < Qt::Object
337
+
338
+ include Extension
339
+
340
+ slots :auto_restore
341
+
342
+ =begin rdoc
343
+ @param [Ruber::DocumentProject] prj the project associated with the document
344
+ =end
345
+ def initialize prj
346
+ super
347
+ @project = prj
348
+ @document = prj.document
349
+ connect @document, SIGNAL('view_created(QObject*, QObject*)'), self, SLOT(:auto_restore)
350
+ end
351
+
352
+ =begin rdoc
353
+ Restores the position of the cursor according to the value saved in the document's
354
+ own project
355
+
356
+ It does nothing if the document isn't associated with a view
357
+ @return [nil]
358
+ =end
359
+ def restore
360
+ view = @document.view
361
+ return unless view
362
+ pos = @document.own_project[:state, :cursor_position]
363
+ view.go_to *pos
364
+ nil
365
+ end
366
+
367
+ =begin rdoc
368
+ Saves the position of the cursor in the document's own project
369
+
370
+ It does nothing if the document isn't associated with a view
371
+ @return [nil]
372
+ =end
373
+ def save_settings
374
+ view = @document.view
375
+ pos = if view
376
+ cur = view.cursor_position
377
+ [cur.line, cur.column]
378
+ else [0,0]
379
+ end
380
+ @project[:state, :cursor_position] = pos
381
+ nil
382
+ end
383
+
384
+ private
385
+
386
+ =begin rdoc
387
+ Moves the cursor in a new view to the position stored in the document's own project
388
+
389
+ It does nothing if the user chose not to have the position restored when opening
390
+ a document.
391
+ @return [nil]
392
+ =end
393
+ def auto_restore
394
+ restore if Ruber[:state].restore_cursor_position?
395
+ nil
396
+ end
397
+
398
+ end
399
+
400
+ =begin rdoc
401
+ Extension for projects needed by the State plugin
402
+
403
+ The scope of this extension is to save and restore the open documents associated
404
+ with projects
405
+ =end
406
+ class ProjectExtension < Qt::Object
407
+
408
+ include Extension
409
+
410
+ slots :auto_restore
411
+
412
+ =begin rdoc
413
+ @param [Ruber::Project] prj the project associated with the extension
414
+ =end
415
+ def initialize prj
416
+ super
417
+ @project = prj
418
+ connect @project, SIGNAL(:activated), self, SLOT(:auto_restore)
419
+ end
420
+
421
+ =begin rdoc
422
+ Opens all the files associated with the proejct which were opened last time the
423
+ project's state was changed
424
+
425
+ Any already open document is closed (after saving)
426
+
427
+ @return [nil]
428
+ =end
429
+
430
+ def restore
431
+ files = @project[:state, :open_documents]
432
+ Ruber[:docs].close_all
433
+ return if files.empty?
434
+ active_file = @project[:state, :active_document]
435
+ active_file = files[-1] unless files.include? active_file
436
+ mw = Ruber[:main_window]
437
+ mw.without_activating do
438
+ files.each{|f| mw.editor_for! f}
439
+ end
440
+ mw.display_document active_file
441
+ nil
442
+ end
443
+
444
+ =begin rdoc
445
+ Saves the list of open project files to the project
446
+
447
+ @return [nil]
448
+ =end
449
+ def save_settings
450
+ files = Ruber[:docs].documents_with_file.map{|d| d.path}
451
+ active = Ruber[:main_window].current_document
452
+ active_path = (active.nil? or active.path.empty?) ? nil : active.path
453
+ @project[:state, :open_documents] = files
454
+ @project[:state, :active_document] = active_path
455
+ nil
456
+ end
457
+
458
+ private
459
+
460
+ =begin rdoc
461
+ Opens all the files associated with the proejct which were opened last time the
462
+ project's state was changed when the project is opened.
463
+
464
+ Any already open document is closed (after saving).
465
+
466
+ It does nothing if the user chose not restore open project files when opening a
467
+ project.
468
+ @return [nil]
469
+ =end
470
+ def auto_restore
471
+ @project.disconnect SIGNAL(:activated), self, SLOT(:auto_restore)
472
+ restore if Ruber[:state].restore_project_files?
473
+ end
474
+
475
+ end
476
+
477
+ =begin rdoc
478
+ Configuration widget for the State plugin
479
+ =end
480
+ class ConfigWidget < Qt::Widget
481
+
482
+ =begin rdoc
483
+ A list of different behaviour the plugin can have at startup
484
+ =end
485
+ STARTUP_BEHAVIOURS = [:restore_all, :restore_documents_only, :restore_projects_only, :restore_nothing]
486
+
487
+ =begin rdoc
488
+ @param [Qt::Widget, nil] parent the parent widget
489
+ =end
490
+ def initialize parent = nil
491
+ super
492
+ @ui = Ui::StateConfigWidget.new
493
+ @ui.setup_ui self
494
+ end
495
+
496
+ =begin rdoc
497
+ Selects the correct startup behaviour in the associated widget
498
+
499
+ @param [Symbol] val the symbol stored in the configuration object. It must be one
500
+ of the entries in {STARTUP_BEHAVIOURS}
501
+ =end
502
+ def startup_behaviour= val
503
+ @ui._state__startup_behaviour.current_index = STARTUP_BEHAVIOURS.index val
504
+ nil
505
+ end
506
+
507
+ =begin rdoc
508
+ Returns the symbol associated with the startup behaviour selected in the widget
509
+ @return [Symbol] the entry in {STARTUP_BEHAVIOURS} corresponding to the selected
510
+ entry in the _Startup behaviour_ widget
511
+ =end
512
+ def startup_behaviour
513
+ STARTUP_BEHAVIOURS[@ui._state__startup_behaviour.current_index]
514
+ end
515
+
516
+ end
517
+
518
+ end
519
+
520
+ end