Class: Ruber::MainWindow

Inherits:
KParts::MainWindow
  • Object
show all
Extended by:
Forwardable
Includes:
GuiStatesHandler, PluginLike
Defined in:
lib/ruber/main_window/main_window.rb,
lib/ruber/main_window/main_window_actions.rb,
lib/ruber/main_window/main_window_internal.rb

Overview

The application’s main window. It is made of a menu bar, a tool bar, a workspace and a status bar. The workspace (see Workspace) is the main window’s central widget and where most of the user interaction happens. It contains the editors and the tool widgets.

Constant Summary

DEFAULT_HINTS =
Ruber::World::Environment::DEFAULT_HINTS
OPEN_DLG_FILTERS =

A list of strings to be used to create the filter for open file dialogs

[
'*.rb|Ruby source file (*.rb)', 
'*.yaml *.yml|YAML files (*.yaml, *.yml)',
'*|All files'
]

Instance Attribute Summary (collapse)

Attributes included from PluginLike

plugin_description

Instance Method Summary (collapse)

Methods included from GuiStatesHandler

#change_state, included, #initialize_states_handler, #register_action_handler, #remove_action_handler_for, #state

Methods included from PluginLike

#add_extensions_to_project, #add_options_to_project, #add_widgets_to_project, #create_tool_widget, #delayed_initialize, #initialize_plugin, #plugin_name, #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

Signal Summary

API for feature main_window

Extensions API

environment
API
Environment
Only for:
  • projects

Constructor Details

- (MainWindow) initialize(_manager, pdf)

Creates a new MainWindow. _manager is the component manager, while pdf is the plugin description for this object.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# File 'lib/ruber/main_window/main_window.rb', line 88

def initialize _manager, pdf
  super nil, 0
  initialize_plugin pdf
  initialize_states_handler
  @active_environment = nil
  @workspace = Workspace.new self
  self.central_widget = @workspace
  @workspace.add_widget Ruber[:world].default_environment.tab_widget
  @ui_states = {}
  @actions_state_handlers = Hash.new{|h, k| h[k] = []}
  @about_plugin_actions = []
  @switch_to_actions = []
  @activate_project_actions = []
  @last_session_data = nil
  self.status_bar = StatusBar.new self
  self.connect(SIGNAL('current_document_changed(QObject*)')) do |doc|
    change_state 'current_document', !doc.nil?
  end
  connect Ruber[:components], SIGNAL('component_loaded(QObject*)'), self, SLOT('add_about_plugin_action(QObject*)')
  connect Ruber[:components], SIGNAL('unloading_component(QObject*)'), self, SLOT('remove_about_plugin_action(QObject*)')
  connect Ruber[:components], SIGNAL('unloading_component(QObject*)'), self, SLOT('remove_plugin_ui_actions(QObject*)')
  connect Ruber[:world], SIGNAL('active_environment_changed_2(QObject*, QObject*)'), self, SLOT('slot_active_environment_changed(QObject*, QObject*)')
  connect Ruber[:world], SIGNAL('document_created(QObject*)'), self, SLOT('document_created(QObject*)')
  connect Ruber[:world], SIGNAL('closing_document(QObject*)'), self, SLOT(:update_switch_to_list)

  setup_actions action_collection
  active_project_action = action_collection.action('project-active_project')
  default_view_action = active_project_action.add_action '&None (single files mode)'
  
  connect Ruber[:world], SIGNAL('project_created(QObject*)'), self, SLOT('slot_project_created(QObject*)')
  connect Ruber[:world], SIGNAL('closing_project(QObject*)'), self, SLOT('slot_project_closing(QObject*)')
  
  Ruber[:world].connect SIGNAL('active_project_changed(QObject*)') do |prj|
    @active_environment = Ruber[:world].environment prj
  end
  setup_GUI
  create_shell_GUI true
  
  config_obj = Ruber[:config].kconfig
  apply_main_window_settings KDE::ConfigGroup.new( config_obj, 'MainWindow')
  recent_files = KDE::ConfigGroup.new config_obj, 'Recent files'
  open_recent_action =action_collection.action("file_open_recent")
  open_recent_action.load_entries recent_files
  switch_to_recent_action = action_collection.action("window-switch_to_recent_file")
  switch_to_recent_action.load_entries recent_files
  
  # Synchronize the two menus, so that when the user clears one of them the also
  # is also cleared
  connect open_recent_action, SIGNAL(:recentListCleared), switch_to_recent_action, SLOT(:clear)
  connect switch_to_recent_action, SIGNAL(:recentListCleared), open_recent_action, SLOT(:clear)
  
  recent_projects = KDE::ConfigGroup.new config_obj, 'Recent projects'
  action_collection.action("project-open_recent").load_entries recent_projects
  status_bar.show
  setup_initial_states
  Ruber[:world].active_environment = Ruber[:world].default_environment
end

Instance Attribute Details

- (Object) last_session_data (readonly)

A hash with the data stored in the session manager by plugins. The hash is only availlable after the restore method has been called (which means that it will always be unavaillable if ruber wasn’t started by the session manager). If the hash isn’t availlable, nil is returned

NOTE: only for use by Application when restoring the session



82
83
84
# File 'lib/ruber/main_window/main_window.rb', line 82

def last_session_data
  @last_session_data
end

- (Workspace) workspace (readonly)

The widget which contains the tool widgets.

The primary use of this method is to connect to the signals emitted from the workspace when a tool widget is raised, shown or hidden. All of its other methods are also provided by the MainWindow, so you shouldn’t need to access the workspace to use them.

Returns:

  • (Workspace)

    the workspace associated with the main window



72
73
74
# File 'lib/ruber/main_window/main_window.rb', line 72

def workspace
  @workspace
end

Instance Method Details

- (Object) :@workspace

:method: tool_widgets Returns a hash having the tool widgets as keys and their positions as values. See Workspace#tool_widgets for more information.



169
# File 'lib/ruber/main_window/main_window.rb', line 169

def_delegator :@workspace, :add_tool_widget, :add_tool

- (KDE::Action) action_for_project(prj) (private)

The action in the Active Project action list associated with a project

Parameters:

  • prj (Project, nil)

    the project. If nil, the action which deactivates all projects is returned

Returns:

  • (KDE::Action)

    the action associated with the given project



598
599
600
601
602
603
604
605
606
607
# File 'lib/ruber/main_window/main_window_actions.rb', line 598

def action_for_project prj
  active_project_action = action_collection.action 'project-active_project'
  if prj
    file = prj.project_file
    active_project_action.actions.find do |a| 
      a.object_name == "projects-activate_project-project_file_#{file}"
    end
  else active_project_action.action 0
  end
end

- (Object) activate_editor(editor)

Activates an editor

If the editor is not in the current tab, the tab it belongs to becomes active.

Activating an editor means merging its GUI with the main window’s GUI, changing the title of the main window accordingly and telling the status bar to refer to that view.

After activating the editor, the #current_document_changed and #active_editor_changed signals are emitted.

Parameters:

  • editor (EditorView, nil)

    the editor to activate. If nil, then the currently active editor will be deactivated



370
371
372
# File 'lib/ruber/main_window/main_window.rb', line 370

def activate_editor editor
  @active_environment.activate_editor editor
end

Slot Signature:

activate_editor(int)

- (Object) active_document Also known as: current_document

The document associated with the active editor



