Class: DragonsKeep::KeepsMain
- Inherits:
-
Wx::Frame
- Object
- Wx::Frame
- DragonsKeep::KeepsMain
- Defined in:
- lib/dragons_keep/keeps_main.rb
Constant Summary collapse
- ID_FILE_NEW =
1001
- ID_FILE_CONNECT =
1002
- ID_FILE_DISCONNECT =
1003
- ID_ACCOUNT_NEW =
3001
- ID_ACCOUNT_EDIT =
3002
- ID_ACCOUNT_DELETE =
3003
- ID_EDIT_COPY =
2001
- ID_TOOL_NEW_ACCOUNT =
101
- ID_TOOL_EDIT_ACCOUNT =
102
- ID_TOOL_DELETE_ACCOUNT =
103
Instance Method Summary collapse
-
#initialize(title) ⇒ KeepsMain
constructor
A new instance of KeepsMain.
- #on_connect_database ⇒ Object
- #on_copy_password ⇒ Object
- #on_delete_account ⇒ Object
- #on_disconnect ⇒ Object
- #on_edit_account ⇒ Object
- #on_new_account ⇒ Object
- #on_new_database ⇒ Object
-
#on_quit ⇒ Object
End the application; it should finish automatically when the last window is closed.
Constructor Details
#initialize(title) ⇒ KeepsMain
Returns a new instance of KeepsMain.
22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dragons_keep/keeps_main.rb', line 22 def initialize(title) #create an instance of frame super(nil, :title => title, :size => [ 400, 300 ]) @account_controller = nil # Create status bar with one cell (1) create_tb create_contents register_events end |
Instance Method Details
#on_connect_database ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/dragons_keep/keeps_main.rb', line 59 def on_connect_database file_dialog = Wx::FileDialog.new(self, "Choose Keep File", :wildcard=>"Keep Files(*.keep)|*.keep") file_dialog.center_on_screen(Wx::BOTH) if file_dialog.show_modal == Wx::ID_OK password_dialog = Wx::PasswordEntryDialog.new(self, "Please enter the password for this database") if password_dialog.show_modal == Wx::ID_OK password = password_dialog.get_value file = file_dialog.get_path #puts file begin @account_controller = AccountController.new file, password @account_controller.establish_connection load_list rescue PasswordException dlg = Wx::MessageDialog.new(self, "The Password you entered is invalid", "Password", Wx::OK | Wx::ICON_ERROR) dlg.show_modal() @account_controller = nil end end end end |
#on_copy_password ⇒ Object
120 121 122 123 124 125 126 |
# File 'lib/dragons_keep/keeps_main.rb', line 120 def on_copy_password account = @list[@account_list.get_selection] @account_controller.decrypt!(account) Wx::Clipboard.open do | clip | clip.data = Wx::TextDataObject.new(account.unencrypted_password) end end |
#on_delete_account ⇒ Object
112 113 114 115 116 117 118 119 |
# File 'lib/dragons_keep/keeps_main.rb', line 112 def on_delete_account account = @list[@account_list.get_selection] dlg = Wx::MessageDialog.new(self, "Are you sure you wish to delete account #{account.name}", "Dragon's Keep", Wx::YES | Wx::NO | Wx::ICON_QUESTION) if dlg.show_modal() == Wx::ID_YES @account_controller.delete account load_list end end |
#on_disconnect ⇒ Object
81 82 83 84 85 |
# File 'lib/dragons_keep/keeps_main.rb', line 81 def on_disconnect @account_controller = nil @list = nil @account_list.clear end |
#on_edit_account ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/dragons_keep/keeps_main.rb', line 96 def on_edit_account begin account = @list[@account_list.get_selection] @account_controller.decrypt!(account) account_dialog = AccountDialog.new(self, -1, "Edit Account") account_dialog.center_on_screen(Wx::BOTH) account_dialog.account = account if account_dialog.show_modal()== Wx::ID_OK @account_controller.save!(account_dialog.account) load_list end rescue PasswordException dlg = Wx::MessageDialog.new(self, "The Password you entered is invalid", "Password", Wx::OK | Wx::ICON_ERROR) dlg.show_modal() end end |
#on_new_account ⇒ Object
87 88 89 90 91 92 93 94 95 |
# File 'lib/dragons_keep/keeps_main.rb', line 87 def on_new_account account_dialog = AccountDialog.new(self, -1, "New Account") account_dialog.center_on_screen(Wx::BOTH) account_dialog.account = Account.new if account_dialog.show_modal()== Wx::ID_OK @account_controller.save!(account_dialog.account) load_list end end |
#on_new_database ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/dragons_keep/keeps_main.rb', line 40 def on_new_database file_dialog = Wx::FileDialog.new(self, "Choose File for new Database", :wildcard=>"Keep Files(*.keep)|*.keep", :style=>Wx::FD_SAVE) file_dialog.center_on_screen(Wx::BOTH) if file_dialog.show_modal == Wx::ID_OK password_dialog = Wx::PasswordEntryDialog.new(self, "Please enter a password for this database") if password_dialog.show_modal == Wx::ID_OK password = password_dialog.get_value file = file_dialog.get_path if (file=~/.keep$/) == nil file << ".keep" end #puts file @account_controller = AccountController.new file, password @account_controller.establish_connection load_list # update_ui end end end |
#on_quit ⇒ Object
End the application; it should finish automatically when the last window is closed.
37 38 39 |
# File 'lib/dragons_keep/keeps_main.rb', line 37 def on_quit close() end |