Exemplo n.º 1
0
		public CommandManager (Gtk.Window root)
		{
			rootWidget = root;
			bindings = new KeyBindingManager ();
			ActionCommand c = new ActionCommand (CommandSystemCommands.ToolbarList, "Toolbar List", null, null, ActionType.Check);
			c.CommandArray = true;
			RegisterCommand (c);
		}
Exemplo n.º 2
0
        void Update(CommandInfo cmdInfo)
        {
            if (lastDesc != cmdInfo.Description)
            {
                string toolTip;
                if (string.IsNullOrEmpty(cmdInfo.AccelKey))
                {
                    toolTip = cmdInfo.Description;
                }
                else
                {
                    toolTip = cmdInfo.Description + " (" + KeyBindingManager.BindingToDisplayLabel(cmdInfo.AccelKey, false) + ")";
                }
                TooltipText = toolTip;
                lastDesc    = cmdInfo.Description;
            }

            if (Label != cmdInfo.Text)
            {
                Label = cmdInfo.Text;
            }
            if (cmdInfo.Icon != stockId)
            {
                stockId         = cmdInfo.Icon;
                this.IconWidget = iconWidget = new ImageView(cmdInfo.Icon, Gtk.IconSize.Menu);
            }
            if (IconWidget != null && cmdInfo.Enabled != Sensitive)
            {
                iconWidget.Image = iconWidget.Image.WithStyles(cmdInfo.Enabled ? "" : "disabled").WithAlpha(cmdInfo.Enabled ? 1.0 : 0.4);
            }
            if (cmdInfo.Enabled != Sensitive)
            {
                Sensitive = cmdInfo.Enabled;
            }
            if (cmdInfo.Visible != Visible)
            {
                Visible = cmdInfo.Visible;
            }
            if (cmdInfo.Icon.IsNull)
            {
                IsImportant = true;
            }
        }
		public static bool TryParse (string str, out KeyBinding binding)
		{
			Gdk.ModifierType chordModifier;
			Gdk.ModifierType modifier;
			uint chordKey;
			uint key;
			
			if (!KeyBindingManager.BindingToKeys (str, out chordKey, out chordModifier, out key, out modifier)) {
				binding = null;
				return false;
			}
			
			KeyboardShortcut chord = new KeyboardShortcut ((Gdk.Key) chordKey, chordModifier);
			KeyboardShortcut accel = new KeyboardShortcut ((Gdk.Key) key, modifier);
			
			binding = new KeyBinding (chord, accel);
			
			return true;
		}