435
436
437
# File 'lib/ruber/main_window/main_window.rb', line 435

def active_document
  (ed = active_editor) ? ed.document : nil
end

- (EditorView?) active_editor Also known as: current_editor

The active editor

Returns:

  • (EditorView, nil)

    the active editor or nil if no active editor exists

See Also:



351
352
353
# File 'lib/ruber/main_window/main_window.rb', line 351

def active_editor
  @active_environment.active_editor
end

- (nil) add_about_plugin_action(comp) (private)

Note:

this method doesn’t check whether the action already exists for the given plugin. Since it’s usually called in response to the component_loaded signal of the component manager, there shouldn’t be problems with this

Note:

this method does nothing for core components

Creates an About entry for a component in the “about plugins list” of the Help menu

Parameters:

  • comp (Plugin)

    the plugin object of the plugin to create the action for

Returns:

  • (nil)


396
397
398
399
400
401
402
403
404
405
406
407
408
409
# File 'lib/ruber/main_window/main_window_actions.rb', line 396

def add_about_plugin_action comp
  name = comp.plugin_name
  return unless comp.is_a? Plugin
  unplug_action_list 'about_plugins_list'
  a = action_collection.add_action "__about_#{name}", self, SLOT(:display_about_plugin_dlg)
  a.object_name = name.to_s
  a.text = comp.plugin_description.about.human_name
  unless comp.plugin_description.about.icon.empty?
    a.icon = KDE::Icon.new(comp.plugin_description.about.icon) 
  end
  @about_plugin_actions << a
  plug_action_list 'about_plugins_list', @about_plugin_actions
  nil
end

Slot Signature:

add_about_plugin_action(QObject*)

- (Project?) change_active_project(act) (private)

Slot connected with the active project action

It makes the project corresponding to the selected action active. If the selected action is the None action, then all projects will be deactivated.

If the project associated with the action is already the current project, nothing will be done

Parameters:

  • act (Qt::Action)

    the selected action

Returns:

  • (Project, nil)

    the new current project



620
621
622
623
624
625
626
# File 'lib/ruber/main_window/main_window_actions.rb', line 620

def change_active_project act
  #object_name returns nil instead of an empty string if not set
  match = (act.object_name || '').match(/projects-activate_project-project_file_(.*)$/)
  prj = match ? Ruber[:world].projects[match[1]] : nil
  Ruber[:world].active_project = prj
  prj
end

Slot Signature:

change_active_project(QAction*)

- (nil) change_title (private)

Changes the title

The title is created basing on the open project, the current document and its modified status

Returns:

  • (nil)


207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/ruber/main_window/main_window_internal.rb', line 207

def change_title 
  title = ''
  prj = @active_environment.project
  if prj
    title << (prj.project_name ? prj.project_name :
              File.basename(prj.project_file, '.ruprj'))
  end
  doc = active_document
  if doc and doc.path.empty? 
    title << ' - ' << doc.document_name
  elsif doc
    title << ' - ' << doc.path
  end
  title.sub!(/\A\s+-/, '')
  mod = doc.modified? rescue false
  set_caption title, mod
  nil
end

- (nil) choose_plugins (private)

Slot connected with the ‘Choose Plugins’ action

It displays the choose plugins dialog then (unless the user canceled the dialog) unloads all plugins and reloads them.

If there’s a problem while reloading the plugins, the application is closed after informing the user

Returns:

  • (nil)


272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/ruber/main_window/main_window_actions.rb', line 272

def choose_plugins
  dlg = ChoosePluginsDlg.new self
  return if dlg.exec == Qt::Dialog::Rejected
  loaded = []
  Ruber[:components].plugins.each do |pl|
    pl.save_settings
    loaded << pl.plugin_name
  end
  loaded.reverse_each{|pl| Ruber[:components].unload_plugin pl}
  res = Ruber[:app].safe_load_plugins dlg.plugins.keys.map(&:to_s)
  close unless res
  nil
end

Slot Signature:

choose_plugins()

- (Boolean) close_all_views(ask = true) (private)

Slot connected with the ‘Close All’ action

It closes all the editors and documents associated with them. If any document is modified and ask is true, the user will be ask whether to save them, discard the changes or don’t close the views. In the latter case, nothing will be done. If ask is false, the documents will be closed even if they’re modified, without asking the user.

otherwise

Parameters:

  • ask (Boolean) (defaults to: true)

    whether or not to ask the user how to proceed if any document is modified. Please, set this to false only if you’ve already asked the user whether he wants to save the documents or not

Returns:

  • (Boolean)

    true if the editors where successfully closed and false



171
172
173
174
175
176
177
178
# File 'lib/ruber/main_window/main_window_actions.rb', line 171

def close_all_views ask = true
  views = @active_environment.views 
  docs = views.map(&:document).uniq
  return false if ask and !save_documents docs
  @active_environment.activate_editor nil
  views.to_a.each{|v| close_editor v, false}
  true
end

Slot Signature:

close_all_views()

- (Boolean) close_current_editor (private)

Slot connected to the ‘Close Current’ action

It closes the current editor, if any. If this is the last editor associated with its document and the document is modified, the user is asked to choose whether to save it, discard changes or not close the view.

Returns:

  • (Boolean)

    true if the editor was closed and false otherwise



98
99
100
# File 'lib/ruber/main_window/main_window_actions.rb', line 98

def close_current_editor
  close_editor active_editor if active_editor
end

Slot Signature:

close_current_editor()

- (nil) close_current_project (private)

Slot connectedto the ‘Close Current Project’ action

It closes the current project, if any, warning the user if, for any reason, the project couldn’t be saved

Returns:

  • (nil)


225
226
227
228
229
230
# File 'lib/ruber/main_window/main_window_actions.rb', line 225

def close_current_project
  unless @active_environment.project.close
    KDE::MessageBox.sorry self, "The project couldn't be saved"
  end
  nil
end

Slot Signature:

close_current_project()

- (Object) close_current_tab (private)



102
103
104
# File 'lib/ruber/main_window/main_window_actions.rb', line 102

def close_current_tab
  @active_environment.close_tab @active_environment.tab_widget.current_index
end

Slot Signature:

close_current_tab()

- (Object) close_editor(editor, ask = true)

Note:

Always use this method to close an editor, rather than calling its close method directly, unless you want to leave the corresponding document without a view

Closes an editor view



509
510
511
512
513
514
515
516
517
# File 'lib/ruber/main_window/main_window.rb', line 509

def close_editor editor, ask = true
  @active_environment.close_editor editor, ask
#       doc = editor.document
#       if doc.views.size > 1 
#         editor.close
#         true
#       else doc.close ask
#       end
end

- (Boolean) close_other_views (private)

Slot connected to the ‘Close All Other’ action

It closes all the editors except the current one. All documents with an open editor, except for the one associated with the current editor, will be closed. If any document is modified, the user will be ask whether to save them, discard the changes or don’t close the views. In the latter case, nothing will be done

Returns:

  • (Boolean)

    true if the editors where successfully closed and false otherwise



143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/ruber/main_window/main_window_actions.rb', line 143

def close_other_views
  to_close = @active_environment.tab_widget.inject([]) do |res, pn|
    res += pn.each_view.to_a
    res
  end
  to_close.delete active_editor
  if save_documents to_close.map{|v| v.document}.uniq
    to_close.each{|v| close_editor v, false}
    true
  else false
  end
