Skip to content

Commit

Permalink
Add Application::Dialog.password_input for asking the user for a pass…
Browse files Browse the repository at this point in the history
…word.
  • Loading branch information
danlucraft committed Jul 31, 2010
1 parent d1e480d commit d2e69f7
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 8 additions & 0 deletions plugins/application/lib/application/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,14 @@ def self.available_message_box_types
def self.input(title, message, initial_value="", &validator)
Redcar.gui.dialog_adapter.input(title, message, initial_value, &validator)
end

# Show a dialog containing a password entry box to the user, and blocks
# until they dismiss it.
#
# The return value is a hash containing :button and :value.
def self.password_input(title, message)
Redcar.gui.dialog_adapter.password_input(title, message)
end

# Shows a tool tip to the user, at the cursor location.
#
Expand Down
34 changes: 30 additions & 4 deletions plugins/application_swt/lib/application_swt/dialog_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,31 @@ def available_message_box_button_combos
MESSAGE_BOX_BUTTON_COMBOS.keys
end

class InputDialog < JFace::Dialogs::InputDialog
def initialize(parentShell, dialogTitle, dialogMessage, initialValue, &block)
super(parentShell, dialogTitle, dialogMessage, initialValue, block)
class PasswordDialog < JFace::Dialogs::Dialog
def initialize(parent_shell, title, message)
super(parent_shell)
@title, @message = title, message
end

def createShell
def createDialogArea(parent)
composite = super(parent)

passwordLabel = Swt::Widgets::Label.new(composite, Swt::SWT::RIGHT)
passwordLabel.setText(@message)

@passwordField = Swt::Widgets::Text.new(composite, Swt::SWT::SINGLE | Swt::SWT::PASSWORD)
data = Swt::Layout::GridData.new(Swt::Layout::GridData::FILL_HORIZONTAL)
@passwordField.setLayoutData(data)

getShell.setText(@title)
end

def value
@password
end

def close
@password = @passwordField.getText
super
end
end
Expand All @@ -89,6 +108,13 @@ def input(title, message, initial_value, &block)
{:button => button, :value => dialog.getValue}
end

def password_input(title, message)
dialog = PasswordDialog.new(parent_shell, title, message)
code = dialog.open
button = (code == 0 ? :ok : :cancel)
{:button => button, :value => dialog.value}
end

def tool_tip(message, location)
tool_tip = Swt::Widgets::ToolTip.new(parent_shell, Swt::SWT::ICON_INFORMATION)
tool_tip.set_message(message)
Expand Down

0 comments on commit d2e69f7

Please sign in to comment.