diff --git a/uppsrc/Core/src.tpp/Path_en-us.tpp b/uppsrc/Core/src.tpp/Path_en-us.tpp index c06043b12..ad66e8edb 100644 --- a/uppsrc/Core/src.tpp/Path_en-us.tpp +++ b/uppsrc/Core/src.tpp/Path_en-us.tpp @@ -1,5 +1,4 @@ topic "File path utilities"; -[2 $$0,0#00000000000000000000000000000000:Default] [i448;a25;kKO9;2 $$1,0#37138531426314131252341829483380:class] [l288;2 $$2,0#27521748481378242620020725143825:desc] [0 $$3,0#96390100711032703541132217272105:end] @@ -9,6 +8,7 @@ topic "File path utilities"; [l288;i1121;b17;O9;~~~.1408;2 $$7,0#10431211400427159095818037425705:param] [i448;b42;O9;2 $$8,8#61672508125594000341940100500538:tparam] [b42;2 $$9,9#13035079074754324216151401829390:normal] +[2 $$0,0#00000000000000000000000000000000:Default] [{_} [s0;%% [*@3;4 File path utilities]&] [s3; &] @@ -228,7 +228,8 @@ st]_[@(0.0.255) char]_`*[*@3 oldpath], [@(0.0.255) const]_[@(0.0.255) char]_`*[* st]_[@(0.0.255) char]_`*[*@3 oldpath], [@(0.0.255) const]_[@(0.0.255) char]_`*[*@3 newpath]) &] [s2;%% Moves a file at [%-*@3 oldpath] to a new file at [%-*@3 newpath] -(if already exists, overwrites it). Returns true on success.&] +(if already exists, overwrites it). Returns true on success. +Works on directories too.&] [s3;%% &] [s4; &] [s5;:FileDelete`(const char`*`): [@(0.0.255) bool]_[* FileDelete]([@(0.0.255) const]_[@(0.0.255) c @@ -326,4 +327,4 @@ nst]_[@(0.0.255) char]_`*[*@3 prefix]_`=_NULL)&] [s2;%% Returns a unique path of temporary file. If [%-*@3 prefix ]is not NULL, it is prepended to the filename.&] [s3;%% &] -[s0; ] \ No newline at end of file +[s0; ]] \ No newline at end of file diff --git a/uppsrc/CtrlLib/CtrlUtil.cpp b/uppsrc/CtrlLib/CtrlUtil.cpp index 1280f4fb0..bef700591 100644 --- a/uppsrc/CtrlLib/CtrlUtil.cpp +++ b/uppsrc/CtrlLib/CtrlUtil.cpp @@ -390,8 +390,14 @@ void FileSelButton::OnAction() Ctrl *owner = button.GetParent(); ASSERT(owner); String old = ~*owner; - if(mode == MODE_DIR) + if(mode == MODE_DIR) { + for(int i = 0; i < 4; i++) { + if(DirectoryExists(old)) + break; + old = GetFileFolder(old); + } ActiveDir(old); + } else Set(old); if(mode == MODE_OPEN ? ExecuteOpen(title) : mode == MODE_SAVE ? ExecuteSaveAs(title) : ExecuteSelectDir(title)) diff --git a/uppsrc/CtrlLib/DropChoice.h b/uppsrc/CtrlLib/DropChoice.h index a4cd472ea..dcfb1ce8f 100644 --- a/uppsrc/CtrlLib/DropChoice.h +++ b/uppsrc/CtrlLib/DropChoice.h @@ -181,6 +181,7 @@ public: void Clear(); void Add(const Value& data); + int Find(const Value& data) const { return list.Find(data); } void FindAdd(const Value& data); void Set(int i, const Value& data) { list.Set(i, 0, data); } void Remove(int i); @@ -245,6 +246,7 @@ public: void ClearList() { select.Clear(); } void AddList(const Value& data) { select.Add(data); } void FindAddList(const Value& data) { select.FindAdd(data); } + int Find(const Value& data) const { return select.Find(data); } void Set(int i, const Value& data) { select.Set(i, data); } void Remove(int i) { select.Remove(i); } void SerializeList(Stream& s) { select.SerializeList(s); } diff --git a/uppsrc/CtrlLib/src.tpp/WithDropChoice_en-us.tpp b/uppsrc/CtrlLib/src.tpp/WithDropChoice_en-us.tpp index bc9e57db2..a32341ebe 100644 --- a/uppsrc/CtrlLib/src.tpp/WithDropChoice_en-us.tpp +++ b/uppsrc/CtrlLib/src.tpp/WithDropChoice_en-us.tpp @@ -54,6 +54,11 @@ indAddList]([@(0.0.255) const]_[_^Upp`:`:Value^ Value][@(0.0.255) `&]_[*@3 data] already there.&] [s3;%% &] [s4; &] +[s5;:Upp`:`:WithDropChoice`:`:Find`(const Upp`:`:Value`&`)const: [@(0.0.255) int]_[* Find +]([@(0.0.255) const]_[_^Upp`:`:Value^ Value][@(0.0.255) `&]_[*@3 data])_[@(0.0.255) const]&] +[s2;%% Finds the index of first list entry equal to [%-*@3 data].&] +[s3;%% &] +[s4; &] [s5;:Upp`:`:WithDropChoice`:`:Set`(int`,const Upp`:`:Value`&`): [@(0.0.255) void]_[* Set]( [@(0.0.255) int]_[*@3 i], [@(0.0.255) const]_[_^Upp`:`:Value^ Value][@(0.0.255) `&]_[*@3 data ])&] diff --git a/uppsrc/ide/Common/Common.h b/uppsrc/ide/Common/Common.h index 0aa1552fd..754c1c220 100644 --- a/uppsrc/ide/Common/Common.h +++ b/uppsrc/ide/Common/Common.h @@ -98,7 +98,10 @@ void StoreToWorkspace(T& x, const char *name) void SerializeWorkspaceConfigs(Stream& s); extern bool IdeExit; +extern bool IdeAgain; // Used to restart theide after checking out SVN (SetupSVNTrunk) bool CopyFolder(const char *dst, const char *src, Progress *pi = NULL); +bool HasSvn(); + #endif diff --git a/uppsrc/ide/Common/Util.cpp b/uppsrc/ide/Common/Util.cpp index e49e79d7f..e47aa9424 100644 --- a/uppsrc/ide/Common/Util.cpp +++ b/uppsrc/ide/Common/Util.cpp @@ -219,6 +219,7 @@ INITBLOCK { } bool IdeExit; +bool IdeAgain; bool CopyFolder(const char *dst, const char *src, Progress *pi) { @@ -243,3 +244,10 @@ bool CopyFolder(const char *dst, const char *src, Progress *pi) } return true; } + +bool HasSvn() +{ + String dummy; + static bool b = Sys("svn", dummy) >= 0; + return b; +} diff --git a/uppsrc/ide/SelectPkg.cpp b/uppsrc/ide/SelectPkg.cpp index 20ca77838..33e8042df 100644 --- a/uppsrc/ide/SelectPkg.cpp +++ b/uppsrc/ide/SelectPkg.cpp @@ -343,6 +343,14 @@ void SelectPackageDlg::ToolBase(Bar& bar) bar.Add("Synchronize " + d[i], IdeImg::svn_dir(), THISBACK1(SyncSvnDir, d[i])); bar.Add("Synchronize everything..", IdeImg::svn(), THISBACK(SyncSvnDirs)); } + if(HasSvn()) { + bar.Separator(); + bar.Add("Checkout and setup U++ SVN trunk sources..", [=] { + String vars = base.Get(0); + SetupSVNTrunk(); + SyncBase(vars); + }); + } } void SelectPackageDlg::OnBaseAdd() diff --git a/uppsrc/ide/SetupSVN.cpp b/uppsrc/ide/SetupSVN.cpp new file mode 100644 index 000000000..b7004adc0 --- /dev/null +++ b/uppsrc/ide/SetupSVN.cpp @@ -0,0 +1,108 @@ +#include "ide.h" + +void SetupSVNTrunk() +{ + WithSetupSVNLayout dlg; + CtrlLayoutOKCancel(dlg, "Checkout U++ trunk"); + SelectDirButton dir_browse("Run in folder"); + dir_browse.Attach(dlg.dir); +#ifdef PLATFORM_WIN32 + dlg.dir <<= GetExeDirFile("upp.src"); +#else + dlg.dir <<= GetHomeDirFile("upp.src"); +#endif + static MapConvert revcv; + ONCELOCK { + revcv.Add(11873, "2018.1 (rev 11873) (Mar 2018)"); + revcv.Add(11540, "2017.2 (rev 11540) (Dec 2017)"); + revcv.Add(10804, "2017.1 (rev 10804) (Jan 2017)"); + revcv.Add(9251, "2015.2 (rev 9251) (Dec 2015)"); + revcv.Add(8227, "2015.1 (rev 8227) (Mar 2015)"); + } + dlg.revision.SetConvert(revcv); + dlg.revision.DropWidthZ(200); + for(int i = 0; i < revcv.GetCount(); i++) + dlg.revision.AddList(revcv.GetKey(i)); + dlg.revision.NullText("HEAD"); + dlg.revision << [&] { + String r = ~~dlg.revision; + dlg.postfix <<= r.GetCount() ? '.' + r : String(); + }; + + UrepoConsole console; + console.WithCancel(); + String dir, tempdir; + for(;;) { + if(dlg.Run() != IDOK) + return; + console.Clear(); + dir = ~dlg.dir; + tempdir = AppendFileName(GetFileFolder(dir), "temp"); + if(DirectoryExists(tempdir)) + tempdir = AppendFileName(GetFileFolder(dir), AsString(Uuid::Create())); + String revision = IsNull(dlg.revision) ? String() : "@" + ~~dlg.revision; + bool direxists = DirectoryExists(dir); + bool fileexists = FileExists(dir); + if((direxists || fileexists) && !PromptYesNo("Target path already exists, overwrite?")) + continue; + int exitcode = 0; +#ifdef _DEBUG + for(auto nest : { "uppsrc", "examples" }) +#else + for(auto nest : { "uppsrc", "reference", "examples", "tutorial", "bazaar" }) +#endif + { + static String svn = "svn checkout svn://www.ultimatepp.org/upp/trunk"; + if(dlg.all) { + exitcode = console.System(svn + revision + ' ' + tempdir); + break; + } + exitcode = console.System(svn + '/' + nest + revision + ' ' + tempdir + '/' + nest); + if(exitcode) + break; + } + if(exitcode == 0) + break; + console.Perform(); + DeleteFolderDeep(tempdir); + } + + FileDelete(dir); + DeleteFolderDeep(dir); + FileMove(tempdir, dir); + +#ifdef PLATFORM_WIN32 + String out = GetExeDirFile("out"); + String ass = GetExeFolder(); + String myapps = GetExeDirFile("MyApps"); +#else + String out = GetHomeDirectoryFile("out"); + String ass = GetConfigFolder(); + String myapps = GetExeDirFile("MyApps"); +#endif + RealizeDirectory(out); + + String uppsrc = AppendFileName(dir, "uppsrc"); + + auto MakeAssembly = [&](String b, String name = Null) { + name = Nvl(name, GetFileTitle(b)); + String a = ass + '/' + ~~dlg.prefix + name + ~~dlg.postfix + ".var"; + if(name != "uppsrc") + b << ';' << uppsrc; + console.Log("Creating assembly " + a); + SaveFile(a, + "UPP = " + AsCString(b) + ";\r\n" + "OUTPUT = " + AsCString(out) + ";\r\n" + ); + }; + + for(FindFile ff(dir + "/*"); ff; ff.Next()) + if(ff.IsFolder()) + MakeAssembly(ff.GetPath()); + + MakeAssembly(myapps); + uppsrc = AppendFileName(dir, "bazaar") + ';' + uppsrc; + MakeAssembly(myapps, "MyApps-bazaar"); + + console.Perform(); +} diff --git a/uppsrc/ide/SrcUpdater/Install.cpp b/uppsrc/ide/SrcUpdater/Install.cpp index 92d3860ab..99cbd5292 100644 --- a/uppsrc/ide/SrcUpdater/Install.cpp +++ b/uppsrc/ide/SrcUpdater/Install.cpp @@ -6,12 +6,6 @@ bool LoadVarFile(const char *name, VectorMap& _var); -bool HasSvn() -{ - String tmp; - return Sys("svn",tmp)>=0; -} - InstallWizard::InstallWizard() { Title("TheIDE - Initial setting wizard"); diff --git a/uppsrc/ide/ide.h b/uppsrc/ide/ide.h index 7d537ba3e..5d703ea30 100644 --- a/uppsrc/ide/ide.h +++ b/uppsrc/ide/ide.h @@ -1193,4 +1193,6 @@ inline void ShowConsole() { if(TheIde()) ((Ide *)TheIde())->ShowConsole(); } void InstantSetup(); +void SetupSVNTrunk(); + #endif diff --git a/uppsrc/ide/ide.lay b/uppsrc/ide/ide.lay index fdafc8e24..0209626d5 100644 --- a/uppsrc/ide/ide.lay +++ b/uppsrc/ide/ide.lay @@ -821,3 +821,17 @@ LAYOUT(NestEditorLayout, 420, 388) ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(8, 64).BottomPosZ(8, 24)) END_LAYOUT +LAYOUT(SetupSVNLayout, 536, 112) + ITEM(Label, dv___0, SetLabel(t_("Target directory")).LeftPosZ(4, 160).TopPosZ(4, 19)) + ITEM(EditString, dir, LeftPosZ(164, 364).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(Option, all, SetLabel(t_("Also checkout development and auxiliary packages")).LeftPosZ(4, 296).TopPosZ(28, 20)) + ITEM(Label, dv___5, SetLabel(t_("Add prefix to assembly names")).LeftPosZ(4, 160).TopPosZ(52, 19)) + ITEM(Label, dv___6, SetLabel(t_("Add postfix to assembly names")).LeftPosZ(304, 160).TopPosZ(52, 19)) + ITEM(EditString, prefix, LeftPosZ(164, 64).TopPosZ(52, 19)) + ITEM(EditString, postfix, LeftPosZ(464, 64).TopPosZ(52, 19)) + ITEM(WithDropChoice, revision, LeftPosZ(464, 64).TopPosZ(28, 19)) + ITEM(Label, dv___10, SetLabel(t_("Revision to checkout")).LeftPosZ(304, 160).TopPosZ(28, 19)) +END_LAYOUT + diff --git a/uppsrc/ide/ide.upp b/uppsrc/ide/ide.upp index 52da94098..c6146237a 100644 --- a/uppsrc/ide/ide.upp +++ b/uppsrc/ide/ide.upp @@ -88,6 +88,7 @@ file Json.cpp, MacroManager.cpp, Update.cpp, + SetupSVN.cpp, Compile readonly separator, MethodsCtrls.h, MethodsCtrls.cpp, diff --git a/uppsrc/ide/idebar.cpp b/uppsrc/ide/idebar.cpp index 89a4f6298..aad235978 100644 --- a/uppsrc/ide/idebar.cpp +++ b/uppsrc/ide/idebar.cpp @@ -391,10 +391,15 @@ void Ide::Setup(Bar& menu) // menu.Add("Legacy compilers automatic setup..", THISBACK(AutoSetup)) // .Help("Automatic setup of build methods for legacy compilers.."); #endif -#ifdef PLATFORM_POSIX - menu.Add("Source managment..", THISBACK(AutoSetup)) - .Help("Source code updater settings.."); -#endif +//#ifdef PLATFORM_POSIX +// menu.Add("Source managment..", THISBACK(AutoSetup)) +// .Help("Source code updater settings.."); +//#endif + menu.Add("Checkout and setup U++ SVN trunk sources..", [=] { + SetupSVNTrunk(); + IdeAgain = true; + Break(); + }); if(menu.IsMenuBar()) SetupMobilePlatforms(menu); #ifdef PLATFORM_POSIX diff --git a/uppsrc/ide/main.cpp b/uppsrc/ide/main.cpp index 5499e8abd..94d009ce2 100644 --- a/uppsrc/ide/main.cpp +++ b/uppsrc/ide/main.cpp @@ -291,20 +291,25 @@ void AppMain___() SetPPDefs(LoadFile(ppdefs)); ide.LoadLastMain(); - if(clset || ide.OpenMainPackage()) { - ide.SaveLastMain(); - ide.isscanning++; - ide.MakeTitle(); - if(!ide.IsEditorMode()) - SyncRefs(); - ide.FileSelected(); - ide.isscanning--; - ide.MakeTitle(); - if(!IdeExit) - ide.Run(); - ide.SaveConfigOnTime(); - ide.SaveLastMain(); + do { + IdeAgain = false; + if(clset || ide.OpenMainPackage()) { + ide.SaveLastMain(); + ide.isscanning++; + ide.MakeTitle(); + if(!ide.IsEditorMode()) + SyncRefs(); + ide.FileSelected(); + ide.isscanning--; + ide.MakeTitle(); + if(!IdeExit) + ide.Run(); + ide.SaveConfigOnTime(); + ide.SaveLastMain(); + ide.Close(); + } } + while(IdeAgain); #ifdef PLATFORM_POSIX StoreAsXMLFile(UpdaterCfg(),"SourceUpdater",ConfigFile("updates.xml")); #endif diff --git a/uppsrc/urepo/Console.cpp b/uppsrc/urepo/Console.cpp index c61197267..2c262ef14 100644 --- a/uppsrc/urepo/Console.cpp +++ b/uppsrc/urepo/Console.cpp @@ -7,6 +7,8 @@ UrepoConsole::UrepoConsole() font = Courier(Ctrl::VertLayoutZoom(12)); list.SetLineCy(font.Info().GetHeight()); exit.Hide(); + cancel.Hide(); + cancel << [=] { canceled = true; }; } void UrepoConsole::AddResult(const String& out) @@ -19,6 +21,11 @@ void UrepoConsole::AddResult(const String& out) list.GoEnd(); } +void UrepoConsole::Log(const Value& s, Color ink) +{ + list.Add(AttrText(s).SetFont(font).NormalInk(ink), s); +} + int UrepoConsole::System(const char *cmd) { // LOG(cmd); @@ -31,7 +38,9 @@ int UrepoConsole::System(const char *cmd) if(!p.Start(cmd)) return -1; String out; - while(p.IsRunning()) { + canceled = false; + cancel.Show(withcancel); + while(p.IsRunning() && IsOpen()) { String h = p.Get(); out.Cat(h); int lf = out.ReverseFind('\n'); @@ -41,11 +50,14 @@ int UrepoConsole::System(const char *cmd) } ProcessEvents(); Sleep(h.GetCount() == 0); // p.Wait would be much better here! + if(canceled) + break; } + cancel.Hide(); out.Cat(p.Get()); AddResult(out); ProcessEvents(); - int code = p.GetExitCode(); + int code = canceled ? -1 : p.GetExitCode(); if(code) while(ii < list.GetCount()) { list.Set(ii, 0, AttrText((String)list.Get(ii, 1)).SetFont(font).Ink(LtRed)); diff --git a/uppsrc/urepo/urepo.h b/uppsrc/urepo/urepo.h index dc32100d9..a2245a47a 100644 --- a/uppsrc/urepo/urepo.h +++ b/uppsrc/urepo/urepo.h @@ -13,12 +13,17 @@ class UrepoConsole : public WithUrepoConsoleLayout { Font font; void AddResult(const String& out); + bool withcancel = false; + bool canceled = false; public: int System(const char *s); int CheckSystem(const char *s); int Git(const char *dir, const char *command); + void Log(const Value& s, Color ink = SColorText()); void Perform() { exit.Show(); Execute(); } + void WithCancel(bool b = true) { withcancel = b; } + void Clear() { list.Clear(); } UrepoConsole(); }; diff --git a/uppsrc/urepo/urepo.lay b/uppsrc/urepo/urepo.lay index 76512a1fa..2e1481f13 100644 --- a/uppsrc/urepo/urepo.lay +++ b/uppsrc/urepo/urepo.lay @@ -7,6 +7,7 @@ END_LAYOUT LAYOUT(UrepoConsoleLayout, 680, 660) ITEM(ArrayCtrl, list, HSizePosZ(4, 4).VSizePosZ(4, 40)) ITEM(Button, exit, SetLabel(t_("Close")).RightPosZ(4, 64).BottomPosZ(8, 24)) + ITEM(Button, cancel, SetLabel(t_("Cancel")).RightPosZ(612, 64).BottomPosZ(8, 24)) END_LAYOUT LAYOUT(SvnOptionsLayout, 140, 16)