Inheritance: IDisposable
		public MDSubMenuItem (CommandManager manager, CommandEntrySet ces, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null)
		{
			this.ces = ces;

			this.Submenu = new MDMenu (manager, ces, commandSource, initialCommandTarget);
			this.Title = this.Submenu.Title;
		}
		public MenuButtonEntry (Gtk.Entry entry, Gtk.Button button)
		{
			if (entry == null) entry = new Gtk.Entry ();
			if (button == null) button = new Gtk.Button (new Gtk.Arrow (Gtk.ArrowType.Right, Gtk.ShadowType.Out));
			
			this.entry = entry;
			this.button = button;
			
			manager = new CommandManager ();
			manager.RegisterGlobalHandler (this);
			
			if (entry.Parent == null)
				PackStart (entry, true, true, 0);
			if (button.Parent == null)
				PackStart (button, false, false, 2);
			
			ActionCommand cmd = new ActionCommand ("InsertOption", "InsertOption", null);
			cmd.CommandArray = true;
			manager.RegisterCommand (cmd);
			entrySet = new CommandEntrySet ();
			entrySet.AddItem ("InsertOption");
			
			button.Clicked += ShowQuickInsertMenu;
			button.StateChanged += ButtonStateChanged;
		}
Beispiel #3
0
		public MDSubMenuItem (CommandManager manager, CommandEntrySet ces)
		{
			this.ces = ces;

			this.Submenu = new MDMenu (manager, ces);
			this.Title = this.Submenu.Title;
		}
		public CommandMenuItem (object commandId, CommandManager commandManager, string overrideLabel, bool disabledVisible): base ("")
		{
			this.commandId = commandId;
			this.commandManager = commandManager;
			this.overrideLabel = overrideLabel;
			this.disabledVisible = disabledVisible;
			ActionCommand cmd = commandManager.GetCommand (commandId) as ActionCommand;
			if (cmd != null)
				isArray = cmd.CommandArray;
		}
Beispiel #5
0
		public MDMenuItem (CommandManager manager, CommandEntry ce, ActionCommand command)
		{
			this.ce = ce;
			this.manager = manager;

			isArrayItem = command.CommandArray;

			Target = this;
			Action = ActionSel;
		}
Beispiel #6
0
		public virtual Command GetCommand (CommandManager manager)
		{
			if (localCmd != null) {
				if (manager.GetCommand (localCmd.Id) == null)
					manager.RegisterCommand (localCmd);
				localCmd = null;
			}
				
			return manager.GetCommand (cmdId);
		}
		public CommandCheckMenuItem (object commandId, CommandManager commandManager, string overrideLabel, bool disabledVisible): base ("")
		{
			this.commandId = commandId;
			this.commandManager = commandManager;
			this.overrideLabel = overrideLabel;
			this.disabledVisible = disabledVisible;
			
			ActionCommand cmd = commandManager.GetCommand (commandId) as ActionCommand;
			if (cmd != null && cmd.ActionType == ActionType.Radio)
				this.DrawAsRadio = true;
		}
		public MDMenuItem (CommandManager manager, CommandEntry ce, ActionCommand command, CommandSource commandSource, object initialCommandTarget)
		{
			this.ce = ce;
			this.manager = manager;
			this.initialCommandTarget = initialCommandTarget;
			this.commandSource = commandSource;

			isArrayItem = command.CommandArray;

			Target = this;
			Action = ActionSel;
		}
Beispiel #9
0
		public MDMenu (CommandManager manager, CommandEntrySet ces, CommandSource commandSource, object initialCommandTarget)
		{
			this.WeakDelegate = this;

			AutoEnablesItems = false;

			Title = (ces.Name ?? "").Replace ("_", "");

			foreach (CommandEntry ce in ces) {
				if (ce.CommandId == Command.Separator) {
					AddItem (NSMenuItem.SeparatorItem);
					if (!string.IsNullOrEmpty (ce.OverrideLabel))
						AddItem (new MDMenuHeaderItem (ce.OverrideLabel));
					continue;
				}

				if (string.Equals (ce.CommandId as string, servicesID, StringComparison.Ordinal)) {
					AddItem (new MDServicesMenuItem ());
					continue;
				}

				var subset = ce as CommandEntrySet;
				if (subset != null) {
					AddItem (new MDSubMenuItem (manager, subset, commandSource, initialCommandTarget));
					continue;
				}

				var lce = ce as LinkCommandEntry;
				if (lce != null) {
					AddItem (new MDLinkMenuItem (lce));
					continue;
				}

				Command cmd = manager.GetCommand (ce.CommandId);
				if (cmd == null) {
					LoggingService.LogError ("MacMenu: '{0}' maps to null command", ce.CommandId);
					continue;
				}

				if (cmd is CustomCommand) {
					LoggingService.LogWarning ("MacMenu: '{0}' is unsupported custom-rendered command' '", ce.CommandId);
					continue;
				}

				var acmd = cmd as ActionCommand;
				if (acmd == null) {
					LoggingService.LogWarning ("MacMenu: '{0}' has unknown command type '{1}'", cmd.GetType (), ce.CommandId);
					continue;
				}

				AddItem (new MDMenuItem (manager, ce, acmd, commandSource, initialCommandTarget));
			}
		}
