Beispiel #1
0
void ProfileManager::SetSelectedProfile(const int & id) {
	for (int i = 0; i < item_lb_->GetCount(); ++i) {
		Profile* profile = static_cast<Profile*>(item_lb_->GetClientData(i));
		if (profile->GetId() == id) {
			item_lb_->SetSelection(i);
			break;
		}
	}
}
Beispiel #2
0
ProfileManager::ProfileManager(wxWindow* parent)
	: wxDialog(parent, -1, "Profile Manager", wxDefaultPosition, 
		wxSize(kDialogWidth, kDialogHeight)), current_profile_(0, "", "") {
	// Setup the listbox
	item_lb_ = new wxListBox(this, -1, wxDefaultPosition);

	// Setup buttons and the button panel
	wxPanel* btn_panel = new wxPanel(this);
	wxBoxSizer* ver_sizer = new wxBoxSizer(wxVERTICAL);

	wxButton* new_profile_btn = new wxButton(btn_panel, -1, "New");
	new_profile_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) {
		ProfileEditor profile_editor(this, Profile::Profile(-1, "", ""));

		if (profile_editor.ShowModal() == wxID_OK) {
			Profile profile = profile_editor.GetProfile();
			database_.AddProfile(profile.GetName(), profile.GetSerializedMap());
			UpdateListBox();
		}
	});

	wxButton* edit_profile_btn = new wxButton(btn_panel, -1, "Edit");
	edit_profile_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) {
		int sel = item_lb_->GetSelection();

		if (sel != -1) {
			Profile* profile = static_cast<Profile*>(item_lb_->GetClientData(sel));
			ProfileEditor profile_editor(this, *profile);

			if (profile_editor.ShowModal() == wxID_OK) {
				Profile profile = profile_editor.GetProfile();

				// Remove the old profile
				database_.RemoveProfile(profile.GetId());
				database_.AddProfile(profile.GetName(), profile.GetSerializedMap());

				UpdateListBox();
			}
		}
	});

	wxButton* removeProfileBtn = new wxButton(btn_panel, -1, "Remove");
	removeProfileBtn->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) {
		int sel = item_lb_->GetSelection();

		if (sel != -1) {
			Profile* profile = static_cast<Profile*>(item_lb_->GetClientData(sel));

			database_.RemoveProfile(profile->GetId());
			item_lb_->Delete(sel);

			delete profile;
		}
	});

	ver_sizer->Add(new_profile_btn, 0, wxBOTTOM, 5);
	ver_sizer->Add(edit_profile_btn, 0, wxBOTTOM, 5);
	ver_sizer->Add(removeProfileBtn, 0);

	btn_panel->SetSizer(ver_sizer);

	wxBoxSizer* upper_hor_sizer = new wxBoxSizer(wxHORIZONTAL);
	upper_hor_sizer->Add(item_lb_, 1, wxEXPAND | wxALL, 10);
	upper_hor_sizer->Add(btn_panel, 0, wxALL, 10);

	// Setup ok/cancel button panel
	wxPanel* bottom_btn_panel = new wxPanel(this);

	wxButton* ok_btn = new wxButton(bottom_btn_panel, -1, "OK");
	ok_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) {
		Profile* profile;

		int sel = item_lb_->GetSelection();
		if (sel != -1) {
			profile = static_cast<Profile*>(item_lb_->GetClientData(sel));
			current_profile_ = *profile;
		}

		EndModal(wxID_OK);
		Destroy();
	});

	wxButton* cancel_btn = new wxButton(bottom_btn_panel, -1, "Cancel");
	cancel_btn->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) {
		EndModal(wxID_CANCEL);
		Destroy();
	});

	wxBoxSizer* bottom_hor_sizer = new wxBoxSizer(wxHORIZONTAL);
	bottom_hor_sizer->Add(ok_btn, 0, wxALL, 10);
	bottom_hor_sizer->Add(cancel_btn, 0, wxALL, 10);

	bottom_btn_panel->SetSizer(bottom_hor_sizer);

	// Setup the outermost vertical layout/sizer
	wxBoxSizer* super_sizer = new wxBoxSizer(wxVERTICAL);

	super_sizer->Add(upper_hor_sizer, 1, wxEXPAND);
	super_sizer->Add(bottom_btn_panel, 0);

	SetSizer(super_sizer);

	UpdateListBox();
}