Code::Blocks  SVN r11506
editarraystringdlg.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  * $Revision: 10912 $
6  * $Id: editarraystringdlg.cpp 10912 2016-09-25 16:10:13Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/editarraystringdlg.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/intl.h>
14  #include <wx/xrc/xmlres.h>
15  #include <wx/button.h>
16  #include <wx/msgdlg.h>
17  #include <wx/listbox.h>
18  #include "globals.h"
19 #endif
20 
21 #include "editarraystringdlg.h"
22 
23 BEGIN_EVENT_TABLE(EditArrayStringDlg, wxScrollingDialog)
24  EVT_LISTBOX_DCLICK(XRCID("lstItems"), EditArrayStringDlg::OnEdit)
25  EVT_BUTTON(XRCID("btnAdd"), EditArrayStringDlg::OnAdd)
26  EVT_BUTTON(XRCID("btnEdit"), EditArrayStringDlg::OnEdit)
27  EVT_BUTTON(XRCID("btnDelete"), EditArrayStringDlg::OnDelete)
28  EVT_UPDATE_UI(-1, EditArrayStringDlg::OnUpdateUI)
29 END_EVENT_TABLE()
30 
32  : m_Array(array)
33 {
34  //ctor
35  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgEditArrayString"),_T("wxScrollingDialog"));
36  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
37 
38  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
39  list->Clear();
40  for (unsigned int i = 0; i < m_Array.GetCount(); ++i)
41  {
42  list->Append(m_Array[i]);
43  }
44 }
45 
47 {
48  //dtor
49 }
50 
52 {
53  if (retCode == wxID_OK)
54  {
55  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
56  m_Array.Clear();
57  for (int i = 0; i < (int)list->GetCount(); ++i)
58  {
59  m_Array.Add(list->GetString(i));
60  }
61  }
63 }
64 
65 // events
66 
68 {
69  wxString w = cbGetTextFromUser(_("Add item"), _("Enter the new item:"));
70  if (!w.IsEmpty())
71  XRCCTRL(*this, "lstItems", wxListBox)->Append(w);
72 }
73 
75 {
76  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
77 
78  wxString w = list->GetStringSelection();
79  w = cbGetTextFromUser(_("Edit item"), _("Edit the item:"), w);
80  if (!w.IsEmpty())
81  list->SetString(list->GetSelection(), w);
82 }
83 
85 {
86  if (cbMessageBox(_("Delete this item?"), _("Confirm"), wxYES_NO) == wxID_YES)
87  {
88  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
89  list->Delete(list->GetSelection());
90  }
91 }
92 
94 {
95  const bool en = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection() != -1;
96  XRCCTRL(*this, "btnEdit", wxButton)->Enable(en);
97  XRCCTRL(*this, "btnDelete", wxButton)->Enable(en);
98 }
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
wxArrayString & m_Array
void EndModal(int retCode) override
DLLIMPORT wxString cbGetTextFromUser(const wxString &message, const wxString &caption=cbGetTextFromUserPromptStr, const wxString &default_value=wxEmptyString, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord, bool centre=true)
Definition: globals.cpp:1465
#define _T(string)
#define wxYES_NO
void OnAdd(wxCommandEvent &event)
void OnUpdateUI(wxUpdateUIEvent &event)
const wxString & _(const wxString &string)
void OnDelete(wxCommandEvent &event)
bool IsEmpty() const
size_t Add(const wxString &str, size_t copies=1)
void OnEdit(wxCommandEvent &event)
static wxXmlResource * Get()
wxObject * LoadObject(wxWindow *parent, const wxString &name, const wxString &classname)
DLLIMPORT int cbMessageBox(const wxString &message, const wxString &caption=wxEmptyString, int style=wxOK, wxWindow *parent=NULL, int x=-1, int y=-1)
wxMessageBox wrapper.
Definition: globals.cpp:1395