|
|
Home » U++ TheIDE » U++ TheIDE: Other Features Wishlist and/or Bugs » [FEATURE] Add submenu "Macro /Edit" to package that use usc macro (patch included)
[FEATURE] Add submenu "Macro /Edit" to package that use usc macro (patch included) [message #46572] |
Thu, 02 June 2016 13:12  |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Hi,
by default, a macro file can reside outside from package that using it, in this case, editing a macro, necessit using a file explorer and a manuel search.
it is usefull if we can edit a macro file from inside theide, from any package that use this macro.
this is the objectif of this pach.

the patch:
1 - file ide/Core/Core.h, line 146
add a new field "filename" to the struct IdeMacro
struct IdeMacro {
IdeMacro();
int hotkey;
String menu;
String submenu;
EscValue code;
String filename; // added field
};
2 - file ide/Common/Util.cpp, line 177
set filename for each IdeMacro from CParser::GetFileName
static void ReadMacro(CParser& p)
{
IdeMacro macro;
macro.filename = p.GetFileName(); // added line
if(p.IsString()) {
3 - file ide/idebar.cpp, line 293
add a menu separator, and the "Edit" menu:
void Ide::MacroMenu(Bar& menu)
{
const Array<IdeMacro>& mlist = UscMacros();
if(!mlist.IsEmpty() && menu.IsMenuBar()) {
VectorMap< String, Vector<int> > submenu_map;
for(int i = 0; i < mlist.GetCount(); i++) {
const IdeMacro& m = mlist[i];
if(!IsNull(m.menu)) {
if(IsNull(m.submenu))
submenu_map.GetAdd(Null).Add(i);
else
submenu_map.GetAdd(m.menu).Add(i);
}
}
if(!submenu_map.IsEmpty()) {
Vector<int> order = GetSortOrder(submenu_map.GetKeys());
for(int o = 0; o < order.GetCount(); o++) {
String m = submenu_map.GetKey(order[o]);
Vector<int>& mx = submenu_map[order[o]];
ValueArray va;
for(int i = 0; i < mx.GetCount(); i++)
va.Add(mx[i]);
if(!IsNull(m))
menu.Add(m, THISBACK1(EditMacroMenu, va));
else
EditMacroMenu(menu, va);
}
}
static SortedIndex<String> files; // the added code START HERE
files.Clear();
for(int i = 0; i < mlist.GetCount(); i++)
files.FindAdd(mlist[i].filename);
Event<Bar&> ev;
ev <<
[&](Bar& b)
{
for(int i = 0; i < files.GetCount(); i++)
b.Add(files[i],THISBACK1(EditFile, files[i]));
}
;
menu.Separator();
menu.Add("Edit", ev); // the added code END HERE
}
}
-
Attachment: macro.png
(Size: 20.33KB, Downloaded 488 times)
regards
omari.
|
|
|
Re: [FEATURE] Add submenu "Macro /Edit" to package that use usc macro (patch included) [message #46615 is a reply to message #46572] |
Sun, 12 June 2016 21:17   |
 |
Klugier
Messages: 1099 Registered: September 2012 Location: Poland, Kraków
|
Senior Contributor |
|
|
Hello,
It seems interesting to me. Can you post your package with macro. I want to test how macros works. I have never tried it before.
I think you can use something like this: (It is new in place bar lambda callbacks added by Mirek in recently version of upp):
bar.Sub("Macro", [=](Bar& subBar) {
for(int i = 0; i < files.GetCount(); i++)
subBar.Sub(files[i], [=] { EditFile(files[i])) });
});
It would be good at least for me if you post diff here. Make sure you checkout official upp mirror - more information you can find in updated article about svn http://www.ultimatepp.org/www$uppweb$svnInstall$en-us.html. I updated this site how to generates diff. It will be available tomorrow.
Sincerely,
Klugier
U++ - one framework to rule them all.
[Updated on: Sun, 12 June 2016 21:52] Report message to a moderator
|
|
|
Re: [FEATURE] Add submenu "Macro /Edit" to package that use usc macro (patch included) [message #46617 is a reply to message #46615] |
Mon, 13 June 2016 14:29   |
omari
Messages: 276 Registered: March 2010
|
Experienced Member |
|
|
Hi Klugier,
Attached my macro file, you can put it in your upp directory.
in order to use macros in all projects, the macro file shall be in the theide bin directory, or in UppLocal directory.
a macro file in a package is visible only in it's package.
for more info about macro, see reference/Macro.
here the diff:
Index: C:/upp/uppsrc/ide/Common/Util.cpp
===================================================================
--- C:/upp/uppsrc/ide/Common/Util.cpp (revision 9938)
+++ C:/upp/uppsrc/ide/Common/Util.cpp (working copy)
@@ -174,6 +174,7 @@
static void ReadMacro(CParser& p)
{
IdeMacro macro;
+ macro.filename = p.GetFileName();
if(p.IsString()) {
macro.menu = p.ReadString();
if(p.Char(':'))
Index: C:/upp/uppsrc/ide/Core/Core.h
===================================================================
--- C:/upp/uppsrc/ide/Core/Core.h (revision 9938)
+++ C:/upp/uppsrc/ide/Core/Core.h (working copy)
@@ -152,6 +152,7 @@
String menu;
String submenu;
EscValue code;
+ String filename;
};
ArrayMap<String, EscValue>& UscGlobal();
Index: C:/upp/uppsrc/ide/idebar.cpp
===================================================================
--- C:/upp/uppsrc/ide/idebar.cpp (revision 9938)
+++ C:/upp/uppsrc/ide/idebar.cpp (working copy)
@@ -289,6 +289,20 @@
EditMacroMenu(menu, va);
}
}
+
+ menu.Separator();
+ menu.Sub("Edit",
+ [&](Bar& b) {
+ SortedIndex<String> files;
+ for(int i = 0; i < mlist.GetCount(); i++) {
+ if(files.Find(mlist[i].filename) < 0) {
+ String filename = mlist[i].filename;
+ files.Add(filename);
+ b.Add(filename, [filename, this]() { EditFile(filename); } );
+ }
+ }
+ }
+ );
}
}
-
Attachment: macros.usc
(Size: 2.24KB, Downloaded 274 times)
regards
omari.
|
|
|
|
|
Goto Forum:
Current Time: Sun May 11 14:40:26 CEST 2025
Total time taken to generate the page: 0.10433 seconds
|
|
|