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