Class: Ruber::Rake::ProjectWidget

Inherits:
ProjectConfigWidget show all
Defined in:
plugins/rake/rake_widgets.rb

Overview

Project configuration widget

Instance Attribute Summary

Attributes inherited from ProjectConfigWidget

project

Instance Method Summary (collapse)

Constructor Details

- (ProjectWidget) initialize(prj)

A new instance of ProjectWidget

Parameters:



361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'plugins/rake/rake_widgets.rb', line 361

def initialize prj
  super
  @ui = Ui::RakeProjectWidget.new
  @ui.setupUi self
  @ui.tasks.model = Qt::StandardItemModel.new @ui.tasks
  @ui.tasks.item_delegate = ShortcutDelegate.new 1, @ui.refresh_tasks
  view = @ui.tasks
  view.header.resize_mode = Qt::HeaderView::ResizeToContents
  def view.mouseDoubleClickEvent e
    idx = index_at e.pos
    if idx.valid? then super
    else
      it = Qt::StandardItem.new
      model.append_row 3.times.map{Qt::StandardItem.new ''}
      edit it.index
    end
  end
  connect @ui.refresh_tasks, SIGNAL(:clicked), self, SLOT(:refresh_tasks)
  connect @ui.add_task, SIGNAL(:clicked), self, SLOT(:add_task)
  connect @ui.remove_task, SIGNAL(:clicked), self, SLOT(:remove_task)
  view.selection_model.connect SIGNAL('selectionChanged(QItemSelection, QItemSelection)') do
    @ui.remove_task.enabled = !view.selection_model.selected_indexes.empty?
  end
  fill_tasks_widget @project[:rake, :tasks]
end

Instance Method Details

- (nil) add_task (private)

Displays a dialog where the user can add a new task and adds it to the task widget

Returns:

  • (nil)


589
590
591
592
593
594
595
# File 'plugins/rake/rake_widgets.rb', line 589

def add_task
  name = Qt::InputDialog.get_text self, 'Add task', 'Task name'
  return if name.nil? or name.empty?
  row = [name, '', ''].map{|i| Qt::StandardItem.new i}
  @ui.tasks.model.append_row row
  nil
end

Slot Signature:

add_task()

- (<String>) environment

The environment variables set in the Environment variables widget to Shellwords.split_with_quotes.

Returns:

  • (<String>)

    the environment variables chosen by the user, split according



470
471
472
# File 'plugins/rake/rake_widgets.rb', line 470

def environment
  Shellwords.split_with_quotes @ui._rake__environment.text
end

- (<String>) environment=(value)

Fills the Rake environment widget entry of the array should have the form ENV_VAR=value (with quotes added as needed)

Parameters:

  • value (<String>)

    an array containing the environment variables to set. Each

Returns:



461
462
463
# File 'plugins/rake/rake_widgets.rb', line 461

def environment= value
  @ui._rake__environment.text = value.join " "
end

- (nil) fill_tasks_widget(tasks) (private)

Fills the task widget keys of the hash are the task names, while the values are arrays of size 1 or 2. The first element of the array is a string representing the task description, while the second, if it exists, is a string representing the shortcut associated with the task Note: the previous contents of the widget will be removed

Parameters:

  • tasks (Hash)

    a hash with the information about the tasks to display. The

Returns:

  • (nil)


535
536
537
538
539
540
541
542
543
544
545
546
547
# File 'plugins/rake/rake_widgets.rb', line 535

def fill_tasks_widget tasks
  mod = @ui.tasks.model
  mod.clear
  tasks = tasks.sort
  @ui.tasks.model.horizontal_header_labels = %w[Task Shortcut Description]
  tasks.each do |n, i|
    name = Qt::StandardItem.new n
    desc = Qt::StandardItem.new i[0]
    key = Qt::StandardItem.new(i[1] || '')
    mod.append_row [name, key, desc]
  end
  nil
end

- (Hash) find_updated_tasks (private)

Uses the values in the Rake, Rake program, Rake options and environment variables widgets to retrieve an up-to-date list of tasks

keys of the hash are the task names, while the values are arrays of size 1 or 2. The first element of the array is a string representing the task description, while the second, if it exists, is a string representing the shortcut associated with the task

Returns:

  • (Hash)

    a hash with the information about the tasks to display. The

Raises:



560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
# File 'plugins/rake/rake_widgets.rb', line 560

