Class: Smartdict::Gui::ExportDialog

Inherits:
Gtk::FileChooserDialog
  • Object
show all
Extended by:
ActiveSupport::Autoload
Defined in:
lib/smartdict/gui/export_dialog.rb

Defined Under Namespace

Classes: FormatComboBox, Label

Constant Summary collapse

DATE_RANGES =
{
  "Today" => lambda { Date.today  },
  "Week"  => lambda { 1.week.ago  },
  "Month" => lambda { 1.month.ago }
}

Instance Method Summary collapse

Constructor Details

#initialize(controller) ⇒ ExportDialog

Returns a new instance of ExportDialog.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/smartdict/gui/export_dialog.rb', line 22

def initialize(controller)
  @controller = controller
  super(
    "Export translations",
    nil,
    Gtk::FileChooser::ACTION_SAVE,
    nil,
    [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL],
    [Gtk::Stock::SAVE, Gtk::Dialog::RESPONSE_ACCEPT]
  )

  self.vbox.pack_start(options_table, false, false)
  show_all

  if run == Gtk::Dialog::RESPONSE_ACCEPT
    export_translations
  end
  destroy
end

Instance Method Details

#export_translationsObject



43
44
45
46
47
# File 'lib/smartdict/gui/export_dialog.rb', line 43

def export_translations
  format = @format_combo_box.selected_format
  options = {:since => since_date}
  @controller.export_translations(format, filename, options)
end

#init_date_range_buttonsObject



49
50
51
52
53
54
55
56
57
# File 'lib/smartdict/gui/export_dialog.rb', line 49

def init_date_range_buttons
  @date_range_buttons = {}
  button = nil
  DATE_RANGES.each do |name, block|
    args = button ? [button, name] : [name]
    button = Gtk::RadioButton.new(*args)
    @date_range_buttons[button] = block
  end
end

#options_tableGtk::Table

Returns:

  • (Gtk::Table)


60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/smartdict/gui/export_dialog.rb', line 60

def options_table
  table_width = DATE_RANGES.size + 2

  # Create table itself
  table = Gtk::Table.new(table_width, 2, false)
  table.column_spacings = 5

  # Format
  format_label = Label.new("Format:")
  @format_combo_box = FormatComboBox.new
  table.attach(format_label, 0, 1, 0, 1, Gtk::SHRINK, Gtk::SHRINK, 0, 0)
  table.attach_defaults(@format_combo_box, 1, table_width, 0, 1)

  # Date range
  date_range_label = Label.new("Date range:")
  init_date_range_buttons
  table.attach(date_range_label, 0, 1, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0)
  @date_range_buttons.keys.each_with_index do |button, index|
    table.attach(button, index+1, index+2, 1, 2, Gtk::SHRINK, Gtk::SHRINK, 0, 0)
  end

  # A trick to make radio buttons have left alignment
  table.attach_defaults(Label.new(''), table_width-1, table_width, 1, 2)
end

#since_dateObject



85
86
87
88
89
# File 'lib/smartdict/gui/export_dialog.rb', line 85

def since_date
  @date_range_buttons.each do |button, block|
    return block.call if button.active?
  end
end