Menu

[r13158]: / trunk / src / sdk / editarrayfiledlg.cpp  Maximize  Restore  History

Download this file

130 lines (116 with data), 4.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include <wx/intl.h>
#include <wx/xrc/xmlres.h>
#include <wx/button.h>
#include <wx/msgdlg.h>
#include <wx/listbox.h>
#include "globals.h"
#endif
#include <wx/filedlg.h>
#include "editarrayfiledlg.h"
#include "filefilters.h"
BEGIN_EVENT_TABLE(EditArrayFileDlg, wxScrollingDialog)
EVT_LISTBOX_DCLICK(XRCID("lstItems"), EditArrayFileDlg::OnEdit)
EVT_BUTTON(XRCID("btnAdd"), EditArrayFileDlg::OnAdd)
EVT_BUTTON(XRCID("btnEdit"), EditArrayFileDlg::OnEdit)
EVT_BUTTON(XRCID("btnDelete"), EditArrayFileDlg::OnDelete)
EVT_UPDATE_UI(-1, EditArrayFileDlg::OnUpdateUI)
END_EVENT_TABLE()
EditArrayFileDlg::EditArrayFileDlg(wxWindow* parent, wxArrayString& array, bool useRelativePaths, const wxString& basePath)
: m_Array(array),
m_UseRelativePaths(useRelativePaths),
m_BasePath(basePath)
{
//ctor
wxXmlResource::Get()->LoadObject(this, parent, _T("dlgEditArrayString"),_T("wxScrollingDialog"));
XRCCTRL(*this, "wxID_OK", wxButton)->SetDefault();
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
list->Clear();
for (unsigned int i = 0; i < m_Array.GetCount(); ++i)
{
wxFileName fname;
fname.Assign(m_Array[i]);
if (!m_UseRelativePaths && fname.IsRelative())
fname.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_TILDE | wxPATH_NORM_ABSOLUTE | wxPATH_NORM_LONG | wxPATH_NORM_SHORTCUT, m_BasePath);
else if (m_UseRelativePaths && fname.IsAbsolute())
fname.MakeRelativeTo(m_BasePath);
m_Array[i] = fname.GetFullPath();
list->Append(m_Array[i]);
}
}
EditArrayFileDlg::~EditArrayFileDlg()
{
//dtor
}
void EditArrayFileDlg::EndModal(int retCode)
{
if (retCode == wxID_OK)
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
m_Array.Clear();
for (int i = 0; i < (int)list->GetCount(); ++i)
{
m_Array.Add(list->GetString(i));
}
}
wxScrollingDialog::EndModal(retCode);
}
// events
void EditArrayFileDlg::OnAdd(wxCommandEvent& WXUNUSED(event))
{
wxFileDialog dlg(this,
_("Select file"),
m_BasePath,
_T(""),
FileFilters::GetFilterAll(),
wxFD_OPEN | compatibility::wxHideReadonly);
PlaceWindow(&dlg);
if (dlg.ShowModal() != wxID_OK)
return;
wxFileName fname;
fname.Assign(dlg.GetPath());
if (m_UseRelativePaths)
fname.MakeRelativeTo(m_BasePath);
XRCCTRL(*this, "lstItems", wxListBox)->Append(fname.GetFullPath());
}
void EditArrayFileDlg::OnEdit(wxCommandEvent& WXUNUSED(event))
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
wxFileDialog dlg(this,
_("Select file"),
m_BasePath,
list->GetStringSelection(),
FileFilters::GetFilterAll(),
wxFD_OPEN | compatibility::wxHideReadonly);
PlaceWindow(&dlg);
if (dlg.ShowModal() != wxID_OK)
return;
wxFileName fname;
fname.Assign(dlg.GetPath());
if (m_UseRelativePaths)
fname.MakeRelativeTo(m_BasePath);
list->SetString(list->GetSelection(), fname.GetFullPath());
}
void EditArrayFileDlg::OnDelete(wxCommandEvent& WXUNUSED(event))
{
if (cbMessageBox(_("Delete this item?"), _("Confirm"), wxYES_NO, this) == wxID_YES)
{
wxListBox* list = XRCCTRL(*this, "lstItems", wxListBox);
list->Delete(list->GetSelection());
}
}
void EditArrayFileDlg::OnUpdateUI(wxUpdateUIEvent& WXUNUSED(event))
{
bool en = XRCCTRL(*this, "lstItems", wxListBox)->GetSelection() != -1;
XRCCTRL(*this, "btnEdit", wxButton)->Enable(en);
XRCCTRL(*this, "btnDelete", wxButton)->Enable(en);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.