end

Slot Signature:

close_other_views()

- (nil) configure_document (private)

Slot associated with the Configure Document action

Displays the configuration dialog for the current document, if it exists

Returns:

  • (nil)


440
441
442
443
# File 'lib/ruber/main_window/main_window_actions.rb', line 440

def configure_document
  active_document.own_project.dialog.exec
  nil
end

Slot Signature:

configure_document()

- (nil) configure_project (private)

Slot connected with the ‘Configure Project’ action

It displays the configure project dialog for the current project. It does nothing if there’s no active project

Returns:

  • (nil)


294
295
296
297
298
299
# File 'lib/ruber/main_window/main_window_actions.rb', line 294

def configure_project
  prj = @active_environment.project
  raise "No project is selected" unless prj
  prj.dialog.exec
  nil
end

Slot Signature:

configure_project()

- (nil) display_about_plugin_dlg (private)

Slot connected to the actions in the “about_plugins_list” action list.

Displays a dialog with the about data regarding a plugin. The plugin to use is determined from the triggered action

Returns:

  • (nil)


377
378
379
380
381
382
383
# File 'lib/ruber/main_window/main_window_actions.rb', line 377

def display_about_plugin_dlg
  name = sender.object_name.to_sym
  data = Ruber[name].about_data
  dlg = KDE::AboutApplicationDialog.new data, self
  dlg.exec
  nil
end

Slot Signature:

display_about_plugin_dlg()

- (EditorView?) display_document(doc, hints = {}) Also known as: display_doc

Displays an editor for the given document

This method is similar to #editor_for! but, after retrieving the editor (creating it and/or the document as needed), it activates and gives focus to it and moves the cursor to the given position.

Besides the keys listed in #editor_for!, hints can also contain the two entries :line and :column.

Parameters:

  • doc (Document, String, KDE::Url)

    the document. If it is a string representing a relative path, it’ll be considered relative to the current directory. If the string is an Url, it’ll be interpreted as such

  • hints (Hash) (defaults to: {})

    options to tailor the algorithm used to retrieve or create the editor

Options Hash (hints):

  • line (Integer, nil) — default: nil

    the line to move the cursor to. If nil, the cursor won’t be moved

  • column (Integer) — default: 0

    the column to move the cursor to. Ignored if the :line entry is nil

Returns:

  • (EditorView, nil)

    the editor which has been activated or nil if the editor couldn’t be found (or created)

See Also:



459
460
461
462
463
464
465
466
467
468
# File 'lib/ruber/main_window/main_window.rb', line 459

def display_document doc, hints = {}
  @active_environment.display_document doc, hints
#       ed = editor_for! doc, hints
#       return unless ed
#       activate_editor ed
#       line = hints[:line]
#       ed.go_to line, hints[:column] || 0 if line
#       ed.set_focus
#       ed
end

- (nil) document_created(doc) (private)

Slot called whenever a new document is created

It adds the document to the part manager and makes several signal-slot connections

Parameters:

  • doc (Document)

    the created document

Returns:

  • (nil)


98
99
100
101
102
103
# File 'lib/ruber/main_window/main_window_internal.rb', line 98

def document_created doc
  connect doc, SIGNAL('modified_changed(bool, QObject*)'), self, SLOT('document_modified_changed(bool)')
  connect doc, SIGNAL('document_url_changed(QObject*)'), self, SLOT(:document_url_changed)
  connect doc, SIGNAL(:completed), self, SLOT(:document_url_changed)
  update_switch_to_list
end

Slot Signature:

document_created(QObject*)

- (nil) document_modified_changed(mod) (private)

Note:

this method uses Qt::Object#sender to determine the document which emitted the signal, so it can only be called as a slot

Slot called whenever the modified status of a document changes

It updates the icon on the tab of the document’s editor and (if the document is active) the window title accordingly.

Nothing is done if the document isn’t associated with a view

Returns:

  • (nil)


237
238
239
240
241
242
# File 'lib/ruber/main_window/main_window_internal.rb', line 237

def document_modified_changed mod
  doc = self.sender
  change_title
#       update_document_icon doc
  nil
end

Slot Signature:

document_modified_changed(bool)

- (nil) document_url_changed (private)

Slot called whenever the document url changes

It changes the title and icon of the tab and changes the title of the window is the document is active.

Nothing is done if the document isn’t associated with a view

Returns:

  • (nil)


254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
# File 'lib/ruber/main_window/main_window_internal.rb', line 254

def document_url_changed
  doc = self.sender
#       return unless doc.has_view?
#       change_title
#       doc.views.each do |v|
#         v.parent.label = @view_manager.label_for_editor v
#         tab = @view_manager.tab v
#         if @view_manager.focus_editor? v, tab
#           idx = @tabs.index_of tab
#           @tabs.set_tab_text idx, doc.document_name
#         end
#       end
#       update_document_icon doc
  unless doc.path.empty?
    action_collection.action('file_open_recent').add_url KDE::Url.new(doc.path) 
  end
  nil
end

Slot Signature:

document_url_changed()

- (EditorView?) editor_for!(doc, hints = {})

Returns an editor associated with the given document, creating it if needed

If doc is not a document and no document for the file representing by the string or URL doc is open, it will be created.

Since there can be more than one editor associated with the document, the optional hints argument can be used to specify which one should be returned. If no editor exists for the document, or none of the exisiting ones statisfy the existing hint, a new one will be created, unless the create_if_needed hint is false.

Parameters:

  • doc (Document, String, KDE::Url)

    the document. If it is a string representing a relative path, it’ll be considered relative to the current directory. If the string is an Url, it’ll be interpreted as such

  • hints (Hash) (defaults to: {})

    options to tailor the algorithm used to retrieve or create the editor

Options Hash (hints):

  • :existing (Symbol) — default: :always

    when it is acceptable to return an already existing editor. It can be:

    • :always: if there’s an existing editor, always use it
    • :never: never use an exisiting editor
    • :current_tab: use an exisiting editor only if it is in the current pane
  • :create_if_needed (Boolean) — default: true

    whether or not a new editor for the given document should be created if none exists. This is different from passing :always as the value of the :existing option because the latter would cause a new editor to be created in case no one already exists for the document

  • :strategy (Symbol, Array<Symbol>) — default: [:current, :current_tab, :first]

    how to choose the exisiting editor to use in case there’s more than one. If it is an array, the strategies will be applied in turn until one has success. If none of the given strategies succeed, :first will be used. The possible values are

    • :current: if the current editor is associated with doc, use it
    • :current_tab: if there are editors associated with doc in the current tab, the first of them will be used
    • :last_current_tab: if there are editors associated with doc in the current tab, the first of them will be used
    • :next: starting from the current tab, the first editor found associated with doc will be used
    • :previous: the first editor associated with doc found by looking in all tabs from the current one in reverse order will be used (the current tab will be the last one where the editor will be looked for)
    • :first: the first editor associated with the document will be used
    • :last: the last editor associated the document will be used

    This option is only useful when using an existing editor

  • :new (Symbol, Integer, EditorView) — default: :new_tab

    where to place the new editor, if it needs to be created. It can have one of the following values:

    • :new_tab: put the new editor as the single editor in a new tab
    • :current: place the new editor in the pane obtained splitting the current editor
    • :current_tab: place the new editor in the pane obtained splitting the first editor in the current tab
    • :replace: replace the current editor, if any, with the new one. If no active editor exists, it’s the same as :new_tab. This value (if there’s an active editor), implies that the :existing option is set to :never
    • an integer: place the new editor in the tab associated with that index (0-based), in the pane obtained by splitting the first view
    • an EditorView: place the new editor in the pane obtained splitting the pane associated with the given editor

    This option is only used when when creating a new editor

  • :split (Symbol) — default: :horizontal

    the orientation in which an existing editor should be split to accomodate the new editor. It can be :horizontal or :vertical. This option is only used when when creating a new editor

  • :show (Boolean) — default: true

    whether the new editor should be shown or not. If it’s false, the editor won’t be placed in any pane. This option is only used when when creating a new editor

