Class | SSHMenu::HostDialog |
In: |
lib/sshmenu.rb
(Git)
|
Parent: | Object |
The SSHMenu::HostDialog class implements the dialog for editing a SSHMenu::HostItem. Once the HostDialog 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 host item on OK.
Constructor expects the following arguments:
# File lib/sshmenu.rb, line 2412 def initialize(app, item, config) @app = app @host = item @config = config end
Helper for build_dialog which adds a checkbox for enabling ‘bcvi’ forwarding.
# File lib/sshmenu.rb, line 2560 def add_bcvi_checkbox @enable_bcvi = Gtk::CheckButton.new( "Enable 'bcvi' forwarding?", false) @enable_bcvi.active = true if @host.enable_bcvi @body.pack_start(@enable_bcvi, false, true, 0) end
Helper for build_dialog which adds the ‘Geometry’ input and label to the dialog.
# File lib/sshmenu.rb, line 2532 def add_geometry_input box = Gtk::HBox.new(false, 4) @geometry_entry = entry = Gtk::Entry.new entry.text = @host.geometry || '' entry.activates_default = true box.pack_start(entry, true, true, 0) grabber = mapper.get_class('app.geograbber') btn = Gtk::Button.new('Grab') btn.sensitive = grabber.can_grab? btn.signal_connect('clicked') { grabber.grab { |g| entry.text = g } } box.pack_start(btn, false, false, 0) add_input('Geometry', @host.geometry, box) end
Helper for build_dialog which adds the ‘Hostname (etc)’ input and label to the dialog.
# File lib/sshmenu.rb, line 2525 def add_hostname_input @params_entry = add_input('Hostname (etc)', @host.sshparams, nil) end
Helper method for adding labelled input boxes to the dialog. The arguments are:
# File lib/sshmenu.rb, line 2572 def add_input(text, content, widget) label = Gtk::Label.new(text) label.set_alignment(0, 1) @body.pack_start(label, false, true, 0) if !widget widget = Gtk::Entry.new widget.width_chars = 36 widget.text = content || '' widget.activates_default = true end @body.pack_start(widget, false, true, 0) return widget end
Helper for build_dialog which adds additional input widgets after the geometry input. By default, the method will call add_bcvi_checkbox if ‘bcvi’ is installed.
# File lib/sshmenu.rb, line 2553 def add_other_inputs add_bcvi_checkbox if @app.have_bcvi? end
Helper for build_dialog which adds the ‘Title’ input and label to the dialog.
# File lib/sshmenu.rb, line 2518 def add_title_input @title_entry = add_input('Title', @host.title, nil) end
Helper routine, called from the invoke method to construct the dialog user interface.
# File lib/sshmenu.rb, line 2488 def build_dialog dialog = Gtk::Dialog.new( "Host Connection Details", nil, Gtk::Dialog::MODAL | Gtk::Dialog::DESTROY_WITH_PARENT, ['Test', TestResponse ], [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 dialog.screen = @app.display @body = Gtk::VBox.new(false, 0) @body.set_border_width(4) dialog.vbox.add(@body) add_title_input add_hostname_input add_geometry_input add_other_inputs dialog.show_all return dialog end
Copies values from the dialog input widgets back to attributes in the host object. If no host item is supplied, a new one will be created.
# File lib/sshmenu.rb, line 2468 def dialog_to_host(host=nil) host ||= mapper.get_class('app.model.hostitem').new host.title = @title_entry.text host.sshparams = @params_entry.text host.geometry = @geometry_entry.text host.enable_bcvi = @enable_bcvi.active? if @enable_bcvi return host end
Validation routine - blocks saving if the title or ssh params entry boxes are empty.
# File lib/sshmenu.rb, line 2453 def inputs_valid? if @title_entry.text.strip.length == 0 @app.alert('You must enter a title') return false end if @params_entry.text.strip.length == 0 @app.alert('You must enter a hostname') 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 host item will be returned, otherwise nil will be returned.
# File lib/sshmenu.rb, line 2428 def invoke dialog = build_dialog while true response = dialog.run if response == Gtk::Dialog::RESPONSE_ACCEPT break if inputs_valid? elsif response == TestResponse test_host else dialog.destroy return end end dialog_to_host(@host) dialog.destroy return @host end
Accessor for the SSHMenu::ClassMapper singleton object
# File lib/sshmenu.rb, line 2420 def mapper ClassMapper.instance end
Called when the ‘Test’ button is pressed. Creates a temporary SSHMenu::HostItem object from the current inputs and passes it to SSHMenu::App#open_win.
# File lib/sshmenu.rb, line 2481 def test_host @app.open_win(dialog_to_host) end