Category management in place

This commit is contained in:
2010-06-22 11:35:21 +02:00
parent c322a01adb
commit 6f1d7734bf
5 changed files with 195 additions and 3 deletions

View File

@@ -158,11 +158,17 @@ void PreferencesPanel::InitCategories(User* user)
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE);
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE);
_categoriesGrid->SetCellAlignment(curLine, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
_categoriesIndexes[curLine] = it->second;
}
_categoriesGrid->SetReadOnly(0, CATEGORY_DELETE, true);
_categoriesGrid->AutoSizeColumns(true);
_categoriesGrid->AppendRows();
_categoriesGrid->SetReadOnly(curLine, CATEGORY_COLOR, true);
_categoriesGrid->SetReadOnly(curLine, CATEGORY_FONT, true);
_categoriesGrid->SetReadOnly(curLine, CATEGORY_DELETE, true);
SET_ROW_COLOR(curLine, OWN_GREEN);
}
@@ -316,4 +322,75 @@ void PreferencesPanel::OnAccountModified(wxGridEvent& event)
void PreferencesPanel::OnCategoryModified(wxGridEvent& event)
{
int op_complete = 1;
wxString value, categoryName ;
User* user = _kiss->GetUser();
int row = event.GetRow();
int col = event.GetCol();
static bool inModification = false ;
if (inModification) return;
inModification = true;
value = _categoriesGrid->GetCellValue(row, CATEGORY_NAME);
if (value != _(""))
{
categoryName = value;
op_complete--;
}
// Categories modification
if (user->GetCategoriesNumber() && row < user->GetCategoriesNumber())
{
if (col == CATEGORY_DELETE)
{
wxMessageDialog dialog(_wxUI, _("Are you sure want to delete : \n")+categoryName, _("KissCount"), wxYES_NO);
if (dialog.ShowModal() == wxID_NO)
{
_categoriesGrid->SetCellValue(row, col, _("0"));
}
else
{
_categoriesIndexes.erase(row);
_categoriesGrid->DeleteRows(row, 1);
_kiss->DeleteCategory(categoryName);
}
_wxUI->Layout();
inModification = false;
return;
}
_kiss->UpdateCategory(_categoriesIndexes[row], categoryName, _categoriesGrid->GetCellBackgroundColour(row, col));
}
// New category
else
{
if (op_complete)
{
inModification = false;
return ;
}
_categoriesIndexes[row] = categoryName;
_kiss->AddCategory(categoryName, _categoriesGrid->GetCellBackgroundColour(row, col));
_categoriesGrid->SetReadOnly(row, CATEGORY_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 ());
_categoriesGrid->SetCellAlignment(row, CATEGORY_COLOR, wxALIGN_CENTRE, wxALIGN_CENTRE);
_categoriesGrid->SetCellAlignment(row, CATEGORY_FONT, wxALIGN_CENTRE, wxALIGN_CENTRE);
_categoriesGrid->SetCellAlignment(row, CATEGORY_DELETE, wxALIGN_CENTRE, wxALIGN_CENTRE);
row++;
_categoriesGrid->AppendRows();
_categoriesGrid->SetReadOnly(row, CATEGORY_COLOR, true);
_categoriesGrid->SetReadOnly(row, CATEGORY_FONT, true);
_categoriesGrid->SetReadOnly(row, CATEGORY_DELETE, true);
SET_ROW_COLOR(row, OWN_GREEN);
}
return;
}