Class: Ruber::Application
- Inherits:
-
KDE::Application
- Object
- KDE::Application
- Ruber::Application
- Includes:
- PluginLike
- Defined in:
- lib/ruber/application/application.rb
Constant Summary collapse
- DEFAULT_PLUGIN_PATHS =
The default paths where to look for plugins.
It includes @$KDEHOME/share/apps/ruber/plugins@ and the @plugins@ subdirectory of the ruber installation directory
[ File.join(KDE::Global.dirs.find_dirs( 'data', '')[0], File.join('ruber','plugins')), RUBER_PLUGIN_DIR ]
- DEFAULT_PLUGINS =
The default plugins to load
Currently, they are: ruby_development, find_in_files, syntax_checker, command and state
%w[ruby_development find_in_files rake command syntax_checker state auto_end project_browser ruby_syntax_checker yaml_syntax_checker]
Instance Attribute Summary collapse
-
#cmd_line_options ⇒ Hash
readonly
The command line options passed to ruber (after they’ve been processed).
-
#status ⇒ Symbol
readonly
The state Ruber is in.
Attributes included from PluginLike
Instance Method Summary collapse
-
#ask_to_quit ⇒ Boolean
Asks the user to confirm quitting Ruber.
-
#chdir(dir) { ... } ⇒ Object
Thread-safe Dir.chdir.
-
#initialize(manager, psf) ⇒ Application
constructor
Creates a new instance of Application.
-
#plugin_directories ⇒ Array<String>
(also: #plugin_dirs)
A list of the directories where Ruber looks for plugins.
-
#plugin_directories=(dirs) ⇒ Object
(also: #plugin_dirs=)
Sets the list of directories where Ruber looks for plugins.
-
#quit_ruber ⇒ nil
Quits ruber.
-
#quitting? ⇒ Boolean
Whether the application is quitting or not.
-
#running? ⇒ Boolean
Whether the application is running or not.
-
#safe_load_plugins(plugins, silent = false, dirs = nil) {|pso, ex| ... } ⇒ Boolen
Loads plugins handling the exceptions they may raise in the meanwhile.
-
#starting? ⇒ Boolean
Whether the application is starting or has already started.
Methods included from PluginLike
#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #plugin_name, #query_close, #register_with_project, #remove_extensions_from_project, #remove_from_project, #remove_options_from_project, #remove_widgets_from_project, #restore_session, #save_settings, #session_data, #shutdown, #unload, #update_project
Methods inherited from KDE::Application
with_override_cursor, #with_override_cursor
Constructor Details
#initialize(manager, psf) ⇒ Application
Creates a new instance of Ruber::Application
It loads the core components and sets up a single shot timer which calls #setup and is fired as soon as the event loop starts.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/ruber/application/application.rb', line 105 def initialize manager, psf super() @components = manager @components.parent = self Ruber.instance_variable_set :@components, @components initialize_plugin psf KDE::Global.dirs.addPrefix File.(File.join( RUBER_DATA_DIR, '..', 'data')) icon_path = KDE::Global.dirs.find_resource('icon', 'ruber') self.window_icon = Qt::Icon.new icon_path KDE::Global.main_component.about_data.program_icon_name = icon_path @cmd_line_options = KDE::CmdLineArgs.parsed_args @plugin_dirs = [] load_core_components @status = :starting @chdir_lock = Mutex.new Qt::Timer.single_shot(0, self, SLOT(:setup)) end |
Instance Attribute Details
#cmd_line_options ⇒ Hash (readonly)
Returns the command line options passed to ruber (after they’ve been processed).
75 76 77 |
# File 'lib/ruber/application/application.rb', line 75 def @cmd_line_options end |
#status ⇒ Symbol (readonly)
The state Ruber is in
Ruber can be in three states:
-
starting:= from the time it’s launched to when #setup returns
-
running:= from after #setup has returend to when the user chooses to quit it (either with the @File/Quit@ menu entry or clicking on the button on the title bar)
-
quitting:= from when the user chooses to quit Ruber onwards
-
asking_to_quit:= while asking the user to confirm quitting Ruber
93 94 95 |
# File 'lib/ruber/application/application.rb', line 93 def status @status end |
Instance Method Details
#ask_to_quit ⇒ Boolean
Asks the user to confirm quitting Ruber
This method is called whenever Ruber needs to be closed and, in turn, calls the query_close method of each plugin and component (using ComponentManager#query_close).
During the execution of this method, #status returns @:asking_to_quit@. After this method returns, the status returns what it was before.
156 157 158 159 160 161 162 |
# File 'lib/ruber/application/application.rb', line 156 def ask_to_quit old_status = @status @status = :asking_to_quit res = @components.query_close @status = old_status res end |
#chdir(dir) { ... } ⇒ Object
Thread-safe Dir.chdir
@Dir.chdir@ is not thread-safe, meaning that a Dir.chdir done in a thread will change the directory in all other threads. To avoid this unpleasant behaviour, don’t use Dir.chdir. Instead, use this method, which uses a mutex to control calls to Dir.chdir.
268 269 270 271 272 |
# File 'lib/ruber/application/application.rb', line 268 def chdir dir @chdir_lock.synchronize do Dir.chdir(dir){yield} end end |
#plugin_directories ⇒ Array<String> Also known as: plugin_dirs
Returns a list of the directories where Ruber looks for plugins.
126 127 128 |
# File 'lib/ruber/application/application.rb', line 126 def plugin_directories @plugin_dirs.dup end |
#plugin_directories=(dirs) ⇒ Object Also known as: plugin_dirs=
Sets the list of directories where Ruber looks for plugins
This also changes the setting in the global configuration object, but it *doesn’t* write the change to file. It’s up to whoever called this method to do so.
139 140 141 142 |
# File 'lib/ruber/application/application.rb', line 139 def plugin_directories= dirs @plugin_directories = dirs Ruber[:config][:general, :plugin_dirs] = @plugin_directories end |
#quit_ruber ⇒ nil
Quits ruber
Sets the application status to @:quitting@ and calls ComponentManager#shutdown
170 171 172 173 174 |
# File 'lib/ruber/application/application.rb', line 170 def quit_ruber @status = :quitting @components.shutdown nil end |
#quitting? ⇒ Boolean
Whether the application is quitting or not
otherwise
209 210 211 |
# File 'lib/ruber/application/application.rb', line 209 def quitting? @status == :quitting end |
#running? ⇒ Boolean
Whether the application is running or not
otherwise
198 199 200 |
# File 'lib/ruber/application/application.rb', line 198 def running? @status == :running end |
#safe_load_plugins(plugins, silent = false, dirs = nil) {|pso, ex| ... } ⇒ Boolen
Loads plugins handling the exceptions they may raise in the meanwhile
It is a wrapper around ComponentManager#load_plugins.
If it’s given a block, it simply calls ComponentManager#load_plugins passing it the block.
If no block is given, the behaviour in case of an exception depends on the silent argument:
-
if true, then the error will be silently ignored and the component manager will go on loading the remaining plugins. Errors caused by those will be ignored as well
-
if false, the user will be shown a ComponentLoadingErrorDialog. According to what the user chooses in the dialog, the component manager will behave in a different way, as described in ComponentManager#load_plugins
Note: this method doesn’t attempt to handle exceptions raised while computing or sorting dependencies.
246 247 248 249 250 251 252 253 |
# File 'lib/ruber/application/application.rb', line 246 def safe_load_plugins plugins, silent = false, dirs = nil, &blk if blk.nil? and silent then blk = proc{|_pl, _e| :silent} elsif blk.nil? blk = Proc.new{|pl, e| ComponentLoadingErrorDialog.new(pl.name, e, nil).exec} end @components.load_plugins plugins, dirs || @plugin_dirs, &blk end |
#starting? ⇒ Boolean
Whether the application is starting or has already started
You should seldom need this method. It’s mostly useful for plugins which need to erform different actions depending on whether they’re loaded at application startup (in which case it’ll return true) or later (when it’ll return false)
187 188 189 |
# File 'lib/ruber/application/application.rb', line 187 def starting? @status == :starting end |