Returns:

  • (EditorView, nil)

    an editor associated with the document and nil if no editor associated with the given document exists and the :create_if_needed hint is set to false.

Raises:

  • (ArgumentError)

    if doc is a path or a KDE::Url but the corresponding file doesn’t exist



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
308
309
310
311
312
# File 'lib/ruber/main_window/main_window.rb', line 279

def editor_for! doc, hints = {}
  @active_environment.editor_for! doc, hints
#       hints = DEFAULT_HINTS.merge hints
#       if hints[:new] == :replace
#         if active_editor
#           hints[:existing] = :never
#           hints[:show] = false
#         else hints[:new] = :new_tab
#         end
#       end
#       docs = Ruber[:documents].documents
#       unless doc.is_a? Document
#         unless hints.has_key? :close_starting_document
#           hints[:close_starting_document] = docs.size == 1 && 
#               docs[0].extension(:ruber_default_document).default_document && 
#               docs[0].pristine?
#         end
#         url = doc
#         if url.is_a? String
#           url = KDE::Url.new url
#           if url.relative?
#             path = File.expand_path url.path
#             url.path = path
#           end
#         end
#         doc = Ruber[:documents].document url
#       end
#       return unless doc
#       ed = @view_manager.without_activating{@view_manager.editor_for doc, hints}
#       if hints[:new] == :replace
#         replace_editor active_editor, ed
#       else ed
#       end
end

- (Object) execute_action(name, *args)

Executes a given action

Parameters:

  • name (String)

    the name by which the action has been registered in the main window’s action_collection

  • args (Array)

    a list of parameters to pass to the signal or slot associated to the action

See Also:



724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
# File 'lib/ruber/main_window/main_window.rb', line 724

