From 765483ff155b6925877bba64f6694f522ed14311 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Mon, 29 Nov 2010 20:11:11 +0100 Subject: [PATCH] Fix bugs in account/category modification/deletion Fix some strings --- ressources/po/french.mo | Bin 7404 -> 7404 bytes ressources/po/french.po | 18 +-- src/controller/KissCount.cpp | 6 + src/model/Database.cpp | 9 +- src/view/AccountPanel.cpp | 35 +++-- src/view/GenerateDialog.cpp | 3 + src/view/PreferencesPanel.cpp | 265 ++++++++++++++++++---------------- src/view/PreferencesPanel.h | 3 + 8 files changed, 188 insertions(+), 151 deletions(-) diff --git a/ressources/po/french.mo b/ressources/po/french.mo index b82cc6783a983f6f32d336f3820c9bb76c8c0c09..1a83bcdb85d0ac71377a0a44302751d00a765371 100644 GIT binary patch delta 993 zcmXZaPe@cz6vy%NX3WVnOP!hYIph-zBXrej0wJ`2i|h|HZAxND5eZ6d7D?#~t|4mUes@^8*J`36H z5GGI~8$=a8gSsJy496~F45v_q3aAcmp*AWy=bevG2Yrls{sjj3!NnVxAr9m1wFv~M z!Us_chfyOMaq)H3t14m_KErB2evB+sMnAH`XmK}uPyv$mc=pZ)Cs z7wY6F>g2;N&ZFM#gmW5I_$F#nchSQKxDDss`hr`3iuz_=VlTdR`3h>kzu2V{ddyoL zbfXIQmp&(UHLJ$cFdLd9M$dipc+|1#rxwdO_;H?T?sGj z=l}=R92`O2cn+0#7!^2&3Vatev4>cI0jjX)&KIbOyur1OQ4^fUI4+{%Eu-%H>#^9! zB1Tq?tQi%!19ih;WH{D^Q9O?dbOF`bRaBy!^S1Los?bNM=bvF3U%UMhrr3M`Sm>Rm zs=~mHs0;g1BkFehEb3L|a2rmb63?PK{Ddm_3+h|?j-9xQG3;Qx>iiHY-!Y^x&$2Aq zIT%KUVee1@zoI^#pQz3)83v9aHCrXBz(!QyR$QAHYC>J8&NFx&hmcSfs|hDvi%Ig^ zZWijK4OMxk+n+$a+q2F=)GNAzN^lb+ID+f&p1VHku8*U>nMrKGm+t%rD&Gp$slq7p zRtMXidxN>cE%8V?_*}LcDQfAxG&6QOJJ6r;^A*>EY@#RXzpa|`Z&drm);7@FKbY>z Xq)+*E$(G<`@?*r`lZyMTsmK2Tg6(f1 diff --git a/ressources/po/french.po b/ressources/po/french.po index 5ee4538..00fa3bf 100644 --- a/ressources/po/french.po +++ b/ressources/po/french.po @@ -31,7 +31,7 @@ msgstr " - " #: src/view/PreferencesPanel.cpp:676 #: src/view/PreferencesPanel.cpp:722 msgid " already exists" -msgstr " existe déjà " +msgstr " existe déjà" #: src/view/SearchPanel.cpp:222 msgid " entries found" @@ -151,7 +151,7 @@ msgstr "Catégorie" #: src/view/PreferencesPanel.cpp:657 #: src/view/PreferencesPanel.cpp:676 msgid "Category " -msgstr "Catégorie" +msgstr "La catégorie " #: src/view/PreferencesPanel.cpp:77 msgid "Change Name" @@ -175,7 +175,7 @@ msgstr "Mode rapprochement" #: src/view/PasswordDialog.cpp:46 msgid "Confirm password " -msgstr "Confirmer le mot de passe" +msgstr "Confirmer le mot de passe " #: src/view/StatsPanel.cpp:130 #: src/view/AccountPanel.cpp:116 @@ -359,7 +359,7 @@ msgstr "Il doit y avoir au moins un compte !" #: src/view/AccountPanel.cpp:724 msgid "It must be at least one month !" -msgstr "Il doit rester au mois un mois" +msgstr "Il doit rester au moins un mois" #: src/view/PreferencesPanel.cpp:79 msgid "Kill me" @@ -400,7 +400,7 @@ msgstr "Nouvel utilisateur" #: src/view/PasswordDialog.cpp:41 msgid "New password " -msgstr "Nouveau mot de passe" +msgstr "Nouveau mot de passe " #: src/model/Database.cpp:135 msgid "" @@ -430,11 +430,11 @@ msgstr "OK" #: src/view/PasswordDialog.cpp:36 msgid "Old password " -msgstr "Ancien mot de passe" +msgstr "Ancien mot de passe " #: src/controller/KissCount.cpp:359 msgid "Operating exepense" -msgstr "Frais de fonctionnement" +msgstr "Fonctionnement" #: src/view/PreferencesPanel.cpp:62 msgid "Operation order" @@ -451,7 +451,7 @@ msgstr "Autres" #: src/view/UsersDialog.cpp:43 msgid "Password " -msgstr "Mot de passe" +msgstr "Mot de passe " #: src/view/PasswordDialog.cpp:84 msgid "Password changed" @@ -570,7 +570,7 @@ msgstr "Utilisateur" #: src/view/UsersDialog.cpp:118 #: src/view/PreferencesPanel.cpp:722 msgid "User " -msgstr "Utilisateur" +msgstr "Utilisateur " #: src/view/UsersDialog.cpp:30 msgid "Users" diff --git a/src/controller/KissCount.cpp b/src/controller/KissCount.cpp index d1892a6..33caf90 100644 --- a/src/controller/KissCount.cpp +++ b/src/controller/KissCount.cpp @@ -155,9 +155,15 @@ void KissCount::SetAccountAmount(int month, int year, const wxString& accountId, wxString KissCount::AddAccount(Account& ac) { + wxDateTime curDate; + ac.id = _db->AddAccount(_user, ac); _user->_accounts.push_back(ac); + curDate.SetToCurrent(); + + SetAccountAmount((int)curDate.GetMonth(), curDate.GetYear(), ac.id, 0.0); + return ac.id; } diff --git a/src/model/Database.cpp b/src/model/Database.cpp index 85b2a51..eb45981 100644 --- a/src/model/Database.cpp +++ b/src/model/Database.cpp @@ -329,10 +329,15 @@ User* Database::LoadUser(const wxString& name) category.forecolor = wxColour(set.GetAsString(wxT("forecolor"))); category.font = set.GetAsString(wxT("font")); if (category.name != _("Fix")) + { user->_categories.push_back(category); + user->_categoriesFonts.push_back(_kiss->ExtractFont(category.font)); + } else + { user->_categories.insert(user->_categories.begin(), category); - user->_categoriesFonts.push_back(_kiss->ExtractFont(category.font)); + user->_categoriesFonts.insert(user->_categoriesFonts.begin(), _kiss->ExtractFont(category.font)); + } } set.Finalize(); @@ -620,7 +625,7 @@ void Database::DeleteOperations(User* user, int month, int year) req += wxT("', '") + it->id ; } req += wxT("')"); - req += wxT(" OR user='") + user->_id + wxT("'"); + req += wxT(" OR user='") + user->_id + wxT("')"); req += wxT(" AND year='") + wxString::Format(wxT("%d"), year) + wxT("'"); if (month != -1) req += wxT(" AND month='") + wxString::Format(wxT("%d"), month) + wxT("'"); diff --git a/src/view/AccountPanel.cpp b/src/view/AccountPanel.cpp index 0a68f66..f90a83c 100644 --- a/src/view/AccountPanel.cpp +++ b/src/view/AccountPanel.cpp @@ -186,13 +186,13 @@ void AccountPanel::InitStatsGrid(User* user) _statsGrid->SetCellValue(TOTAL_CREDIT, 0, _("Total Credit")); _statsGrid->SetCellValue(TOTAL_DEBIT, 0, _("Total Debit")); - _statsGrid->AutoSizeColumn(0, false); - for(i=0; iGetCategoriesNumber(); i++) { _statsGrid->SetCellValue(CATS_STATS+i, 0, _categories[i]); _statsGrid->SetCellAlignment(CATS_STATS+i, 1, wxALIGN_RIGHT, wxALIGN_CENTRE); } + + _statsGrid->AutoSizeColumn(0, false); font.SetWeight(wxFONTWEIGHT_BOLD); _statsGrid->SetCellFont(CUR_CREDIT, 0, font); _statsGrid->SetCellFont(CUR_DEBIT, 0, font); @@ -227,21 +227,30 @@ void AccountPanel::ChangeUser() rootNode = _tree.AddRoot(wxT("")); curDate.SetToCurrent(); - for(it = ops.begin(); it != ops.end(); it++) + if (ops.size()) { - if ((int)it->first <= curDate.GetYear()) + for(it = ops.begin(); it != ops.end(); it++) { - curYear = it->first; - curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); + if ((int)it->first <= curDate.GetYear()) + { + curYear = it->first; + curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); + } + else + _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); + } + Fit(); + if (curYear != -1) + { + _tree.SelectItem(curNode, true); + LoadYear(curYear); } - else - _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), it->first)); } - Fit(); - if (curYear != -1) + else { - _tree.SelectItem(curNode, true); - LoadYear(curYear); + curNode = _tree.AppendItem(rootNode, wxString::Format(wxT("%d"), curDate.GetYear())); + _tree.AppendItem(curNode, months[(int)curDate.GetYear()]); + Fit(); } } @@ -719,7 +728,7 @@ void AccountPanel::OnMenuDelete(wxCommandEvent& event) ops = _kiss->GetAllOperations(); - if (ops.size() == 1 && ops[year].size() == 1) + if (ops.size() == 1 && (ops[year].size() == 1 || month == -1)) { wxMessageBox(_("It must be at least one month !"), _("Error"), wxICON_ERROR | wxOK); return; diff --git a/src/view/GenerateDialog.cpp b/src/view/GenerateDialog.cpp index cae65ce..9019318 100644 --- a/src/view/GenerateDialog.cpp +++ b/src/view/GenerateDialog.cpp @@ -111,7 +111,10 @@ GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int yea _yearTo->Select(year-2000); OnYearToChange(event); if (_ops[year].size()) + { month = _ops[year][0]; + _yearTo->Select(year-1999); + } if (month == -1) _monthTo->Select(0); diff --git a/src/view/PreferencesPanel.cpp b/src/view/PreferencesPanel.cpp index 91060aa..7e73bf6 100644 --- a/src/view/PreferencesPanel.cpp +++ b/src/view/PreferencesPanel.cpp @@ -191,42 +191,54 @@ void PreferencesPanel::InitAccounts(User* user) for (it = user->_accounts.begin(); it != user->_accounts.end(); it++, curLine++) { _accountsGrid->AppendRows(); - - _accountsGrid->SetCellValue(curLine, ACCOUNT_NAME, it->name); - if (it->shared) - _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number + wxT("*")); - else - _accountsGrid->SetCellValue(curLine, ACCOUNT_NUMBER, it->number); - - _accountsGrid->SetCellEditor(curLine, ACCOUNT_NUMBER, new wxGridCellStarEditor ()); - _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); - _accountsGrid->SetCellRenderer(curLine, ACCOUNT_BLOCKED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_BLOCKED, new wxGridCellFastBoolEditor ()); - _accountsGrid->SetCellRenderer(curLine, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(curLine, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellValue(curLine, ACCOUNT_DEFAULT, (it->_default)?wxT("1"):wxT("0")); - _accountsGrid->SetCellValue(curLine, ACCOUNT_BLOCKED, (it->blocked)?wxT("1"):wxT("0")); - - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_BLOCKED, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(curLine, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - - if (!it->is_owner) - { - _accountsGrid->SetReadOnly(curLine, ACCOUNT_NAME, true); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_NUMBER, true); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_DEFAULT, true); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_BLOCKED, true); - } + AddAccount(curLine, *it); } - _accountsGrid->AutoSizeColumns(true); _accountsGrid->AppendRows(); + account.id = wxT("0"); + AddAccount(curLine, account); +} - _accountsGrid->SetReadOnly(curLine, ACCOUNT_DEFAULT, true); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_BLOCKED, true); - _accountsGrid->SetReadOnly(curLine, ACCOUNT_DELETE, true); +void PreferencesPanel::AddAccount(int line, Account ac) +{ + if (ac.id != wxT("0")) + { + _accountsGrid->SetCellValue(line, ACCOUNT_NAME, ac.name); + if (ac.shared) + _accountsGrid->SetCellValue(line, ACCOUNT_NUMBER, ac.number + wxT("*")); + else + _accountsGrid->SetCellValue(line, ACCOUNT_NUMBER, ac.number); + + _accountsGrid->SetCellEditor(line, ACCOUNT_NUMBER, new wxGridCellStarEditor ()); + _accountsGrid->SetCellRenderer(line, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(line, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); + _accountsGrid->SetCellRenderer(line, ACCOUNT_BLOCKED, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(line, ACCOUNT_BLOCKED, new wxGridCellFastBoolEditor ()); + _accountsGrid->SetCellRenderer(line, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); + _accountsGrid->SetCellEditor(line, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); + _accountsGrid->SetCellValue(line, ACCOUNT_DEFAULT, (ac._default)?wxT("1"):wxT("0")); + _accountsGrid->SetCellValue(line, ACCOUNT_BLOCKED, (ac.blocked)?wxT("1"):wxT("0")); + + _accountsGrid->SetCellAlignment(line, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(line, ACCOUNT_BLOCKED, wxALIGN_CENTRE, wxALIGN_CENTRE); + _accountsGrid->SetCellAlignment(line, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + + if (!ac.is_owner) + { + _accountsGrid->SetReadOnly(line, ACCOUNT_NAME, true); + _accountsGrid->SetReadOnly(line, ACCOUNT_NUMBER, true); + _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true); + _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true); + } + } + else + { + _accountsGrid->SetReadOnly(line, ACCOUNT_DEFAULT, true); + _accountsGrid->SetReadOnly(line, ACCOUNT_BLOCKED, true); + _accountsGrid->SetReadOnly(line, ACCOUNT_DELETE, true); + + _accountsGrid->AutoSizeColumns(true); + } } #define SET_ROW_COLOR(row, backcolor, forecolor) for(int i=0; i::iterator it; int curLine = 0; DEFAULT_FONT(font); - + Category cat; + _categoriesGrid->CreateGrid(0, NUMBER_COLS_CATEGORY); _categoriesGrid->SetRowLabelSize(0); _categoriesGrid->SetDefaultCellFont(font); @@ -259,41 +272,56 @@ void PreferencesPanel::InitCategories(User* user) for (it=user->_categories.begin(); it!=user->_categories.end(); it++, curLine++) { _categoriesGrid->AppendRows(); - - _categoriesGrid->SetCellValue(curLine, CATEGORY_NAME, it->name); - SET_ROW_COLOR(curLine, it->backcolor, it->forecolor); - if (curLine) - { - _categoriesGrid->SetCellRenderer(curLine, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); - _categoriesGrid->SetCellEditor(curLine, CATEGORY_DELETE, new wxGridCellBoolEditor ()); - } - - _categoriesGrid->SetCellRenderer(curLine, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonRenderer (wxT("..."))); - _categoriesGrid->SetCellRenderer(curLine, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonRenderer (wxT("..."))); - _categoriesGrid->SetCellRenderer(curLine, CATEGORY_FONT, new wxGridCellButtonRenderer (wxT("..."))); - _categoriesGrid->SetCellEditor(curLine, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonEditor (wxT("..."))); - _categoriesGrid->SetCellEditor(curLine, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonEditor (wxT("..."))); - _categoriesGrid->SetCellEditor(curLine, CATEGORY_FONT, new wxGridCellButtonEditor (wxT("..."))); - - if (it->font.Length()) - { - wxFont font = user->GetCategoryFont(it->id); - SET_ROW_FONT(curLine, font); - } - - _categoriesGrid->SetCellAlignment(curLine, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + AddCategory(curLine, *it); } _categoriesGrid->SetReadOnly(0, CATEGORY_NAME, true); _categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true); - _categoriesGrid->AutoSizeColumns(true); + cat.id = wxT("0"); _categoriesGrid->AppendRows(); - _categoriesGrid->SetReadOnly(curLine, CATEGORY_BACKGROUND_COLOR, true); - _categoriesGrid->SetReadOnly(curLine, CATEGORY_FOREGROUND_COLOR, true); - _categoriesGrid->SetReadOnly(curLine, CATEGORY_FONT, true); - _categoriesGrid->SetReadOnly(curLine, CATEGORY_DELETE, true); - SET_ROW_COLOR(curLine, OWN_GREEN, *wxBLACK); + AddCategory(curLine, cat); +} + +void PreferencesPanel::AddCategory(int line, Category cat) +{ + User* user = _kiss->GetUser(); + + if (cat.id != wxT("0")) + { + _categoriesGrid->SetCellValue(line, CATEGORY_NAME, cat.name); + SET_ROW_COLOR(line, cat.backcolor, cat.forecolor); + if (line) + { + _categoriesGrid->SetCellRenderer(line, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); + _categoriesGrid->SetCellEditor(line, CATEGORY_DELETE, new wxGridCellBoolEditor ()); + } + + _categoriesGrid->SetCellRenderer(line, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonRenderer (wxT("..."))); + _categoriesGrid->SetCellRenderer(line, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonRenderer (wxT("..."))); + _categoriesGrid->SetCellRenderer(line, CATEGORY_FONT, new wxGridCellButtonRenderer (wxT("..."))); + _categoriesGrid->SetCellEditor(line, CATEGORY_BACKGROUND_COLOR, new wxGridCellButtonEditor (wxT("..."))); + _categoriesGrid->SetCellEditor(line, CATEGORY_FOREGROUND_COLOR, new wxGridCellButtonEditor (wxT("..."))); + _categoriesGrid->SetCellEditor(line, CATEGORY_FONT, new wxGridCellButtonEditor (wxT("..."))); + + if (cat.font.Length()) + { + wxFont font = user->GetCategoryFont(cat.id); + SET_ROW_FONT(line, font); + } + + _categoriesGrid->SetCellAlignment(line, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); + } + else + { + _categoriesGrid->SetReadOnly(line, CATEGORY_BACKGROUND_COLOR, true); + _categoriesGrid->SetReadOnly(line, CATEGORY_FOREGROUND_COLOR, true); + _categoriesGrid->SetReadOnly(line, CATEGORY_FONT, true); + _categoriesGrid->SetReadOnly(line, CATEGORY_DELETE, true); + SET_ROW_COLOR(line, OWN_GREEN, *wxBLACK); + + _categoriesGrid->AutoSizeColumns(true); + } } void PreferencesPanel::InitLanguage(User* user) @@ -362,24 +390,6 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) else new_account.blocked = false; - if (col == ACCOUNT_DEFAULT) - { - for (i=0; iGetAccountsNumber(); i++) - { - if (i != row) - { - account = user->_accounts[i]; - if (account._default) - { - account._default = false; - _kiss->UpdateAccount(account); - _accountsGrid->SetCellValue(i, ACCOUNT_DEFAULT, wxT("")); - break; - } - } - } - } - // Account modification if (user->GetAccountsNumber() && row < user->GetAccountsNumber()) { @@ -406,18 +416,48 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) _kiss->DeleteAccount(new_account); } + if (user->_accounts.size() == 1) + { + user->_accounts[0]._default = true; + _kiss->UpdateAccount(user->_accounts[0]); + _accountsGrid->SetCellValue(0, ACCOUNT_DEFAULT, wxT("1")); + } + _wxUI->Layout(); inModification = false; _wxUI->NeedReload(); return; } - if (user->GetAccountId(new_account.name) != new_account.id) + if (col == ACCOUNT_DEFAULT) { - wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); - _accountsGrid->SetCellValue(row, ACCOUNT_NAME, user->_accounts[row].name); - inModification = false; - return ; + for (i=0; iGetAccountsNumber(); i++) + { + if (i != row) + { + account = user->_accounts[i]; + if (account._default) + { + account._default = false; + _kiss->UpdateAccount(account); + _accountsGrid->SetCellValue(i, ACCOUNT_DEFAULT, wxT("")); + break; + } + } + } + } + + + if (col == ACCOUNT_NAME) + { + value = user->GetAccountId(new_account.name); + if (value != wxT("0") && value != new_account.id) + { + wxMessageBox(_("Account ")+new_account.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); + _accountsGrid->SetCellValue(row, ACCOUNT_NAME, user->_accounts[row].name); + inModification = false; + return ; + } } _kiss->UpdateAccount(new_account); @@ -441,34 +481,13 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event) new_account.shared = false; new_account.blocked = false; - _accountsGrid->SetCellRenderer(row, ACCOUNT_DEFAULT, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_DEFAULT, new wxGridCellFastBoolEditor ()); - _accountsGrid->SetCellRenderer(row, ACCOUNT_BLOCKED, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_BLOCKED, new wxGridCellFastBoolEditor ()); - _accountsGrid->SetCellRenderer(row, ACCOUNT_DELETE, new wxGridCellBoolRenderer ()); - _accountsGrid->SetCellEditor(row, ACCOUNT_DELETE, new wxGridCellBoolEditor ()); - _accountsGrid->SetCellAlignment(row, ACCOUNT_DEFAULT, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(row, ACCOUNT_BLOCKED, wxALIGN_CENTRE, wxALIGN_CENTRE); - _accountsGrid->SetCellAlignment(row, ACCOUNT_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE); - - _accountsGrid->SetReadOnly(row, ACCOUNT_DEFAULT, false); - _accountsGrid->SetReadOnly(row, ACCOUNT_BLOCKED, false); - _accountsGrid->SetReadOnly(row, ACCOUNT_DELETE, false); - - if (!user->GetAccountsNumber()) - { - new_account._default = true; - _accountsGrid->SetCellValue(row, ACCOUNT_DEFAULT, wxT("1")); - } - - _accountsGrid->AutoSizeColumns(true); - _accountsGrid->AppendRows(); - - _accountsGrid->SetReadOnly(row+1, ACCOUNT_DEFAULT, true); - _accountsGrid->SetReadOnly(row+1, ACCOUNT_BLOCKED, true); - _accountsGrid->SetReadOnly(row+1, ACCOUNT_DELETE, true); - + AddAccount(row, new_account); _kiss->AddAccount(new_account); + + _accountsGrid->AppendRows(); + new_account.id = wxT("0"); + + AddAccount(row, new_account); } _wxUI->Layout(); @@ -552,7 +571,7 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event) int row = event.GetRow(); int col = event.GetCol(); static bool inModification = false ; - Category new_cat; + Category new_cat, cat_tmp; if (inModification) return; @@ -652,7 +671,8 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event) return; } - if (user->GetCategoryId(new_cat.name) != new_cat.id) + value = user->GetCategoryId(new_cat.name); + if (value != wxT("0") && value != new_cat.id) { wxMessageBox(_("Category ")+new_cat.name+_(" already exists"), _("Error"), wxICON_ERROR | wxOK ); _categoriesGrid->SetCellValue(row, CATEGORY_NAME, user->_categories[row].name); @@ -679,20 +699,11 @@ void PreferencesPanel::OnCategoryModified(wxGridEvent& event) } _kiss->AddCategory(new_cat); - _categoriesGrid->SetReadOnly(row, CATEGORY_BACKGROUND_COLOR, false); - _categoriesGrid->SetReadOnly(row, CATEGORY_FOREGROUND_COLOR, false); - _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, false); - _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, false); - _categoriesGrid->SetCellRenderer(row, CATEGORY_DELETE, new wxGridCellBoolRenderer ()); - _categoriesGrid->SetCellEditor(row, CATEGORY_DELETE, new wxGridCellBoolEditor ()); + AddCategory(row, new_cat); - row++; - _categoriesGrid->AppendRows(); - _categoriesGrid->SetReadOnly(row, CATEGORY_BACKGROUND_COLOR, true); - _categoriesGrid->SetReadOnly(row, CATEGORY_FOREGROUND_COLOR, true); - _categoriesGrid->SetReadOnly(row, CATEGORY_FONT, true); - _categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, true); - SET_ROW_COLOR(row, OWN_GREEN, *wxBLACK); + new_cat.id = wxT("0"); + _categoriesGrid->AppendRows(); + AddCategory(++row, new_cat); } _wxUI->Layout(); diff --git a/src/view/PreferencesPanel.h b/src/view/PreferencesPanel.h index 24b4f85..e45437c 100644 --- a/src/view/PreferencesPanel.h +++ b/src/view/PreferencesPanel.h @@ -75,6 +75,9 @@ private: void InitLanguage(User* user); void InitOperationOrder(User* user); + void AddAccount(int line, Account ac); + void AddCategory(int line, Category cat); + DECLARE_EVENT_TABLE(); };