Beispiel #10
0
		internal protected override Gtk.MenuItem CreateMenuItem (CommandManager manager)
		{
			Gtk.ImageMenuItem item = new Gtk.ImageMenuItem (text != null ? text : url);
			item.Image = new Gtk.Image (icon, Gtk.IconSize.Menu);
			item.Activated += new EventHandler (HandleActivation);
			item.Selected += delegate {
				CommandInfo ci = new CommandInfo (Text);
				ci.Icon = icon;
				ci.Description = AddinManager.CurrentLocalizer.GetString ("Open {0}", Url);
				manager.NotifySelected (ci);
			};
			item.Deselected += delegate {
				manager.NotifyDeselected ();
			};
			return item;
		}
Beispiel #11
0
		internal protected virtual Gtk.ToolItem CreateToolItem (CommandManager manager)
		{
			if (cmdId == CommandManager.ToCommandId (Command.Separator))
				return new Gtk.SeparatorToolItem ();

			Command cmd = GetCommand (manager);
			if (cmd == null)
				return new Gtk.ToolItem ();
			
			if (cmd is CustomCommand) {
				Gtk.Widget child = (Gtk.Widget) Activator.CreateInstance (((CustomCommand)cmd).WidgetType);
				Gtk.ToolItem ti;
				if (child is Gtk.ToolItem)
					ti = (Gtk.ToolItem) child;
				else {
					ti = new Gtk.ToolItem ();
					ti.Child = child;
				}
				if (cmd.Text != null && cmd.Text.Length > 0) {
					//strip "_" accelerators from tooltips
					string text = cmd.Text;
					while (true) {
						int underscoreIndex = text.IndexOf ('_');
						if (underscoreIndex > -1)
							text = text.Remove (underscoreIndex, 1);
						else
							break;
					}
					ti.TooltipText = text;
				}
				return ti;
			}
			
			ActionCommand acmd = cmd as ActionCommand;
			if (acmd == null)
				throw new InvalidOperationException ("Unknown cmd type.");

			if (acmd.CommandArray) {
				CommandMenu menu = new CommandMenu (manager);
				menu.Append (CreateMenuItem (manager));
				return new MenuToolButton (menu, acmd.Icon);
			}
			else if (acmd.ActionType == ActionType.Normal)
				return new CommandToolButton (cmdId, manager);
			else
				return new CommandToggleToolButton (cmdId, manager);
		}
		public static void Start (CommandManager commandManager, bool publishServer)
		{
			AutoTestService.commandManager = commandManager;
			
			string sref = Environment.GetEnvironmentVariable ("MONO_AUTOTEST_CLIENT");
			if (!string.IsNullOrEmpty (sref)) {
				Console.WriteLine ("AutoTest service starting");
				MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel ();
				byte[] data = Convert.FromBase64String (sref);
				MemoryStream ms = new MemoryStream (data);
				BinaryFormatter bf = new BinaryFormatter ();
				IAutoTestClient client = (IAutoTestClient) bf.Deserialize (ms);
				client.Connect (manager.AttachClient (client));
			}
			if (publishServer && !manager.IsClientConnected) {
				MonoDevelop.Core.Execution.RemotingService.RegisterRemotingChannel ();
				BinaryFormatter bf = new BinaryFormatter ();
				ObjRef oref = RemotingServices.Marshal (manager);
				MemoryStream ms = new MemoryStream ();
				bf.Serialize (ms, oref);
				sref = Convert.ToBase64String (ms.ToArray ());
				File.WriteAllText (SessionReferenceFile, sref);
			}
		}
Beispiel #13
0
		internal static Gtk.MenuItem CreateMenuItem (CommandManager manager, object cmdId, bool isArrayMaster)		
		{
			return CreateMenuItem (manager, null, cmdId, isArrayMaster, null, true);
		}
