1
0
forked from cheng/wallet

Cleaned up the add name on the dry prinicple

fixed bug in the position of the inserted
name that happened with names identical
except for capitalization.
This commit is contained in:
Cheng 2023-11-12 04:44:17 +00:00
parent 55d0d69c8f
commit c65f2fbf6e
No known key found for this signature in database
GPG Key ID: 571C3A9C3B9E6FCA
2 changed files with 37 additions and 32 deletions

View File

@ -9,7 +9,7 @@ display_wallet::display_wallet(wxWindow* parent, wxFileName& walletfile) :
m_read_from_misc(m_db), m_read_from_misc(m_db),
m_insert_name(m_db), m_insert_name(m_db),
m_find_position(m_db, R"|( SELECT COUNT(*) FROM UserZookoIDs m_find_position(m_db, R"|( SELECT COUNT(*) FROM UserZookoIDs
WHERE LOWER("name")<LOWER(?1) AND "name"<?1;)|") WHERE LOWER("name")<LOWER(?1) OR (LOWER("name")=LOWER(?1) AND "name"<?1);)|")
{ {
wxLogMessage(wxT("Loading %s"), walletfile.GetFullPath()); wxLogMessage(wxT("Loading %s"), walletfile.GetFullPath());
try { try {
@ -59,6 +59,39 @@ void display_wallet::close_menu_event_handler(wxCommandEvent& event) {
Close(true); Close(true);
} }
struct display_wallet::cleanup {
cleanup() = delete;
// copy constructor
cleanup(const cleanup& a) = delete;
// move constructor
cleanup(cleanup&& p) = delete;
// copy assignment
cleanup& operator=(cleanup) = delete;
// Move assignment
cleanup& operator=(cleanup&&) = delete;
display_wallet* m_win;
wxSizer* sizer;
wxSize dirty_area;
cleanup(display_wallet* win) :
m_win(win),
sizer(win->GetSizer()),
dirty_area(sizer->ComputeFittingClientSize(singletonFrame))
{
assert(sizer);
}
~cleanup() {
auto desired_size = sizer->ComputeFittingClientSize(singletonFrame);
dirty_area.IncTo(desired_size);
//singletonFrame->SetMinClientSize(desired_size);
auto clientSize = singletonFrame->GetClientSize();
desired_size.IncTo(clientSize);
if (desired_size.GetHeight() > clientSize.GetHeight()
|| desired_size.GetWidth() > clientSize.GetWidth()
)singletonFrame->SetClientSize(desired_size);
}
};
void display_wallet::add_name_event_handler(wxCommandEvent& event) { void display_wallet::add_name_event_handler(wxCommandEvent& event) {
wxTextEntryDialog dialog(this, wxTextEntryDialog dialog(this,
R"("A Zooko name has a human readable name, R"("A Zooko name has a human readable name,
@ -76,13 +109,8 @@ and a public key defined by the name and the wallet master secret)",
pubkey pubkey
); );
m_find_position.read_one(zookoNickname_psz); m_find_position.read_one(zookoNickname_psz);
auto sizer = this->GetSizer();
auto dirty_area = sizer->ComputeFittingClientSize(singletonFrame);
auto m_lsizer = sizer->GetItem((size_t)0)->GetSizer();
assert(m_lsizer);
auto m_rsizer = sizer->GetItem(1)->GetSizer();
assert(m_rsizer);
auto position = m_find_position.column<int64_t>(0); auto position = m_find_position.column<int64_t>(0);
cleanup cln(this);
m_lSizer->Insert(position, m_lSizer->Insert(position,
new wxStaticText( new wxStaticText(
this, this,
@ -103,15 +131,6 @@ and a public key defined by the name and the wallet master secret)",
10, 10,
wxALL, // and make border all around wxALL, // and make border all around
2); 2);
auto desired_size = sizer->ComputeFittingClientSize(singletonFrame);
dirty_area.IncTo(desired_size);
//singletonFrame->SetMinClientSize(desired_size);
auto clientSize = singletonFrame->GetClientSize();
desired_size.IncTo(clientSize);
if (desired_size.GetHeight() > clientSize.GetHeight()
|| desired_size.GetWidth() > clientSize.GetWidth()
)singletonFrame->SetClientSize(desired_size);
} }
} }
@ -129,14 +148,7 @@ void display_wallet::OnClose(wxCloseEvent& event) {
} }
void display_wallet::refresh_from_database() { void display_wallet::refresh_from_database() {
auto sizer = this->GetSizer(); cleanup cln(this);
auto dirty_area = sizer->ComputeFittingClientSize(singletonFrame);
auto m_lsizer = sizer->GetItem((size_t)0)->GetSizer();
assert(m_lsizer);
auto m_rsizer = sizer->GetItem(1)->GetSizer();
assert(m_rsizer);
m_lsizer->Clear(true);
m_rsizer->Clear(true);
try { try {
m_read_names_and_keys.reset(); m_read_names_and_keys.reset();
while (m_read_names_and_keys.step() == Icompiled_sql::ROW) { while (m_read_names_and_keys.step() == Icompiled_sql::ROW) {
@ -177,12 +189,4 @@ void display_wallet::refresh_from_database() {
szError = sz_unknown_error; szError = sz_unknown_error;
throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename); throw MyException(sz_unknown_error, __LINE__, __func__, SrcFilename);
} }
auto desired_size = sizer->ComputeFittingClientSize(singletonFrame);
dirty_area.IncTo(desired_size);
//singletonFrame->SetMinClientSize(desired_size);
auto clientSize = singletonFrame->GetClientSize();
desired_size.IncTo(clientSize);
if (desired_size.GetHeight() > clientSize.GetHeight()
|| desired_size.GetWidth() > clientSize.GetWidth()
)singletonFrame->SetClientSize(desired_size);
} }

View File

@ -5,6 +5,7 @@ public:
display_wallet(wxWindow*, wxFileName&); display_wallet(wxWindow*, wxFileName&);
~display_wallet(); ~display_wallet();
private: private:
struct cleanup;
typedef MenuLink<display_wallet> MenuLink; typedef MenuLink<display_wallet> MenuLink;
ro::dbconnect m_db; ro::dbconnect m_db;
sql_read_from_misc m_read_from_misc; sql_read_from_misc m_read_from_misc;