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: externaldepsdlg.cpp 10912 2016-09-25 16:10:13Z fuscated $
7  * $HeadURL: svn://svn.code.sf.net/p/codeblocks/code/branches/release-20.xx/src/sdk/externaldepsdlg.cpp $
8  */
9 
10 #include "sdk_precomp.h"
11 
12 #ifndef CB_PRECOMP
13     #include "cbproject.h"
14     #include "projectbuildtarget.h"
15     #include <wx/xrc/xmlres.h>
16     #include <wx/button.h>
17     #include <wx/listbox.h>
18     #include "globals.h"
19 #endif
20 
21 #include "externaldepsdlg.h"
22 #include <wx/msgdlg.h>
23 #include "editpathdlg.h"
24 
BEGIN_EVENT_TABLE(ExternalDepsDlg,wxScrollingDialog)25 BEGIN_EVENT_TABLE(ExternalDepsDlg, wxScrollingDialog)
26     EVT_UPDATE_UI(-1, ExternalDepsDlg::OnUpdateUI)
27     EVT_LISTBOX_DCLICK(XRCID("lstAdditionalFiles"), ExternalDepsDlg::OnEditAdditional)
28     EVT_LISTBOX_DCLICK(XRCID("lstExternalFiles"), ExternalDepsDlg::OnEditExternal)
29     EVT_BUTTON(XRCID("btnAddAdditional"), ExternalDepsDlg::OnAddAdditional)
30     EVT_BUTTON(XRCID("btnEditAdditional"), ExternalDepsDlg::OnEditAdditional)
31     EVT_BUTTON(XRCID("btnDelAdditional"), ExternalDepsDlg::OnDelAdditional)
32     EVT_BUTTON(XRCID("btnAddExternal"), ExternalDepsDlg::OnAddExternal)
33     EVT_BUTTON(XRCID("btnEditExternal"), ExternalDepsDlg::OnEditExternal)
34     EVT_BUTTON(XRCID("btnDelExternal"), ExternalDepsDlg::OnDelExternal)
35 END_EVENT_TABLE()
36 
37 ExternalDepsDlg::ExternalDepsDlg(wxWindow* parent, cbProject* project, ProjectBuildTarget* target)
38     : m_pProject(project),
39     m_pTarget(target)
40 {
41     //ctor
42     wxXmlResource::Get()->LoadObject(this, parent, _T("dlgExternalDeps"),_T("wxScrollingDialog"));
43     XRCCTRL(*this, "wxID_CANCEL", wxButton)->SetDefault();
44     FillAdditional();
45     FillExternal();
46 }
47 
~ExternalDepsDlg()48 ExternalDepsDlg::~ExternalDepsDlg()
49 {
50     //dtor
51 }
52 
FillAdditional()53 void ExternalDepsDlg::FillAdditional()
54 {
55     wxListBox* lst = XRCCTRL(*this, "lstAdditionalFiles", wxListBox);
56     lst->Clear();
57     wxArrayString array = GetArrayFromString(m_pTarget->GetAdditionalOutputFiles());
58     for (unsigned int i = 0; i < array.GetCount(); ++i)
59     {
60         lst->Append(array[i]);
61     }
62 }
63 
FillExternal()64 void ExternalDepsDlg::FillExternal()
65 {
66     wxListBox* lst = XRCCTRL(*this, "lstExternalFiles", wxListBox);
67     lst->Clear();
68     wxArrayString array = GetArrayFromString(m_pTarget->GetExternalDeps());
69     for (unsigned int i = 0; i < array.GetCount(); ++i)
70     {
71         lst->Append(array[i]);
72     }
73 }
74 
EndModal(int retCode)75 void ExternalDepsDlg::EndModal(int retCode)
76 {
77     wxString deps;
78     wxListBox* lst = XRCCTRL(*this, "lstExternalFiles", wxListBox);
79     for (unsigned int i = 0; i < (unsigned int)lst->GetCount(); ++i)
80     {
81         deps << lst->GetString(i) << _T(';');
82     }
83     m_pTarget->SetExternalDeps(deps);
84 
85     wxString files;
86     lst = XRCCTRL(*this, "lstAdditionalFiles", wxListBox);
87     for (unsigned int i = 0; i < (unsigned int)lst->GetCount(); ++i)
88     {
89         files << lst->GetString(i) << _T(';');
90     }
91     m_pTarget->SetAdditionalOutputFiles(files);
92 
93     return wxScrollingDialog::EndModal(retCode);
94 }
95 
96 //void ExternalDepsDlg::DoAdd(const wxString& listbox, const wxString& message)
97 #define DoAdd(listbox,message)                              \
98 {                                                           \
99     wxListBox* lst = XRCCTRL(*this, listbox, wxListBox);    \
100     EditPathDlg dlg(this,                                   \
101                     m_pProject->GetBasePath(),              \
102                     m_pProject->GetBasePath(),              \
103                     message,                                \
104                     wxEmptyString,                          \
105                     false);                                 \
106     PlaceWindow(&dlg);                                      \
107     if (dlg.ShowModal() == wxID_OK)                         \
108         lst->Append(dlg.GetPath());                         \
109 }
110 
111 //void ExternalDepsDlg::DoEdit(const wxString& listbox, const wxString& message)
112 #define DoEdit(listbox,message)                             \
113 {                                                           \
114     wxListBox* lst = XRCCTRL(*this, listbox, wxListBox);    \
115     int sel = lst->GetSelection();                          \
116     if (sel == -1)                                          \
117         return;                                             \
118     EditPathDlg dlg(this,                                   \
119                     lst->GetStringSelection(),              \
120                     m_pProject->GetBasePath(),              \
121                     message,                                \
122                     wxEmptyString,                          \
123                     false);                                 \
124     PlaceWindow(&dlg);                                      \
125     if (dlg.ShowModal() == wxID_OK)                         \
126         lst->SetString(sel, dlg.GetPath());                 \
127 }
128 
129 //void ExternalDepsDlg::DoDel(const wxString& listbox)
130 #define DoDel(listbox)                                      \
131 {                                                           \
132     wxListBox* lst = XRCCTRL(*this, listbox, wxListBox);    \
133     int sel = lst->GetSelection();                          \
134     if (sel == -1)                                          \
135         return;                                             \
136     if (cbMessageBox(_("Are you sure you want to remove this file?"), _("Remove file"), wxYES_NO | wxNO_DEFAULT, this) == wxID_NO)   \
137         return;                                             \
138     lst->Delete(sel);                                       \
139 }
140 
OnAddAdditional(cb_unused wxCommandEvent & event)141 void ExternalDepsDlg::OnAddAdditional(cb_unused wxCommandEvent& event)
142 {
143     DoAdd("lstAdditionalFiles", _("Add additional output file"));
144 }
145 
OnEditAdditional(cb_unused wxCommandEvent & event)146 void ExternalDepsDlg::OnEditAdditional(cb_unused wxCommandEvent& event)
147 {
148     DoEdit("lstAdditionalFiles", _("Edit additional output file"));
149 }
150 
OnDelAdditional(cb_unused wxCommandEvent & event)151 void ExternalDepsDlg::OnDelAdditional(cb_unused wxCommandEvent& event)
152 {
153     DoDel("lstAdditionalFiles");
154 }
155 
OnAddExternal(cb_unused wxCommandEvent & event)156 void ExternalDepsDlg::OnAddExternal(cb_unused wxCommandEvent& event)
157 {
158     DoAdd("lstExternalFiles", _("Add external dependency file"));
159 }
160 
OnEditExternal(cb_unused wxCommandEvent & event)161 void ExternalDepsDlg::OnEditExternal(cb_unused wxCommandEvent& event)
162 {
163     DoEdit("lstExternalFiles", _("Edit external dependency file"));
164 }
165 
OnDelExternal(cb_unused wxCommandEvent & event)166 void ExternalDepsDlg::OnDelExternal(cb_unused wxCommandEvent& event)
167 {
168     DoDel("lstExternalFiles");
169 }
170 
OnUpdateUI(cb_unused wxUpdateUIEvent & event)171 void ExternalDepsDlg::OnUpdateUI(cb_unused wxUpdateUIEvent& event)
172 {
173     int selAdd = XRCCTRL(*this, "lstAdditionalFiles", wxListBox)->GetSelection();
174     int selExt = XRCCTRL(*this, "lstExternalFiles", wxListBox)->GetSelection();
175 
176     XRCCTRL(*this, "btnEditAdditional", wxButton)->Enable(selAdd != -1);
177     XRCCTRL(*this, "btnDelAdditional", wxButton)->Enable(selAdd != -1);
178     XRCCTRL(*this, "btnEditExternal", wxButton)->Enable(selExt != -1);
179     XRCCTRL(*this, "btnDelExternal", wxButton)->Enable(selExt != -1);
180 }
181