Class: Ruber::Application

Inherits:
KDE::Application show all
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

Attributes included from PluginLike

#plugin_description

Instance Method Summary collapse

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.

Parameters:



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.expand_path(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_optionsHash (readonly)

Returns the command line options passed to ruber (after they’ve been processed).

Returns:

  • (Hash)

    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
  @cmd_line_options
end

#statusSymbol (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

Returns:

  • (Symbol)

    the status of the application. It can be: @:starting@, @:running@ or @:quitting@



93
94
95
# File 'lib/ruber/application/application.rb', line 93

def status
  @status
end

Instance Method Details

#ask_to_quitBoolean

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.

Returns:

  • (Boolean)

    true if the application can be closed and false otherwise



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.

Parameters:

  • dir (String)

    the directory to change to

Yields:

  • the block to execute from within dir. The current directory will be changed back after executing the block.

Returns:

  • (Object)

    the value returned by the block otherwise

Raises:

  • (LocalJumpError)

    if no block is given



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_directoriesArray<String> Also known as: plugin_dirs

Returns a list of the directories where Ruber looks for plugins.

Returns:

  • (Array<String>)

    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.

Parameters:

  • the (Array<String> dirs)

    directories Ruber should search for plugins



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_rubernil

Quits ruber

Sets the application status to @:quitting@ and calls ComponentManager#shutdown

Returns:

  • (nil)


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

Returns:

  • (Boolean)

    true if the application status is @quitting@ and false

See Also:



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

Returns:

  • (Boolean)

    true if the application status is @running@ and false

See Also:



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.

Parameters:

  • plugins (Array<Symbol>)

    the names of the plugins to load. It doesn’t need to include dependencies, as they’re computed automatically

  • silent (Boolean) (defaults to: false)

    whether errors while loading plugins should be silently ignored or not

  • dirs (Array<String>, nil) (defaults to: nil)

    the directories where to look for plugins. If nil, then the value returned by #plugin_directories will be used

Yields:

  • (pso, ex)

    block called when loading a plugin raises an exception

Yield Parameters:

  • pso (PluginSpecification)

    the plugin specification object associated with the plugin which raised the exception

  • ex (Exception)

    the exception raised while loading the plugin

Returns:

  • (Boolen)

    true if the plugins were loaded successfully and false otherwise

See Also:



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)

Returns:

  • (Boolean)

    true if the application status is @starting@ and false otherwise

See Also:



187
188
189
# File 'lib/ruber/application/application.rb', line 187

def starting?
  @status == :starting
end