Fix bugs in account/category modification/deletion

Fix some strings
This commit is contained in:
2010-11-29 20:11:11 +01:00
parent c88c3b4836
commit 765483ff15
8 changed files with 188 additions and 151 deletions

View File

@@ -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<NUMBER_COLS_CATEGORY; i++) \
@@ -245,7 +257,8 @@ void PreferencesPanel::InitCategories(User* user)
std::vector<Category>::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; i<user->GetAccountsNumber(); 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; i<user->GetAccountsNumber(); 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();