Class: Ruber::Application

Inherits:
KDE::Application show all
Includes:
PluginLike
Defined in:
lib/ruber/application/application.rb

Defined Under Namespace

Classes: DefaultDocumentExtension

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]

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
# 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
  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)



74
75
76
# File 'lib/ruber/application/application.rb', line 74

def cmd_line_options
  @cmd_line_options
end

#statusSymbol (readonly)

<<<<<<< HEAD

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

>>>>>>> master

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

#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



125
126
127
# File 'lib/ruber/application/application.rb', line 125

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



138
139
140
141
# File 'lib/ruber/application/application.rb', line 138

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)


150
151
152
153
154
# File 'lib/ruber/application/application.rb', line 150

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:



189
190
191
# File 'lib/ruber/application/application.rb', line 189

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:



178
179
180
# File 'lib/ruber/application/application.rb', line 178

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:



226
227
228
229
230
231
232
233
# File 'lib/ruber/application/application.rb', line 226

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:



167
168
169
# File 'lib/ruber/application/application.rb', line 167

def starting?
  @status == :starting
end