Class: Alexandria::UI::ExportDialog

Inherits:
Object
  • Object
show all
Extended by:
GetText
Includes:
GetText
Defined in:
lib/alexandria/ui/export_dialog.rb

Constant Summary collapse

FORMATS =
Alexandria::ExportFormat.all
THEMES =
Alexandria::WebTheme.all

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(parent, library, sort_order) ⇒ ExportDialog

Returns a new instance of ExportDialog.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/alexandria/ui/export_dialog.rb', line 23

def initialize(parent, library, sort_order)
  @dialog = Gtk::FileChooserDialog.new(title: _("Export '%s'") % library.name,
                                       parent: parent,
                                       action: :save,
                                       buttons: [[Gtk::Stock::HELP, :help],
                                                 [Gtk::Stock::CANCEL, :cancel],
                                                 [_("_Export"), :accept]])
  @dialog.current_name = library.name
  @dialog.signal_connect("destroy") { @dialog.hide }

  @parent = parent
  @library = library
  @sort_order = sort_order

  preview_image = Gtk::Image.new

  @theme_combo = Gtk::ComboBoxText.new
  @theme_combo.valign = :center
  @theme_combo.vexpand = false
  THEMES.each do |theme|
    @theme_combo.append_text(theme.name)
  end
  @theme_combo.signal_connect("changed") do
    file = THEMES[@theme_combo.active].preview_file
    preview_image.pixbuf = GdkPixbuf::Pixbuf.new(file: file)
  end
  @theme_combo.active = 0
  theme_label = Gtk::Label.new(_("_Theme:"), use_underline: true)
  theme_label.xalign = 0
  theme_label.mnemonic_widget = @theme_combo

  @types_combo = Gtk::ComboBoxText.new
  @types_combo.vexpand = false
  @types_combo.valign = :center
  FORMATS.each do |format|
    text = format.name + " ("
    text += if format.ext
              "*." + format.ext
            else
              _("directory")
            end
    text += ")"
    @types_combo.append_text(text)
  end
  @types_combo.active = 0
  @types_combo.signal_connect("changed") do
    visible = FORMATS[@types_combo.active].needs_preview?
    theme_label.visible = @theme_combo.visible = preview_image.visible = visible
  end
  @types_combo.show

  types_label = Gtk::Label.new(_("Export for_mat:"), use_underline: true)
  types_label.xalign = 0
  types_label.mnemonic_widget = @types_combo
  types_label.show

  # TODO: Re-design extra widget layout
  grid = Gtk::Grid.new
  grid.column_spacing = 6
  grid.attach types_label, 0, 0, 1, 1
  grid.attach @types_combo, 1, 0, 1, 1
  grid.attach theme_label, 0, 1, 1, 1
  grid.attach @theme_combo, 1, 1, 1, 1
  grid.attach preview_image, 2, 0, 1, 3
  @dialog.set_extra_widget grid
end

Instance Attribute Details

#dialogObject (readonly)

Returns the value of attribute dialog.



21
22
23
# File 'lib/alexandria/ui/export_dialog.rb', line 21

def dialog
  @dialog
end

Instance Method Details

#performObject



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/alexandria/ui/export_dialog.rb', line 90

def perform
  while ((response = dialog.run) != Gtk::ResponseType::CANCEL) &&
      (response != Gtk::ResponseType::DELETE_EVENT)

    if response == Gtk::ResponseType::HELP
      Alexandria::UI.display_help(self, "exporting")
    else
      begin
        break if on_export(FORMATS[@types_combo.active],
                           THEMES[@theme_combo.active])
      rescue StandardError => ex
        ErrorDialog.new(@dialog, _("Export failed"), ex.message).display
        break
      end
    end
  end
  dialog.destroy
end