Beispiel #14
0
		void InitApp (CommandManager commandManager)
		{
			if (initedApp)
				return;

			commandManager.CommandActivating += OnCommandActivating;

			//mac-ify these command names
			commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences...");
			commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies...");
			commandManager.GetCommand (HelpCommands.About).Text = GettextCatalog.GetString ("About {0}", BrandingService.ApplicationName);
			commandManager.GetCommand (MacIntegrationCommands.HideWindow).Text = GettextCatalog.GetString ("Hide {0}", BrandingService.ApplicationName);
			commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager...");
			
			initedApp = true;
			
			IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent;

			if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) {
				IdeApp.Workbench.RootWindow.Realized += (sender, args) => {
					var win = GtkQuartz.GetWindow ((Gtk.Window) sender);
					win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary;
				};
			}
		}
		public static void Initialize (IProgressMonitor monitor)
		{
			Counters.Initialization.Trace ("Creating Workbench");
			workbench = new Workbench ();
			Counters.Initialization.Trace ("Creating Root Workspace");
			workspace = new RootWorkspace ();
			Counters.Initialization.Trace ("Creating Services");
			projectOperations = new ProjectOperations ();
			helpOperations = new HelpOperations ();
			commandService = new CommandManager ();
			ideServices = new IdeServices ();
			CustomToolService.Init ();
			AutoTestService.Start (commandService, Preferences.EnableAutomatedTesting);
			
			commandService.CommandTargetScanStarted += CommandServiceCommandTargetScanStarted;
			commandService.CommandTargetScanFinished += CommandServiceCommandTargetScanFinished;

			KeyBindingService.LoadBindingsFromExtensionPath ("/MonoDevelop/Ide/KeyBindingSchemes");
			KeyBindingService.LoadCurrentBindings ("MD2");

			commandService.CommandError += delegate (object sender, CommandErrorArgs args) {
				MessageService.ShowException (args.Exception, args.ErrorMessage);
			};
			
			FileService.ErrorHandler = FileServiceErrorHandler;
		
			monitor.BeginTask (GettextCatalog.GetString("Loading Workbench"), 5);
			Counters.Initialization.Trace ("Loading Commands");
			
			commandService.LoadCommands ("/MonoDevelop/Ide/Commands");
			monitor.Step (1);

			Counters.Initialization.Trace ("Initializing Workbench");
			workbench.Initialize (monitor);
			monitor.Step (1);
			
			InternalLog.EnableErrorNotification ();
			
			monitor.Step (1);

			Counters.Initialization.Trace ("Restoring Workbench State");
			workbench.Show ("SharpDevelop.Workbench.WorkbenchMemento");
			monitor.Step (1);
			
			Counters.Initialization.Trace ("Flushing GUI events");
			DispatchService.RunPendingEvents ();
			Counters.Initialization.Trace ("Flushed GUI events");
			
			MessageService.RootWindow = workbench.RootWindow;
		
			commandService.EnableIdleUpdate = true;
			
			// Default file format
			MonoDevelop.Projects.Services.ProjectServiceLoaded += delegate(object sender, EventArgs e) {
				((ProjectService)sender).DefaultFileFormatId = IdeApp.Preferences.DefaultProjectFileFormat;
			};
			
			IdeApp.Preferences.DefaultProjectFileFormatChanged += delegate {
				IdeApp.Services.ProjectService.DefaultFileFormatId = IdeApp.Preferences.DefaultProjectFileFormat;
			};

			// Perser service initialization
			MonoDevelop.Projects.Dom.Parser.ProjectDomService.TrackFileChanges = true;
			MonoDevelop.Projects.Dom.Parser.ProjectDomService.ParseProgressMonitorFactory = new ParseProgressMonitorFactory (); 

			
			// Startup commands
			Counters.Initialization.Trace ("Running Startup Commands");
			AddinManager.AddExtensionNodeHandler ("/MonoDevelop/Ide/StartupHandlers", OnExtensionChanged);
			monitor.EndTask ();

			// Set initial run flags
			Counters.Initialization.Trace ("Upgrading Settings");

			if (PropertyService.Get("MonoDevelop.Core.FirstRun", false)) {
				isInitialRun = true;
				PropertyService.Set ("MonoDevelop.Core.FirstRun", false);
				PropertyService.Set ("MonoDevelop.Core.LastRunVersion", BuildVariables.PackageVersion);
				PropertyService.Set ("MonoDevelop.Core.LastRunVersion", CurrentRevision);
				PropertyService.SaveProperties ();
			}

			string lastVersion = PropertyService.Get ("MonoDevelop.Core.LastRunVersion", "1.9.1");
			int lastRevision = PropertyService.Get ("MonoDevelop.Core.LastRunRevision", 0);
			if (lastRevision != CurrentRevision && !isInitialRun) {
				isInitialRunAfterUpgrade = true;
				if (lastRevision == 0) {
					switch (lastVersion) {
						case "1.0": lastRevision = 1; break;
						case "2.0": lastRevision = 2; break;
						case "2.2": lastRevision = 3; break;
						case "2.2.1": lastRevision = 4; break;
					}
				}
				upgradedFromRevision = lastRevision;
				PropertyService.Set ("MonoDevelop.Core.LastRunVersion", BuildVariables.PackageVersion);
				PropertyService.Set ("MonoDevelop.Core.LastRunRevision", CurrentRevision);
				PropertyService.SaveProperties ();
			}
			
			// The ide is now initialized

			isInitialized = true;
			
			if (isInitialRun) {
				try {
					OnInitialRun ();
				} catch (Exception e) {
					LoggingService.LogError ("Error found while initializing the IDE", e);
				}
			}

			if (isInitialRunAfterUpgrade) {
				try {
					OnUpgraded (upgradedFromRevision);
				} catch (Exception e) {
					LoggingService.LogError ("Error found while initializing the IDE", e);
				}
			}
			
			if (initializedEvent != null)
				initializedEvent (null, EventArgs.Empty);
			
			// load previous combine
			if ((bool)PropertyService.Get("SharpDevelop.LoadPrevProjectOnStartup", false)) {
				RecentOpen recentOpen = Workbench.RecentOpen;

				if (recentOpen.RecentProjectsCount > 0) { 
					IdeApp.Workspace.OpenWorkspaceItem(recentOpen.RecentProjects.First ().ToString()).WaitForCompleted ();
				}
			}
			
			commandService.CommandSelected += OnCommandSelected;
			commandService.CommandDeselected += OnCommandDeselected;
			
			//FIXME: we should really make this on-demand. consumers can display a "loading help cache" message like VS
			MonoDevelop.Projects.HelpService.AsyncInitialize ();
			
			UpdateInstrumentationIcon ();
			IdeApp.Preferences.EnableInstrumentationChanged += delegate {
				UpdateInstrumentationIcon ();
			};
			AutoTestService.NotifyEvent ("MonoDevelop.Ide.IdeStart");
		}
		public CommandFrame (CommandManager manager)
		{
			this.manager = manager;
			manager.RegisterGlobalHandler (this);
		}
