Class: Ruber::Rake::ConfigWidget

Inherits:
Qt::Widget
  • Object
show all
Defined in:
plugins/rake/rake_widgets.rb

Overview

The configuration widget for the plugin

Defined Under Namespace

Classes: AddQuickActionDlg

Instance Method Summary (collapse)

Constructor Details

- (ConfigWidget) initialize(parent = nil)

A new instance of ConfigWidget

Parameters:

  • parent (Qt::Widget, nil) (defaults to: nil)

    the widget’s parent widget



263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
# File 'plugins/rake/rake_widgets.rb', line 263

def initialize parent = nil
  super
  @ui = Ui::RakeConfigWidget.new
  @ui.setupUi self
  m = Qt::StandardItemModel.new self
  v = @ui._rake__quick_tasks
  @ui._rake__quick_tasks.model = m
  
  connect m, SIGNAL('itemChanged(QStandardItem*)'), v, SIGNAL(:tasks_changed)
  connect m, SIGNAL('rowsInserted(QModelIndex, int, int)'), v, SIGNAL(:tasks_changed)
  connect m, SIGNAL('rowsRemoved(QModelIndex, int, int)'), v, SIGNAL(:tasks_changed)
  
  @ui._rake__quick_tasks.model.horizontal_header_labels = %w[Tasks Shortcuts]
  delegate = ShortcutDelegate.new 1, @ui._rake__quick_tasks
  @ui._rake__quick_tasks.item_delegate = delegate
  connect @ui.add_task, SIGNAL(:clicked), self, SLOT(:add_task)
  connect @ui.remove_task, SIGNAL(:clicked), self, SLOT(:remove_current_task)
  @ui._rake__quick_tasks.selection_model.connect SIGNAL('selectionChanged(QItemSelection, QItemSelection)') do 
    @ui.remove_task.enabled = @ui._rake__quick_tasks.selection_model.has_selection
  end
end

Instance Method Details

- (nil) add_task (private)

Displays a dialog where the user can create a quick task by associating a (task) name with a shortcut.

If the user presses the Ok button in the dialog, the new task is added to the task widget. If he presses the Cancel button, nothing is done.

Returns:

  • (nil)


326
327
328
329
330
331
332
333
# File 'plugins/rake/rake_widgets.rb', line 326

def add_task
  dlg = AddQuickActionDlg.new
  return if dlg.exec == Qt::Dialog::Rejected
  row = [Qt::StandardItem.new(dlg.task), Qt::StandardItem.new(dlg.shortcut)]
  @ui._rake__quick_tasks.model.append_row(row)
  @ui._rake__quick_tasks.selection_model.select row[0].index, Qt::ItemSelectionModel::ClearAndSelect|Qt::ItemSelectionModel::Rows|Qt::ItemSelectionModel::Current
  nil
end

Slot Signature:

add_task()

- (nil) read_quick_tasks(tasks)

Fills the “Quick tasks” widget while the values are strings representing the shortcuts to associate to each task

Parameters:

  • tasks (Hash)

    the tasks to insert in the widget. The keys are the task names,

Returns:

  • (nil)


291
292
293
294
295
296
297
298
299
300
# File 'plugins/rake/rake_widgets.rb', line 291

def read_quick_tasks tasks
  m = @ui._rake__quick_tasks.model
  tasks.each_pair do |k, v|
    m.append_row [Qt::StandardItem.new(k), Qt::StandardItem.new(v)]
  end
  if m.row_count > 0
    @ui._rake__quick_tasks.selection_model.select m.index(0,0), Qt::ItemSelectionModel::ClearAndSelect|Qt::ItemSelectionModel::Rows|Qt::ItemSelectionModel::Current
  end
  nil
end

- (nil) remove_current_task (private)

Removes the currently selected entry from the “Quick tasks” widget

Note: this method assumes an item is selected.

Returns:

  • (nil)


341
342
343
344
345
346
347
# File 'plugins/rake/rake_widgets.rb', line 341

def remove_current_task
  #We don't check wheter there's a selected item because the Remove task
  #button is disabled if no entry is selected
  row = @ui._rake__quick_tasks.selection_model.selected_rows[0].row
  @ui._rake__quick_tasks.model.remove_row row
  nil
end

Slot Signature:

remove_current_task()

- (Hash) store_quick_tasks

Gathers data from the “Quick tasks” widget associated shortcuts as values

Returns:

  • (Hash)

    a hash having the task names as keys and strings representing the



307
308
309
310
311
312
313
314
# File 'plugins/rake/rake_widgets.rb', line 307

def store_quick_tasks
  m = @ui._rake__quick_tasks.model
  res = {}
  m.each_row do |task, short|
    res[task.text] = short.text
  end
  res
end