Index: tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosContribution.java
===================================================================
--- tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosContribution.java	(revision 1973)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosContribution.java	(revision 1974)
@@ -1,68 +0,0 @@
-package org.txm.rcp.menu;
-
-import java.io.File;
-
-import org.eclipse.jface.action.ContributionItem;
-import org.eclipse.osgi.util.NLS;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionAdapter;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.widgets.Menu;
-import org.eclipse.swt.widgets.MenuItem;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.txm.Toolbox;
-import org.txm.rcp.TXMWindows;
-import org.txm.rcp.handlers.scripts.ExecuteGroovyMacro;
-import org.txm.rcp.views.corpora.CorporaView;
-import org.txm.utils.logger.Log;
-
-public class MacrosContribution extends ContributionItem {
-
-	public MacrosContribution() {
-	}
-
-	public MacrosContribution(String id) {
-		super(id);
-	}
-
-	@Override
-	public void fill(Menu menu, int index) {
-		
-		
-		//create the menu item
-		final File macroDirectory = new File(Toolbox.getTxmHomePath(), "scripts/groovy/user/org/txm/macro/ui");
-		File[] files = macroDirectory.listFiles();
-		if (files == null || files.length == 0) {
-			MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
-			menuItem.setText("<no macro>");
-			menuItem.addSelectionListener(new SelectionAdapter() {
-
-				public void widgetSelected(SelectionEvent e) {
-					Log.info(NLS.bind("To populate this menu, you must create macros in the {0} directory .", macroDirectory));
-				}
-			});
-			return;
-		}
-		for (File f : files) {
-			if (f.getName().endsWith("Macro.groovy")) {
-				MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
-				menuItem.setText(f.getName());
-				menuItem.addSelectionListener(new MacroSelectionAdapter(f));
-			}
-		}
-	}
-	
-	public class MacroSelectionAdapter extends SelectionAdapter {
-		File macro;
-		public MacroSelectionAdapter(File macro) {
-			this.macro = macro;
-		}
-		
-		public void widgetSelected(SelectionEvent e) {
-			IWorkbenchWindow acWindow = TXMWindows.getActiveWindow();
-			IWorkbenchPart page = acWindow.getActivePage().getActivePart();
-			ExecuteGroovyMacro.execute(macro.getAbsolutePath(), page, CorporaView.getInstance().getTreeViewer().getSelection(), "");
-		}
-	}
-}
Index: tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosMenuContribution.java
===================================================================
--- tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosMenuContribution.java	(revision 0)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosMenuContribution.java	(revision 1974)
@@ -0,0 +1,165 @@
+package org.txm.rcp.menu;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Comparator;
+
+import org.eclipse.jface.action.ContributionItem;
+import org.eclipse.osgi.util.NLS;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.events.MenuListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.MenuItem;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.txm.Toolbox;
+import org.txm.rcp.TXMWindows;
+import org.txm.rcp.handlers.scripts.ExecuteGroovyMacro;
+import org.txm.rcp.views.corpora.CorporaView;
+import org.txm.utils.logger.Log;
+
+public class MacrosMenuContribution extends ContributionItem {
+
+	Menu menu;
+	int index;
+	public MacrosMenuContribution() {
+		super();
+	}
+	public MacrosMenuContribution(String id) {
+		super(id);
+	}
+
+	@Override
+	public void fill(Menu menu, int index) {
+		this.menu = menu;
+		this.index = index;
+
+
+		menu.addMenuListener(new MenuListener() {
+
+			@Override
+			public void menuShown(MenuEvent e) {
+				onOpen(MacrosMenuContribution.this.menu, MacrosMenuContribution.this.index);
+			}
+
+			@Override
+			public void menuHidden(MenuEvent e) { }
+		});
+	}
+
+	public File getMacroDirectory() {
+		//create the menu item
+		String w = Toolbox.getTxmHomePath();
+		if (w == null || w.length() == 0) return null;
+
+		return new File(w, "scripts/groovy/user/org/txm/macro/ui/menu/main");
+	}
+
+	public void onOpen(Menu menu, int index) {
+
+		File macroDirectory = getMacroDirectory();
+		if (macroDirectory == null) return;
+
+		File[] files = macroDirectory.listFiles();
+		if (files == null || files.length == 0) {
+
+			MenuItem[] menuItems = menu.getItems();
+			for (int i = 0; i < menuItems.length; i++) {
+				menuItems[i].dispose();
+			}
+
+			MenuItem menuItem = new MenuItem(menu, SWT.CHECK, index);
+			menuItem.setText("<no macro>");
+			menuItem.addSelectionListener(new SelectionAdapter() {
+				public void widgetSelected(SelectionEvent e) {
+					Log.info(NLS.bind("To populate this menu, you must create macros in the ''{0}'' directory.", getMacroDirectory()));
+				}
+			});
+			return;
+		}
+
+		populate(menu, macroDirectory, index);
+	}
+
+	public static void populate(Menu menu, File directory, int index) {
+
+		// First empty
+		MenuItem[] menuItems = menu.getItems();
+		for (int i = 0; i < menuItems.length; i++) {
+			menuItems[i].dispose();
+		}
+
+		// Find files
+		File[] files = directory.listFiles();
+
+		// first are directories
+		Arrays.sort(files, new Comparator<File>() {
+			@Override
+			public int compare(File arg0, File arg1) {
+				if (arg0.isDirectory()) {
+					if (arg1.isDirectory()) {
+						return arg0.getName().compareTo(arg1.getName());
+					} else {
+						return -1;
+					}
+				} else if (arg1.isFile()) {
+					return arg0.getName().compareTo(arg1.getName());
+				} else {
+					return 1;
+				}
+			}
+
+		});
+		for (File f : files) {
+			if (f.getName().endsWith("Macro.groovy")) {
+				MenuItem menuItem = new MenuItem(menu, SWT.PUSH);
+				menuItem.setText(f.getName());
+				menuItem.addSelectionListener(new MacroSelectionAdapter(f));
+			} else if (f.isDirectory()) {
+				MenuItem subMenuItem = new MenuItem(menu, SWT.CASCADE);
+				subMenuItem.setText(f.getName());
+				Menu submenu = new Menu(menu);
+				subMenuItem.setMenu(submenu);
+				populate(submenu, f, 0);
+			}
+		}
+	}
+
+	public static class MacroSelectionAdapter extends SelectionAdapter {
+		File macro;
+		public MacroSelectionAdapter(File macro) {
+			this.macro = macro;
+		}
+
+		public void widgetSelected(SelectionEvent e) {
+			IWorkbenchWindow acWindow = TXMWindows.getActiveWindow();
+			IWorkbenchPart page = acWindow.getActivePage().getActivePart();
+			ExecuteGroovyMacro.execute(macro.getAbsolutePath(), page, CorporaView.getInstance().getTreeViewer().getSelection(), "");
+		}
+	}
+
+	public static class MacroDirectoryMenu extends Menu {
+
+		File directory;
+		int index;
+
+		public MacroDirectoryMenu(Menu parentMenu, File dir, int i) {
+			super(parentMenu);
+			this.directory = dir;
+			this.index = i;
+			this.addMenuListener(new MenuListener() {
+
+				@Override
+				public void menuShown(MenuEvent e) {
+					populate(MacroDirectoryMenu.this, directory, index);
+				}
+
+				@Override
+				public void menuHidden(MenuEvent e) { }
+			});
+		}
+	}
+}

