NewFile1.diff

Zbigniew Rebacz, 05/15/2016 07:55 PM

Download (9.04 KB)

View differences:

ide/NewFile.cpp (kopia robocza)
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
}
ide/ide.h (kopia robocza)
753 753

  
754 754
	void      File(Bar& menu);
755 755
		void   EditWorkspace();
756
		void   NewFile();
756 757
		void   EditAnyFile();
757 758
		bool   IsProjectFile(const String& f) const;
758 759
		void   SaveEditorFile(Stream& out);
ide/ide.lay (kopia robocza)
800 800
	ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24))
801 801
END_LAYOUT
802 802

  
803
LAYOUT(NewFileLayout, 480, 404)
804
	ITEM(Button, back, SetLabel(t_("Back")).RightPosZ(212, 64).BottomPosZ(8, 24))
805
	ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24))
806
	ITEM(Button, next, SetLabel(t_("Next")).RightPosZ(144, 64).BottomPosZ(8, 24))
807
	ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(8, 24))
808
	ITEM(ParentCtrl, parent, HSizePosZ(0, 0).VSizePosZ(0, 40))
809
END_LAYOUT
810

  
811
LAYOUT(NewFileBasicInformationsLayout, 480, 384)
812
	ITEM(Label, dv___0, SetLabel(t_("Package:")).LeftPosZ(8, 56).TopPosZ(4, 20))
813
	ITEM(DropList, package, HSizePosZ(72, 12).TopPosZ(4, 20))
814
	ITEM(Label, dv___2, SetLabel(t_("Category:")).LeftPosZ(8, 120).TopPosZ(28, 19))
815
	ITEM(Label, dv___3, SetLabel(t_("File type:")).HSizePosZ(232, 128).TopPosZ(28, 19))
816
	ITEM(ArrayCtrl, categories, Header(false).AutoHideSb(true).LeftPosZ(8, 216).VSizePosZ(52, 8))
817
	ITEM(ArrayCtrl, files, Header(false).AutoHideSb(true).HSizePosZ(232, 12).VSizePosZ(52, 8))
818
END_LAYOUT
819

  
820
LAYOUT(NewFileSummaryLayout, 480, 392)
821
	ITEM(Label, dv___0, SetLabel(t_("File name:")).LeftPosZ(8, 116).TopPosZ(8, 24))
822
	ITEM(EditString, fileName, HSizePosZ(132, 8).TopPosZ(8, 24))
823
	ITEM(Label, dv___2, SetLabel(t_("File path in package:")).LeftPosZ(8, 116).TopPosZ(40, 24))
824
	ITEM(EditString, filePathInPackage, SetEditable(false).HSizePosZ(132, 8).TopPosZ(40, 24))
825
	ITEM(Label, dv___4, SetLabel(t_("Absolute file path:")).LeftPosZ(8, 116).TopPosZ(72, 24))
826
	ITEM(EditString, absoluteFilePath, SetEditable(false).HSizePosZ(132, 8).TopPosZ(72, 24))
827
END_LAYOUT
828

  
ide/ide.upp (kopia robocza)
41 41
	Config.cpp,
42 42
	ide.cpp,
43 43
	idefile.cpp charset "iso8859-1",
44
	NewFile.cpp,
44 45
	EditorTabBar.cpp,
45 46
	Bottom.cpp,
46 47
	t.cpp,
ide/idebar.cpp (kopia robocza)
46 46
{
47 47
	menu.Add(AK_SETMAIN, THISBACK(NewMainPackage))
48 48
		.Help("Select global configuration (var), select / add main project package");
49

  
49
	menu.Separator();
50
	
51
	menu.Add("New file", CtrlImg::new_doc(), THISBACK(NewFile))
52
		.Help("Create new file");
50 53
	menu.AddMenu(AK_EDITFILE, CtrlImg::open(), THISBACK(EditAnyFile))
51 54
		.Help("Select any file in file selector and open it in editor");
52 55
	menu.AddMenu(!IsNull(GetOpposite()), AK_OPPOSITE, IdeImg::opposite(), THISBACK(GoOpposite))