PageRenderTime 110ms CodeModel.GetById 31ms app.highlight 45ms RepoModel.GetById 15ms app.codeStats 0ms

/ActionManager.cs

https://github.com/moscrif/ide
C# | 842 lines | 467 code | 112 blank | 263 comment | 23 complexity | 2f08d9fa049ebf2772b017dcb315de7e MD5 | raw file
  1using System;
  2using System.Collections;
  3using System.Collections.Generic;
  4using System.Threading;
  5using Mono.Unix;
  6using Gtk;
  7using System.IO;
  8using Moscrif.IDE.Actions;
  9using Moscrif.IDE.Execution;
 10using Moscrif.IDE.Components;
 11using Moscrif.IDE.Editors;
 12using Moscrif.IDE.Workspace;
 13using Moscrif.IDE.Task;
 14using Moscrif.IDE.Controls;
 15using MessageDialogs = Moscrif.IDE.Controls.MessageDialog;
 16using MessageDialogsUrl = Moscrif.IDE.Controls.MessageDialogUrl;
 17using Moscrif.IDE.Iface.Entities;
 18using Moscrif.IDE.Iface;
 19using Moscrif.IDE.Option;
 20using Moscrif.IDE.Tool;
 21using Moscrif.IDE.Controls.Wizard;
 22using Mono.TextEditor;
 23using Mono.TextEditor.Highlighting;
 24using System.Diagnostics;
 25using System.Data;
 26using Mono.Data.Sqlite;
 27using System.Text;
 28using Moscrif.IDE.Extensions;
 29using System.Net;
 30using System.Net.Sockets;
 31
 32namespace Moscrif.IDE
 33{
 34	public class ActionManager : IEnumerable
 35	{
 36		private UIManager ui = new UIManager();
 37		//static uint mergeId = 0;
 38		private ActionGroup main_window_actions = new ActionGroup("MainWindow");
 39
 40		public ActionManager()
 41		{
 42			PopulateActionGroups();
 43		}
 44
 45		public void LoadInterface()
 46		{
 47			string cPath = MainClass.Paths.ConfingDir;
 48			//System.Environment.CurrentDirectory ;
 49			string fullpath = System.IO.Path.Combine(cPath, "MenuStructure.Xml");
 50			
 51			if (File.Exists(fullpath)) {
 52				ui.AddUiFromFile(fullpath);
 53			} else {
 54				string ui_info = "<toolbar name=\"toolbarLeft\">\n" + "<toolitem name=\"Run\" action=\"run\" />\n" + "<toolitem name=\"What\" action=\"what\" />\n" + "<toolitem name=\"Save\" action=\"save\" />\n" + "</toolbar>\n" + "<toolbar name=\"toolbarMiddle\">\n" + "</toolbar>\n" + "<toolbar name=\"toolbarRight\">\n" + "<toolitem name=\"About\" action=\"about\" />\n" + "<toolitem name=\"Quit\" action=\"quit\" />\n" + "</toolbar>\n" + "<menubar >\n" + "<menu name=\"Ide\" action=\"IdeAction\">\n" + "<menuitem name=\"About\" action=\"about\" />\n" + "<menuitem name=\"Preferences\" action=\"preferences\" />\n" + "<separator name=\"sep1\" />\n" + "<menuitem name=\"Quit\" action=\"quit\" />\n" + "</menu>\n" + "<menu name=\"File\" action=\"File\">\n" + "<menuitem name=\"NewProject\" action=\"newproject\" />\n" + "<menuitem name=\"LoadProject\" action=\"loadproject\" />\n" + "<menuitem name=\"AppToMsp\" action=\"apptomsp\" />\n" + "<separator name=\"sep2\" />	\n" + "<menuitem name=\"Open\" action=\"open\" />    	\n" + "<menuitem name=\"Save\" action=\"save\" />\n" + "<menuitem name=\"Save All\" action=\"saveall\" />	\n" + "<separator name=\"sep3\" />\n" + "<menu name=\"RecentFile\" action=\"RecentFile\">\n" + "</menu>	\n" + "<menu name=\"RecentProject\" action=\"RecentProject\">	\n" + "</menu>   					  		\n" + "<separator name=\"sep4\" />	    	\n" + "<menuitem name=\"Close\"  action=\"close\" />\n" + "<menuitem name=\"Close All\"  action=\"closeall\" />				\n" + "</menu>\n" + "<menu name=\"Edit\" action=\"EditAction\">\n" + "<menuitem name=\"inserttemplate\" action=\"inserttemplate\" />\n" + "<menuitem name=\"insertcomplete\" action=\"insertcomplete\" />\n" + "<menuitem name=\"Undo\" action=\"undo\" />\n" + "<menuitem name=\"Redo\" action=\"redo\" />\n" + "</menu>	\n" + "<menu name=\"Search\" action=\"SearchAction\">\n" + "<menuitem name=\"Find\" action=\"find\" />\n" + "<menuitem name=\"FindNext\" action=\"findnext\" />\n" + "<menuitem name=\"FindPrevious\" action=\"findprevious\" />\n" + "<separator name=\"sep5\" />\n" + "<menuitem name=\"PreviousBookmark\" action=\"previouBookmark\" />\n" + "<menuitem name=\"NextBookmark\" action=\"nextBookmark\" />		\n" + "<separator name=\"sep5\" />\n" + "<menuitem name=\"ToggleBookmark\" action=\"toggleBookmark\" />\n" + "<menuitem name=\"PreviousBookmark\" action=\"previouBookmark\" />\n" + "<menuitem name=\"NextBookmark\" action=\"nextBookmark\" />				\n" + "<menuitem name=\"ClearBookmarks\" action=\"clearBookmarks\" />\n" + "</menu>					\n" + "<menu name=\"Emulator\" action=\"EmulatorAction\">\n" + "<menuitem name=\"Run\" action=\"run\" />\n" + "<separator name=\"sep6\" />	    	\n" + "<menuitem name=\"Clear\" action=\"clear\" />\n" + "<menuitem name=\"Test\" action=\"test\" />	    	\n" + "</menu>				\n" + "</menubar>\n" + "<popup name='iconMarginPopup'>\n" + "<menuitem name=\"ToggleBookmark\" action=\"toggleBookmark\" />\n" + "<menuitem name=\"ClearBookmarks\" action=\"clearBookmarks\" />\n" + "<separator name=\"sep7\" />\n" + "<menuitem name=\"AddBreakpoint\" action=\"addBreakpoint\" />\n" + "<menuitem name=\"RemoveBreakpoint\" action=\"removeBreakpoint\" />\n" + "<menuitem name=\"ToggleBreakpoint\" action=\"toggleBreakpoint\" />\n" + "<menuitem name=\"EnableDisableBreakpoint\" action=\"enableDisableBreakpoint\" /> \n" + "<menuitem name=\"DisableAllBreakpoints\" action=\"disableAllBreakpoints\" />\n" + "<menuitem name=\"ClearAllBreakpoints\" action=\"clearAllBreakpoints\" />	\n" + "<menuitem name=\"ShowBreakpointProperties\"  action=\"showBreakpointProperties\" />\n" + "</popup>\n" + "<popup name='netbookPagePopup'>\n" + "<menuitem name=\"Close\"  action=\"close\" />\n" + "<menuitem name=\"Close All\"  action=\"closeall\" />\n" + "<menuitem name=\"Close all but this\"  action=\"closeallbutthis\" />\n" + "<separator name=\"sep8\" />\n" + "<menuitem name=\"Save\" action=\"save\" />\n" + "<menuitem name=\"Save All\" action=\"saveall\" />\n" + "</popup>	\n" + "<popup name='workspacePagePopupDirectory'>\n" + "<!--<menu name=\"addgroup\" action=\"addgroup\">\n" + "<menuitem name=\"newfile\"  action=\"newfile\" />\n" + "<separator name=\"sep9\" />\n" + "<menuitem name=\"addfile\"  action=\"addfile\" />\n" + "<menuitem name=\"adddirectory\"  action=\"adddirectory\" />\n" + "</menu>-->	\n" + "<menuitem name=\"unloadproject\"  action=\"unloadproject\" />\n" + "<separator name=\"sep9\" />\n" + "<menuitem name=\"newfile\"  action=\"newfile\" />\n" + "<menuitem name=\"newdirectory\"  action=\"newdirectory\" />\n" + "<separator name=\"sep9\" />\n" + "<menuitem name=\"addfile\"  action=\"addfile\" />\n" + "<menuitem name=\"adddirectory\"  action=\"adddirectory\" />	\n" + "<separator name=\"sep10\" />		\n" + "<menuitem name=\"setasstart\"  action=\"setasstart\" />\n" + "<menuitem name=\"toggleexclude\"  action=\"toggleexclude\" />		\n" + "<menuitem name=\"delete\" action=\"deletefile\" />	    	\n" + "<menuitem name=\"rename\" action=\"renamefile\" />	    	    	\n" + "</popup>\n";
 55				ui.AddUiFromString(ui_info);
 56			}
 57		}
 58
 59	private void PopulateActionGroups()
 60	{
 61	    main_window_actions.Add(new ActionEntry[] { new ActionEntry("IdeAction",null,"Ide",	null,null,null ),
 62				new ActionEntry("FileAction", null, "File", null, null, null),
 63				new ActionEntry("Workspace", null, "Workspace", null, null, null),
 64				new ActionEntry("Project", null, "Project", null, null, null),
 65				new ActionEntry("File", null, "File", null, null, null),
 66				new ActionEntry("newProject", null, "Open Project", null, null, null),
 67				new ActionEntry("RecentAll", null, "Recent", null, null, null),
 68				new ActionEntry("HelpAction", null, "Help", null, null, null),
 69
 70			new ActionEntry("RecentFile", null, "Recent File", null, null, null),new ActionEntry("RecentProject", null, "Recent Project", null, null, null),
 71			new ActionEntry("RecentWorkspace", null, "Recent Workspace", null, null, null),
 72			new ActionEntry("EditAction", null, "Edit", null, null, null),
 73			new ActionEntry("SearchAction", null, "Search", null, null, null),
 74			new ActionEntry("EmulatorAction", null, "Emulator", null, null, null),
 75			new ActionEntry("ViewAction", null, "View", null, null, null),
 76
 77			new ActionEntry("FileGroup", null, "Files", null, null, null),
 78			new ActionEntry("DirGroup", null, "Directories", null, null, null),
 79			new ActionEntry("addFileSubmenu",null,"New",null,null,null ),
 80			//new ActionEntry("copy", "copy.png", "_Copy", "<control>C", "Copy the selected text to the clipboard", new EventHandler(OnActivate)),
 81			//new ActionEntry("paste", "paste.png", "_Paste", "<control>V", "Paste the text from the clipboard", new EventHandler(OnActivate)),
 82
 83			new ActionEntry("removeBreakpoint", "mobil.png", "Remove Breakpoint", null, "Remove Breakpoint", new EventHandler(OnActivate)),
 84			new ActionEntry("toggleBreakpoint", "mobil.png", "Toggle Breakpoint", null, "Toggle Breakpoint", new EventHandler(OnActivate)),
 85			new ActionEntry("enableDisableBreakpoint", "mobil.png", "Enable/Disable Breakpoint", null, "Enable/Disable Breakpoint", new EventHandler(OnActivate)),
 86			new ActionEntry("disableAllBreakpoints", "mobil.png", "Disable All Breakpoints", null, "Disable All Breakpoints", new EventHandler(OnActivate)),
 87			new ActionEntry("clearAllBreakpoints", "mobil.png", "Clear All Breakpoints", null, "Clear All Breakpoints", new EventHandler(OnActivate)),
 88			new ActionEntry("showBreakpointProperties", "mobil.png", "Show Breakpoint Properties", null, "Show Breakpoint Properties", new EventHandler(OnActivate)),
 89
 90			new ActionEntry("ToolsAction", null, "Tools", null, null, null),
 91				new ActionEntry("remoteconsole", null, "Remote Console", null, null, null),	
 92			new ActionEntry("test", "mobil.png", "Test", null, "test", new EventHandler(OnTest))
 93			});
 94
 95			//main_window_actions.Add(new Gtk.Action("test", "mobil.png", "Test",null), keyBind.FindAccelerator("test"));
 96
 97			main_window_actions.Add(new AddBreakpointAction(), null);
 98			main_window_actions.Add(new AboutAction(), null);
 99			main_window_actions.Add(new QuitAction(),"<control>Q");
100			main_window_actions.Add(new NewAction(), null);
101			main_window_actions.Add(new NewProjectAction(), null);
102			main_window_actions.Add(new NewProjectWizzardAction(), null);
103			main_window_actions.Add(new ProjectPreferencesAction(),null);
104
105			main_window_actions.Add(new OpenAction(), "<control>O");
106			main_window_actions.Add(new OpenProjectAction(), "<control><shift>O");
107			main_window_actions.Add(new SavePageAction(), "<control>S");
108			main_window_actions.Add(new SaveAsPageAction(), "<control><shift>S");
109			main_window_actions.Add(new SaveAllPageAction(), "<control><shift>A");
110			
111			main_window_actions.Add(new UndoAction(), "<control>Z");
112			main_window_actions.Add(new RedoAction(), "<control><shift>Z");
113			
114			main_window_actions.Add(new ToggleBookmarkAction(), "<control>F2");
115			main_window_actions.Add(new NextBookmarkAction(), "F2");
116			main_window_actions.Add(new PreviousBookmarkAction(), "<shift>F2");
117			main_window_actions.Add(new ClearBookmarksAction(), null);
118			
119			main_window_actions.Add(new ClosePageAction(), "<control>F4");
120			main_window_actions.Add(new CloseAllPageAction(), "<control><shift>F4");
121			main_window_actions.Add(new CloseAllButThisAction(), null);
122			
123			main_window_actions.Add(new FindAction(), "<control>F");
124			main_window_actions.Add(new FindNextAction(), "F3");
125			main_window_actions.Add(new FindPreviousAction(), "<control>F3");
126			main_window_actions.Add(new DeleteFileAction(), null);
127			main_window_actions.Add(new RenameFileAction(), null);
128			main_window_actions.Add(new AddFileAction(), null);
129			main_window_actions.Add(new AddDirectoryAction(), null);
130			main_window_actions.Add(new SetAsStartAction(), null);
131			main_window_actions.Add(new ToggleExcludeAction(), null);
132			main_window_actions.Add(new NewDirectoryAction(), null);
133			main_window_actions.Add(new UnloadProjectAction(), null);
134			main_window_actions.Add(new DeleteProjectAction(), null);
135			main_window_actions.Add(new ShowDirectoryAction(), null);
136
137			main_window_actions.Add(new RenameProjectAction(), null);			
138			main_window_actions.Add(new InsertTemplateAction(), "<control>" + Gdk.Key.T);
139			main_window_actions.Add(new InsertAutoCompletAction(), "<control>" + Gdk.Key.space);
140			main_window_actions.Add(new ClearConsoleAction(), null);
141			main_window_actions.Add(new NewWorkspaceAction(), null);
142			main_window_actions.Add(new OpenWorkspace(), null);
143			main_window_actions.Add(new IdePreferencesAction(), null);
144
145			main_window_actions.Add(new UniqueSequenceAction(), null);
146			main_window_actions.Add(new OpenStartPageAction(), null);
147			main_window_actions.Add(new CheckVersionAction(), null);
148
149			main_window_actions.Add(new CommentUncommentAction(), "<control><alt>c");
150
151			main_window_actions.Add(new GoToLineAction(), "<control>G");
152
153			main_window_actions.Add(new RunEmulatorAction(), "<control>F5");
154			main_window_actions.Add(new RunEmulatorNoWindAction(), "<shift>F5");
155			main_window_actions.Add(new RunEmulatorDebugAction(), null);
156			main_window_actions.Add(new StopEmulatorAction(), null);
157			main_window_actions.Add(new CompileProjectAction(), "F9");
158			main_window_actions.Add(new PublishAction(), "<control><shift>F9");
159			main_window_actions.Add(new ImportZipProjectAction(), "");
160			main_window_actions.Add(new ImportFolderProjectAction(), "");
161			main_window_actions.Add(new ExportZipProjectAction(), "");
162			main_window_actions.Add(new ArchiveProjectAction(), "");
163
164			main_window_actions.Add(new PropertyAllAction(), "");
165			main_window_actions.Add(new FilePropertyAction(), "");
166
167			main_window_actions.Add(new OpenOutputAction(), "");
168			main_window_actions.Add(new OpenOutputPopUpAction(), "");
169			main_window_actions.Add(new ShowProject(), "");
170
171			main_window_actions.Add(new SendFeedbackAction(), "");
172			main_window_actions.Add(new OpenApiReferenceAction(), "");
173			main_window_actions.Add(new OpenOnlineApiReferenceAction(), "");
174			main_window_actions.Add(new OpenOnlineDocument(), "");
175			main_window_actions.Add(new OpenSubmitSupport(), "");
176			main_window_actions.Add(new OpenOnlineDemos(), "");
177			main_window_actions.Add(new OpenOnlineSamples(), "");
178
179			main_window_actions.Add(new PasteTextAction(), "");
180			main_window_actions.Add(new CopyTextAction(), "");
181			main_window_actions.Add(new CutTextAction(), "");
182			main_window_actions.Add(new GoToDefinitionAction(), "");
183
184			main_window_actions.Add(new ViewProjectAppAction(), null);
185			main_window_actions.Add(new ViewFileAction(), null);
186			main_window_actions.Add(new AddThemeAction(), null);
187
188			main_window_actions.Add(new FilePreferencesPopUpAction(), null);
189			main_window_actions.Add(new DirectoryPreferencesPopUpAction(), null);
190			main_window_actions.Add(new ProjectPreferencesPopUpAction(), null);
191			main_window_actions.Add(new RefreshProjectAction(), null);
192
193			main_window_actions.Add(new GenerateAutoCompleteWords(), null);
194			main_window_actions.Add(new SettingPlatformAction(), null);
195
196			main_window_actions.Add(new ShowLeftPaneAction(), null);
197			main_window_actions.Add(new ShowBottomPaneAction(), null);
198			main_window_actions.Add(new ShowRightPaneAction(), null);
199			main_window_actions.Add(new ShowFullscreenAction(), null);
200
201
202			ui.InsertActionGroup(main_window_actions, 0);
203			ui.EnsureUpdate();
204
205			ReloadKeyBind();
206
207		}
208
209	public void CreateMacMenu(MenuBar mainMenu)
210	{
211
212	    //enable the global key handler for keyboard shortcuts
213	    IgeMacMenu.GlobalKeyHandlerEnabled = false;
214	
215	    //Tell the IGE library to use your GTK menu as the Mac main menu
216	    IgeMacMenu.MenuBar = mainMenu;
217	
218	    //tell IGE which menu item should be used for the app menu's quit item
219	    MenuItem miQ = (MenuItem)this.GetWidget("/menubar/FileAction/Quit");
220	    IgeMacMenu.QuitMenuItem = miQ;
221
222	    //add a new group to the app menu, and add some items to it
223	    var appGroup = IgeMacMenu.AddAppMenuGroup();
224
225	    MenuItem miA = (MenuItem)this.GetWidget("/menubar/Help/About");
226	    appGroup.AddMenuItem(
227		miA,
228		MainClass.Languages.Translate("menu_about").Replace("_", "")
229	    );
230
231		MenuItem miP = (MenuItem)this.GetWidget("/menubar/ToolsAction/idepreferences");
232	    appGroup.AddMenuItem(
233		miP,
234		MainClass.Languages.Translate("menu_preferences").Replace("_", "")
235	    );
236
237	    appGroup.AddMenuItem(
238		miQ,
239		MainClass.Languages.Translate("menu_quit").Replace("_", "")
240	    );	
241	    //hide the menu bar so it no longer displays within the window
242		mainMenu.Hide ();
243	}
244
245	public void ReloadKeyBind(){
246
247		KeyBindings keyBindFile = MainClass.KeyBinding;
248
249		foreach (ActionGroup @group in ui.ActionGroups){
250			foreach (Gtk.Action action in @group.ListActions()){
251
252				string accel = keyBindFile.FindAccelerator(action.Name);
253				if(!String.IsNullOrEmpty(accel)){
254					keyBindFile.ConnectAccelerator(action,accel,ui.AccelGroup);
255					//ConnectAccelerator(action,accel);
256				}
257
258			}
259		}
260	}
261
262	#region SocetServer
263		uint mergeIdSocket = 1;
264		ActionGroup dynGroupSocket = new ActionGroup("SocketMenu");
265
266		public void SocetServerMenu()
267		{
268			ui.InsertActionGroup(dynGroupSocket, 0);
269			mergeIdSocket = ui.NewMergeId();
270			
271			string nameStopC = "StopConsole";
272			string labelStopC = String.Format("Stop Remote Console");
273			Gtk.Action actionStopC = new Gtk.Action(nameStopC, labelStopC);
274			actionStopC.Activated += delegate(object sender, EventArgs e) { 
275				MainClass.MainWindow.StopSocetServer();
276			};
277			dynGroupSocket.Add(actionStopC);
278			ui.AddUi(mergeIdSocket, "/menubar/ToolsAction/remoteconsole", nameStopC, nameStopC, UIManagerItemType.Menuitem, false);
279
280			string nameStartC = "StartConsole";
281			string labelStartC = String.Format("Start Remote Console");
282			Gtk.Action actionStartC = new Gtk.Action(nameStartC, labelStartC );
283			actionStartC.Activated += delegate(object sender, EventArgs e) { 
284				MainClass.MainWindow.StartSocetServer(MainClass.Settings.RemoteIpAdress);
285			};
286			dynGroupSocket.Add(actionStartC);
287			ui.AddUi(mergeIdSocket, "/menubar/ToolsAction/remoteconsole", nameStartC, nameStartC, UIManagerItemType.Menuitem, false);
288
289
290			/*string nameRestarC = "RestartConsole";
291			string labelRestartC = String.Format("Restart Remote Console");
292			Gtk.Action actionRestartC = new Gtk.Action(nameRestarC, labelRestartC);
293			actionRestartC.Activated += delegate(object sender, EventArgs e) { 
294				MainClass.MainWindow.StopSocetServer();
295				MainClass.MainWindow.StartSocetServer(MainClass.Settings.RemoteIpAdress);
296			};
297			dynGroupSocket.Add(actionRestartC);
298			ui.AddUi(mergeIdSocket, "/menubar/ToolsAction/remoteconsole", nameRestarC, nameRestarC, UIManagerItemType.Menuitem, false);
299*/
300			ui.AddUi(mergeIdSocket, "/menubar/ToolsAction/remoteconsole", null, null, UIManagerItemType.Separator, false);
301			List<string> listIp = Moscrif.IDE.Tool.Network.GetIpAdress();
302
303			int i=0;
304			int indxIP = 0;
305
306			List<RadioActionEntry> listIP = new List<RadioActionEntry>();
307			foreach (string ip in listIp){
308				string name = "ipAdress" + ip;
309				string label = String.Format("{0}",  ip);
310				RadioActionEntry rae = new RadioActionEntry(name,null,label,null,null,i);
311				listIP.Add(rae);
312				ui.AddUi(mergeIdSocket, "/menubar/ToolsAction/remoteconsole", name, name, UIManagerItemType.Menuitem, false);
313
314				if(MainClass.Settings.RemoteIpAdress == ip){
315					indxIP =i;
316				}
317				i++;
318			}
319
320			RadioActionEntry[] ipEntries =listIP.ToArray();
321			dynGroupSocket.Add(ipEntries,indxIP, new ChangedHandler (RadioActionActivated));
322
323			MainClass.Settings.RemoteIpAdress = listIP[indxIP].label;
324		}
325
326
327		private void RadioActionActivated (object sender, ChangedArgs args)
328		{
329			MainClass.MainWindow.StopSocetServer();
330			Console.WriteLine("Ip Address -"+args.Current.Label);
331			MainClass.Settings.RemoteIpAdress = args.Current.Label;
332			//MainClass.MainWindow.StartSocetServer(MainClass.Settings.RemoteIpAdress);
333		}
334	#endregion
335
336	
337	#region RecentFileALL
338	uint mergeIdAll = 1;
339	ActionGroup dynGroupAll = new ActionGroup("RecentAll");
340	public void RecentAll(IList<RecentFile> lRecentFile,IList<RecentFile> lRecentProject,IList<RecentFile> lRecentWorkspace)
341	{
342		ui.InsertActionGroup(dynGroupAll, 0);
343		mergeIdAll = ui.NewMergeId();
344
345		int i = 0;
346		
347		foreach (RecentFile rf in lRecentFile) {
348			string name = "RecentAll" + i;
349			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
350			Gtk.Action action = new Gtk.Action(name, label);
351
352			string fileName = rf.FileName;
353			action.Activated += delegate(object sender, EventArgs e) {
354				MainClass.MainWindow.OpenFile(fileName,false);
355			};
356			dynGroupAll.Add(action);
357			ui.AddUi(mergeIdAll, "/menubar/FileAction/RecentAll", name, name, UIManagerItemType.Menuitem, false);
358			i++;
359		}
360		if(i>0){
361			ui.AddUi(mergeIdAll,"/menubar/FileAction/RecentAll","separatorAll11","",UIManagerItemType.Separator, false);
362		}
363		int j = i;
364			/*
365		foreach (RecentFile rf in lRecentProject) {
366			string name = "RecentAll" + i;
367			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
368			Gtk.Action action = new Gtk.Action(name, label);
369
370			string fileName = rf.FileName;
371			action.Activated += delegate(object sender, EventArgs e) {
372				MainClass.MainWindow.OpenFile(fileName,true);
373			};
374			dynGroupAll.Add(action);
375			ui.AddUi(mergeIdAll, "/menubar/FileAction/RecentAll", name, name, UIManagerItemType.Menuitem, false);
376			i++;
377		}
378		ui.AddUi(mergeIdAll,"/menubar/FileAction/RecentAll","separatorAll12","",UIManagerItemType.Separator, false);
379			i++;*/
380
381		foreach (RecentFile rf in lRecentWorkspace) {
382			string name = "RecentAll" + i;
383			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
384			Gtk.Action action = new Gtk.Action(name, label);
385
386			string fileName = rf.FileName;
387			action.Activated += delegate(object sender, EventArgs e) {
388				Workspace.Workspace workspace = Workspace.Workspace.OpenWorkspace(fileName);
389				if (workspace != null)
390						MainClass.MainWindow.ReloadWorkspace(workspace,true,true);
391			};
392			dynGroupAll.Add(action);
393			ui.AddUi(mergeIdAll, "/menubar/FileAction/RecentAll", name, name, UIManagerItemType.Menuitem, false);
394			i++;
395		}
396		if(i>j){
397			ui.AddUi(mergeIdAll,"/menubar/FileAction/RecentAll","separatorAll13","",UIManagerItemType.Separator, false);
398		}
399
400		string nameCF = "ClearFile";
401		string labelCF = String.Format("Clear Menu");
402		Gtk.Action actionCF = new Gtk.Action(nameCF, labelCF);
403		actionCF.Activated += delegate(object sender, EventArgs e) { 
404				MainClass.Settings.RecentFiles.ClearFiles();
405				MainClass.Settings.RecentFiles.ClearProjects();
406				MainClass.Settings.RecentFiles.ClearWorkspace();
407				//ClearRecentAll();
408				RefreshRecentAll(MainClass.Settings.RecentFiles.GetFiles(),
409				                 MainClass.Settings.RecentFiles.GetProjects(),
410				                 MainClass.Settings.RecentFiles.GetWorkspace());
411			};
412		dynGroupAll.Add(actionCF);
413		ui.AddUi(mergeIdAll, "/menubar/FileAction/RecentAll", nameCF, nameCF, UIManagerItemType.Menuitem, false);
414		 
415	}
416
417	public void RefreshRecentAll(IList<RecentFile> lRecentFile,IList<RecentFile> lRecentProject,IList<RecentFile> lRecentWorkspace)
418	{
419		//ui.RemoveUi(mergeIdAll);
420		//ui.RemoveActionGroup(dynGroupAll);
421		Menu subMenu = new Menu();
422
423
424		MenuItem miR = (MenuItem)this.GetWidget("/menubar/FileAction/RecentAll");
425		if(miR!= null)
426				miR.Submenu = subMenu;
427
428
429		//dynGroupAll = new ActionGroup("RecentAll");
430		//ui.InsertActionGroup(dynGroupAll, 0);
431
432		int i = 0;
433		
434		foreach (RecentFile rf in lRecentFile) {
435			string name = "RecentAll" + i;
436			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
437
438
439			MenuItem mi = new MenuItem(label);
440			mi.Name = name;
441			string fileName = rf.FileName;
442			mi.Activated+= delegate(object sender, EventArgs e) {
443					MainClass.MainWindow.OpenFile(fileName,true);
444			};
445			i++;
446			subMenu.Add(mi);
447		}
448		if(i>0){
449			subMenu.Add(new SeparatorMenuItem());
450		}
451		int j = i;
452
453		/*foreach (RecentFile rf in lRecentProject) {
454			string name = "RecentAll" + i;
455			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
456			Gtk.Action action = new Gtk.Action(name, label);
457
458			string fileName = rf.FileName;
459			action.Activated += delegate(object sender, EventArgs e) {
460				MainClass.MainWindow.OpenFile(fileName,true);
461			};
462			dynGroupAll.Add(action);
463			ui.AddUi(mergeIdAll, "/menubar/FileAction/RecentAll", name, name, UIManagerItemType.Menuitem, false);
464			i++;
465		}
466		ui.AddUi(mergeIdAll,"/menubar/FileAction/RecentAll","separatorAll12","",UIManagerItemType.Separator, false);
467			i++;*/
468
469		foreach (RecentFile rf in lRecentWorkspace) {
470			string name = "RecentAll" + i;
471			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
472			
473			MenuItem mi = new MenuItem(label);
474			mi.Name = name;
475			string fileName = rf.FileName;
476			mi.Activated+= delegate(object sender, EventArgs e) {
477				Workspace.Workspace workspace = Workspace.Workspace.OpenWorkspace(fileName);
478				if (workspace != null)
479					MainClass.MainWindow.ReloadWorkspace(workspace,true,true);
480			};
481			i++;
482			subMenu.Add(mi);
483		}
484
485		if(i>j){
486			subMenu.Add(new SeparatorMenuItem());		
487		}
488
489		string nameCF = "ClearFile";
490		string labelCF = String.Format("Clear Menu");
491
492		MenuItem miCF = new MenuItem(labelCF);
493		miCF.Name = nameCF;
494		miCF.Activated+= delegate(object sender, EventArgs e) {
495			MainClass.Settings.RecentFiles.ClearFiles();
496			MainClass.Settings.RecentFiles.ClearProjects();
497			MainClass.Settings.RecentFiles.ClearWorkspace();
498			RefreshRecentAll(MainClass.Settings.RecentFiles.GetFiles(),
499			                 MainClass.Settings.RecentFiles.GetProjects(),
500			                 MainClass.Settings.RecentFiles.GetWorkspace());
501		};
502		i++;
503		subMenu.Add(miCF);
504
505		miR.ShowAll();
506	}
507	#endregion
508
509
510		/*
511	uint mergeIdWorkspace = 1;
512	ActionGroup dynGroupWorkspace = new ActionGroup("RecentWorkspace");
513	
514		//int workspaceCount ;
515	public void RecentWorkspace(IList<RecentFile> lRecentProjects)
516	{
517	    ui.InsertActionGroup(dynGroupWorkspace, 0);
518	    mergeIdWorkspace = ui.NewMergeId();
519	    int workspaceCount = 0;
520
521	    foreach (RecentFile rf in lRecentProjects) {
522
523		string name = "RecentWorkspace" + workspaceCount;
524		string label = String.Format(
525		    "_{0} {1}",
526		    workspaceCount,
527		    rf.DisplayName.Replace("_", "__")
528		);
529		Gtk.Action action = new Gtk.Action(name, label);
530
531		string fileName = rf.FileName;
532
533		action.Activated += delegate(object sender, EventArgs e)
534		{
535		    Workspace.Workspace workspace = Workspace.Workspace.OpenWorkspace(fileName);
536		    if (workspace != null)
537			MainClass.MainWindow.ReloadWorkspace(workspace, true, true);
538
539		};
540		dynGroupWorkspace.Add(action);
541		///menubar/IdeAction/RecentWorkspace
542
543		ui.AddUi(
544		    mergeIdWorkspace,"/menubar/FileAction/RecentWorkspace", name, name, UIManagerItemType.Menuitem, false);
545		workspaceCount++;
546		}
547	}
548
549	public void RefreshRecentWorkspace(IList<RecentFile> lRecentProjects)
550	{
551		ui.RemoveUi(mergeIdWorkspace);
552		ui.RemoveActionGroup(dynGroupWorkspace);
553
554		dynGroupWorkspace = new ActionGroup("RecentWorkspace");
555		ui.InsertActionGroup(dynGroupWorkspace, 0);
556		int workspaceCount = 0;
557
558		foreach (RecentFile rf in lRecentProjects) {
559
560			string name = "RecentWorkspace" + workspaceCount;
561			string label = String.Format("_{0} {1}", workspaceCount, rf.DisplayName.Replace("_","__"));
562			Gtk.Action action = new Gtk.Action(name, label);
563
564			string fileName = rf.FileName;
565
566			action.Activated += delegate(object sender, EventArgs e) {
567			Workspace.Workspace workspace = Workspace.Workspace.OpenWorkspace(fileName);
568				if (workspace != null)
569					MainClass.MainWindow.ReloadWorkspace(workspace,true,true);
570
571			};
572			dynGroupWorkspace.Add(action);
573			ui.AddUi(mergeIdWorkspace, "/menubar/FileAction/RecentWorkspace", name, name, UIManagerItemType.Menuitem, false);
574			workspaceCount++;
575		}
576		ui.EnsureUpdate();
577	}
578
579	uint mergeIdProject = 1;
580	ActionGroup dynGroupProject = new ActionGroup("RecentProject");
581
582	public void RecentProjects(IList<RecentFile> lRecentProjects)
583	{
584		//uint mergeId = 1;
585		;
586		ui.InsertActionGroup(dynGroupProject, 0);
587		mergeIdProject = ui.NewMergeId();
588		
589		int i = 0;
590		
591		foreach (RecentFile rf in lRecentProjects) {
592			string name = "RecentProject" + i;
593			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
594			Gtk.Action action = new Gtk.Action(name, label);
595
596			string fileName = rf.FileName;
597
598			action.Activated += delegate(object sender, EventArgs e) {
599				MainClass.MainWindow.OpenProject(fileName, true);
600			};
601			dynGroupProject.Add(action);
602			ui.AddUi(mergeIdProject, "/menubar/FileAction/RecentProject", name, name, UIManagerItemType.Menuitem, false);
603			i++;
604		}
605	}
606
607	public void RefreshRecentProjects(IList<RecentFile> lRecentProjects)
608	{
609		ui.RemoveUi(mergeIdProject);
610		ui.RemoveActionGroup(dynGroupProject);
611
612		dynGroupProject = new ActionGroup("RecentProject");
613		ui.InsertActionGroup(dynGroupProject, 0);
614
615		int i = 0;
616		
617		foreach (RecentFile rf in lRecentProjects) {
618			string name = "RecentProject" + i;
619			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
620			Gtk.Action action = new Gtk.Action(name, label);
621
622			string fileName = rf.FileName;
623
624			action.Activated += delegate(object sender, EventArgs e) {
625				MainClass.MainWindow.OpenProject(fileName, true);
626			};
627			dynGroupProject.Add(action);
628			ui.AddUi(mergeIdProject, "/menubar/FileAction/RecentProject", name, name, UIManagerItemType.Menuitem, false);
629			i++;
630		}
631	}
632
633
634	uint mergeIdFiles = 1;
635	ActionGroup dynGroupFiles = new ActionGroup("RecentFile");
636	public void RecentFiles(IList<RecentFile> lRecentFiles)
637	{
638		ui.InsertActionGroup(dynGroupFiles, 0);
639		mergeIdFiles = ui.NewMergeId();
640
641		int i = 0;
642		
643		foreach (RecentFile rf in lRecentFiles) {
644			string name = "RecentFile" + i;
645			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
646			Gtk.Action action = new Gtk.Action(name, label);
647
648			string fileName = rf.FileName;
649			action.Activated += delegate(object sender, EventArgs e) {
650				MainClass.MainWindow.OpenFile(fileName,true);
651			};
652			dynGroupFiles.Add(action);
653			ui.AddUi(mergeIdFiles, "/menubar/FileAction/RecentFile", name, name, UIManagerItemType.Menuitem, false);
654			i++;
655		}
656	}
657
658	public void RefreshRecentFiles(IList<RecentFile> lRecentFiles)
659	{
660		ui.RemoveUi(mergeIdFiles);
661		ui.RemoveActionGroup(dynGroupFiles);
662
663		dynGroupFiles = new ActionGroup("RecentFile");
664		ui.InsertActionGroup(dynGroupFiles, 0);
665
666		int i = 0;
667		
668		foreach (RecentFile rf in lRecentFiles) {
669			string name = "RecentFile" + i;
670			string label = String.Format("_{0} {1}", i, rf.DisplayName.Replace("_","__"));
671			Gtk.Action action = new Gtk.Action(name, label);
672
673			string fileName = rf.FileName;
674			action.Activated += delegate(object sender, EventArgs e) {
675				//en.Open(fileName);
676				MainClass.MainWindow.OpenFile(fileName,true);
677			};
678			dynGroupFiles.Add(action);
679			ui.AddUi(mergeIdFiles, "/menubar/FileAction/RecentFile", name, name, UIManagerItemType.Menuitem, false);
680			i++;
681		}
682	}
683		*/
684		/*
685		string name = "ClearFile";
686		string label = String.Format("Clear Recent File");
687		Gtk.Action action = new Gtk.Action(name, label);
688		action.Activated += delegate(object sender, EventArgs e) {  };
689		dynGroup.Add(action);
690		ui.AddUi(mergeId, "/menubar/File/RecentFile", name, name, UIManagerItemType.Menuitem, false);
691		 */			
692	
693	public void SetDefaultMenu(bool state){
694		//ActionUiManager.SetSensitive("propertyall",state);
695		SetSensitive("FileGroup",state);
696		SetSensitive("DirGroup",state);
697		
698		SetSensitive("adddirectory",state);		
699		SetSensitive("newdirectory",state);
700		//SetSensitive("addtheme",state);
701		SetSensitive("addfile",state);
702		SetSensitive("newfile",state);
703	}
704
705	public void SetEditMenu(bool state){
706		SetSensitive("EditAction",state);
707
708		SetSensitive("cutText",state);
709		SetSensitive("copyText",state);
710		SetSensitive("pasteText",state);
711		SetSensitive("inserttemplate",state);
712		SetSensitive("insertcomplete",state);
713		SetSensitive("undo",state);
714		SetSensitive("redo",state);
715		SetSensitive("gotoline",state);
716
717		/*MenuItem wgt = (MenuItem)ActionUiManager.GetWidget("/menubar/Edit");
718		if(wgt != null){
719			foreach ( Widget mi in wgt.Children){
720				if(mi.GetType() == typeof(MenuItem)){
721					mi.Visible = state;
722				}
723			}
724		}*/
725	}
726
727	public Gtk.Action FindActionByName(string action_name)
728	{
729		foreach (ActionGroup @group in ui.ActionGroups)
730			foreach (Gtk.Action action in @group.ListActions())
731				if (action.Name == action_name)
732					return action;
733		
734		return null;
735	}
736
737	public Gtk.Action this[string widget_path_or_action_name]
738	{
739		get {
740			Gtk.Action action = FindActionByName(widget_path_or_action_name);
741			if (action == null)
742				return ui.GetAction(widget_path_or_action_name);
743			
744			return action;
745		}
746	}
747
748	public Widget GetWidget(string widget_path)
749	{
750		return ui.GetWidget(widget_path);
751	}
752
753	public void SetActionLabel(string action_name, string label)
754	{
755		this[action_name].Label = label;
756	}
757
758	public void SetActionIcon(string action_name, string icon)
759	{
760		this[action_name].StockId = icon;
761	}
762
763	public void UpdateAction(string action_name, string label, string icon)
764	{
765		Gtk.Action action = this[action_name];
766		action.Label = label;
767		action.StockId = icon;
768	}
769
770	public void UpdateAccel(string action_name, string accel)
771	{
772		Gtk.Action action = this[action_name];
773		if(action!= null){
774			action.AccelPath = accel;
775			Console.WriteLine(action.AccelPath);
776		}
777	}
778
779	public void SetSensitive(string action_name, bool sensitive)
780	{
781		if( this.FindActionByName(action_name)!= null)
782			this[action_name].Sensitive = sensitive;
783	}
784
785	public void SetVisible(string action_name, bool sensitive)
786	{
787		if( this.FindActionByName(action_name)!= null)
788			this[action_name].Visible = sensitive;
789	}
790
791	public IEnumerator GetEnumerator()
792	{
793		foreach (ActionGroup @group in ui.ActionGroups)
794			foreach (Gtk.Action action in @group.ListActions())
795				yield return action;
796	}
797
798	public UIManager UI
799	{
800		get { return ui; }
801	}
802
803	public ActionGroup MainWindowActions
804	{
805		get { return main_window_actions; }
806	}
807
808	#region Default action
809	static void OnActivate(object obj, EventArgs args)
810	{
811
812	}
813
814	void OnTest(object obj, EventArgs args)
815	{
816		LoginRegisterDialog ld = new LoginRegisterDialog(MainClass.MainWindow);
817		if(ld.Run() == (int)ResponseType.Ok){
818			
819		}
820		ld.Destroy();
821
822		Console.WriteLine("MainClass.MainWindow.hpRight.Position SW 1 -:"+MainClass.MainWindow.hpRight.Position );
823			//	throw new NotImplementedException();
824		return;
825		/*PublishDialogWizzard npw = new PublishDialogWizzard();
826		int result = npw.Run();
827		if (result == (int)ResponseType.Ok) {
828
829		}
830		npw.Destroy();*/
831		/*PublishDialog pd = new PublishDialog();
832		if(pd.Run() == (int)ResponseType.Ok){
833			
834		}
835		pd.Destroy();
836		*/			
837	}
838	#endregion	
839	}
840	
841}
842