Property changes on: tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosMenuContribution.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosCorporaMenuContribution.java
===================================================================
--- tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosCorporaMenuContribution.java	(revision 0)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosCorporaMenuContribution.java	(revision 1974)
@@ -0,0 +1,24 @@
+package org.txm.rcp.menu;
+
+import java.io.File;
+
+import org.txm.Toolbox;
+
+public class MacrosCorporaMenuContribution extends MacrosMenuContribution {
+
+	public MacrosCorporaMenuContribution() {
+		super();
+	}
+	
+	public MacrosCorporaMenuContribution(String id) {
+		super(id);
+	}
+	
+	public File getMacroDirectory() {
+		//create the menu item
+		String w = Toolbox.getTxmHomePath();
+		if (w == null || w.length() == 0) return null;
+
+		return new File(w, "scripts/groovy/user/org/txm/macro/ui/menu/window");
+	}
+}

Property changes on: tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosCorporaMenuContribution.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosEditorMenuContribution.java
===================================================================
--- tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosEditorMenuContribution.java	(revision 0)
+++ tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosEditorMenuContribution.java	(revision 1974)
@@ -0,0 +1,24 @@
+package org.txm.rcp.menu;
+
+import java.io.File;
+
+import org.txm.Toolbox;
+
+public class MacrosEditorMenuContribution extends MacrosMenuContribution {
+
+	public MacrosEditorMenuContribution() {
+		super();
+	}
+	
+	public MacrosEditorMenuContribution(String id) {
+		super(id);
+	}
+	
+	public File getMacroDirectory() {
+		//create the menu item
+		String w = Toolbox.getTxmHomePath();
+		if (w == null || w.length() == 0) return null;
+
+		return new File(w, "scripts/groovy/user/org/txm/macro/ui/menu/object");
+	}
+}

Property changes on: tmp/org.txm.rcp/src/main/java/org/txm/rcp/menu/MacrosEditorMenuContribution.java
___________________________________________________________________
Added: svn:mime-type
   + text/plain

Index: tmp/org.txm.rcp/plugin.xml
===================================================================
--- tmp/org.txm.rcp/plugin.xml	(revision 1973)
+++ tmp/org.txm.rcp/plugin.xml	(revision 1974)
@@ -1057,7 +1057,7 @@
                id="menu.macros"
                label="Macros">
             <dynamic
-                  class="org.txm.rcp.menu.MacrosContribution"
+                  class="org.txm.rcp.menu.MacrosMenuContribution"
                   id="org.txm.rcp.menu.MacrosContribution">
             </dynamic>
          </menu>
@@ -1977,6 +1977,15 @@
                   name="org.txm.rcp.corporaview.tools.misc"
                   visible="true">
             </separator>
+            <menu
+                  icon="icons/objects/script.png"
+                  id="org.txm.rcp.corporaview.macros"
+                  label="Macros">
+               <dynamic
+                     class="org.txm.rcp.menu.MacrosCorporaMenuContribution"
+                     id="org.txm.rcp.menu.MacrosCorporaMenuContribution">
+               </dynamic>
+            </menu>
          <separator
                name="org.txm.rcp.corporaview.text"
                visible="true">
