Debian Codegraph @

wxcrafter/src/import_dlg.cpp

raw
1 #include "import_dlg.h"
2 #include "VirtualDirectorySelectorDlg.h"
3 #include "wxgui_helpers.h"
4 #include <windowattrmanager.h>
5 #include <workspace.h>
6 #include <wx/app.h>
7 #include <wx/dirdlg.h>
8 #include <wx/filedlg.h>
9
10 ImportDlg::ImportDlg(IPD_ProjectType type, wxWindow* parent, const wxString& sourceFile)
11 : ImportDlgBaseClass(parent)
12 , m_Type(type)
13 , m_modified(false)
14 {
15 if(m_Type == IPD_FB) {
16 SetLabel(_("Choose a wxFormBuilder project to import"));
17 } else if(m_Type == IPD_Smith) {
18 SetLabel(_("Choose a wxSmith project to import"));
19 }
20
21 wxFileName fn(sourceFile);
22 fn.SetExt("wxcp");
23 m_filepathText->ChangeValue(sourceFile);
24 m_textName->ChangeValue(fn.GetFullPath());
25
26 #if STANDALONE_BUILD
27 m_checkBoxAddToProject->SetValue(false);
28 #endif
29 SetName("ImportDlg");
30 WindowAttrManager::Load(this);
31 }
32
33 ImportDlg::~ImportDlg() {}
34
35 void ImportDlg::OnBrowse(wxCommandEvent& event)
36 {
37 wxUnusedVar(event);
38
39 wxString title, ext;
40 if(m_Type == IPD_FB) {
41 ext << (wxT("wxFB Project (*.fbp)|*.fbp|Any File (")) << wxFileSelectorDefaultWildcardStr << wxT(")|")
42 << wxFileSelectorDefaultWildcardStr;
43 title = _("Import a wxFormBuilder project");
44 }
45 if(m_Type == IPD_Smith) {
46 ext << (wxT("wxSmith Project (*.wxs)|*.wxs|Any File (")) << wxFileSelectorDefaultWildcardStr << wxT(")|")
47 << wxFileSelectorDefaultWildcardStr;
48 title = _("Import a wxSmith project");
49 }
50 if(m_Type == IPD_XRC) {
51 ext << (wxT("XRC File (*.xrc)|*.xrc|Any File (")) << wxFileSelectorDefaultWildcardStr << wxT(")|")
52 << wxFileSelectorDefaultWildcardStr;
53 title = _("Import an XRC file");
54 }
55 wxString path = wxFileSelector(title, wxEmptyString, wxEmptyString, wxEmptyString, ext, wxFD_OPEN, this);
56 if(path.empty()) { return; }
57 m_filepathText->ChangeValue(path);
58
59 // Use that filepath as the suggested destination, but using .wxcp as the ext
60 wxFileName fn(path);
61 fn.SetExt("wxcp");
62 m_textName->ChangeValue(fn.GetFullPath());
63 }
64
65 void ImportDlg::OnOKButtonUpdateUI(wxUpdateUIEvent& event)
66 {
67 event.Enable(!m_filepathText->IsEmpty() && !m_textName->IsEmpty());
68 }
69
70 void ImportDlg::OnBrowseForOutputFolder(wxCommandEvent& event)
71 {
72 wxString curtext = m_textName->GetValue();
73 wxFileName fn(curtext);
74 wxString dir = wxDirSelector();
75 if(dir.IsEmpty()) return;
76
77 wxFileName newpath(dir, fn.GetFullName());
78 m_textName->ChangeValue(newpath.GetFullPath());
79 }
80
81 void ImportDlg::OnBrowseForVirtualFolder(wxCommandEvent& event)
82 {
83 VirtualDirectorySelectorDlg vds(wxCrafter::TopFrame(), clCxxWorkspaceST::Get());
84 if(vds.ShowModal() == wxID_OK) {
85 wxString vd = vds.GetVirtualDirectoryPath();
86 m_textCtrl1VirtualFolder->ChangeValue(vd);
87 }
88 }
89
90 void ImportDlg::OnAddFileToProjectUI(wxUpdateUIEvent& event) { event.Enable(m_checkBoxAddToProject->IsChecked()); }
91
92 ImportDlg::ImportFileData ImportDlg::GetData() const
93 {
94 ImportFileData d;
95 d.addToProject = m_checkBoxAddToProject->IsChecked();
96 d.loadWhenDone = m_checkBoxLoadWhenDone->IsChecked();
97 d.wxcpFilename = m_textName->GetValue();
98 d.virtualFolder = m_textCtrl1VirtualFolder->GetValue();
99 return d;
100 }
101 void ImportDlg::OnAddToProjectUI(wxUpdateUIEvent& event)
102 {
103 #if STANDALONE_BUILD
104 event.Enable(false);
105 #endif
106 }
107
108 void ImportDlg::OnFileImportTextUpdated(wxCommandEvent& event)
109 {
110 if(!m_modified) {
111 wxFileName fnWXCPFile(m_filepathText->GetValue());
112 fnWXCPFile.SetExt("wxcp");
113 m_textName->ChangeValue(fnWXCPFile.GetFullPath());
114 }
115 }
116
117 void ImportDlg::OnDestFilePathUpdated(wxCommandEvent& event)
118 {
119 event.Skip();
120 m_modified = true;
121 }