From c814bcb925dc8cfce3eef5710433700e7cec3ca0 Mon Sep 17 00:00:00 2001 From: klugier Date: Thu, 26 Oct 2017 20:39:02 +0000 Subject: [PATCH] Expor globals is not active when there is no global macros in ide. Thanks Omari! #1781 git-svn-id: svn://ultimatepp.org/upp/trunk@11417 f0d560ea-af0d-0410-9eb7-867de7ffcac7 --- uppsrc/ide/MacroManager/MacroManager.cpp | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/uppsrc/ide/MacroManager/MacroManager.cpp b/uppsrc/ide/MacroManager/MacroManager.cpp index 4eaf679ed..51d7a4812 100644 --- a/uppsrc/ide/MacroManager/MacroManager.cpp +++ b/uppsrc/ide/MacroManager/MacroManager.cpp @@ -47,7 +47,7 @@ void MacroManagerWindow::InitToolBar() newGlobalLabel.Enable(); importGlobalsLabel.Enable(); - exportGlobalsLabel.Enable(); + exportGlobalsLabel.Enable(globalTree.GetChildCount(0)); } void MacroManagerWindow::InitToolButton( @@ -223,14 +223,25 @@ void MacroManagerWindow::OnNewMacroFile() fileName << ".usc"; String fullPath = AppendFileName(GetLocalDir(), fileName); + RealizeDirectory(GetLocalDir()); if(FileExists(fullPath)) { PromptOK(String() << t_("file") << " \"" << fileName << "\" " << t_("already exists!")); return; } - SaveFile(fullPath, "macro \"" + GetFileTitle(fileName) + "\" {}"); - ReloadGlobalMacros(); // TODO: This is a little bit overkill we add one element to the tree and we reload all tree... - globalTree.FindSetCursor(fileName); + if(!SaveFile(fullPath, "macro \"" + GetFileTitle(fileName) + "\" {}")) { + PromptOK(String() << t_("Error occured while saving file") << " \"" << fileName << "\""); + return; + } + + int fileNode = globalTree.Add(0, Image(), fullPath, fileName); + auto list = UscFileParser(fullPath).Parse(); + for(const auto& element : list) { + globalTree.Add(fileNode, element.GetImage(), RawToValue(element), element.name); + } + + globalTree.OpenDeep(fileNode); + globalTree.FindSetCursor(fullPath); OnGlobalMacrosChanged(); } @@ -238,7 +249,7 @@ void MacroManagerWindow::OnNewMacroFile() void MacroManagerWindow::OnDeleteMacroFile() { auto fileName = static_cast(globalTree.GetValue()); - if(!PromptOKCancel(t_("Are you sure you want to remove followin macro file \"" + fileName + "\"?"))) + if(!PromptOKCancel(t_("Are you sure you want to remove following macro file \"" + fileName + "\"?"))) return; FileDelete(AppendFileName(GetLocalDir(), fileName)); @@ -250,6 +261,7 @@ void MacroManagerWindow::OnDeleteMacroFile() void MacroManagerWindow::OnGlobalMacrosChanged() { + exportGlobalsLabel.Enable(globalTree.GetChildCount(0)); globalMacrosChanged = true; }