Class: Ruber::State::Plugin

Inherits:
Plugin show all
Includes:
EnvironmentState
Defined in:
plugins/state/state.rb

Overview

Plugin object for the State plugin

Constant Summary

Constants inherited from Plugin

LICENSES

Instance Attribute Summary

Attributes included from PluginLike

plugin_description

Instance Method Summary (collapse)

Methods included from EnvironmentState

#restore_environment, #restore_tab, #tab_to_tree, #tabs_state

Methods inherited from Plugin

#about_data

Methods included from PluginLike

#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #create_tool_widget, #initialize_plugin, #load_settings, #plugin_name, #query_close, #register_options, #register_with_project, #remove_extensions_from_project, #remove_from_project, #remove_options_from_project, #remove_widgets_from_project, #restore_session, #session_data, #setup_action, #setup_actions, #shutdown, #unload, #update_project

Constructor Details

- (Plugin) initialize(psf)

A new instance of Plugin

Parameters:



231
232
233
234
235
# File 'plugins/state/state.rb', line 231

def initialize psf
  super
  @force_restore_project_files = nil
  @force_restore_cursor_position = nil
end

Instance Method Details

- (nil) delayed_initialize

Override of PluginLike#delayed_initialize

If the application is starting and there’s no open project and a single, pristine document, it uses the #restore_last_state method to restore the last state Ruber was according to the user preferences.

Returns:

  • (nil)


246
247
248
249
250
251
252
253
254
# File 'plugins/state/state.rb', line 246

def delayed_initialize
  return unless Ruber[:app].starting?
  docs = Ruber[:world].documents
  if Ruber[:world].projects.empty? and docs.size == 1 and docs[0].pristine?
    Ruber[:app].sessionRestored? ? restore_last_state(:force) : restore_last_state
  end
  connect Ruber[:world], SIGNAL('project_created(QObject*)'), self, SLOT('restore_project(QObject*)')
  nil
end

- (Array<String>) projects_state

The open projects in a form suitable to be written to a configuration object

Returns:

  • (Array<String>)

    an array containing the names of the project files for the currently open projects. The active project is the first one. This value is the one to write under the state/open_projects entry in a project or configuration object



343
344
345
346
347
348
349
350
# File 'plugins/state/state.rb', line 343

def projects_state
  projects = Ruber[:world].projects.map{|pr| pr.project_file}
  unless projects.empty?
    active_prj = Ruber[:world].active_document
    projects.unshift projects.delete(active_prj.project_file) if active_prj
  end
  projects
end

- (nil) restore_last_state(mode = nil)

Restores Ruber’s state according to the user settings so that it matches the state it was when it was last shut down

The state information is read from the global configuration object.

Returns:

  • (nil)


278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
# File 'plugins/state/state.rb', line 278

def restore_last_state mode = nil
  force = mode == :force
  cfg = Ruber[:config][:state]
  if force or cfg[:startup_behaviour].include? :default_environment
    default_env_data = {
      :tabs => cfg[:default_environment_tabs],
      :active_view => cfg[:default_environment_active_view],
      :cursor_positions => cfg[:default_environment_cursor_positions]
    }
    restore_environment Ruber[:world].default_environment, default_env_data
  end
  active_prj = nil
  if force || cfg[:startup_behaviour].include?(:projects)
    cfg[:last_state].each_with_index do |f, i|
      next if f.nil?
      begin prj = Ruber[:world].project f
      rescue Ruber::AbstractProject::InvalidProjectFile
        next
      end
      active_prj = prj if i == 0
      data = {
        :tabs => prj[:state, :tabs],
        :cursor_positions => prj[:state, :cursor_positions],
        :active_view => prj[:state, :active_view]
      }
      restore_environment Ruber[:world].environment(prj), data
    end
    Ruber[:world].active_project = active_prj
  end
end

- (Object) restore_project(prj)



256
257
258
259
260
261
262
263
264
265
266
267
# File 'plugins/state/state.rb', line 256

def restore_project prj
  prx = prj[:state]
  data = {
    :tabs => prx[:tabs],
    :cursor_positions => prx[:cursor_positions],
    :active_view => prx[:active_view]
  }
  env = Ruber[:world].environment(prj)
  if Ruber[:config][:state, :restore_projects] and env.tabs.count == 0
    restore_environment env, data
  end
end

Slot Signature:

restore_project(QObject*)

- (nil) save_settings

Saves Ruber’s state to the global config object

Returns:

  • (nil)


314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'plugins/state/state.rb', line 314

def save_settings
  files = Ruber[:world].environments.map do |e|
    prj = e.project
    prj ? prj.project_file : nil
  end
  active_env = Ruber[:world].active_environment
  if active_env and active_env.project
    active_project = active_env.project.project_file
  else active_project = nil
  end
  files.unshift files.delete(active_project)
  Ruber[:config][:state, :last_state] = files
  default_env_state = tabs_state Ruber[:world].default_environment
  Ruber[:config][:state, :default_environment_tabs] = default_env_state[:tabs]
  Ruber[:config][:state, :default_environment_active_view] =
      default_env_state[:active_view]
  Ruber[:config][:state, :default_environment_cursor_positions] = 
      default_env_state[:cursor_positions]
  nil
end