Exemplo n.º 4
0
        void Update(CommandInfo cmdInfo)
        {
            if (lastCmdInfo != null)
            {
                lastCmdInfo.CancelAsyncUpdate();
                lastCmdInfo.Changed -= CommandInfoChanged;
            }
            lastCmdInfo          = cmdInfo;
            lastCmdInfo.Changed += CommandInfoChanged;

            if (isArray && !isArrayItem)
            {
                this.Visible = false;
                Gtk.Menu menu = (Gtk.Menu)Parent;

                if (itemArray != null)
                {
                    foreach (Gtk.MenuItem item in itemArray)
                    {
                        menu.Remove(item);
                    }
                }

                itemArray = new ArrayList();
                int i = Array.IndexOf(menu.Children, this);

                if (cmdInfo.ArrayInfo != null)
                {
                    foreach (CommandInfo info in cmdInfo.ArrayInfo)
                    {
                        Gtk.MenuItem item;
                        if (info.IsArraySeparator)
                        {
                            item = new Gtk.SeparatorMenuItem();
                            item.Show();
                        }
                        else
                        {
                            item = CommandEntry.CreateMenuItem(commandManager, commandId, false);
                            ICommandMenuItem mi = (ICommandMenuItem)item;
                            mi.SetUpdateInfo(info, initialTarget);
                        }
                        menu.Insert(item, ++i);
                        itemArray.Add(item);
                    }
                }
            }
            else
            {
                Gtk.Widget child = Child;
                if (child == null)
                {
                    return;
                }

                Gtk.Label accel_label = null;
                Gtk.Label label       = null;

                if (!(child is Gtk.HBox))
                {
                    child       = new Gtk.HBox(false, 0);
                    accel_label = new Gtk.Label("");
                    accel_label.UseUnderline = false;
                    accel_label.Xalign       = 1.0f;
                    accel_label.Show();

                    label = new Gtk.Label("");
                    label.UseUnderline = true;
                    label.Xalign       = 0.0f;
                    label.Show();

                    ((Gtk.Box)child).PackStart(label);
                    ((Gtk.Box)child).PackStart(accel_label);
                    child.Show();

                    this.Remove(Child);
                    this.Add(child);
                }
                else
                {
                    accel_label = (Gtk.Label)((Gtk.Box)child).Children[1];
                    label       = (Gtk.Label)((Gtk.Box)child).Children[0];
                }

                if (cmdInfo.AccelKey != null)
                {
                    accel_label.Text = "    " + KeyBindingManager.BindingToDisplayLabel(cmdInfo.AccelKey, true);
                }
                else
                {
                    accel_label.Text = String.Empty;
                }

                if (cmdInfo.UseMarkup)
                {
                    label.Markup    = overrideLabel ?? cmdInfo.Text;
                    label.UseMarkup = true;
                }
                else
                {
                    label.Text      = overrideLabel ?? cmdInfo.Text;
                    label.UseMarkup = false;
                }

                if (!string.IsNullOrEmpty(cmdInfo.Description) && label.TooltipText != cmdInfo.Description)
                {
                    label.TooltipText = cmdInfo.Description;
                }
                label.UseUnderline = true;

                this.Sensitive = cmdInfo.Enabled;
                this.Visible   = cmdInfo.Visible && (disabledVisible || cmdInfo.Enabled);

                if (!cmdInfo.Icon.IsNull && cmdInfo.Icon != lastIcon)
                {
                    Image    = new ImageView(cmdInfo.Icon, Gtk.IconSize.Menu);
                    lastIcon = cmdInfo.Icon;
                }

                if (cmdInfo is CommandInfoSet)
                {
                    CommandInfoSet ciset = (CommandInfoSet)cmdInfo;
                    Gtk.Menu       smenu = new Gtk.Menu();
                    Submenu = smenu;
                    foreach (CommandInfo info in ciset.CommandInfos)
                    {
                        Gtk.MenuItem item;
                        if (info.IsArraySeparator)
                        {
                            item = new Gtk.SeparatorMenuItem();
                            item.Show();
                        }
                        else
                        {
                            item = CommandEntry.CreateMenuItem(commandManager, commandId, false);
                            ICommandMenuItem mi = (ICommandMenuItem)item;
                            mi.SetUpdateInfo(info, initialTarget);
                        }
                        smenu.Add(item);
                    }
                }
            }
        }
        void Update(CommandInfo cmdInfo)
        {
            lastCmdInfo = cmdInfo;

            Gtk.Widget child = Child;
            if (child == null)
            {
                return;
            }

            updating = true;

            Gtk.Label accel_label = null;
            Gtk.Label label       = null;

            if (!(child is Gtk.HBox))
            {
                child       = new Gtk.HBox(false, 0);
                accel_label = new Gtk.Label("");
                accel_label.UseUnderline = false;
                accel_label.Xalign       = 1.0f;
                accel_label.Show();

                label = new Gtk.Label("");
                label.UseUnderline = true;
                label.Xalign       = 0.0f;
                label.Show();

                ((Gtk.Box)child).PackStart(label);
                ((Gtk.Box)child).PackStart(accel_label);
                child.Show();

                this.Remove(Child);
                this.Add(child);
            }
            else
            {
                accel_label = (Gtk.Label)((Gtk.Box)child).Children[1];
                label       = (Gtk.Label)((Gtk.Box)child).Children[0];
            }

            if (cmdInfo.AccelKey != null)
            {
                accel_label.Text = "    " + KeyBindingManager.BindingToDisplayLabel(cmdInfo.AccelKey, true);
            }
            else
            {
                accel_label.Text = String.Empty;
            }

            if (cmdInfo.UseMarkup)
            {
                label.Markup    = overrideLabel ?? cmdInfo.Text;
                label.UseMarkup = true;
            }
            else
            {
                label.Text      = overrideLabel ?? cmdInfo.Text;
                label.UseMarkup = false;
            }

            label.UseUnderline = true;

            Sensitive    = cmdInfo.Enabled;
            Visible      = cmdInfo.Visible && (disabledVisible || cmdInfo.Enabled);
            Active       = cmdInfo.Checked;
            Inconsistent = cmdInfo.CheckedInconsistent;

            updating = false;
        }
Exemplo n.º 6
0
		public CommandManager (Gtk.Window root)
		{
			rootWidget = root;
			bindings = new KeyBindingManager ();
			ActionCommand c = new ActionCommand (CommandSystemCommands.ToolbarList, "Toolbar List", null, null, ActionType.Check);
			c.CommandArray = true;
			RegisterCommand (c);

			#if MAC
			AppKit.NSEvent.AddLocalMonitorForEventsMatchingMask (AppKit.NSEventMask.KeyDown, OnNSEventKeyPress);
			#endif
		}
Exemplo n.º 7
0
        internal bool LoadScheme(XmlTextReader reader, string id)
        {
            bool   foundSchemes = false;
            bool   foundScheme  = false;
            string command;
            string binding;

            bindings.Clear();

            while (reader.Read())
            {
                if (reader.IsStartElement("schemes") || reader.IsStartElement("scheme"))
                {
                    foundSchemes = true;
                    break;
                }
            }

            if (!foundSchemes || reader.GetAttribute("version") != version)
            {
                return(false);
            }

            if (reader.IsStartElement("schemes"))
            {
                while (reader.Read())
                {
                    if (reader.IsStartElement("scheme") && reader.GetAttribute("name") == id)
                    {
                        foundScheme = true;
                        break;
                    }
                }
                if (!foundScheme)
                {
                    return(false);
                }
            }

            while (reader.Read())
            {
                if (reader.IsStartElement())
                {
                    switch (reader.LocalName)
                    {
                    case "scheme":
                        // this is the beginning of the next scheme
                        return(true);

                    case "binding":
                        command = reader.GetAttribute(commandAttr);
                        binding = reader.GetAttribute(shortcutAttr);

                        if (!string.IsNullOrEmpty(command))
                        {
                            bindings.Add(command, KeyBindingManager.FixChordSeparators(binding));
                        }

                        break;
                    }
                }
            }

            return(true);
        }