def execute_action name, *args
  data = plugin_description.actions[name.to_s]
  if data
    slot = data.slot.sub(/\(.*/, '')
    instance_eval(data.receiver).send slot, *args
    true
  elsif (action = action_collection.action(name))
    if action.class == KDE::ToggleAction then KDE::ToggleAction
      action.instance_eval{emit toggled(*args)}
    elsif action.class == KDE::Action 
      action.instance_eval{emit triggered()}
    else action.instance_eval{emit triggered(*args)}
    end
    true
  else false
  end
end

- (Pane?) find_next_pane(from, orientation, direction) (private)

TODO:

Maybe move this method to Pane class

Finds the next or previous pane in single view mode from a given pane

According to the second argument, the direction will be either horizontal or vertical.

The search will be carried out first among siblings and their children, then among ancestors.

Parameters:

  • from (Pane)

    the pane next/previous is relative to. It must be a single view pane

  • orientation (Integer)

    whether to look for the next/previous pane horizontally or vertically. It may be either Qt::Horizontal or Qt::Vertical

  • direction (Symbol)

    whether to look for the next or previous pane. It must be either :next or :previous

Returns:

  • (Pane, nil)

    the next/previous single view mode pane or nil if no such pane has been found (either because the pane is toplevel or because it’s the first/last)



705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'lib/ruber/main_window/main_window_actions.rb', line 705

def find_next_pane from, orientation, direction
  loop do
    parent = from.parent_pane
    return nil unless parent
    idx = parent.splitter.index_of from
    if parent.orientation == orientation
      new_idx = idx + (direction == :next ? 1 : -1)
      pane = parent.splitter.widget new_idx
      return pane.views[0].parent if pane
    end
    to_try = parent.panes[direction == :next ? (idx+1)..-1 : 0...idx]
    until to_try.empty? do
      idx = direction == :next ? 0 : -1
      pane = to_try[idx]
      if pane.single_view? then to_try.delete_at idx
      else
        if pane.orientation == orientation then return pane.views[idx].parent
        else 
          to_try.delete_at idx
          to_try.unshift *pane.panes
        end
      end
    end
    from = parent
  end
end

- (EditorView?) focus_on_editor - (EditorView?) focus_on_editor(editor) - (EditorView?) focus_on_editor(doc, hints = DEFAULT_HINTS)

Gives focus to an editor view

Giving focus to the editor implies:

  • bringing the tab containing it to the foreground
  • activating the editor
  • giving focus to the editor

Overloads:

  • - (EditorView?) focus_on_editor

    Gives focus to the active editor

    Returns:

  • - (EditorView?) focus_on_editor(editor)

    Parameters:

    • editor (EditorView)

      the editor to give focus to

    Returns:

  • - (EditorView?) focus_on_editor(doc, hints = DEFAULT_HINTS)

    Parameters:

    • doc (Document, String, KDE::Url)

      the document. If it is a string representing a relative path, it’ll be considered relative to the current directory. If the string is an Url, it’ll be interpreted as such

    • hints (Hash)

      options to tailor the algorithm used to retrieve or create the editor. See #editor_for! for a description of the values it can contain

    Returns:

Returns:

  • (EditorView, nil)

    the editor which was given focus or nil if no editor received focus

    def focus_on_editor ed = nil, hints = DEFAULT_HINTS if ed ed = editor_for! ed, hints unless ed.is_a? EditorView activate_editor ed ed.set_focus else active_editor.set_focus if active_editor end active_editor end


701
702
703
704
# File 'lib/ruber/main_window/main_window.rb', line 701

def focus_on_editor
  active_editor.set_focus if active_editor
  active_editor
end

Slot Signature:

focus_on_editor()

- (EditorView?) gui_open_file(file, give_focus = true, hints = DEFAULT_HINTS) (private)

Opens a file in an editor, gives focus to it and adds it to the list of recent files

If needed, a document is created for the file.

If the file can’t be opened, nothing is done.

See #editor_for! for the values which can be included in hints

Parameters:

  • the (String, KDE::Url)

    absolute path of the file to open.

  • hints (Hash) (defaults to: DEFAULT_HINTS)

    options to tailor the algorithm used to retrieve or create the editor

Returns:

  • (EditorView, nil)

    the editor displaying the file or nil if the file couldn’t be opened



189
190
191
192
193
194
195
196
197
# File 'lib/ruber/main_window/main_window_internal.rb', line 189

def gui_open_file file, give_focus = true, hints = DEFAULT_HINTS
  editor = @active_environment.editor_for! file, hints
  return unless editor
  editor.set_focus if give_focus
  url = KDE::Url.new file
  action_collection.action('file_open_recent').add_url url, url.file_name
  action_collection.action('window-switch_to_recent_file').add_url url, url.file_name
  editor
end

- (nil) load_settings

Returns:

  • (nil)


659
660
661
662
663
664
665
# File 'lib/ruber/main_window/main_window.rb', line 659

def load_settings
  c = Ruber[:config][:general]
  @default_script_dir = KDE::Url.from_path c.default_script_directory
  @default_project_dir = KDE::Url.from_path c.default_project_directory
  @tabs.tabs_closable = Ruber[:config][:workspace, :close_buttons] if @tabs
  nil
end

Slot Signature:

load_settings()

- (EditorView) move_among_views (private)

Slot associated with the Next/Previous View Horizontally/Vertically actions

According to the name of the action, it gives focus to the next/previous view in the current tab going horizontally/vertically. If the current tab only contains one view, nothing is done.

note this method uses sender to find out which action emitted the signal, so you can’t call it directly

Returns:



675
676
677
678
679
680
681
682
683
# File 'lib/ruber/main_window/main_window_actions.rb', line 675

def move_among_views
  action_name = sender.object_name
  direction = action_name.match('next') ? :next : :previous
  orientation = action_name.match(/horizontal/) ? Qt::Horizontal : Qt::Vertical
  pane = find_next_pane active_editor.parent, orientation, direction
  tabs = @active_environment.tab_widget
  view = pane ? pane.view : tabs.current_widget.views[direction == :next ? 0 : -1]
  view.set_focus
end

Slot Signature:

move_among_views()

- (EditorView) new_file (private)

Slot connected to the ‘New File’ action

It creates and activates a new, empty file

Returns:

  • (EditorView)

    the editor used to display the new file



49
50
51
# File 'lib/ruber/main_window/main_window_actions.rb', line 49

def new_file
  display_doc Ruber[:world].new_document
end

Slot Signature:

new_file()

- (nil) new_project (private)

Slot connected with the ‘New Project’ action

It displays the new project dialog. Unless the user cancels the dialog, it creates the project directory and creates and saves a new project with the parameters chosen by the user. The new project is then activated. If there was another active project, it’s closed

Returns:

  • (nil)


311
312
313
314
315
316
317
318
319
320
321
322
# File 'lib/ruber/main_window/main_window_actions.rb', line 311

def new_project
  dlg = NewProjectDialog.new self
  return if dlg.exec == Qt::Dialog::Rejected
  dir = File.dirname dlg.project_file
  FileUtils.mkdir dir unless File.directory? dir
  prj = Ruber[:world].new_project dlg.project_file, dlg.project_name
  prj.save
  action_collection.action('project-open_recent').add_url KDE::Url.new(dlg.project_file)
#       Ruber[:projects].close_current_project if Ruber[:projects].current
  Ruber[:world].active_project = prj
  nil
end

Slot Signature:

new_project()

- (EditorView?) next_document (private)

Slot connected with the ‘Next Document’ action

Activates the tab to the right of the current one. If the current tab is the last one, it returns to the first

Returns:



332
333
334
335
336
337
338
# File 'lib/ruber/main_window/main_window_actions.rb', line 332

def next_document
  tabs = @active_environment.tab_widget
  idx = tabs.current_index
  new_idx = idx + 1 < tabs.count ? idx + 1 : 0
  tabs.current_index = new_idx
  active_editor
end

Slot Signature:

next_document()

- (Array<EditorView>) open_file (private)

Slot connected to the ‘Open File’ action.

It asks the user for the file(s) or URL to open, then creates a document and and editor for each of them. If a document for some of the files already exists, it will be used. If an editor for one of the files already exists, it will be used.

After calling this method, the editor associated with the last file chosen by the user will become active

Returns:



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/ruber/main_window/main_window_actions.rb', line 66

def open_file
  dir = KDE::Url.from_path(@active_environment.project.project_directory) rescue KDE::Url.new
  filenames = KDE::FileDialog.get_open_urls(dir, OPEN_DLG_FILTERS.join("\n") , self)
#       editors = []
#       without_activating do
  editors = filenames.map{|f| gui_open_file(f, false)}
#       end
  unless editors.empty?
    @active_environment.activate_editor editors[0]
    editors[-1].set_focus
  end
  editors
end

Slot Signature:

open_file()

- (EditorView?) open_file_in_project (private)

Slot connected to the ‘Quick Open File’ action

It opens the file chosen by the user in a quick open file dialog

Returns:

  • (EditorView, nil)

    the editor where the document has been displayed



239
240
241
242
243
244
245
246
247
# File 'lib/ruber/main_window/main_window_actions.rb', line 239

def open_file_in_project
  dlg = OpenFileInProjectDlg.new @active_environment.project, self
  if dlg.exec == Qt::Dialog::Accepted
    editor = @active_environment.display_document dlg.chosen_file
    editor.set_focus
    action_collection.action('file_open_recent').add_url( KDE::Url.new(dlg.chosen_file) )
    editor
  end
end

Slot Signature:

open_file_in_project()

- (Project?) open_project (private)

Slot connected to the ‘Open Project’ action

It opens the project chosen by the user using an open dialog

Returns:

  • (Project, nil)

    the project chosen by the user or nil if either the user cancels the dialog or an error occurs while loading the project



205
206
207
208
209
210
211
212
213
214
215
216
# File 'lib/ruber/main_window/main_window_actions.rb', line 205

def open_project
  filename = KDE::FileDialog.get_open_file_name KDE::Url.from_path( 
    ENV['HOME'] ), '*.ruprj|Ruber project files (*.ruprj)', self,
    KDE::i18n('Open project')
  return unless filename
  prj = safe_open_project filename
  return unless prj
  Ruber[:world].active_project = prj
  url = KDE::Url.new prj.project_file
  action_collection.action('project-open_recent').add_url url, url.file_name
  prj
end

Slot Signature:

open_project()

- (EditorView) open_recent_file(url) (private)

Slot connected to the ‘Open Recent File’ action

It opens the file associated with the specified URL in an editor and gives it focus

Parameters:

  • the (KDE::Url)

    url of the file to open

Returns:

  • (EditorView)

    the editor used to display the URL



85
86
87
# File 'lib/ruber/main_window/main_window_actions.rb', line 85

def open_recent_file url
  gui_open_file url.path
end

Slot Signature:

open_recent_file(KUrl)

- (Project?) open_recent_project(url) (private)

Slot connected to the ‘Open Recent Projet’ action

It opens and activates the project associated with the file described by the given URL

Parameters:

  • the (KDE::Url)

    url of the project file to open

Returns:

  • (Project, nil)

    the open project or nil if an error occurs



189
190
191
192
193
194
195
# File 'lib/ruber/main_window/main_window_actions.rb', line 189

def open_recent_project url
  prj = safe_open_project url.path
  return unless prj
  Ruber[:world].active_project = prj
  action_collection.action('project-open_recent').add_url url, url.file_name
  prj
end

Slot Signature:

open_recent_project(KUrl)

- (nil) preferences (private)

Slot connected to the ‘Configure Ruber’ action

It displays the configuration dialog

Returns:

  • (nil)


256
257
258
259
# File 'lib/ruber/main_window/main_window_actions.rb', line 256

def preferences
  Ruber[:config].dialog.exec
  nil
end

Slot Signature:

preferences()

- (EditorView?) previous_document (private)

Slot connected with the ‘Previous Document’ action

Activates the tab to the left of the current one. If the current tab is the first one, it jumps to the last

Returns:



348
349
350
351
352
353
354
# File 'lib/ruber/main_window/main_window_actions.rb', line 348

def previous_document
  tabs = @active_environment.tab_widget
  idx = tabs.current_index
  new_idx = idx > 0 ? idx - 1 : tabs.count - 1
  tabs.current_index = new_idx
  nil
end

Slot Signature:

previous_document()

- (String) projects_directory

The default directory where to look for, and create, projects

Returns:

  • (String)

    the default directory where to look for, and create, projects



710
711
712
# File 'lib/ruber/main_window/main_window.rb', line 710

def projects_directory
  @default_project_dir
end

- (TrueClass) query_close

Override of PluginLike#query_close

It stores the session data retrieved by the component manager in case of session saving and does nothing otherwise.

Returns:

  • (TrueClass)


575
576
577
578
579
580
# File 'lib/ruber/main_window/main_window.rb', line 575

def query_close
  if Ruber[:app].session_saving
    @session_data = Ruber[:components].session_data
  end
  true
end

- (Boolean) queryClose (protected)

Override of KParts::MainWindow#queryClose

It calls the ask_to_quit method of the application.

Returns:



49
50
51
52
# File 'lib/ruber/main_window/main_window_internal.rb', line 49

def queryClose
  res = Ruber[:app].ask_to_quit
  res
end

- (TrueClass) queryExit (protected)

Override of KParts::MainWindow#queryExit

It calls the quit_ruber method of the application

Returns:

  • (TrueClass)

    true



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ruber/main_window/main_window_internal.rb', line 59

def queryExit
  #There's a C++-side crash in any view is open after this method when closing
  #a session. As I have no clue as why this happens, for the time being, as
  #a workaround, we close all the documents.
  
  #For some reason, this method is called twice when closing a session
  #but only when Ruber is launched from the global installation (that is, typing
  #ruber in the shell), and not when testing from xsm. This causes a number of
  #problems, the most evident is the save_settings method being called twice,
  #one of the times after all documents have been closed. This obviously breaks
  #the state plugin. To avoid the issue, we use an instance variable to keep
  #trace of whether the method has already been called or not. Ruber[:app].quit_ruber
  #is only called the first time, while the documents are only closed the
  #second time
  if @query_exit_called
    Ruber[:world].close_all :documents, :discard
  else 
    Ruber[:app].quit_ruber
    @query_exit_called = true
  end
  true
end

- (nil) readProperties(conf) (protected)

Reads the properties from the config object for session management

Returns:

  • (nil)


83
84
85
86
# File 'lib/ruber/main_window/main_window_internal.rb', line 83

def readProperties conf
  @last_session_data = YAML.load conf.read_entry('Ruber', '{}')
  nil
end

- (nil) remove_about_plugin_action(comp) (private)

Note:

this method doesn’t check whether the action for the given plugin actually exists. Since it’s usually called in response to the unloading_component signal of the component manager, there shouldn’t be problems with this

Note:

this method does nothing for core components

Removes the About entry for the given menu from the “about plugins list” of the Help menu

Parameters:

  • comp (Plugin)

    the plugin object of the plugin to remove the action for

Returns:

  • (nil)


423
424
425
426
427
428
429
430
431
# File 'lib/ruber/main_window/main_window_actions.rb', line 423

def remove_about_plugin_action comp
  name = comp.plugin_name.to_s
  return unless comp.is_a? Plugin
  unplug_action_list 'about_plugins_list'
  a = @about_plugin_actions.find{|i| i.object_name == comp.plugin_name.to_s}
  @about_plugin_actions.delete a
  plug_action_list 'about_plugins_list', @about_plugin_actions
  a.delete_later
end

Slot Signature:

remove_about_plugin_action(QObject*)

- (nil) remove_plugin_ui_actions(plug) (private)

Removes the gui action handlers for all the actions belonging to the given plugin from the list of handlers

Parameters:

  • plug (Plugin)

    the plugin whose action handlers should be removed

Returns:

  • (nil)


280
281
282
283
284
285
286
# File 'lib/ruber/main_window/main_window_internal.rb', line 280

def remove_plugin_ui_actions plug
  @actions_state_handlers.delete_if do |state, hs|
    hs.delete_if{|h| h.plugin == plug}
    hs.empty?
  end
  nil
end

Slot Signature:

remove_plugin_ui_actions(QObject*)

- (EditorView?) replace_editor(old, new_ed) - (EditorView?) replace_editor(old, doc)

Replaces an editor with another

If the editor to be replaced is the only one associated witha given document and the document is modified, the user is asked whether he wants to save it or not. If he chooses to abort, the editor is not replaced, otherwise the document is closed.

The new editor is put in the same pane which contained the old one (without splitting it).

Overloads:

  • - (EditorView?) replace_editor(old, new_ed)

    Parameters:

    Returns:

  • - (EditorView?) replace_editor(old, doc)
    Note:

    whether or not the user needs to be asked about saving the document is determined regardless of the value of doc. This means that the user may be asked to save the document even if doc is the same document associated with the view (or the URL corresponding to it). To avoid this, create the replacement editor before calling this method, using editor_for doc, :existing => :never, :show => false, then use the overloaded version of this method which takes an editor

    Parameters:

    • old (EditorView)

      the editor to replace

    • doc (Document, String, KDE::Url)

      the document to create the editor for or the name of the corresponding file (absolute or relative to the current directory) or the corresponding URL

    Returns:

Returns:

  • (EditorView, nil)

    the new editor or nil if the user choose to abort



402
403
404
# File 'lib/ruber/main_window/main_window.rb', line 402

def replace_editor old, editor_or_doc
  @active_environment.replace_editor old, editor_or_doc
end

- (Project?) safe_open_project(file, allow_reuse = false)

Opens a project, displaying amessage boxe in case of errors

This method provides a standard interface for creating a project from a project file named, automatically handling the possible exceptions.

In particular, a message box will be displayed if the project file doesn’t exist or if it exists but it’s not a valid project file.

If the project corresponding to the given file is already open, the behaviour depends on the value of allow_reuse. If false, the user is warned with a message box that the project is already open and nothing is done. If allow_reuse is true, the existing project is returned.

The new project will be made active and the existing one (if any) will be closed

Parameters:

  • file (String)

    the absolute path of the project file to open

  • allow_reuse (Boolean) (defaults to: false)

    what to do in case the project associated to file is already open. If true, the existing project will be returned; if false, the user will be warned and nil will be returned

Returns:

  • (Project, nil)

    the project associated with file or nil if an error occurs (including the project being already open in case allow_reuse is false)



604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
# File 'lib/ruber/main_window/main_window.rb', line 604

def safe_open_project file, allow_reuse = false
  prj = Ruber[:world].projects[file]
  if !allow_reuse and prj
    text = i18n("A project corresponding to the file %s is already open. Please, close it before attempting to open it again" % file)
    KDE::MessageBox.sorry self, KDE.i18n(text)
    return nil
  elsif prj then return prj
  end
  message = nil
  begin prj = Ruber[:world].project file
  rescue Project::InvalidProjectFile => ex
    text = "%s isn't a valid project file. The error reported was:\n%s"
    message = i18n(text) % [file, ex.message]
  rescue LoadError then message = i18n(ex.message)
  end
  if prj
    # The following two line should be removed when we'll allow more than one project
    # open at the same time
#         Ruber[:projects].current_project.close if Ruber[:projects].current_project
    Ruber[:world].active_project = prj
    prj
  else
    KDE::MessageBox.sorry self, message
    nil
  end
end

- (Boolean) save_documents(docs = nil)

Asks the user to save multiple documents

This method is meant to be called in situation where the user may want to save a number of documents, for example when the application is quitting, as it avoids displaying a dialog box for each modified document.

It displays a dialog where the user can choose, among the documents passed as first argument, which ones he wants to save. The user has three choiches:

  • save some (or all) the files, then proceed with the operation which has caused the dialog to be shown (for example, quitting the application)
  • don’t save any file and go on with the operation
  • abort the operation.

In the first case, this method attempts to perform save the selected files. If any of them can’t be saved, the dialog to choose the files to save will be displayed again, with only those files which couldn’t be saved (after informing the user of the failure). The user can again chose which of those files this method should attempt to save again, or whether to abort the operation or skip saving. This will be repeated until all files have been saved or the user gives up

In the second and third cases, the method simply returns respectively true or false.

Parameters:

  • docs (Array<Document>) (defaults to: nil)

    the list of documents to save. If any document isn’t modified, it’ll be ignored. If no document is mdified, nothing will be done

Returns:

  • (Boolean)

    true if the operation which caused the dialog to be shown can be carried on and false if the user chose to abort it



548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
# File 'lib/ruber/main_window/main_window.rb', line 548

def save_documents docs = nil
  docs ||= Ruber[:world].documents
  to_save = docs.select{|d| d.modified?}
  until to_save.empty?
    dlg = SaveModifiedFilesDlg.new to_save, self
    to_save = dlg.to_save
    case dlg.exec
    when KDE::Dialog::Yes
      to_save.delete_if{|doc| doc.save}
      unless to_save.empty?
        msg = "The following documents couldn't be saved: #{to_save.join "\n"}\nPlease, choose how to proceed"
        KDE::MessageBox.sorry nil, KDE.i18n(msg)
      end
    when KDE::Dialog::No then to_save.clear
    when Qt::Dialog::Rejected then return false
    end
  end
  true
end

- (nil) save_settings

Override of PluginLike#save_settings

It saves recent files and projects, the position of the splitters and the size of the window.

Returns:

  • (nil)


639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
# File 'lib/ruber/main_window/main_window.rb', line 639

def save_settings
  @workspace.store_sizes
# TODO see if the following line works. Otherwise, remove it and uncomment the one
# following it
  config = Ruber[:config].kconfig
#       config = KDE::Global.config
  recent_files = KDE::ConfigGroup.new config, 'Recent files'
  action_collection.action("file_open_recent").save_entries recent_files
  recent_projects = KDE::ConfigGroup.new config, 'Recent projects'
  action_collection.action("project-open_recent").save_entries recent_projects
  config.sync
  c = Ruber[:config][:main_window]
  c.window_size = rect.size
  nil
end

- (nil) saveProperties(conf) (protected)

Saves the properties for session management

Returns:

  • (nil)


69
70
71
72
73
# File 'lib/ruber/main_window/main_window_internal.rb', line 69

def saveProperties conf
  data = YAML.dump @session_data 
  conf.write_entry 'Ruber', data
  nil
end

- (nil) select_active_project_entry (private)

Checks the entry in the Active Project action which corresponds to the current project

If there’s no current project, the action which deactivates all projects is selected.

If the action corresponding to the current project is already selected, nothing is done.

Returns:

  • (nil)


582
583
584
585
586
587
588
589
# File 'lib/ruber/main_window/main_window_actions.rb', line 582

def select_active_project_entry
  active_project_action = action_collection.action 'project-active_project'
  to_select = action_for_project Ruber[:world].active_project
  unless to_select == active_project_action.current_action
    active_project_action.current_action = to_select
  end
  nil
end

- (nil) setup_initial_states (private)

Gives the UI states their initial values

Returns:

  • (nil)


292
293
294
295
296
# File 'lib/ruber/main_window/main_window_internal.rb', line 292

def setup_initial_states
  change_state 'active_project_exists', false
  change_state 'current_document', false
  nil
end

- (nil) show_user_manual (private)

Slot connected to the ‘Ruber User Manual’ action

Opens the user’s browser and points it to the user manual

Returns:

  • (nil)


363
364
365
366
# File 'lib/ruber/main_window/main_window_actions.rb', line 363

def show_user_manual
  KDE::Run.run_url KDE::Url.new('http://stcrocco.github.com/ruber/user_manual'), 'text/html', self
  nil
end

Slot Signature:

show_user_manual()

- (nil) slot_active_editor_changed(view) (private)

Slot called whenever the active editor changes

It emits the #current_document_changed and #active_editor_changed signals and updates the title and the statusbar

Parameters:

  • the (EditorView, nil)

    new active editor, or nil if there’s no active editor

Returns:

  • (nil)


131
132
133
134
135
136
137
138
# File 'lib/ruber/main_window/main_window_internal.rb', line 131

def slot_active_editor_changed view
  status_bar.view = view
  emit current_document_changed view ?  view.document : nil
  emit active_editor_changed view
  change_title
  set_state 'current_document', !view.nil?
  nil
end

Slot Signature:

slot_active_editor_changed(QWidget*)

- (Object) slot_active_environment_changed(new, old) (private)



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/ruber/main_window/main_window_internal.rb', line 106

def slot_active_environment_changed(new, old)
  if old
    old.disconnect SIGNAL('active_editor_changed(QWidget*)'), self, SLOT('slot_active_editor_changed(QWidget*)')
  end
  @active_environment = new
  if new
    connect new, SIGNAL('active_editor_changed(QWidget*)'), self, SLOT('slot_active_editor_changed(QWidget*)')
    @workspace.main_widget = new.tab_widget
    change_state 'active_project_exists', !new.project.nil?
    select_active_project_entry
    change_title
  else Ruber[:world].active_environment = Ruber[:world].default_environment
  end
end

Slot Signature:

slot_active_environment_changed(QObject*, QObject*)

- (Object) slot_project_closing(prj) (private)



147
148
149
150
# File 'lib/ruber/main_window/main_window_internal.rb', line 147

def slot_project_closing prj
  @workspace.remove_widget prj.environment.tab_widget
  update_active_project_menu prj
end

Slot Signature:

slot_project_closing(QObject*)

- (Object) slot_project_created(prj) (private)



141
142
143
144
# File 'lib/ruber/main_window/main_window_internal.rb', line 141

def slot_project_created prj
  @workspace.add_widget prj.environment.tab_widget
  update_active_project_menu
end

Slot Signature:

slot_project_created(QObject*)

- (EditorView) split_horizontally (private)

Slot associated with the Split Horizontally action

It splits the active view horizontally, so that a new copy of the view is created. note this method can only be called when there’s an active view.

Returns:



468
469
470
471
472
473
# File 'lib/ruber/main_window/main_window_actions.rb', line 468

def split_horizontally
  ed = @active_environment.active_editor
  @active_environment.display_document ed.document, :existing => :never,
      :new => ed, :split => :horizontal
  ed.set_focus
end

Slot Signature:

split_horizontally()

- (EditorView) split_vertically (private)

Slot associated with the Split Vertically action

It splits the active view vertically, so that a new copy of the view is created. note this method can only be called when there’s an active view.

Returns:



484
485
486
487
488
489
# File 'lib/ruber/main_window/main_window_actions.rb', line 484

def split_vertically
  ed = @active_environment.active_editor
  @active_environment.display_document ed.document, :existing => :never,
      :new => ed, :split => :vertical
  ed.set_focus
end

Slot Signature:

split_vertically()

- (EditorView) switch_to_document (private)

Note:

this method can only be called when there’s an active view

Note:

this method uses sender to find out the action which emitted the signal, so it shouldn’t be called directly

Slot associated with the actions in the Switch to Document submenu

It creates a new editor for an already-existing document and replaces the active editor with it, giving focus to it. The document to use is determined from the object_name of the action.

Returns:



640
641
642
643
644
# File 'lib/ruber/main_window/main_window_actions.rb', line 640

def switch_to_document
  doc = Ruber[:world].documents.document_with_name sender.object_name
  ed = replace_editor active_editor, doc
  ed.set_focus if ed
end

Slot Signature:

switch_to_document()

- (EditorView) switch_to_file (private)

Slot associated with the Switch to File action

It allows the user to choose a file, then creates a document for that file, replaces the active editor with a new one associated with the document and gives focus to it. note this method can only be called when there’s an active view

Returns:



517
518
519
520
521
522
523
524
525
# File 'lib/ruber/main_window/main_window_actions.rb', line 517

def switch_to_file
  dir = KDE::Url.from_path(@active_environment.project.project_directory) rescue KDE::Url.new
  filename = KDE::FileDialog.get_open_url(dir, OPEN_DLG_FILTERS.join("\n") , self)
  return unless filename.valid?
  Ruber::Application.process_events
  ed = replace_editor active_editor, filename
  ed.set_focus if ed
  ed
end

Slot Signature:

switch_to_file()

- (EditorView) switch_to_new_document (private)

Slot associated with the Switch to New Document action

It creates a new empty document, replaces the current editor with an editor associated to it and gives focus to it. note this method can only be called when there’s an active view

Returns:



501
502
503
504
505
# File 'lib/ruber/main_window/main_window_actions.rb', line 501

def switch_to_new_document
  old = active_editor
  ed = replace_editor old, Ruber[:world].new_document
  ed.set_focus if ed
end

Slot Signature:

switch_to_new_document()

- (EditorView) switch_to_recent_file(url) (private)

Slot associated with Switch to Recent File action

It creates a new document for the given URL (if needed), creates a new editor for it, replaces the active editor with it and gives focus to it.

note this method can only be called when there’s an active view

Parameters:

  • url (KDE::Url)

    the URL associated with the editor

Returns:



658
659
660
661
# File 'lib/ruber/main_window/main_window_actions.rb', line 658

def switch_to_recent_file url
  ed = replace_editor active_editor, url
  ed.set_focus if ed
end

Slot Signature:

switch_to_recent_file(KUrl)

- (Pane) tab(idx) - (Pane) tab(editor)

The toplevel pane corresponding to the given index or editor

Overloads:

  • - (Pane) tab(idx)

    The toplevel pane in the tab number idx

    Parameters:

    • idx (Integer)

      the index of the tab

    Returns:

    • (Pane)

      the toplevel pane in the tab number idx

  • - (Pane) tab(editor)

    The toplevel pane containing the given editor

    Parameters:

    • editor (EditorView)

      the editor to retrieve the pane for

    Returns:

    • (Pane)

      the toplevel pane containing the given editor



425
426
427
# File 'lib/ruber/main_window/main_window.rb', line 425

def tab arg
  @active_environment.tab arg
end

- (Object) tabs

The toplevel panes associated with the active environment



150
151
152
# File 'lib/ruber/main_window/main_window.rb', line 150

def tabs
  @active_environment.tabs
end

- (nil) toggle_tool_widget (private)

Slot associated with the Toggle * Tool Widget action

It identifies the tool widget to toggle basing on the name of the triggered action

Returns:

  • (nil)


452
453
454
455
456
457
458
# File 'lib/ruber/main_window/main_window_actions.rb', line 452

def toggle_tool_widget
  side = sender.object_name.match(/(left|right|bottom)/)[1].to_sym
  w = @workspace.current_widget(side)
  return unless w
  @workspace.toggle_tool w
  nil
end

Slot Signature:

toggle_tool_widget()

- (nil) update_active_project_menu(project = nil) (private)

Updates the Active Project menu

Parameters:

  • project (Project, nil) (defaults to: nil)

    if not nil, a project to exclude from the menu. This is meant to be used when a project is closed, since the project list notifies that a project is being closed before removing it from the list

Returns:

  • (nil)


555
556
557
558
559
560
561
562
563
564
565
566
567
568
# File 'lib/ruber/main_window/main_window_actions.rb', line 555

def update_active_project_menu project = nil
  activate_action = action_collection.action 'project-active_project'
  old_actions = activate_action.actions
  activate_action.remove_all_actions
  activate_action.add_action old_actions.delete_at(0)
  old_actions.each{|a| a.delete_later}
  Ruber[:world].projects.sort_by{|pr| pr.project_name}.each do |prj|
    next if prj == project
    name = "projects-activate_project-project_file_#{prj.project_file}"
    a = activate_action.add_action prj.project_name
    a.object_name = name
  end
  nil
end

Slot Signature:

update_active_project_menu(QObject*)

- (Object) update_switch_to_list (private)

Slot which updates the window-switch_to_open_document_list action list

This method is called whenever a document is created or deleted. It updates the action list so that it contains an action for each of the open documents



534
535
536
537
538
539
540
541
542
543
544
# File 'lib/ruber/main_window/main_window_actions.rb', line 534

def update_switch_to_list
  unplug_action_list "window-switch_to_open_document_list"
  @switch_to_actions = Ruber[:world].documents.map do |doc|
    a = action_collection.add_action "switch_to_#{doc.document_name}", self, SLOT(:switch_to_document)
    a.text = KDE.i18n("Switch to %s") % [doc.document_name]
    a.object_name = doc.document_name
    a
  end
  @switch_to_actions = @switch_to_actions.sort_by{|a| a.object_name}
  plug_action_list "window-switch_to_open_document_list", @switch_to_actions
end

Slot Signature:

update_switch_to_list()

- (Object) views(doc = nil)

The views contained in the active environment



161
162
163
# File 'lib/ruber/main_window/main_window.rb', line 161

def views doc = nil
  @active_environment.views
end

- (Object) without_activating { ... }

Note:

automatical editor activation will be restored at the end of this method (even if exceptions occur).

Executes the given block without automatically activating an editor whenever the current tab changes

This method should be used, for example, when more than one editor should be opened at once. Without this, every new editor would become (for a little time) the active one, with its gui merged with the main window and so on. This slows things down and should be avoided. To do so, you use this method:

Ruber[:main_window].without_activating do
    ed = nil
    files.each do |f|
      ed = Ruber[:main_window].editor_for! f
    end
    Ruber[:main_window].activate_editor ed
  end

After calling this method, the focus widget of the current tab gets focus

Yields:

  • the block which should be executed without automatically activating editors

Returns:

  • (Object)

    the value returned by the block



495
496
497
498
# File 'lib/ruber/main_window/main_window.rb', line 495

def without_activating &blk
  blk.call
#       @view_manager.without_activating &blk
end

Signal Details

- current_document_changed(QObject* arg1)

- active_editor_changed(QObject* arg1)