Move directories, fix a bug into month generation (tree), add tooltips
This commit is contained in:
212
src/view/GenerateDialog.cpp
Normal file
212
src/view/GenerateDialog.cpp
Normal file
@@ -0,0 +1,212 @@
|
||||
#include "GenerateDialog.h"
|
||||
|
||||
enum {BUTTON_OK_ID=1, BUTTON_CANCEL_ID, YEAR_FROM_ID, MONTH_FROM_ID, YEAR_TO_ID, MONTH_TO_ID};
|
||||
|
||||
BEGIN_EVENT_TABLE(GenerateDialog, wxDialog)
|
||||
EVT_BUTTON(BUTTON_OK_ID, GenerateDialog::OnOK)
|
||||
EVT_BUTTON(BUTTON_CANCEL_ID, GenerateDialog::OnCancel)
|
||||
EVT_CHOICE(YEAR_FROM_ID, GenerateDialog::OnYearFromChange)
|
||||
EVT_CHOICE(YEAR_TO_ID, GenerateDialog::OnYearToChange)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
GenerateDialog::GenerateDialog(KissCount* kiss, wxUI *parent, int month, int year) : wxDialog(&(*parent), -1, _("Generate month")), _kiss(kiss), _wxUI(parent)
|
||||
{
|
||||
wxGridBagSizer *gridBagSizer;
|
||||
wxStaticText* label;
|
||||
std::map<int, std::vector<int> >::iterator it;
|
||||
int i, a, toSelect=-1;
|
||||
wxDateTime curDate;
|
||||
wxCommandEvent event;
|
||||
std::vector<int>::iterator monthIt;
|
||||
|
||||
curDate.SetToCurrent();
|
||||
|
||||
gridBagSizer = new wxGridBagSizer(4, 5);
|
||||
|
||||
label = new wxStaticText(this, -1, _("From "));
|
||||
gridBagSizer->Add(label, wxGBPosition(0, 0));
|
||||
_yearFrom = new wxChoice(this, YEAR_FROM_ID);
|
||||
gridBagSizer->Add(_yearFrom, wxGBPosition(0, 1));
|
||||
_monthFrom = new wxChoice(this, MONTH_FROM_ID);
|
||||
gridBagSizer->Add(_monthFrom, wxGBPosition(0, 2));
|
||||
|
||||
label = new wxStaticText(this, -1, _("To "));
|
||||
gridBagSizer->Add(label, wxGBPosition(1, 0));
|
||||
_yearTo = new wxChoice(this, YEAR_TO_ID);
|
||||
gridBagSizer->Add(_yearTo, wxGBPosition(1, 1));
|
||||
_monthTo = new wxChoice(this, MONTH_TO_ID);
|
||||
gridBagSizer->Add(_monthTo, wxGBPosition(1, 2));
|
||||
|
||||
wxButton* ok = new wxButton(this, BUTTON_OK_ID, _("OK"));
|
||||
wxButton* cancel = new wxButton(this, BUTTON_CANCEL_ID, _("Cancel"));
|
||||
gridBagSizer->Add(ok, wxGBPosition(3, 3));
|
||||
gridBagSizer->Add(cancel, wxGBPosition(3, 4));
|
||||
|
||||
_ops = _kiss->GetAllOperations();
|
||||
|
||||
_yearFrom->Append(wxT(""));
|
||||
_monthFrom->Append(wxT(""));
|
||||
|
||||
for(i=1, it = _ops.begin(); it != _ops.end(); it++, i++)
|
||||
{
|
||||
_yearFrom->Append(wxString::Format(wxT("%d"), it->first));
|
||||
if (year == it->first)
|
||||
toSelect = i;
|
||||
}
|
||||
|
||||
if (toSelect != -1)
|
||||
{
|
||||
_yearFrom->Select(toSelect);
|
||||
OnYearFromChange(event);
|
||||
toSelect=0;
|
||||
if (month != -1)
|
||||
{
|
||||
for(i=0; i<(int)_monthFrom->GetCount(); i++)
|
||||
{
|
||||
if (_monthFrom->GetString(i) == months[month])
|
||||
{
|
||||
toSelect = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
_monthFrom->Select(toSelect);
|
||||
}
|
||||
else
|
||||
{
|
||||
_yearFrom->Select(0);
|
||||
OnYearFromChange(event);
|
||||
}
|
||||
|
||||
for(i=2000; i<=2050; i++)
|
||||
_yearTo->Append(wxString::Format(wxT("%d"), i));
|
||||
|
||||
if (year == -1)
|
||||
{
|
||||
_yearTo->Select(curDate.GetYear()-2000);
|
||||
OnYearToChange(event);
|
||||
_monthTo->Select(curDate.GetMonth()-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
_yearTo->Select(year-2000);
|
||||
OnYearToChange(event);
|
||||
if (_ops[year].size())
|
||||
month = _ops[year][0];
|
||||
|
||||
if (month == -1)
|
||||
_monthTo->Select(0);
|
||||
else
|
||||
{
|
||||
for(a=0, i=0, monthIt=_ops[year].begin(); monthIt!=_ops[year].end() && i<12; i++)
|
||||
{
|
||||
if (i != *monthIt)
|
||||
{
|
||||
a++;
|
||||
continue;
|
||||
}
|
||||
if (*monthIt > month)
|
||||
break;
|
||||
monthIt++;
|
||||
}
|
||||
_monthTo->Select(a);
|
||||
}
|
||||
}
|
||||
|
||||
SetSizer(gridBagSizer);
|
||||
|
||||
Layout();
|
||||
Center();
|
||||
}
|
||||
|
||||
void GenerateDialog::OnYearFromChange(wxCommandEvent& event)
|
||||
{
|
||||
wxString years = _yearFrom->GetString(_yearFrom->GetCurrentSelection());
|
||||
int year;
|
||||
std::vector<int>::iterator it;
|
||||
|
||||
_monthFrom->Clear();
|
||||
|
||||
if (years == wxT(""))
|
||||
{
|
||||
_monthFrom->Append(wxT(""));
|
||||
return;
|
||||
}
|
||||
|
||||
year = wxAtoi(years);
|
||||
|
||||
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
|
||||
_monthFrom->Append(months[*it]);
|
||||
_monthFrom->Select(0);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void GenerateDialog::OnYearToChange(wxCommandEvent& event)
|
||||
{
|
||||
int year, i, ok;
|
||||
std::vector<int>::iterator it;
|
||||
|
||||
_monthTo->Clear();
|
||||
|
||||
year = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection()));
|
||||
|
||||
for (i=0; i<12; i++)
|
||||
{
|
||||
ok = 1;
|
||||
for(it=_ops[year].begin(); it!=_ops[year].end(); it++)
|
||||
{
|
||||
if (*it == i)
|
||||
{
|
||||
ok=0; break;
|
||||
}
|
||||
}
|
||||
if (ok)
|
||||
_monthTo->Append(months[i]);
|
||||
}
|
||||
|
||||
_monthTo->Select(0);
|
||||
|
||||
Layout();
|
||||
}
|
||||
|
||||
void GenerateDialog::OnOK(wxCommandEvent& event)
|
||||
{
|
||||
int monthFrom, yearFrom, monthTo, yearTo, i;
|
||||
|
||||
if (_yearFrom->GetString(_yearFrom->GetCurrentSelection()) == wxT(""))
|
||||
{
|
||||
monthFrom = -1;
|
||||
yearFrom = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (i=0; i<12; i++)
|
||||
{
|
||||
if (months[i] == _monthFrom->GetString(_monthFrom->GetCurrentSelection()))
|
||||
{
|
||||
monthFrom = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
yearFrom = wxAtoi(_yearFrom->GetString(_yearFrom->GetCurrentSelection()));
|
||||
}
|
||||
|
||||
for (i=0; i<12; i++)
|
||||
{
|
||||
if (months[i] == _monthTo->GetString(_monthTo->GetCurrentSelection()))
|
||||
{
|
||||
monthTo = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
yearTo = wxAtoi(_yearTo->GetString(_yearTo->GetCurrentSelection()));
|
||||
|
||||
Close();
|
||||
_kiss->GenerateMonth(monthFrom, yearFrom, monthTo, yearTo);
|
||||
}
|
||||
|
||||
void GenerateDialog::OnCancel(wxCommandEvent& event)
|
||||
{
|
||||
Close();
|
||||
}
|
Reference in New Issue
Block a user