Beispiel #17
0
		public override bool SetGlobalMenu (CommandManager commandManager, string commandMenuAddinPath, string appMenuAddinPath)
		{
			if (setupFail)
				return false;

			try {
				InitApp (commandManager);

				NSApplication.SharedApplication.HelpMenu = null;

				var rootMenu = NSApplication.SharedApplication.MainMenu;
				if (rootMenu == null) {
					rootMenu = new NSMenu ();
					NSApplication.SharedApplication.MainMenu = rootMenu;
				} else {
					rootMenu.RemoveAllItems ();
				}

				CommandEntrySet appCes = commandManager.CreateCommandEntrySet (appMenuAddinPath);
				rootMenu.AddItem (new MDSubMenuItem (commandManager, appCes));

				CommandEntrySet ces = commandManager.CreateCommandEntrySet (commandMenuAddinPath);
				foreach (CommandEntry ce in ces) {
					rootMenu.AddItem (new MDSubMenuItem (commandManager, (CommandEntrySet) ce));
				}
			} catch (Exception ex) {
				try {
					var m = NSApplication.SharedApplication.MainMenu;
					if (m != null) {
						m.Dispose ();
					}
					NSApplication.SharedApplication.MainMenu = null;
				} catch {}
				LoggingService.LogError ("Could not install global menu", ex);
				setupFail = true;
				return false;
			}
			return true;
		}
Beispiel #18
0
		public override bool ShowContextMenu (CommandManager commandManager, Gtk.Widget widget, double x, double y, CommandEntrySet entrySet, object initialCommandTarget = null)
		{
			Gtk.Application.Invoke (delegate {
				// Explicitly release the grab because the menu is shown on the mouse position, and the widget doesn't get the mouse release event
				Gdk.Pointer.Ungrab (Gtk.Global.CurrentEventTime);
				var menu = new MDMenu (commandManager, entrySet, CommandSource.ContextMenu, initialCommandTarget);
				var nsview = MacInterop.GtkQuartz.GetView (widget);
				var toplevel = widget.Toplevel as Gtk.Window;
				int trans_x, trans_y;
				widget.TranslateCoordinates (toplevel, (int)x, (int)y, out trans_x, out trans_y);

				// Window coordinates in gtk are the same for cocoa, with the exception of the Y coordinate, that has to be flipped.
				var pt = new PointF ((float)trans_x, (float)trans_y);
				int w,h;
				toplevel.GetSize (out w, out h);
				pt.Y = h - pt.Y;

				var tmp_event = NSEvent.MouseEvent (NSEventType.LeftMouseDown,
					pt,
					0, 0,
					MacInterop.GtkQuartz.GetWindow (toplevel).WindowNumber,
					null, 0, 0, 0);

				NSMenu.PopUpContextMenu (menu, tmp_event, nsview);
			});

			return true;
		}
