Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
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 Go to next message
omari is currently offline  omari
Messages: 264
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.

index.php?t=getfile&id=5026&private=0

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 396 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 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1076
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 Go to previous messageGo to next message
omari is currently offline  omari
Messages: 264
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 215 times)


regards
omari.
Re: [FEATURE] Add submenu "Macro /Edit" to package that use usc macro (patch included) [message #46618 is a reply to message #46617] Mon, 13 June 2016 20:46 Go to previous messageGo to next message
Klugier is currently offline  Klugier
Messages: 1076
Registered: September 2012
Location: Poland, Kraków
Senior Contributor
Hello Omari,

I putted your macro to my test package and ide shows it fines. Then i removed it and put it where ide binary resident. But nothing has happed (I tried to do this on Linux). Is it TheIDE bug or it is Linux related? One more question - where can I find UppLocal directory - seems it doesn't exist on my machine.

Can you post diff as single file? Current solution will probably applied spaces instead of tabs. I think you force limit of file attached per message Sad

Sincerely and thanks in advanced,
Klugier


U++ - one framework to rule them all.
Re: [FEATURE] Add submenu "Macro /Edit" to package that use usc macro (patch included) [message #46623 is a reply to message #46618] Wed, 15 June 2016 11:50 Go to previous message
omari is currently offline  omari
Messages: 264
Registered: March 2010
Experienced Member
Hello Klugier,

theide search for macro files in:
	UscProcessDir(GetLocalDir());
	UscProcessDir(GetFileFolder(ConfigFile("x")));


on Windows ( when theide.exe is in c:\upp),
  GetLocalDir() : c:\upp\UppLocal  
  GetFileFolder(ConfigFile("x")) : c:\upp


on Linux (based on the code source)
  GetLocalDir() : ~/.upp/theide/UppLocal/  
  GetFileFolder(ConfigFile("x")) : ~/.upp/theide/
  • Attachment: macro.diff
    (Size: 1.38KB, Downloaded 174 times)


regards
omari.

[Updated on: Wed, 15 June 2016 17:46]

Report message to a moderator

Previous Topic: [ACCEPTED] New file
Next Topic: Bookmarks hotkeys Ctrl+0-9 and Ctrl+Shift+0-9 dont works
Goto Forum:
  


Current Time: Fri Apr 19 17:21:21 CEST 2024

Total time taken to generate the page: 0.07285 seconds