mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-07-11 22:03:01 -06:00
NewPackageFile refactored
git-svn-id: svn://ultimatepp.org/upp/trunk@10221 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
f12744b117
commit
8e88ed3fb0
4 changed files with 88 additions and 169 deletions
|
|
@ -1,81 +1,103 @@
|
|||
#include "ide.h"
|
||||
|
||||
class NewPackageFileWindow : public WithNewPackageFileLayout<TopWindow> {
|
||||
public:
|
||||
NewPackageFileWindow(const String& packageDir, const String& extension);
|
||||
|
||||
|
||||
String GetFileName() const;
|
||||
|
||||
private:
|
||||
void OnFileNameChanged();
|
||||
struct NewPackageFileWindow : public WithNewPackageFileLayout<TopWindow> {
|
||||
NewPackageFileWindow();
|
||||
|
||||
void CheckFilePath();
|
||||
void Type(const char *ext, const char *desc);
|
||||
String GetError();
|
||||
void Sync();
|
||||
|
||||
private:
|
||||
String packageDir;
|
||||
String extension;
|
||||
String folder;
|
||||
};
|
||||
|
||||
NewPackageFileWindow::NewPackageFileWindow(const String& packageDir, const String& extension)
|
||||
: packageDir(packageDir)
|
||||
, extension(extension)
|
||||
NewPackageFileWindow::NewPackageFileWindow()
|
||||
{
|
||||
CtrlLayoutOKCancel(*this, "");
|
||||
CtrlLayoutOKCancel(*this, "New package file");
|
||||
|
||||
type.SetLineCy(max(Zy(16), Draw::GetStdFontCy()));
|
||||
type.SetDropLines(20);
|
||||
Type("cpp", "C++ source file");
|
||||
Type("h", "C++ header file");
|
||||
type.AddSeparator();
|
||||
Type("lay", "Layout file (dialog templates)");
|
||||
Type("iml", "Image file (icons)");
|
||||
Type("icpp", "Initialization C++ source file");
|
||||
Type("usc", "Escape script file (scripting TheIDE)");
|
||||
Type("witz", "Skylark template file (web framework files)");
|
||||
type.AddSeparator();
|
||||
Type("json", "JSON file");
|
||||
Type("xml", "XML file");
|
||||
Type("html", "HTML file");
|
||||
Type("css", "CSS file");
|
||||
type.AddSeparator();
|
||||
Type("java", "Java");
|
||||
Type("js", "JavaScript");
|
||||
Type("py", "Python");
|
||||
type.AddSeparator();
|
||||
Type("", "Other");
|
||||
|
||||
fileName.WhenAction << [=] { OnFileNameChanged(); };
|
||||
name << [=] {
|
||||
String ext = GetFileExt(~~name);
|
||||
if(ext.GetCount()) {
|
||||
ext = ext.Mid(1);
|
||||
type <<= type.HasKey(ext) ? ext : Null;
|
||||
}
|
||||
Sync();
|
||||
};
|
||||
name <<= ".cpp";
|
||||
|
||||
fullFileName.Disable();
|
||||
if (extension.IsEmpty()) {
|
||||
fullFileNameLabel.Hide();
|
||||
fullFileName.Hide();
|
||||
|
||||
info.VSizePosZ(28, 36);
|
||||
}
|
||||
type <<= "cpp";
|
||||
|
||||
OnFileNameChanged();
|
||||
type << [=] {
|
||||
String ext = ~type;
|
||||
if(ext.GetCount()) {
|
||||
String h = ~name;
|
||||
name <<= ForceExt(h, "." + ext);
|
||||
int q = GetFileTitle(h).GetCount();
|
||||
name.SetSelection(q, q);
|
||||
}
|
||||
Sync();
|
||||
};
|
||||
|
||||
Sync();
|
||||
}
|
||||
|
||||
void NewPackageFileWindow::OnFileNameChanged()
|
||||
String NewPackageFileWindow::GetError()
|
||||
{
|
||||
String name = fileName.GetData();
|
||||
if (!extension.IsEmpty())
|
||||
fullFileName.SetData(name + "." + extension);
|
||||
else
|
||||
fullFileName.SetData(name);
|
||||
|
||||
CheckFilePath();
|
||||
String n = ~name;
|
||||
String p = AppendFileName(folder, n);
|
||||
if(FileExists(p))
|
||||
return String().Cat() << "File&[* \1" << p << "\1]&already exists!";
|
||||
if(*n == '.')
|
||||
return "Invalid filename!";
|
||||
return Null;
|
||||
}
|
||||
|
||||
void NewPackageFileWindow::CheckFilePath()
|
||||
|
||||
void NewPackageFileWindow::Sync()
|
||||
{
|
||||
String name = fileName.GetData();
|
||||
String fullName = fullFileName.GetData();
|
||||
|
||||
info.Clear();
|
||||
if (name.IsEmpty()) {
|
||||
ok.Disable();
|
||||
}
|
||||
else
|
||||
if (FileExists(packageDir + DIR_SEPS + fullName)) {
|
||||
ok.Disable();
|
||||
info.SetData("[ [ [@(170.42.0) File already exists.]]]");
|
||||
}
|
||||
else {
|
||||
ok.Enable();
|
||||
}
|
||||
name.Error(GetError().GetCount());
|
||||
}
|
||||
|
||||
String NewPackageFileWindow::GetFileName() const
|
||||
void NewPackageFileWindow::Type(const char *ext, const char *desc)
|
||||
{
|
||||
return fullFileName.GetData();
|
||||
type.Add(ext, AttrText(desc).SetImage(IdeFileImage(String() << "x." << ext, false, false)));
|
||||
}
|
||||
|
||||
void WorkspaceWork::NewPackageFile(const String& title, const String& extension)
|
||||
void WorkspaceWork::NewPackageFile()
|
||||
{
|
||||
NewPackageFileWindow dlg(GetFileFolder(GetActivePackagePath()), extension);
|
||||
dlg.Title(title);
|
||||
|
||||
if (dlg.ExecuteOK())
|
||||
AddItem(dlg.GetFileName(), false, false);
|
||||
NewPackageFileWindow dlg;
|
||||
dlg.folder = GetFileFolder(GetActivePackagePath());
|
||||
dlg.Open();
|
||||
dlg.name.SetFocus();
|
||||
dlg.name.SetSelection(0, 0);
|
||||
for(;;) {
|
||||
if(dlg.Run() != IDOK)
|
||||
return;
|
||||
String e = dlg.GetError();
|
||||
if(e.GetCount() == 0)
|
||||
break;
|
||||
Exclamation(e);
|
||||
}
|
||||
AddItem(~dlg.name, false, false);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -281,36 +281,6 @@ struct WorkspaceWork {
|
|||
|
||||
ArrayMap<String, Backup> backup;
|
||||
|
||||
class FileType : public Moveable<FileType> {
|
||||
public:
|
||||
FileType()
|
||||
: separator(true)
|
||||
{}
|
||||
|
||||
FileType(const String& name, const String& extension)
|
||||
: separator(false)
|
||||
, name(name)
|
||||
, extension(extension)
|
||||
{}
|
||||
|
||||
bool IsSeparator() const { return separator; }
|
||||
|
||||
String GetName() const { return name; }
|
||||
String GetExtension() const { return extension; }
|
||||
const Image& GetImage() const { return img; }
|
||||
|
||||
void SetImage(const Image& image) { img = image; }
|
||||
|
||||
private:
|
||||
bool separator;
|
||||
|
||||
String name;
|
||||
String extension;
|
||||
Image img;
|
||||
};
|
||||
|
||||
VectorMap<String, Vector<FileType>> categories;
|
||||
|
||||
bool organizer;
|
||||
bool showtime;
|
||||
bool sort;
|
||||
|
|
@ -372,9 +342,7 @@ struct WorkspaceWork {
|
|||
void DnDInsert(int line, PasteClip& d);
|
||||
void Drag();
|
||||
|
||||
void LoadCategories();
|
||||
void LoadCategoriesImages();
|
||||
void NewPackageFile(const String& title, const String& extension);
|
||||
void NewPackageFile();
|
||||
|
||||
enum ADDFILE { PACKAGE_FILE, OUTPUT_FILE, HOME_FILE, LOCAL_FILE, CONFIG_FILE, ANY_FILE };
|
||||
void AddFile(ADDFILE type);
|
||||
|
|
@ -409,7 +377,6 @@ struct WorkspaceWork {
|
|||
|
||||
void PackageMenu(Bar& bar);
|
||||
void FileMenu(Bar& bar);
|
||||
void NewMenu(Bar& bar);
|
||||
void SpecialFileMenu(Bar& bar);
|
||||
void InsertSpecialMenu(Bar& menu);
|
||||
|
||||
|
|
|
|||
|
|
@ -859,13 +859,13 @@ void WorkspaceWork::FileMenu(Bar& menu)
|
|||
{
|
||||
bool sel = filelist.IsCursor() && filelist[filelist.GetCursor()].isdir;
|
||||
|
||||
menu.Add("New", THISBACK(NewMenu));
|
||||
menu.Separator();
|
||||
|
||||
bool isaux = IsAux();
|
||||
if(isaux)
|
||||
InsertSpecialMenu(menu);
|
||||
else {
|
||||
menu.Add("New package file..", [=] { NewPackageFile(); });
|
||||
menu.Add("Insert separator", [=] { AddSeparator(); })
|
||||
.Help("Add text separator line");
|
||||
menu.Add(!isaux, "Insert package directory file(s)", THISBACK1(AddFile, PACKAGE_FILE))
|
||||
.Help("Insert file relative to current package");
|
||||
menu.Add(!isaux, "Insert topic++ group", THISBACK(AddTopicGroup));
|
||||
|
|
@ -920,31 +920,6 @@ void WorkspaceWork::FileMenu(Bar& menu)
|
|||
FilePropertiesMenu(menu);
|
||||
}
|
||||
|
||||
void WorkspaceWork::NewMenu(Bar& bar)
|
||||
{
|
||||
bar.Add("File", CtrlImg::File(), [=] { NewPackageFile("New file", ""); });
|
||||
bar.Add("Separator", [=] { AddSeparator(); })
|
||||
.Help("Add text separator line");
|
||||
|
||||
bar.Separator();
|
||||
for (int i = 0; i < categories.GetCount(); i++) {
|
||||
bar.Sub(categories.GetKey(i), [=](Bar& subBar) {
|
||||
for (FileType& fileType : categories[i]) {
|
||||
String name = fileType.GetName();
|
||||
String extension = fileType.GetExtension();
|
||||
|
||||
if (fileType.IsSeparator())
|
||||
subBar.Separator();
|
||||
else {
|
||||
subBar.Add(name, fileType.GetImage(), [=] {
|
||||
NewPackageFile("New " + name, extension);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void WorkspaceWork::TogglePCH()
|
||||
{
|
||||
if(IsActiveFile()) {
|
||||
|
|
@ -1146,46 +1121,6 @@ void WorkspaceWork::Drag()
|
|||
filelist.GetDragSample(), DND_MOVE);
|
||||
}
|
||||
|
||||
void WorkspaceWork::LoadCategories()
|
||||
{
|
||||
Vector<FileType> cppFiles;
|
||||
cppFiles.Add(FileType("C++ source file", "cpp"));
|
||||
cppFiles.Add(FileType("C++ header file", "h"));
|
||||
categories.Add("C/C++", cppFiles);
|
||||
|
||||
Vector<FileType> uppFiles;
|
||||
uppFiles.Add(FileType("Layout file", "lay"));
|
||||
uppFiles.Add(FileType("Image file", "iml"));
|
||||
uppFiles.Add(FileType("Escape script file", "usc"));
|
||||
uppFiles.Add(FileType("Skylark template file", "witz"));
|
||||
uppFiles.Add(FileType());
|
||||
uppFiles.Add(FileType("Initialization C++ source file", "icpp"));
|
||||
categories.Add("U++", uppFiles);
|
||||
|
||||
Vector<FileType> javaFiles;
|
||||
javaFiles.Add(FileType("Java source file", "java"));
|
||||
categories.Add("Java", javaFiles);
|
||||
|
||||
Vector<FileType> webFiles;
|
||||
webFiles.Add(FileType("HTML source file", "html"));
|
||||
webFiles.Add(FileType("CSS source file", "css"));
|
||||
webFiles.Add(FileType("JavaScript source file", "js"));
|
||||
webFiles.Add(FileType("JSON file", "json"));
|
||||
webFiles.Add(FileType("XML file", "xml"));
|
||||
categories.Add("Web", webFiles);
|
||||
|
||||
Vector<FileType> otherFiles;
|
||||
otherFiles.Add(FileType("Text file", "txt"));
|
||||
categories.Add("Other", otherFiles);
|
||||
}
|
||||
|
||||
void WorkspaceWork::LoadCategoriesImages()
|
||||
{
|
||||
for (int i = 0; i < categories.GetCount(); i++)
|
||||
for (FileType& type : categories[i])
|
||||
type.SetImage(IdeFileImage("." + type.GetExtension(), false, false));
|
||||
}
|
||||
|
||||
WorkspaceWork::WorkspaceWork()
|
||||
{
|
||||
package <<= THISBACK(PackageCursor);
|
||||
|
|
@ -1206,9 +1141,6 @@ WorkspaceWork::WorkspaceWork()
|
|||
showtime = false;
|
||||
sort = true;
|
||||
svn_dirs = false;
|
||||
|
||||
LoadCategories();
|
||||
LoadCategoriesImages();
|
||||
}
|
||||
|
||||
void WorkspaceWork::SerializeClosed(Stream& s)
|
||||
|
|
|
|||
|
|
@ -795,13 +795,11 @@ LAYOUT(RenamePackage2Layout, 228, 100)
|
|||
ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24))
|
||||
END_LAYOUT
|
||||
|
||||
LAYOUT(NewPackageFileLayout, 372, 132)
|
||||
ITEM(Label, fullFileNameLabel, SetLabel(t_("Full file name:")).LeftPosZ(4, 76).TopPosZ(28, 21))
|
||||
ITEM(EditString, fullFileName, HSizePosZ(84, 4).TopPosZ(28, 19))
|
||||
ITEM(RichTextView, info, Background(Null).AutoHideSb(true).SetFrame(TopSeparatorFrame()).HSizePosZ(4, 4).VSizePosZ(56, 36))
|
||||
LAYOUT(NewPackageFileLayout, 260, 88)
|
||||
ITEM(EditString, name, HSizePosZ(44, 8).TopPosZ(28, 19))
|
||||
ITEM(Label, dv___1, SetLabel(t_("Name ")).LeftPosZ(4, 64).TopPosZ(28, 19))
|
||||
ITEM(DropList, type, HSizePosZ(4, 8).TopPosZ(4, 19))
|
||||
ITEM(Button, ok, SetLabel(t_("OK")).RightPosZ(76, 64).BottomPosZ(8, 24))
|
||||
ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24))
|
||||
ITEM(Label, dv___5, SetLabel(t_("File name:")).LeftPosZ(4, 76).TopPosZ(4, 21))
|
||||
ITEM(EditString, fileName, HSizePosZ(84, 4).TopPosZ(4, 19))
|
||||
END_LAYOUT
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue