NewFile.diff

Initial version (working copy) - Zbigniew Rebacz, 05/15/2016 11:45 AM

Download (6.06 KB)

View differences:

ide/NewFile.cpp (kopia robocza)
1
#include "ide.h"
2

  
3
class NewFileBasicInformationsWindow : public WithNewFileBasicInformationsLayout<TopWindow> {
4
	typedef NewFileBasicInformationsWindow CLASSNAME;
5
	
6
public:
7
	NewFileBasicInformationsWindow(const Vector<String>& packages);
8
};
9

  
10
NewFileBasicInformationsWindow::NewFileBasicInformationsWindow(const Vector<String>& packages)
11
{
12
	CtrlLayout(*this);
13
	
14
	for (const String& currentPackage : packages)
15
		package.Add(currentPackage);
16
	
17
	Zoomable();
18
}
19

  
20
class NewFileSummaryWindow : public WithNewFileSummaryLayout<TopWindow> {
21
	typedef NewFileSummaryWindow CLASSNAME;
22
	
23
public:
24
	NewFileSummaryWindow();
25
};
26

  
27
NewFileSummaryWindow::NewFileSummaryWindow()
28
{
29
	CtrlLayout(*this);
30
	
31
	Zoomable();
32
}
33

  
34
class NewFileWindow : public WithNewFileLayout<TopWindow> {
35
	typedef NewFileWindow CLASSNAME;
36
	enum class State;
37
	
38
public:
39
	NewFileWindow(const Vector<String>& packages);
40
	
41
	String GetFilePath();
42
	
43
private:
44
	void SetState(State newState);
45
	void ResetStateComponents();
46

  
47
	void OnNext();
48
	void OnBack();
49
	
50
private:
51
	enum class State {
52
		BasicInformations,
53
		Summary,
54
		Unknown
55
	};
56
	
57
	State state;
58

  
59
	NewFileBasicInformationsWindow basicInformations;
60
	NewFileSummaryWindow           summary;
61
};
62

  
63
NewFileWindow::NewFileWindow(const Vector<String>& packages)
64
	: state(State::Unknown)
65
	, basicInformations(packages)
66
{
67
	CtrlLayoutOKCancel(*this, "New file");
68
	Zoomable();
69
	
70
	parent.Add(basicInformations.SizePos());
71
	parent.Add(summary.SizePos());
72
	
73
	next <<= THISBACK(OnNext);
74
	back <<= THISBACK(OnBack);
75
	
76
	SetState(State::BasicInformations);
77
}
78

  
79
String NewFileWindow::GetFilePath()
80
{
81
	// TODO: This should be generated better
82
	return summary.fileName;
83
}
84

  
85
void NewFileWindow::SetState(State newState)
86
{
87
	if(state == newState)
88
		return;
89
	
90
	ResetStateComponents();
91
	
92
	state = newState;
93
	switch (state) {
94
		case State::BasicInformations:
95
			basicInformations.Show();
96
			next.Enable();
97
			break;
98
		case State::Summary:
99
			summary.Show();
100
			ok.Enable();
101
			back.Enable();
102
			break;
103
		default:
104
			ASSERT(0);
105
	}
106
}
107

  
108
void NewFileWindow::ResetStateComponents()
109
{
110
	basicInformations.Hide();
111
	summary.Hide();
112
	
113
	ok.Disable();
114
	
115
	next.Disable();
116
	back.Disable();
117
}
118

  
119
void NewFileWindow::OnNext()
120
{
121
	SetState(State::Summary);
122
}
123

  
124
void NewFileWindow::OnBack()
125
{
126
	SetState(State::BasicInformations);
127
}
128

  
129
void Ide::NewFile()
130
{
131
	Vector<String> packages;
132
	
133
	const Workspace& wspc = IdeWorkspace();
134
	for(int i = 0; i < wspc.GetCount(); i++){
135
		packages.Add(wspc[i]);
136
	}
137
	
138
	NewFileWindow newFileWindow(packages);
139
	if (newFileWindow.ExecuteOK()) {
140
		String file = newFileWindow.GetFilePath();
141
		
142
		Cout() << "File: " << file << "\n";
143
	}
144
}
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, 8).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, types, 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, filePathInProject, 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))