Exemplo n.º 1
0
        private static void OutputToolBarNodes(IOutputService outputService, ToolBarItemViewModelCollection toolBarItems, int level = 0)
        {
            if (toolBarItems == null || toolBarItems.Count == 0)
            {
                return;
            }

            var indent = Indent(level);

            foreach (var toolBarItem in toolBarItems)
            {
                outputService.WriteLine(Invariant($"{indent}\"{toolBarItem.CommandItem.Name}\""), NodesView);
            }
        }
Exemplo n.º 2
0
        private static void CoerceVisibility(ToolBarItemViewModelCollection toolBarItems)
        {
            if (toolBarItems == null || toolBarItems.Count == 0)
            {
                return;
            }

            // ----- Hide unnecessary separators.
            bool hasVisiblePredecessor = false;

            for (int i = 0; i < toolBarItems.Count; i++)
            {
                var toolBarItem = toolBarItems[i];

                var toolBarSeparator = toolBarItem as ToolBarSeparatorViewModel;
                if (toolBarSeparator == null)
                {
                    // Toolbar item is not a separator.

                    if (toolBarItem.CommandItem.IsVisible)
                    {
                        hasVisiblePredecessor = true;
                    }

                    continue;
                }

                // Toolbar item is a separator.
                // A separator is only visible if there are visible items before and after.
                if (!hasVisiblePredecessor)
                {
                    toolBarSeparator.IsVisible = false;
                    continue;
                }

                bool hasVisibleSuccessor = false;
                for (int j = i + 1; j < toolBarItems.Count; j++)
                {
                    var successor = toolBarItems[j];

                    // Skip separators.
                    if (successor.CommandItem is CommandSeparator)
                    {
                        continue;
                    }

                    if (!successor.CommandItem.IsVisible)
                    {
                        continue;
                    }

                    hasVisibleSuccessor = true;
                    break;
                }

                if (!hasVisibleSuccessor)
                {
                    toolBarSeparator.IsVisible = false;
                    continue;
                }

                toolBarSeparator.IsVisible = true;
                hasVisiblePredecessor      = false;
            }
        }
Exemplo n.º 3
0
        private static void CreateToolBarItems(MergeableNodeCollection <ICommandItem> nodes, ToolBarItemViewModelCollection toolBarItems)
        {
            foreach (var node in nodes)
            {
                if (node?.Content == null)
                {
                    continue;
                }

                var toolBarItem = node.Content.CreateToolBarItem();
                toolBarItems.Add(toolBarItem);
            }
        }
Exemplo n.º 4
0
        private static void OutputToolBarNodes(IOutputService outputService, ToolBarItemViewModelCollection toolBarItems, int level = 0)
        {
            if (toolBarItems == null || toolBarItems.Count == 0)
                return;

            var indent = Indent(level);
            foreach (var toolBarItem in toolBarItems)
            {
                outputService.WriteLine(Invariant($"{indent}\"{toolBarItem.CommandItem.Name}\""), NodesView);
            }
        }
Exemplo n.º 5
0
        private static void CreateToolBarItems(MergeableNodeCollection<ICommandItem> nodes, ToolBarItemViewModelCollection toolBarItems)
        {
            foreach (var node in nodes)
            {
                if (node?.Content == null)
                    continue;

                var toolBarItem = node.Content.CreateToolBarItem();
                toolBarItems.Add(toolBarItem);
            }
        }
Exemplo n.º 6
0
        private static void CoerceVisibility(ToolBarItemViewModelCollection toolBarItems)
        {
            if (toolBarItems == null || toolBarItems.Count == 0)
                return;

            // ----- Hide unnecessary separators.
            bool hasVisiblePredecessor = false;
            for (int i = 0; i < toolBarItems.Count; i++)
            {
                var toolBarItem = toolBarItems[i];

                var toolBarSeparator = toolBarItem as ToolBarSeparatorViewModel;
                if (toolBarSeparator == null)
                {
                    // Toolbar item is not a separator.

                    if (toolBarItem.CommandItem.IsVisible)
                        hasVisiblePredecessor = true;

                    continue;
                }

                // Toolbar item is a separator.
                // A separator is only visible if there are visible items before and after.
                if (!hasVisiblePredecessor)
                {
                    toolBarSeparator.IsVisible = false;
                    continue;
                }

                bool hasVisibleSuccessor = false;
                for (int j = i + 1; j < toolBarItems.Count; j++)
                {
                    var successor = toolBarItems[j];

                    // Skip separators.
                    if (successor.CommandItem is CommandSeparator)
                        continue;

                    if (!successor.CommandItem.IsVisible)
                        continue;

                    hasVisibleSuccessor = true;
                    break;
                }

                if (!hasVisibleSuccessor)
                {
                    toolBarSeparator.IsVisible = false;
                    continue;
                }

                toolBarSeparator.IsVisible = true;
                hasVisiblePredecessor = false;
            }
        }