Beispiel #19
0
        public TitleMenuItem(MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null, Menu menu = null)
        {
            this.manager = manager;
            this.initialCommandTarget = initialCommandTarget;
            this.commandSource        = commandSource;
            this.commandArrayInfo     = commandArrayInfo;

            this.menu     = menu;
            menuEntry     = entry;
            menuEntrySet  = entry as CommandEntrySet;
            menuLinkEntry = entry as LinkCommandEntry;

            if (commandArrayInfo != null)
            {
                Header = commandArrayInfo.Text;

                var commandArrayInfoSet = commandArrayInfo as CommandInfoSet;
                if (commandArrayInfoSet != null)
                {
                    foreach (var item in commandArrayInfoSet.CommandInfos)
                    {
                        if (item.IsArraySeparator)
                        {
                            Items.Add(new Separator {
                                UseLayoutRounding = true,
                            });
                        }
                        else
                        {
                            Items.Add(new TitleMenuItem(manager, entry, item, commandSource, initialCommandTarget, menu));
                        }
                    }
                }
            }

            if (menuEntrySet != null)
            {
                Header = menuEntrySet.Name;

                foreach (CommandEntry item in menuEntrySet)
                {
                    if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator)
                    {
                        Items.Add(new Separator {
                            UseLayoutRounding = true,
                        });
                    }
                    else
                    {
                        Items.Add(new TitleMenuItem(manager, item, menu: menu));
                    }
                }
            }
            else if (menuLinkEntry != null)
            {
                Header = menuLinkEntry.Text;
                Click += OnMenuLinkClicked;
            }
            else if (entry != null)
            {
                actionCommand = manager.GetCommand(menuEntry.CommandId) as ActionCommand;
                if (actionCommand == null)
                {
                    return;
                }

                IsCheckable = actionCommand.ActionType == ActionType.Check;

                // FIXME: Use proper keybinding text.
                if (actionCommand.KeyBinding != null)
                {
                    InputGestureText = KeyBindingManager.BindingToDisplayLabel(actionCommand.KeyBinding, true);
                }

                try {
                    if (!actionCommand.Icon.IsNull)
                    {
                        Icon = new ImageBox(actionCommand.Icon.GetStockIcon().WithSize(Xwt.IconSize.Small));
                    }
                } catch (Exception ex) {
                    MonoDevelop.Core.LoggingService.LogError("Failed loading menu icon: " + actionCommand.Icon, ex);
                }
                Click += OnMenuClicked;
            }

            Height            = SystemParameters.CaptionHeight;
            UseLayoutRounding = true;
        }
Beispiel #20
0
		public override bool SetGlobalMenu (CommandManager commandManager, string commandMenuAddinPath, string appMenuAddinPath)
		{
			if (setupFail)
				return false;
			
			try {
				InitApp (commandManager);
				CommandEntrySet ces = commandManager.CreateCommandEntrySet (commandMenuAddinPath);
				MacMainMenu.Recreate (commandManager, ces);

				CommandEntrySet aes = commandManager.CreateCommandEntrySet (appMenuAddinPath);
				MacMainMenu.SetAppMenuItems (commandManager, aes);
			} catch (Exception ex) {
				try {
					MacMainMenu.Destroy (true);
				} catch {}
				LoggingService.LogError ("Could not install global menu", ex);
				setupFail = true;
				return false;
			}
			
			return true;
		}
Beispiel #21
0
		void InitApp (CommandManager commandManager)
		{
			if (initedApp)
				return;

			MacMainMenu.SetAppQuitCommand (CommandManager.ToCommandId (FileCommands.Exit));
			
			MacMainMenu.AddCommandIDMappings (new Dictionary<object, CarbonCommandID> ()
			{
				{ CommandManager.ToCommandId (EditCommands.Copy), CarbonCommandID.Copy },
				{ CommandManager.ToCommandId (EditCommands.Cut), CarbonCommandID.Cut },
				{ CommandManager.ToCommandId (EditCommands.MonodevelopPreferences), CarbonCommandID.Preferences }, 
				{ CommandManager.ToCommandId (EditCommands.Redo), CarbonCommandID.Redo },
				{ CommandManager.ToCommandId (EditCommands.Undo), CarbonCommandID.Undo },
				{ CommandManager.ToCommandId (EditCommands.SelectAll), CarbonCommandID.SelectAll },
				{ CommandManager.ToCommandId (FileCommands.NewFile), CarbonCommandID.New },
				{ CommandManager.ToCommandId (FileCommands.OpenFile), CarbonCommandID.Open },
				{ CommandManager.ToCommandId (FileCommands.Save), CarbonCommandID.Save },
				{ CommandManager.ToCommandId (FileCommands.SaveAs), CarbonCommandID.SaveAs },
				{ CommandManager.ToCommandId (FileCommands.CloseFile), CarbonCommandID.Close },
				{ CommandManager.ToCommandId (FileCommands.Exit), CarbonCommandID.Quit },
				{ CommandManager.ToCommandId (FileCommands.ReloadFile), CarbonCommandID.Revert },
				{ CommandManager.ToCommandId (HelpCommands.About), CarbonCommandID.About },
				{ CommandManager.ToCommandId (HelpCommands.Help), CarbonCommandID.AppHelp },
				{ CommandManager.ToCommandId (MacIntegrationCommands.HideWindow), CarbonCommandID.Hide },
				{ CommandManager.ToCommandId (MacIntegrationCommands.HideOthers), CarbonCommandID.HideOthers },
			});
			
			//mac-ify these command names
			commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences...");
			commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies...");
			commandManager.GetCommand (HelpCommands.About).Text = GettextCatalog.GetString ("About {0}", BrandingService.ApplicationName);
			commandManager.GetCommand (MacIntegrationCommands.HideWindow).Text = GettextCatalog.GetString ("Hide {0}", BrandingService.ApplicationName);
			commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager...");
			
			initedApp = true;
			
			IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent;

			if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) {
				IdeApp.Workbench.RootWindow.Realized += (sender, args) => {
					var win = GtkQuartz.GetWindow ((Gtk.Window) sender);
					win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary;
				};
			}
		}
