Code::Blocks  SVN r11506
projectsfilemasksdlg.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: projectsfilemasksdlg.cpp 10912 2016-09-25 16:10:13Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/projectsfilemasksdlg.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/xrc/xmlres.h>
14  #include <wx/intl.h>
15  #include <wx/button.h>
16  #include <wx/textctrl.h>
17  #include <wx/msgdlg.h>
18  #include <wx/listbox.h>
19  #include "globals.h"
20 #endif
21 
22 #include "projectsfilemasksdlg.h"
23 
24 BEGIN_EVENT_TABLE(ProjectsFileMasksDlg, wxScrollingDialog)
25  EVT_UPDATE_UI( -1, ProjectsFileMasksDlg::OnUpdateUI)
26  EVT_BUTTON(XRCID("btnAdd"), ProjectsFileMasksDlg::OnAdd)
27  EVT_BUTTON(XRCID("btnEdit"), ProjectsFileMasksDlg::OnEdit)
28  EVT_BUTTON(XRCID("btnDelete"), ProjectsFileMasksDlg::OnDelete)
29  EVT_BUTTON(XRCID("btnSetDefault"), ProjectsFileMasksDlg::OnSetDefault)
30  EVT_LISTBOX(XRCID("lstCategories"), ProjectsFileMasksDlg::OnListChanged)
31 END_EVENT_TABLE()
32 
34  m_FileGroupsAndMasksCopy(*fgam), // store a local copy, so if we press "Cancel", we can revert to the original...
35  m_pFileGroupsAndMasks(fgam),
36  m_LastListSelection(0)
37 {
38  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgProjectsFileMasks"),_T("wxScrollingDialog"));
39  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
40 
41  RebuildList();
42 }
43 
45 {
46  //dtor
47 }
48 
50 {
51  wxListBox* pList = XRCCTRL(*this, "lstCategories", wxListBox);
52  pList->Clear();
53  for (unsigned int i = 0; i < m_FileGroupsAndMasksCopy.GetGroupsCount(); ++i)
54  pList->Append(m_FileGroupsAndMasksCopy.GetGroupName(i));
55 
56  if (pList->GetCount() != 0)
57  {
58  pList->SetSelection(m_LastListSelection);
59  ListChange();
60  }
61 }
62 
64 {
65  wxTextCtrl* pText = XRCCTRL(*this, "txtFileMasks", wxTextCtrl);
66  int sel = XRCCTRL(*this, "lstCategories", wxListBox)->GetSelection();
67 
68  if (sel != m_LastListSelection)
69  {
70  // switching group; see if the user changed the masks...
73  }
74 
75  pText->SetValue(m_FileGroupsAndMasksCopy.GetFileMasks(sel));
76  m_LastListSelection = sel;
77 }
78 
80 {
81  int sel = XRCCTRL(*this, "lstCategories", wxListBox)->GetSelection();
82 
83  XRCCTRL(*this, "btnEdit", wxButton)->Enable(sel >= 0);
84  XRCCTRL(*this, "btnDelete", wxButton)->Enable(sel >= 0);
85 }
86 
88 {
89  wxString groupName = cbGetTextFromUser(_("Enter the new group name:"),
90  _("New group"));
91  if (groupName.IsEmpty())
92  return;
94  wxListBox* pList = XRCCTRL(*this, "lstCategories", wxListBox);
95  pList->Append(groupName);
96  pList->SetSelection(pList->GetCount() - 1);
97  ListChange();
98  XRCCTRL(*this, "txtFileMasks", wxTextCtrl)->SetFocus();
99 }
100 
102 {
103  wxListBox* pList = XRCCTRL(*this, "lstCategories", wxListBox);
104  wxString oldName = pList->GetStringSelection();
105  wxString groupName = cbGetTextFromUser(_("Rename the group:"),
106  _("Edit group"), oldName);
107  if (!groupName.IsEmpty() && groupName != oldName)
108  {
109  m_FileGroupsAndMasksCopy.RenameGroup(pList->GetSelection(), groupName);
110  pList->SetString(pList->GetSelection(), groupName);
111  }
112 }
113 
115 {
116  wxListBox* pList = XRCCTRL(*this, "lstCategories", wxListBox);
117  wxString name = pList->GetStringSelection();
118  wxString caption;
119  caption.Printf(_("Are you sure you want to delete the group \"%s\"?"), name.c_str());
120  if (cbMessageBox(caption, _("Confirmation"), wxYES_NO | wxNO_DEFAULT | wxICON_QUESTION, this) == wxID_NO)
121  return;
122  m_FileGroupsAndMasksCopy.DeleteGroup(pList->GetSelection());
123  RebuildList();
124 }
125 
127 {
129  RebuildList();
130 }
131 
133 {
134  ListChange();
135 }
136 
138 {
139  if (retCode == wxID_OK)
140  {
141  wxTextCtrl* pText = XRCCTRL(*this, "txtFileMasks", wxTextCtrl);
144 
146  }
147 
149 }
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
void EndModal(int retCode) override
#define wxICON_QUESTION
void OnAdd(wxCommandEvent &event)
FilesGroupsAndMasks m_FileGroupsAndMasksCopy
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
FilesGroupsAndMasks * m_pFileGroupsAndMasks
void OnDelete(wxCommandEvent &event)
void OnUpdateUI(wxUpdateUIEvent &event)
unsigned int GetGroupsCount() const
Return total number of groups.
void OnListChanged(wxCommandEvent &event)
wxCStrData c_str() const
#define wxNO_DEFAULT
#define _T(string)
#define wxYES_NO
void OnEdit(wxCommandEvent &event)
wxString GetFileMasks(unsigned int group) const
Return a specific group file mask.
void CopyFrom(const FilesGroupsAndMasks &rhs)
copy ctor helper
void SetFileMasks(unsigned int group, const wxString &masks)
Set file mask for a group (e.g.
const wxString & _(const wxString &string)
void RenameGroup(unsigned int group, const wxString &newName)
Rename a group.
bool IsEmpty() const
void SetDefault(bool do_clear=true)
Set the default file groups and masks.
static wxXmlResource * Get()
wxString GetGroupName(unsigned int group) const
Return a specific group name.
int Printf(const wxString &pszFormat,...)
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
void DeleteGroup(unsigned int group)
Delete a group.
void OnSetDefault(wxCommandEvent &event)
unsigned int AddGroup(const wxString &name)
Add a file group.