Code::Blocks  SVN r11506
editarrayfiledlg.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: 10978 $
6  * $Id: editarrayfiledlg.cpp 10978 2017-01-23 01:12:01Z fuscated $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/sdk/editarrayfiledlg.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 <wx/filedlg.h>
22 #include "editarrayfiledlg.h"
23 #include "filefilters.h"
24 
25 BEGIN_EVENT_TABLE(EditArrayFileDlg, wxScrollingDialog)
26  EVT_LISTBOX_DCLICK(XRCID("lstItems"), EditArrayFileDlg::OnEdit)
27  EVT_BUTTON(XRCID("btnAdd"), EditArrayFileDlg::OnAdd)
28  EVT_BUTTON(XRCID("btnEdit"), EditArrayFileDlg::OnEdit)
29  EVT_BUTTON(XRCID("btnDelete"), EditArrayFileDlg::OnDelete)
30  EVT_UPDATE_UI(-1, EditArrayFileDlg::OnUpdateUI)
31 END_EVENT_TABLE()
32 
33 EditArrayFileDlg::EditArrayFileDlg(wxWindow* parent, wxArrayString& array, bool useRelativePaths, const wxString& basePath)
34  : m_Array(array),
35  m_UseRelativePaths(useRelativePaths),
36  m_BasePath(basePath)
37 {
38  //ctor
39  wxXmlResource::Get()->LoadObject(this, parent, _T("dlgEditArrayString"),_T("wxScrollingDialog"));
40  XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
41 
42  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
43  list->Clear();
44  for (unsigned int i = 0; i < m_Array.GetCount(); ++i)
45  {
46  wxFileName fname;
47  fname.Assign(m_Array[i]);
48  if (!m_UseRelativePaths && fname.IsRelative())
49  fname.Normalize(wxPATH_NORM_ALL & ~wxPATH_NORM_CASE, m_BasePath);
50  else if (m_UseRelativePaths && fname.IsAbsolute())
51  fname.MakeRelativeTo(m_BasePath);
52  m_Array[i] = fname.GetFullPath();
53  list->Append(m_Array[i]);
54  }
55 }
56 
58 {
59  //dtor
60 }
61 
62 void EditArrayFileDlg::EndModal(int retCode)
63 {
64  if (retCode == wxID_OK)
65  {
66  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
67  m_Array.Clear();
68  for (int i = 0; i < (int)list->GetCount(); ++i)
69  {
70  m_Array.Add(list->GetString(i));
71  }
72  }
74 }
75 
76 // events
77 
79 {
80  wxFileDialog dlg(this,
81  _("Select file"),
82  m_BasePath,
83  _T(""),
85  wxFD_OPEN | compatibility::wxHideReadonly);
86  PlaceWindow(&dlg);
87  if (dlg.ShowModal() != wxID_OK)
88  return;
89  wxFileName fname;
90  fname.Assign(dlg.GetPath());
93  XRCCTRL(*this, "lstItems", wxListBox)->Append(fname.GetFullPath());
94 }
95 
97 {
98  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
99  wxFileDialog dlg(this,
100  _("Select file"),
101  m_BasePath,
102  list->GetStringSelection(),
104  wxFD_OPEN | compatibility::wxHideReadonly);
105  PlaceWindow(&dlg);
106  if (dlg.ShowModal() != wxID_OK)
107  return;
108  wxFileName fname;
109  fname.Assign(dlg.GetPath());
110  if (m_UseRelativePaths)
111  fname.MakeRelativeTo(m_BasePath);
112  list->SetString(list->GetSelection(), fname.GetFullPath());
113 }
114 
116 {
117  if (cbMessageBox(_("Delete this item?"), _("Confirm"), wxYES_NO, this) == wxID_YES)
118  {
119  wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
120  list->Delete(list->GetSelection());
121  }
122 }
123 
125 {
126  bool en = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection() != -1;
127  XRCCTRL(*this, "btnEdit", wxButton)->Enable(en);
128  XRCCTRL(*this, "btnDelete", wxButton)->Enable(en);
129 }
void EndModal(int retCode)
Definition: sc_dialog.cpp:112
virtual int ShowModal()
void Assign(const wxFileName &filepath)
#define _T(string)
#define wxYES_NO
bool IsAbsolute(wxPathFormat format=wxPATH_NATIVE) const
DLLIMPORT wxString GetFilterAll()
Generates a simple special filter "All files".
Definition: filefilters.cpp:98
bool MakeRelativeTo(const wxString &pathBase=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
wxArrayString & m_Array
virtual wxString GetPath() const
const wxString & _(const wxString &string)
DLLIMPORT void PlaceWindow(wxTopLevelWindow *w, cbPlaceDialogMode mode=pdlBest, bool enforce=false)
Definition: globals.cpp:1177
bool IsRelative(wxPathFormat format=wxPATH_NATIVE) const
~EditArrayFileDlg() override
void OnUpdateUI(wxUpdateUIEvent &event)
size_t Add(const wxString &str, size_t copies=1)
bool Normalize(int flags=wxPATH_NORM_ALL, const wxString &cwd=wxEmptyString, wxPathFormat format=wxPATH_NATIVE)
void OnAdd(wxCommandEvent &event)
static wxXmlResource * Get()
void EndModal(int retCode) override
void OnDelete(wxCommandEvent &event)
void OnEdit(wxCommandEvent &event)
wxString GetFullPath(wxPathFormat format=wxPATH_NATIVE) const
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