Beispiel #22
0
		internal virtual Gtk.MenuItem CreateMenuItem (CommandManager manager)
		{
			return CreateMenuItem (manager, GetCommand (manager), cmdId, true, overrideLabel, disabledVisible);
		}
        public TitleMenuItem(MonoDevelop.Components.Commands.CommandManager manager, CommandEntry entry, CommandInfo commandArrayInfo = null, CommandSource commandSource = CommandSource.MainMenu, object initialCommandTarget = null)
        {
            this.manager = manager;
            this.initialCommandTarget = initialCommandTarget;
            this.commandSource        = commandSource;
            this.commandArrayInfo     = commandArrayInfo;

            menuEntry     = entry;
            menuEntrySet  = entry as CommandEntrySet;
            menuLinkEntry = entry as LinkCommandEntry;

            if (commandArrayInfo != null)
            {
                Header = commandArrayInfo.Text;

                var commandArrayInfoSet = commandArrayInfo as CommandInfoSet;
                if (commandArrayInfoSet != null)
                {
                    foreach (var item in commandArrayInfoSet.CommandInfos)
                    {
                        if (item.IsArraySeparator)
                        {
                            Items.Add(new Separator {
                                UseLayoutRounding = true,
                            });
                        }
                        else
                        {
                            Items.Add(new TitleMenuItem(manager, entry, item, commandSource, initialCommandTarget));
                        }
                    }
                }
            }

            if (menuEntrySet != null)
            {
                Header = menuEntrySet.Name;

                foreach (CommandEntry item in menuEntrySet)
                {
                    if (item.CommandId == MonoDevelop.Components.Commands.Command.Separator)
                    {
                        Items.Add(new Separator {
                            UseLayoutRounding = true,
                        });
                    }
                    else
                    {
                        Items.Add(new TitleMenuItem(manager, item));
                    }
                }
            }
            else if (menuLinkEntry != null)
            {
                Header = menuLinkEntry.Text;
                Click += OnMenuLinkClicked;
            }
            else if (entry != null)
            {
                actionCommand = manager.GetCommand(menuEntry.CommandId) as ActionCommand;
                if (actionCommand == null)
                {
                    return;
                }

                IsCheckable = actionCommand.ActionType == ActionType.Check;

                // FIXME: Use proper keybinding text.
                if (actionCommand.KeyBinding != null)
                {
                    InputGestureText = actionCommand.KeyBinding.ToString();
                }

                if (!actionCommand.Icon.IsNull)
                {
                    Icon = new Image {
                        Source = actionCommand.Icon.GetImageSource(Xwt.IconSize.Small)
                    }
                }
                ;
                Click += OnMenuClicked;
            }

            Height            = SystemParameters.CaptionHeight;
            UseLayoutRounding = true;
        }

        /// <summary>
        /// Updates a command entry. Should only be called from a toplevel node.
        /// This will update all the menu's children.
        /// </summary>
        void Update()
        {
            hasCommand = false;
            if (menuLinkEntry != null)
            {
                return;
            }

            if (menuEntrySet != null || commandArrayInfo is CommandInfoSet)
            {
                for (int i = 0; i < Items.Count; ++i)
                {
                    var titleMenuItem = Items[i] as TitleMenuItem;

                    if (titleMenuItem != null)
                    {
                        titleMenuItem.Update();
                        continue;
                    }

                    // If we have a separator, don't draw another one if the previous visible item is a separator.
                    var separatorMenuItem = Items [i] as Separator;
                    separatorMenuItem.Visibility = Visibility.Collapsed;
                    for (int j = i - 1; j >= 0; --j)
                    {
                        var iterMenuItem = Items [j] as Control;

                        if (iterMenuItem is Separator)
                        {
                            break;
                        }

                        if (iterMenuItem.Visibility != Visibility.Visible)
                        {
                            continue;
                        }

                        separatorMenuItem.Visibility = Visibility.Visible;
                        break;
                    }
                }
                if (menuEntrySet != null && menuEntrySet.AutoHide)
                {
                    Visibility = Items.Cast <Control> ().Any(item => item.Visibility == Visibility.Visible) ? Visibility.Visible : Visibility.Collapsed;
                }
                return;
            }

            var info = manager.GetCommandInfo(menuEntry.CommandId, new CommandTargetRoute(initialCommandTarget));

            if (actionCommand != null)
            {
                if (!string.IsNullOrEmpty(info.Description) && (string)ToolTip != info.Description)
                {
                    ToolTip = info.Description;
                }

                if (actionCommand.CommandArray && commandArrayInfo == null)
                {
                    Visibility = Visibility.Collapsed;

                    var parent = (TitleMenuItem)Parent;

                    int count       = 1;
                    int indexOfThis = parent.Items.IndexOf(this);
                    foreach (var child in info.ArrayInfo)
                    {
                        Control toAdd;
                        if (child.IsArraySeparator)
                        {
                            toAdd = new Separator();
                        }
                        else
                        {
                            toAdd = new TitleMenuItem(manager, menuEntry, child);
                        }

                        toRemoveFromParent.Add(toAdd);
                        parent.Items.Insert(indexOfThis + (count++), toAdd);
                    }
                    return;
                }
            }

            SetInfo(commandArrayInfo != null ? commandArrayInfo : info);
        }

        bool hasCommand = false;
        void SetInfo(CommandInfo info)
        {
            hasCommand = true;
            Header     = info.Text;
            Icon       = new Image {
                Source = info.Icon.GetImageSource(Xwt.IconSize.Small)
            };
            IsEnabled  = info.Enabled;
            Visibility = info.Visible && (menuEntry.DisabledVisible || IsEnabled) ?
                         Visibility.Visible : Visibility.Collapsed;
            IsChecked = info.Checked || info.CheckedInconsistent;
            ToolTip   = info.Description;
        }

        /// <summary>
        /// Clears a command entry's saved data. Should only be called from a toplevel node.
        /// This will update all the menu's children.
        /// </summary>
        IEnumerable <Control> Clear()
        {
            if (menuLinkEntry != null)
            {
                return(Enumerable.Empty <TitleMenuItem> ());
            }

            if (menuEntrySet != null)
            {
                var toRemove = Enumerable.Empty <Control> ();
                foreach (var item in Items)
                {
                    var titleMenuItem = item as TitleMenuItem;
                    if (titleMenuItem == null)
                    {
                        continue;
                    }

                    toRemove = toRemove.Concat(titleMenuItem.Clear());
                }

                foreach (var item in toRemove)
                {
                    Items.Remove(item);
                }

                return(Enumerable.Empty <TitleMenuItem> ());
            }

            var ret = toRemoveFromParent;

            toRemoveFromParent = new List <Control> ();
            return(ret);
        }