def find_updated_tasks
  rake = @ui._rake__rake.text
  rakefile = @ui._rake__rakefile.text
  rakefile = nil if rakefile.empty?
  rake_options = Shellwords.split_with_quotes @ui._rake__options.text
  rake_options << '-T'
  env = Shellwords.split_with_quotes(@ui._rake__environment.text).select{|s| s.include? '='}
  dir = @project.project_directory
  if rakefile
    rel_dir = File.dirname(rakefile)
    dir = File.join dir, rel_dir unless rel_dir == '.'
  end
  ruby, *ruby_opts = Ruber[:rake].ruby_command_for @project, dir
  Ruber[:app].with_override_cursor do
    begin
      Ruber[:rake].tasks ruby, dir, :env => env, :ruby_options => ruby_opts,
        :rake_options => rake_options, :rakefile => rakefile, :rake => rake,
        :timeout => @ui._rake__timeout.value
    rescue Error => ex
      display_task_retrival_error_dialog ex
      return
    end
  end
end

- (<String>) options

The options set in the Rake options widget quoted according to Shellwords.split_with_quotes

Returns:

  • (<String>)

    an array containing the options chosen by the user, split and



451
452
453
# File 'plugins/rake/rake_widgets.rb', line 451

def options
  Shellwords.split_with_quotes @ui._rake__options.text
end

- (<String>) options=(value)

Fills the Rake options widget

Parameters:

  • value (<String>)

    an array with the rake options

Returns:



442
443
444
# File 'plugins/rake/rake_widgets.rb', line 442

def options= value
  @ui._rake__options.text = value.join " "
end

- (String?) rakefile

The rakefile chosen by the user rake decide

Returns:

  • (String, nil)

    the path to the rakefile chosen by the user or nil to let



489
490
491
492
# File 'plugins/rake/rake_widgets.rb', line 489

def rakefile
  text = @ui._rake__rakefile.text
  text.empty? ? nil : text
end

- (String) rakefile=(value)

Fills the rakefile widget decide

Parameters:

  • value (String, nil)

    the path to the rakefile to use or nil to let rake

Returns:



480
481
482
# File 'plugins/rake/rake_widgets.rb', line 480

def rakefile= value
  @ui._rake__rakefile.text = value || ''
end

- (ni;) read_default_settings

Clears the task widget

Returns:

  • (ni;)


411
412
413
414
415
# File 'plugins/rake/rake_widgets.rb', line 411

def read_default_settings
  mod = @ui.tasks.model
  mod.remove_rows 0, mod.row_count
  nil
end

- (nil) read_settings

Fills the Tasks widget according to the rake/tasks and rake/quick_tasks project options

Returns:

  • (nil)


392
393
394
395
# File 'plugins/rake/rake_widgets.rb', line 392

def read_settings
  fill_tasks_widget @project[:rake, :tasks]
  nil
end

- (nil) refresh_tasks (private)

Fills the task widget with an up to date list of tasks, according to the current content of the various widgets

Shortcut assigned to tasks which still exist after the update are kept.

This also enables the Tasks widget and hides the outdated tasks warning.

If the tasks couldn’t be retrieved because of a rake error, a message box is shown and nothing is done

Returns:

  • (nil)


508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
# File 'plugins/rake/rake_widgets.rb', line 508

def refresh_tasks
  new_tasks = begin find_updated_tasks
  rescue Rake::Error => e
    Ruber[:rake].display_task_retrival_error_dialog ex
  end
  new_tasks.each_pair{|k, v| new_tasks[k] = [v]}
  old_tasks = tasks
  old_tasks.each_pair do |t, data|
    if data[1]
      new = new_tasks[t]
      new << data[1] if new
    end
  end
  fill_tasks_widget new_tasks
  nil
end

Slot Signature:

refresh_tasks()

- (nil) remove_task (private)

Removes the currently selected task from the task widget

Note: this method assumes a task is selected

Returns:

  • (nil)


603
604
605
606
607
608
609
# File 'plugins/rake/rake_widgets.rb', line 603

def remove_task
  #We don't check whether a task is selected or not as the button should
  #be disabled otherwise
  idx = @ui.tasks.selection_model.selected_indexes.first
  @ui.tasks.model.remove_row idx.row
  nil
end

Slot Signature:

remove_task()

- (nil) store_settings

Sets the rake/tasks and rake/quick_task project options according to the contents of the Tasks widget

Returns:

  • (nil)


402
403
404
405
# File 'plugins/rake/rake_widgets.rb', line 402

def store_settings
  @project[:rake, :tasks] = tasks
  nil
end

- (Hash) tasks

The list of tasks

while the values are arrays having as first argument the task descriptions and as second argument a string corresponding to the shortcut chosen by the user, or nil if no shortcut has been chosen.

Returns:

  • (Hash)

    a hash containing the tasks. The keys are the names of the tasks,



425
426
427
428
429
430
431
432
433
434
435
# File 'plugins/rake/rake_widgets.rb', line 425

def tasks
  res = {}
  @ui.tasks.model.each_row do |r|
    unless r[0].text.empty?
      new_task = [r[2].text]
      new_task << r[1].text unless r[1].text.empty?
      res[r[0].text] = new_task
    end
  end
  res
end