Index: ide/NewFile.cpp =================================================================== --- ide/NewFile.cpp (nonexistent) +++ ide/NewFile.cpp (kopia robocza) @@ -0,0 +1,273 @@ +#include "ide.h" + +class CategoryFile : public Moveable { +public: + CategoryFile(const String& description, const String& extension) + : description(description) + , extension(extension) + {} + + const String& GetDescription() const { return description; } + const String& GetExtension() const { return extension; } + +private: + String description; + String extension; +}; + +class NewFileBasicInformationsWindow : public WithNewFileBasicInformationsLayout { + typedef NewFileBasicInformationsWindow CLASSNAME; + +public: + NewFileBasicInformationsWindow(const Vector& packages); + + String GetPackage() const; + String GetFileExt() const; + +private: + void InitCategories(); + void InitCategoriesArray(); + + void OnCategorySelection(); + +private: + VectorMap> categoriesFiles; +}; + +NewFileBasicInformationsWindow::NewFileBasicInformationsWindow(const Vector& packages) +{ + CtrlLayout(*this); + Zoomable(); + + for (const String& currentPackage : packages) + package.Add(currentPackage); + if (package.GetCount()) + package.SetIndex(0); + + InitCategories(); + InitCategoriesArray(); +} + +String NewFileBasicInformationsWindow::GetPackage() const +{ + return package.Get(); +} + +String NewFileBasicInformationsWindow::GetFileExt() const +{ + int cursor = files.GetCursor(); + if (cursor < 0) + return ""; + + return files.Get(cursor, 1); +} + +void NewFileBasicInformationsWindow::InitCategories() +{ + Vector cppFiles; + cppFiles.Add(CategoryFile("C source file (.c)", "c")); + cppFiles.Add(CategoryFile("C header (.h)", "h")); + cppFiles.Add(CategoryFile("C++ source file (.cpp)", "cpp")); + + categoriesFiles.Add("C/C++ source files", cppFiles); + + Vector uppFiles; + uppFiles.Add(CategoryFile("Layout file (.lay)", "lay")); + uppFiles.Add(CategoryFile("Image file (.iml)", "iml")); + + categoriesFiles.Add("Upp files", uppFiles); +} + +void NewFileBasicInformationsWindow::InitCategoriesArray() +{ + categories.AddColumn(); + files.AddColumn(); + files.AddColumn(); + files.ColumnWidths("100 0"); + for (int i = 0; i < categoriesFiles.GetCount(); i++) + categories.Add(categoriesFiles.GetKey(i)); + categories <<= THISBACK(OnCategorySelection); +} + +void NewFileBasicInformationsWindow::OnCategorySelection() +{ + int cursor = categories.GetCursor(); + if (cursor < 0) + return; + + String key = categories.Get(cursor, 0); + int idx = categoriesFiles.Find(key); + if (idx < 0) + return; + + files.Clear(); + for (const CategoryFile& cf : categoriesFiles[idx]) + files.Add(cf.GetDescription(), cf.GetExtension()); +} + +class NewFileSummaryWindow : public WithNewFileSummaryLayout { + typedef NewFileSummaryWindow CLASSNAME; + +public: + NewFileSummaryWindow(); + + String GetAbsoluteFilePath(); + void SetPackage(const String& newPackage); + void SetExtension(const String& newExtension); + + void UpdateFields(); + +private: + String package; + String extension; +}; + +NewFileSummaryWindow::NewFileSummaryWindow() +{ + CtrlLayout(*this); + + fileName <<= THISBACK(UpdateFields); + + Zoomable(); +} + +String NewFileSummaryWindow::GetAbsoluteFilePath() +{ + return absoluteFilePath.GetData(); +} + +void NewFileSummaryWindow::SetPackage(const String& newPackage) +{ + package = newPackage; +} + +void NewFileSummaryWindow::SetExtension(const String& newExtension) +{ + extension = newExtension; +} + +void NewFileSummaryWindow::UpdateFields() +{ + String file = fileName.GetData(); + String packageFile = file + "." + extension; + String absoluteFile = GetFileFolder(PackagePath(package)) + DIR_SEP + packageFile; + + filePathInPackage.SetData(packageFile); + absoluteFilePath.SetData(absoluteFile); +} + +class NewFileWindow : public WithNewFileLayout { + typedef NewFileWindow CLASSNAME; + enum class State; + +public: + NewFileWindow(const Vector& packages); + + String GetFilePath(); + +private: + void SetState(State newState); + void ResetStateComponents(); + + void OnNext(); + void OnBack(); + +private: + enum class State { + BasicInformations, + Summary, + Unknown + }; + + State state; + + NewFileBasicInformationsWindow basicInformations; + NewFileSummaryWindow summary; +}; + +NewFileWindow::NewFileWindow(const Vector& packages) + : state(State::Unknown) + , basicInformations(packages) +{ + CtrlLayoutOKCancel(*this, "New file"); + Zoomable(); + + parent.Add(basicInformations.SizePos()); + parent.Add(summary.SizePos()); + + next <<= THISBACK(OnNext); + back <<= THISBACK(OnBack); + + SetState(State::BasicInformations); +} + +String NewFileWindow::GetFilePath() +{ + return summary.GetAbsoluteFilePath(); +} + +void NewFileWindow::SetState(State newState) +{ + if(state == newState) + return; + + ResetStateComponents(); + + state = newState; + switch (state) { + case State::BasicInformations: + basicInformations.Show(); + next.Enable(); + break; + case State::Summary: + summary.SetPackage(basicInformations.GetPackage()); + summary.SetExtension(basicInformations.GetFileExt()); + summary.fileName.Clear(); + summary.UpdateFields(); + summary.Show(); + summary.fileName.SetFocus(); + ok.Enable(); + back.Enable(); + break; + default: + ASSERT(0); + } +} + +void NewFileWindow::ResetStateComponents() +{ + basicInformations.Hide(); + summary.Hide(); + + ok.Disable(); + + next.Disable(); + back.Disable(); +} + +void NewFileWindow::OnNext() +{ + SetState(State::Summary); +} + +void NewFileWindow::OnBack() +{ + SetState(State::BasicInformations); +} + +void Ide::NewFile() +{ + Vector packages; + + const Workspace& wspc = IdeWorkspace(); + for(int i = 0; i < wspc.GetCount(); i++){ + packages.Add(wspc[i]); + } + + NewFileWindow newFileWindow(packages); + if (newFileWindow.ExecuteOK()) { + String file = newFileWindow.GetFilePath(); + + Cout() << "File: " << file << "\n"; + } +} Index: ide/ide.h =================================================================== --- ide/ide.h (wersja 9829) +++ ide/ide.h (kopia robocza) @@ -753,6 +753,7 @@ void File(Bar& menu); void EditWorkspace(); + void NewFile(); void EditAnyFile(); bool IsProjectFile(const String& f) const; void SaveEditorFile(Stream& out); Index: ide/ide.lay =================================================================== --- ide/ide.lay (wersja 9829) +++ ide/ide.lay (kopia robocza) @@ -800,3 +800,29 @@ ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24)) END_LAYOUT +LAYOUT(NewFileLayout, 480, 404) + ITEM(Button, back, SetLabel(t_("Back")).RightPosZ(212, 64).BottomPosZ(8, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24)) + ITEM(Button, next, SetLabel(t_("Next")).RightPosZ(144, 64).BottomPosZ(8, 24)) + ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(8, 24)) + ITEM(ParentCtrl, parent, HSizePosZ(0, 0).VSizePosZ(0, 40)) +END_LAYOUT + +LAYOUT(NewFileBasicInformationsLayout, 480, 384) + ITEM(Label, dv___0, SetLabel(t_("Package:")).LeftPosZ(8, 56).TopPosZ(4, 20)) + ITEM(DropList, package, HSizePosZ(72, 12).TopPosZ(4, 20)) + ITEM(Label, dv___2, SetLabel(t_("Category:")).LeftPosZ(8, 120).TopPosZ(28, 19)) + ITEM(Label, dv___3, SetLabel(t_("File type:")).HSizePosZ(232, 128).TopPosZ(28, 19)) + ITEM(ArrayCtrl, categories, Header(false).AutoHideSb(true).LeftPosZ(8, 216).VSizePosZ(52, 8)) + ITEM(ArrayCtrl, files, Header(false).AutoHideSb(true).HSizePosZ(232, 12).VSizePosZ(52, 8)) +END_LAYOUT + +LAYOUT(NewFileSummaryLayout, 480, 392) + ITEM(Label, dv___0, SetLabel(t_("File name:")).LeftPosZ(8, 116).TopPosZ(8, 24)) + ITEM(EditString, fileName, HSizePosZ(132, 8).TopPosZ(8, 24)) + ITEM(Label, dv___2, SetLabel(t_("File path in package:")).LeftPosZ(8, 116).TopPosZ(40, 24)) + ITEM(EditString, filePathInPackage, SetEditable(false).HSizePosZ(132, 8).TopPosZ(40, 24)) + ITEM(Label, dv___4, SetLabel(t_("Absolute file path:")).LeftPosZ(8, 116).TopPosZ(72, 24)) + ITEM(EditString, absoluteFilePath, SetEditable(false).HSizePosZ(132, 8).TopPosZ(72, 24)) +END_LAYOUT + Index: ide/ide.upp =================================================================== --- ide/ide.upp (wersja 9829) +++ ide/ide.upp (kopia robocza) @@ -41,6 +41,7 @@ Config.cpp, ide.cpp, idefile.cpp charset "iso8859-1", + NewFile.cpp, EditorTabBar.cpp, Bottom.cpp, t.cpp, Index: ide/idebar.cpp =================================================================== --- ide/idebar.cpp (wersja 9829) +++ ide/idebar.cpp (kopia robocza) @@ -46,7 +46,10 @@ { menu.Add(AK_SETMAIN, THISBACK(NewMainPackage)) .Help("Select global configuration (var), select / add main project package"); - + menu.Separator(); + + menu.Add("New file", CtrlImg::new_doc(), THISBACK(NewFile)) + .Help("Create new file"); menu.AddMenu(AK_EDITFILE, CtrlImg::open(), THISBACK(EditAnyFile)) .Help("Select any file in file selector and open it in editor"); menu.AddMenu(!IsNull(GetOpposite()), AK_OPPOSITE, IdeImg::opposite(), THISBACK(GoOpposite))