Beispiel #24
0
		public override bool SetGlobalMenu (CommandManager commandManager, string commandMenuAddinPath)
		{
			if (setupFail)
				return false;
			
			try {
				InitApp (commandManager);
				CommandEntrySet ces = commandManager.CreateCommandEntrySet (commandMenuAddinPath);
				OSXMenu.Recreate (commandManager, ces, ignoreCommands);
			} catch (Exception ex) {
				try {
					OSXMenu.Destroy (true);
				} catch {}
				MonoDevelop.Core.LoggingService.LogError ("Could not install global menu", ex);
				setupFail = true;
				return false;
			}
			
			return true;
		}
Beispiel #25
0
		internal protected override Gtk.ToolItem CreateToolItem (CommandManager manager)
		{
			Gtk.ToolButton item = new Gtk.ToolButton (text);
			item.StockId = icon;
			item.Clicked += new EventHandler (HandleActivation);
			return item;
		}
Beispiel #26
0
		static void InitApp (CommandManager commandManager)
		{
			if (initedApp)
				return;
			
			MacMainMenu.AddCommandIDMappings (new Dictionary<object, CarbonCommandID> ()
			{
				{ CommandManager.ToCommandId (EditCommands.Copy), CarbonCommandID.Copy },
				{ CommandManager.ToCommandId (EditCommands.Cut), CarbonCommandID.Cut },
				//FIXME: for some reason mapping this causes two menu items to be created
				// { EditCommands.MonodevelopPreferences, CarbonCommandID.Preferences }, 
				{ CommandManager.ToCommandId (EditCommands.Redo), CarbonCommandID.Redo },
				{ CommandManager.ToCommandId (EditCommands.Undo), CarbonCommandID.Undo },
				{ CommandManager.ToCommandId (EditCommands.SelectAll), CarbonCommandID.SelectAll },
				{ CommandManager.ToCommandId (FileCommands.NewFile), CarbonCommandID.New },
				{ CommandManager.ToCommandId (FileCommands.OpenFile), CarbonCommandID.Open },
				{ CommandManager.ToCommandId (FileCommands.Save), CarbonCommandID.Save },
				{ CommandManager.ToCommandId (FileCommands.SaveAs), CarbonCommandID.SaveAs },
				{ CommandManager.ToCommandId (FileCommands.CloseFile), CarbonCommandID.Close },
				{ CommandManager.ToCommandId (FileCommands.Exit), CarbonCommandID.Quit },
				{ CommandManager.ToCommandId (FileCommands.ReloadFile), CarbonCommandID.Revert },
				{ CommandManager.ToCommandId (HelpCommands.About), CarbonCommandID.About },
				{ CommandManager.ToCommandId (HelpCommands.Help), CarbonCommandID.AppHelp },
			});
			
			//mac-ify these command names
			commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences...");
			commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies...");
			commandManager.GetCommand (HelpCommands.About).Text = string.Format (GettextCatalog.GetString ("About {0}"), BrandingService.ApplicationName);
			commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager...");
			
			initedApp = true;
			MacMainMenu.SetAppQuitCommand (CommandManager.ToCommandId (FileCommands.Exit));
			MacMainMenu.AddAppMenuItems (
				commandManager,
			    CommandManager.ToCommandId (HelpCommands.About),
				CommandManager.ToCommandId (MonoDevelop.Ide.Updater.UpdateCommands.CheckForUpdates),
				CommandManager.ToCommandId (Command.Separator),
				CommandManager.ToCommandId (EditCommands.MonodevelopPreferences),
				CommandManager.ToCommandId (EditCommands.DefaultPolicies),
				CommandManager.ToCommandId (ToolCommands.AddinManager));
			
			IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent;
		}
