Index: NewFile.cpp =================================================================== --- NewFile.cpp (nonexistent) +++ NewFile.cpp (kopia robocza) @@ -0,0 +1,377 @@ +#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 { +public: + NewFileBasicInformationsWindow(const Workspace& wspc, const String& activePackage, Button* parentNext); + + String GetPackage() const; + String GetFileExt() const; + + bool IsTypeChoosen() const; + +private: + void InitCategories(); + void InitCategoriesArray(); + + void OnCategorySelection(); + void OnTypeDeclarationChange(); + void OnFileTypeChange(); + +private: + VectorMap> categoriesFiles; + + Button* parentNext; +}; + +NewFileBasicInformationsWindow::NewFileBasicInformationsWindow( + const Workspace& wspc, + const String& activePackage, + Button* parentNext) + : parentNext(parentNext) +{ + CtrlLayout(*this); + Zoomable(); + + for(int i = 0; i < wspc.GetCount(); i++) + package.Add(wspc[i]); + if (package.GetCount()) { + int activeIdx = package.Find(activePackage); + package.SetIndex(activeIdx >= 0 ? activeIdx : 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); +} + +bool NewFileBasicInformationsWindow::IsTypeChoosen() const +{ + return typeDeclaration.Get() == 0; +} + +void NewFileBasicInformationsWindow::InitCategories() +{ + // TODO: Maybe we should have separate file for this? + + 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")); + cppFiles.Add(CategoryFile("C++ header file (.hpp)", "hpp")); + categoriesFiles.Add("C/C++ source files", cppFiles); + + Vector javaFiles; + javaFiles.Add(CategoryFile("Java source file (.java)", "java")); + categoriesFiles.Add("Java source files", javaFiles); + + Vector uppFiles; + uppFiles.Add(CategoryFile("Layout file (.lay)", "lay")); + uppFiles.Add(CategoryFile("Image file (.iml)", "iml")); + uppFiles.Add(CategoryFile("Escape script file (.usc)", "usc")); + categoriesFiles.Add("Upp files", uppFiles); + + Vector webFiles; + webFiles.Add(CategoryFile("JavaScript source file (.js)", "js")); + webFiles.Add(CategoryFile("Skylark template file (.witz)", "witz")); + categoriesFiles.Add("Web", webFiles); + + Vector otherFiles; + otherFiles.Add(CategoryFile("Text file (.txt)", "txt")); + categoriesFiles.Add("Other", otherFiles); +} + +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 << [&] { OnCategorySelection(); }; + files << [&] { OnFileTypeChange(); }; + typeDeclaration << [&] { OnTypeDeclarationChange(); }; +} + +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()); + + parentNext->Disable(); +} + +void NewFileBasicInformationsWindow::OnTypeDeclarationChange() +{ + if (typeDeclaration.Get() == 1) { + categories.Disable(); + files.Disable(); + + parentNext->Enable(); + } + else { + categories.Enable(); + files.Enable(); + } +} + +void NewFileBasicInformationsWindow::OnFileTypeChange() +{ + parentNext->Enable(files.GetCursor() >= 0); +} + +class NewFileSummaryWindow : public WithNewFileSummaryLayout { + typedef NewFileSummaryWindow CLASSNAME; + +public: + NewFileSummaryWindow(Button* newFileWindowOK); + + String GetAbsoluteFilePath(); + String GetFilePathInPackage(); + void SetPackage(const String& newPackage); + void SetExtension(const String& newExtension); + + void UpdateFields(); + +private: + void CheckPaths(const String& file, const String& absoluteFile); + void OnTypeDeclarationChange(); + +private: + String package; + String extension; + + Button* parentOK; +}; + +NewFileSummaryWindow::NewFileSummaryWindow(Button* okButton) + : parentOK(okButton) +{ + CtrlLayout(*this); + + fileName <<= THISBACK(UpdateFields); + /* + fileName <<= [&] { + UpdateFields(); + }; + */ + + Zoomable(); +} + +String NewFileSummaryWindow::GetAbsoluteFilePath() +{ + return absoluteFilePath.GetData(); +} + +String NewFileSummaryWindow::GetFilePathInPackage() +{ + return filePathInPackage.GetData(); +} + +void NewFileSummaryWindow::SetPackage(const String& newPackage) +{ + package = newPackage; +} + +void NewFileSummaryWindow::SetExtension(const String& newExtension) +{ + extension = newExtension; +} + +void NewFileSummaryWindow::UpdateFields() +{ + String file = fileName.GetData(); + file.IsEmpty() ? parentOK->Disable() : parentOK->Enable(); + + String packageFile = file; + if (!extension.IsEmpty()) + packageFile += "." + extension; + String absoluteFile = GetFileFolder(PackagePath(package)) + DIR_SEP + packageFile; + + filePathInPackage.SetData(packageFile); + absoluteFilePath.SetData(absoluteFile); + + CheckPaths(file, absoluteFilePath); +} + +void NewFileSummaryWindow::CheckPaths(const String& file, const String& absoluteFile) +{ + if (file.IsEmpty()) { + parentOK->Disable(); + } + else + if (FileExists(absoluteFile)) { + info.SetData("[ [ [@(170.42.0) Error: file already exists.]]]"); + parentOK->Disable(); + } + else { + info.Clear(); + parentOK->Enable(); + } +} + +class NewFileWindow : public WithNewFileLayout { + enum class State; + +public: + NewFileWindow(const Workspace& wspc, const String& activePackage); + + String GetAbsoluteFilePath(); + String GetFilePathInPackage(); + +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 Workspace& wspc, const String& activePackage) + : state(State::Unknown) + , basicInformations(wspc, activePackage, &next) + , summary(&ok) +{ + CtrlLayoutOKCancel(*this, "New file"); + Zoomable(); + + parent.Add(basicInformations.SizePos()); + parent.Add(summary.SizePos()); + + next << [&] { OnNext(); }; + back << [&] { OnBack(); }; + + SetState(State::BasicInformations); +} + +String NewFileWindow::GetAbsoluteFilePath() +{ + return summary.GetAbsoluteFilePath(); +} + +String NewFileWindow::GetFilePathInPackage() +{ + return summary.GetFilePathInPackage(); +} + +void NewFileWindow::SetState(State newState) +{ + if(state == newState) + return; + + ResetStateComponents(); + + switch (newState) { + case State::BasicInformations: + basicInformations.Show(); + if (state == State::Summary) + next.Enable(); + break; + case State::Summary: + summary.SetPackage(basicInformations.GetPackage()); + summary.SetExtension(basicInformations.IsTypeChoosen() ? basicInformations.GetFileExt() : ""); + summary.fileName.Clear(); + summary.UpdateFields(); + summary.Show(); + summary.fileName.SetFocus(); + back.Enable(); + break; + default: + ASSERT(0); + } + + state = newState; +} + +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; + + String activePackage = GetActivePackage(); + NewFileWindow newFileWindow(IdeWorkspace(), activePackage); + if (!newFileWindow.ExecuteOK()) + return; + + Package pkg; + String uppManifestPath = PackagePath(activePackage); + pkg.Load(uppManifestPath); + Package::File& packageFile = pkg.file.Add(); + packageFile = newFileWindow.GetFilePathInPackage(); + pkg.Save(uppManifestPath); + + // TODO: Bad solution <- We should open this file in TheIDE like in workspace. + SaveFile(absolutePath); +} Index: icon.ico =================================================================== Nie można wyświetlić: plik binarny. svn:mime-type = application/octet-stream Index: ide.h =================================================================== --- ide.h (wersja 9872) +++ 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.key =================================================================== --- ide.key (wersja 9872) +++ ide.key (kopia robocza) @@ -1,4 +1,5 @@ KEY(SETMAIN, "Set main package..", K_CTRL_M) +KEY(NEWFILE, "New file", K_CTRL_N|K_SHIFT) KEY(EDITFILE, "Edit file", K_CTRL_O) KEY(OPPOSITE, "Opposite file", K_ALT_O) KEY(SAVEFILE, "Save", K_CTRL_S) Index: ide.lay =================================================================== --- ide.lay (wersja 9872) +++ ide.lay (kopia robocza) @@ -795,3 +795,31 @@ 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(208, 64).BottomPosZ(8, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(4, 64).BottomPosZ(8, 24)) + ITEM(Button, next, SetLabel(t_("Next")).RightPosZ(140, 64).BottomPosZ(8, 24)) + ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(72, 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, 8).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).VertGrid(false).HorzGrid(false).LeftPosZ(8, 216).VSizePosZ(52, 32)) + ITEM(ArrayCtrl, files, Header(false).AutoHideSb(true).VertGrid(false).HorzGrid(false).HSizePosZ(232, 8).VSizePosZ(52, 32)) + ITEM(Option, typeDeclaration, SetLabel(t_("I want to choose the file type by myself")).HSizePosZ(8, 8).BottomPosZ(8, 16)) +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)) + ITEM(RichTextView, info, Background(Null).AutoHideSb(true).SetFrame(TopSeparatorFrame()).HSizePosZ(8, 8).TopPosZ(104, 72)) +END_LAYOUT + Index: ide.upp =================================================================== --- ide.upp (wersja 9872) +++ 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: idebar.cpp =================================================================== --- idebar.cpp (wersja 9872) +++ 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(AK_NEWFILE, CtrlImg::new_doc(), THISBACK(NewFile)) + .Help("Create new file with creator"); 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))