Class | SSHMenu::MenuDialog |
In: |
lib/sshmenu.rb
(Git)
|
Parent: | Object |
The SSHMenu::MenuDialog class implements the dialog for editing a SSHMenu::MenuItem. Once the MenuDialog object has been constructed, its invoke method is called to display the dialog. When the user dismisses the dialog, the invoke method will return nil on cancel or the edited menu item on OK.
Constructor expects the following arguments:
# File lib/sshmenu.rb, line 2604 def initialize(app, menu) @app = app @menu = menu end
Helper routine, called from the invoke method to construct the dialog user interface.
# File lib/sshmenu.rb, line 2646 def build_dialog dialog = Gtk::Dialog.new( "Submenu Name", nil, Gtk::Dialog::MODAL | Gtk::Dialog::DESTROY_WITH_PARENT, [Gtk::Stock::OK, Gtk::Dialog::RESPONSE_ACCEPT], [Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_REJECT] ) dialog.default_response = Gtk::Dialog::RESPONSE_ACCEPT dialog.window_position = Gtk::Window::POS_MOUSE @body = Gtk::VBox.new(false, 0) @body.set_border_width(4) dialog.vbox.add(@body) label = Gtk::Label.new('Title') label.set_alignment(0, 1) @body.pack_start(label, false, true, 0) widget = Gtk::Entry.new widget.width_chars = 36 widget.text = @menu.title widget.activates_default = true @title_entry = widget @body.pack_start(widget, false, true, 0) dialog.show_all return dialog end
Validation routine - blocks saving if the title input is empty.
# File lib/sshmenu.rb, line 2635 def inputs_valid? if @title_entry.text.strip.length == 0 @app.alert('You must enter a title') return false end return true end
Causes the dialog to be displayed. The invoke method does not return until the user dismisses the dialog. If the user presses OK, the edited menu item will be returned, otherwise nil will be returned.
# File lib/sshmenu.rb, line 2613 def invoke dialog = build_dialog while true response = dialog.run if response == Gtk::Dialog::RESPONSE_ACCEPT break if inputs_valid? else dialog.destroy return end end @menu.title = @title_entry.text dialog.destroy return @menu end