Beispiel #27
0
		static Gtk.MenuItem CreateMenuItem (CommandManager manager, Command cmd, object cmdId, bool isArrayMaster, string overrideLabel, bool disabledVisible)
		{
			cmdId = CommandManager.ToCommandId (cmdId);
			if (cmdId == CommandManager.ToCommandId (Command.Separator))
				return new Gtk.SeparatorMenuItem ();
			
			if (cmd == null)
				cmd = manager.GetCommand (cmdId);

			if (cmd == null) {
				MonoDevelop.Core.LoggingService.LogWarning ("Unknown command '{0}'", cmdId);
				return new Gtk.MenuItem ("<Unknown Command>");
			}
			
			if (cmd is CustomCommand) {
				Gtk.Widget child = (Gtk.Widget) Activator.CreateInstance (((CustomCommand)cmd).WidgetType);
				CustomMenuItem ti = new CustomMenuItem ();
				ti.Child = child;
				return ti;
			}
			
			ActionCommand acmd = cmd as ActionCommand;
			if (acmd.ActionType == ActionType.Normal || (isArrayMaster && acmd.CommandArray))
				return new CommandMenuItem (cmdId, manager, overrideLabel, disabledVisible);
			else
				return new CommandCheckMenuItem (cmdId, manager, overrideLabel, disabledVisible);
		}	
Beispiel #28
0
		void InitApp (CommandManager commandManager)
		{
			if (initedApp)
				return;

			commandManager.CommandActivating += OnCommandActivating;

			//mac-ify these command names
			commandManager.GetCommand (EditCommands.MonodevelopPreferences).Text = GettextCatalog.GetString ("Preferences...");
			commandManager.GetCommand (EditCommands.DefaultPolicies).Text = GettextCatalog.GetString ("Custom Policies...");
			commandManager.GetCommand (HelpCommands.About).Text = GettextCatalog.GetString ("About {0}", BrandingService.ApplicationName);
			commandManager.GetCommand (MacIntegrationCommands.HideWindow).Text = GettextCatalog.GetString ("Hide {0}", BrandingService.ApplicationName);
			commandManager.GetCommand (ToolCommands.AddinManager).Text = GettextCatalog.GetString ("Add-in Manager...");

			initedApp = true;

			IdeApp.Workbench.RootWindow.DeleteEvent += HandleDeleteEvent;

			if (MacSystemInformation.OsVersion >= MacSystemInformation.Lion) {
				IdeApp.Workbench.RootWindow.Realized += (sender, args) => {
					var win = GtkQuartz.GetWindow ((Gtk.Window) sender);
					win.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary;
				};
			}

			PatchGtkTheme ();
			NSNotificationCenter.DefaultCenter.AddObserver (NSCell.ControlTintChangedNotification, notif => Runtime.RunInMainThread (
				delegate {
					Styles.LoadStyle();
					PatchGtkTheme();
				}));
			
			// FIXME: Immediate theme switching disabled, until NSAppearance issues are fixed 
			//IdeApp.Preferences.UserInterfaceTheme.Changed += (s,a) => PatchGtkTheme ();
		}
		public CommandMenuItem (object commandId, CommandManager commandManager): this (commandId, commandManager, null, true)
		{
		}
		public CommandMenuBar (CommandManager manager)
		{
			this.manager = manager;
		}
Beispiel #31
0
		public MultiCastDelegator (CommandManager manager, IMultiCastCommandRouter mcr, CommandTargetRoute route)
		{
			this.manager = manager;
			enumerator = mcr.GetCommandTargets ().GetEnumerator ();
			this.route = route;
		}
		public CommandToolButton (object commandId, CommandManager commandManager): base ("")
		{
			this.commandId = commandId;
			this.commandManager = commandManager;
			UseUnderline = true;
		}