|
1 |
#include "ide.h"
|
|
2 |
|
|
3 |
class CategoryFile : public Moveable<CategoryFile> {
|
|
4 |
public:
|
|
5 |
CategoryFile(const String& description, const String& extension)
|
|
6 |
: description(description)
|
|
7 |
, extension(extension)
|
|
8 |
{}
|
|
9 |
|
|
10 |
const String& GetDescription() const { return description; }
|
|
11 |
const String& GetExtension() const { return extension; }
|
|
12 |
|
|
13 |
private:
|
|
14 |
String description;
|
|
15 |
String extension;
|
|
16 |
};
|
|
17 |
|
|
18 |
class NewFileBasicInformationsWindow : public WithNewFileBasicInformationsLayout<TopWindow> {
|
|
19 |
typedef NewFileBasicInformationsWindow CLASSNAME;
|
|
20 |
|
|
21 |
public:
|
|
22 |
NewFileBasicInformationsWindow(const Vector<String>& packages);
|
|
23 |
|
|
24 |
String GetPackage() const;
|
|
25 |
String GetFileExt() const;
|
|
26 |
|
|
27 |
private:
|
|
28 |
void InitCategories();
|
|
29 |
void InitCategoriesArray();
|
|
30 |
|
|
31 |
void OnCategorySelection();
|
|
32 |
|
|
33 |
private:
|
|
34 |
VectorMap<String, Vector<CategoryFile>> categoriesFiles;
|
|
35 |
};
|
|
36 |
|
|
37 |
NewFileBasicInformationsWindow::NewFileBasicInformationsWindow(const Vector<String>& packages)
|
|
38 |
{
|
|
39 |
CtrlLayout(*this);
|
|
40 |
Zoomable();
|
|
41 |
|
|
42 |
for (const String& currentPackage : packages)
|
|
43 |
package.Add(currentPackage);
|
|
44 |
if (package.GetCount())
|
|
45 |
package.SetIndex(0);
|
|
46 |
|
|
47 |
InitCategories();
|
|
48 |
InitCategoriesArray();
|
|
49 |
}
|
|
50 |
|
|
51 |
String NewFileBasicInformationsWindow::GetPackage() const
|
|
52 |
{
|
|
53 |
return package.Get();
|
|
54 |
}
|
|
55 |
|
|
56 |
String NewFileBasicInformationsWindow::GetFileExt() const
|
|
57 |
{
|
|
58 |
int cursor = files.GetCursor();
|
|
59 |
if (cursor < 0)
|
|
60 |
return "";
|
|
61 |
|
|
62 |
return files.Get(cursor, 1);
|
|
63 |
}
|
|
64 |
|
|
65 |
void NewFileBasicInformationsWindow::InitCategories()
|
|
66 |
{
|
|
67 |
Vector<CategoryFile> cppFiles;
|
|
68 |
cppFiles.Add(CategoryFile("C source file (.c)", "c"));
|
|
69 |
cppFiles.Add(CategoryFile("C header (.h)", "h"));
|
|
70 |
cppFiles.Add(CategoryFile("C++ source file (.cpp)", "cpp"));
|
|
71 |
|
|
72 |
categoriesFiles.Add("C/C++ source files", cppFiles);
|
|
73 |
|
|
74 |
Vector<CategoryFile> uppFiles;
|
|
75 |
uppFiles.Add(CategoryFile("Layout file (.lay)", "lay"));
|
|
76 |
uppFiles.Add(CategoryFile("Image file (.iml)", "iml"));
|
|
77 |
|
|
78 |
categoriesFiles.Add("Upp files", uppFiles);
|
|
79 |
}
|
|
80 |
|
|
81 |
void NewFileBasicInformationsWindow::InitCategoriesArray()
|
|
82 |
{
|
|
83 |
categories.AddColumn();
|
|
84 |
files.AddColumn();
|
|
85 |
files.AddColumn();
|
|
86 |
files.ColumnWidths("100 0");
|
|
87 |
for (int i = 0; i < categoriesFiles.GetCount(); i++)
|
|
88 |
categories.Add(categoriesFiles.GetKey(i));
|
|
89 |
categories <<= THISBACK(OnCategorySelection);
|
|
90 |
}
|
|
91 |
|
|
92 |
void NewFileBasicInformationsWindow::OnCategorySelection()
|
|
93 |
{
|
|
94 |
int cursor = categories.GetCursor();
|
|
95 |
if (cursor < 0)
|
|
96 |
return;
|
|
97 |
|
|
98 |
String key = categories.Get(cursor, 0);
|
|
99 |
int idx = categoriesFiles.Find(key);
|
|
100 |
if (idx < 0)
|
|
101 |
return;
|
|
102 |
|
|
103 |
files.Clear();
|
|
104 |
for (const CategoryFile& cf : categoriesFiles[idx])
|
|
105 |
files.Add(cf.GetDescription(), cf.GetExtension());
|
|
106 |
}
|
|
107 |
|
|
108 |
class NewFileSummaryWindow : public WithNewFileSummaryLayout<TopWindow> {
|
|
109 |
typedef NewFileSummaryWindow CLASSNAME;
|
|
110 |
|
|
111 |
public:
|
|
112 |
NewFileSummaryWindow();
|
|
113 |
|
|
114 |
String GetAbsoluteFilePath();
|
|
115 |
void SetPackage(const String& newPackage);
|
|
116 |
void SetExtension(const String& newExtension);
|
|
117 |
|
|
118 |
void UpdateFields();
|
|
119 |
|
|
120 |
private:
|
|
121 |
String package;
|
|
122 |
String extension;
|
|
123 |
};
|
|
124 |
|
|
125 |
NewFileSummaryWindow::NewFileSummaryWindow()
|
|
126 |
{
|
|
127 |
CtrlLayout(*this);
|
|
128 |
|
|
129 |
fileName <<= THISBACK(UpdateFields);
|
|
130 |
|
|
131 |
Zoomable();
|
|
132 |
}
|
|
133 |
|
|
134 |
String NewFileSummaryWindow::GetAbsoluteFilePath()
|
|
135 |
{
|
|
136 |
return absoluteFilePath.GetData();
|
|
137 |
}
|
|
138 |
|
|
139 |
void NewFileSummaryWindow::SetPackage(const String& newPackage)
|
|
140 |
{
|
|
141 |
package = newPackage;
|
|
142 |
}
|
|
143 |
|
|
144 |
void NewFileSummaryWindow::SetExtension(const String& newExtension)
|
|
145 |
{
|
|
146 |
extension = newExtension;
|
|
147 |
}
|
|
148 |
|
|
149 |
void NewFileSummaryWindow::UpdateFields()
|
|
150 |
{
|
|
151 |
String file = fileName.GetData();
|
|
152 |
String packageFile = file + "." + extension;
|
|
153 |
String absoluteFile = GetFileFolder(PackagePath(package)) + DIR_SEP + packageFile;
|
|
154 |
|
|
155 |
filePathInPackage.SetData(packageFile);
|
|
156 |
absoluteFilePath.SetData(absoluteFile);
|
|
157 |
}
|
|
158 |
|
|
159 |
class NewFileWindow : public WithNewFileLayout<TopWindow> {
|
|
160 |
typedef NewFileWindow CLASSNAME;
|
|
161 |
enum class State;
|
|
162 |
|
|
163 |
public:
|
|
164 |
NewFileWindow(const Vector<String>& packages);
|
|
165 |
|
|
166 |
String GetFilePath();
|
|
167 |
|
|
168 |
private:
|
|
169 |
void SetState(State newState);
|
|
170 |
void ResetStateComponents();
|
|
171 |
|
|
172 |
void OnNext();
|
|
173 |
void OnBack();
|
|
174 |
|
|
175 |
private:
|
|
176 |
enum class State {
|
|
177 |
BasicInformations,
|
|
178 |
Summary,
|
|
179 |
Unknown
|
|
180 |
};
|
|
181 |
|
|
182 |
State state;
|
|
183 |
|
|
184 |
NewFileBasicInformationsWindow basicInformations;
|
|
185 |
NewFileSummaryWindow summary;
|
|
186 |
};
|
|
187 |
|
|
188 |
NewFileWindow::NewFileWindow(const Vector<String>& packages)
|
|
189 |
: state(State::Unknown)
|
|
190 |
, basicInformations(packages)
|
|
191 |
{
|
|
192 |
CtrlLayoutOKCancel(*this, "New file");
|
|
193 |
Zoomable();
|
|
194 |
|
|
195 |
parent.Add(basicInformations.SizePos());
|
|
196 |
parent.Add(summary.SizePos());
|
|
197 |
|
|
198 |
next <<= THISBACK(OnNext);
|
|
199 |
back <<= THISBACK(OnBack);
|
|
200 |
|
|
201 |
SetState(State::BasicInformations);
|
|
202 |
}
|
|
203 |
|
|
204 |
String NewFileWindow::GetFilePath()
|
|
205 |
{
|
|
206 |
return summary.GetAbsoluteFilePath();
|
|
207 |
}
|
|
208 |
|
|
209 |
void NewFileWindow::SetState(State newState)
|
|
210 |
{
|
|
211 |
if(state == newState)
|
|
212 |
return;
|
|
213 |
|
|
214 |
ResetStateComponents();
|
|
215 |
|
|
216 |
state = newState;
|
|
217 |
switch (state) {
|
|
218 |
case State::BasicInformations:
|
|
219 |
basicInformations.Show();
|
|
220 |
next.Enable();
|
|
221 |
break;
|
|
222 |
case State::Summary:
|
|
223 |
summary.SetPackage(basicInformations.GetPackage());
|
|
224 |
summary.SetExtension(basicInformations.GetFileExt());
|
|
225 |
summary.fileName.Clear();
|
|
226 |
summary.UpdateFields();
|
|
227 |
summary.Show();
|
|
228 |
summary.fileName.SetFocus();
|
|
229 |
ok.Enable();
|
|
230 |
back.Enable();
|
|
231 |
break;
|
|
232 |
default:
|
|
233 |
ASSERT(0);
|
|
234 |
}
|
|
235 |
}
|
|
236 |
|
|
237 |
void NewFileWindow::ResetStateComponents()
|
|
238 |
{
|
|
239 |
basicInformations.Hide();
|
|
240 |
summary.Hide();
|
|
241 |
|
|
242 |
ok.Disable();
|
|
243 |
|
|
244 |
next.Disable();
|
|
245 |
back.Disable();
|
|
246 |
}
|
|
247 |
|
|
248 |
void NewFileWindow::OnNext()
|
|
249 |
{
|
|
250 |
SetState(State::Summary);
|
|
251 |
}
|
|
252 |
|
|
253 |
void NewFileWindow::OnBack()
|
|
254 |
{
|
|
255 |
SetState(State::BasicInformations);
|
|
256 |
}
|
|
257 |
|
|
258 |
void Ide::NewFile()
|
|
259 |
{
|
|
260 |
Vector<String> packages;
|
|
261 |
|
|
262 |
const Workspace& wspc = IdeWorkspace();
|
|
263 |
for(int i = 0; i < wspc.GetCount(); i++){
|
|
264 |
packages.Add(wspc[i]);
|
|
265 |
}
|
|
266 |
|
|
267 |
NewFileWindow newFileWindow(packages);
|
|
268 |
if (newFileWindow.ExecuteOK()) {
|
|
269 |
String file = newFileWindow.GetFilePath();
|
|
270 |
|
|
271 |
Cout() << "File: " << file << "\n";
|
|
272 |
}
|
|
273 |
}
|