Ejemplo n.º 1
0
        private void LoadQatItemIfMatchesControl(
            QatItemCollection previouslyMatchedItems,
            QatItemCollection matchedItems,
            int matchLevel,
            int controlIndex,
            object control,
            ref int remainingItemsCount)
        {
            for (int qatIndex = 0; qatIndex < previouslyMatchedItems.Count; qatIndex++)
            {
                QatItem qatItem = previouslyMatchedItems[qatIndex];

                if (qatItem.ControlIndices[matchLevel] == controlIndex)
                {
                    if (qatItem.ControlIndices.Count == matchLevel + 1)
                    {
                        qatItem.Instance = control;
                        remainingItemsCount--;
                    }
                    else if (qatItem.ControlIndices.Count == matchLevel + 2 && qatItem.ControlIndices[matchLevel + 1] == -1)
                    {
                        qatItem.IsSplitHeader = true;
                        Control element = control as Control;

                        if (element != null)
                        {
                            object splitControl = element.Template.FindName("PART_HeaderButton", element);

                            if (splitControl == null)
                            {
                                element.ApplyTemplate();
                                splitControl = element.Template.FindName("PART_HeaderButton", element);
                            }

                            if (splitControl != null)
                            {
                                qatItem.Instance = splitControl;
                            }
                        }

                        remainingItemsCount--;
                    }
                    else
                    {
                        matchedItems.Add(qatItem);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void SaveQatItems(RibbonQuickAccessToolBar qat)
        {
            if (qat != null)
            {
                QatItemCollection qatItems       = new QatItemCollection();
                QatItemCollection remainingItems = new QatItemCollection();

                if (qat.Items.Count > 0)
                {
                    for (int qatIndex = 0; qatIndex < qat.Items.Count; qatIndex++)
                    {
                        object instance      = qat.Items[qatIndex];
                        bool   isSplitHeader = false;

                        if (instance is ICommandSource)
                        {
                            ICommandSource element = (ICommandSource)instance;

                            if (element.Command != null)
                            {
                                isSplitHeader = instance is RibbonSplitMenuItem || instance is RibbonSplitButton;
                                instance      = element.Command;
                            }
                        }

                        QatItem qatItem = new QatItem(instance, isSplitHeader);
                        qatItems.Add(qatItem);
                        remainingItems.Add(qatItem);
                    }

                    for (int tabIndex = 0; tabIndex < _ribbon.Items.Count && remainingItems.Count > 0; tabIndex++)
                    {
                        RibbonTab tab = _ribbon.Items[tabIndex] as RibbonTab;
                        SaveQatItemsAmongChildren(remainingItems, tab, tabIndex);
                    }
                }

                if (!Directory.Exists(Static.LocalAppData))
                {
                    Directory.CreateDirectory(Static.LocalAppData);
                }

                XmlWriter xmlWriter = XmlWriter.Create(_qatFileName);
                XamlWriter.Save(qatItems, xmlWriter);
                xmlWriter.Close();
            }
        }
Ejemplo n.º 3
0
        private void SaveQatItemsAmongChildren(QatItemCollection remainingItems, object control, int controlIndex)
        {
            if (control == null)
            {
                return;
            }

            for (int qatIndex = 0; qatIndex < remainingItems.Count; qatIndex++)
            {
                QatItem qatItem = remainingItems[qatIndex];
                qatItem.ControlIndices.Add(controlIndex);
            }

            SaveQatItemsAmongChildrenInner(remainingItems, control);

            for (int qatIndex = 0; qatIndex < remainingItems.Count; qatIndex++)
            {
                QatItem qatItem = remainingItems[qatIndex];
                int     tail    = qatItem.ControlIndices.Count - 1;
                qatItem.ControlIndices.RemoveAt(tail);
            }
        }
Ejemplo n.º 4
0
        private bool SaveQatItemsIfMatchesControl(QatItemCollection remainingItems, object control)
        {
            bool           matched = false;
            ICommandSource element = control as ICommandSource;

            if (element != null)
            {
                object data = element.Command;

                if (data != null)
                {
                    for (int qatIndex = 0; qatIndex < remainingItems.Count; qatIndex++)
                    {
                        QatItem qatItem = remainingItems[qatIndex];

                        if (qatItem.Instance == data)
                        {
                            if (qatItem.IsSplitHeader)
                            {
                                // This is the case of the Header of a SplitButton
                                // or a SplitMenuItem added to the QAT. Note -1 is
                                // the sentinel being used to indicate this case.

                                qatItem.ControlIndices.Add(-1);
                            }

                            remainingItems.Remove(qatItem);
                            qatIndex--;
                            matched = true;
                        }
                    }
                }
            }

            return(matched);
        }
Ejemplo n.º 5
0
        private void LoadQatItems(RibbonQuickAccessToolBar qat)
        {
            Dispatcher.CurrentDispatcher.BeginInvoke(() =>
            {
                try
                {
                    if (qat != null)
                    {
                        if (File.Exists(_qatFileName))
                        {
                            XmlReader xmlReader        = XmlReader.Create(_qatFileName);
                            QatItemCollection qatItems = (QatItemCollection)XamlReader.Load(xmlReader);
                            xmlReader.Close();

                            if (qatItems != null)
                            {
                                int remainingItemsCount        = qatItems.Count;
                                QatItemCollection matchedItems = new QatItemCollection();

                                if (qatItems.Count > 0)
                                {
                                    for (int tabIndex = 0; tabIndex < _ribbon.Items.Count && remainingItemsCount > 0; tabIndex++)
                                    {
                                        matchedItems.Clear();

                                        for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                                        {
                                            QatItem qatItem = qatItems[qatIndex];

                                            if (qatItem.ControlIndices[0] == tabIndex)
                                            {
                                                matchedItems.Add(qatItem);
                                            }
                                        }

                                        RibbonTab tab = _ribbon.Items[tabIndex] as RibbonTab;

                                        if (tab != null)
                                        {
                                            LoadQatItemsAmongChildren(matchedItems, 0, tabIndex, tab, ref remainingItemsCount);
                                        }
                                    }

                                    for (int qatIndex = 0; qatIndex < qatItems.Count; qatIndex++)
                                    {
                                        QatItem qatItem = qatItems[qatIndex];
                                        Control control = qatItem.Instance as Control;

                                        if (control != null)
                                        {
                                            if (RibbonCommands.AddToQuickAccessToolBarCommand.CanExecute(null, control))
                                            {
                                                RibbonCommands.AddToQuickAccessToolBarCommand.Execute(null, control);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                catch { }
            });
        }