Пример #1
0
        public override void OnLoad(EventArgs args)
        {
            // Defer creating menu items until plugins have loaded
            LibraryWidget.CreateMenuActions(libraryView, menuActions, libraryContext, mainViewWidget, theme, allowPrint: true);

            navBar.OverflowButton.Name = "Print Library Overflow Menu";
            navBar.ExtendOverflowMenu  = (popupMenu) =>
            {
                // Create menu items in the DropList for each element in this.menuActions
                foreach (var menuAction in menuActions)
                {
                    if (menuAction is MenuSeparator)
                    {
                        popupMenu.CreateSeparator();
                    }
                    else
                    {
                        var menuItem = popupMenu.CreateMenuItem(menuAction.Title, menuAction.Icon);
                        menuItem.Name    = $"{menuAction.Title} Menu Item";
                        menuItem.Enabled = menuAction.Action != null && menuAction.IsEnabled(libraryView.SelectedItems, libraryView);
                        menuItem.Click  += (s, e) =>
                        {
                            menuAction.Action?.Invoke(libraryView.SelectedItems.Select(i => i.Model), libraryView);
                        };
                    }
                }
            };

            base.OnLoad(args);
        }
Пример #2
0
        public PrintLibraryWidget(MainViewWidget mainViewWidget, PartWorkspace workspace, ThemeConfig theme, Color libraryBackground, PopupMenuButton popupMenuButton)
        {
            this.theme          = theme;
            this.mainViewWidget = mainViewWidget;
            this.Padding        = 0;
            this.AnchorAll();

            var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);

            libraryContext = workspace.LibraryView;

            libraryView = new LibraryListView(libraryContext, theme)
            {
                Name = "LibraryView",
                // Drop containers if ShowContainers != 1
                ContainerFilter = (container) => this.ShowContainers,
                BackgroundColor = libraryBackground,
                Border          = new BorderDouble(top: 1)
            };

            navBar = new OverflowBar(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
            };
            allControls.AddChild(navBar);
            theme.ApplyBottomBorder(navBar);

            var toolbar = new OverflowBar(StaticData.Instance.LoadIcon("fa-sort_16.png", 32, 32, theme.InvertIcons), theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Name    = "Folders Toolbar",
            };

            toolbar.OverflowButton.ToolTipText = "Sorting".Localize();

            theme.ApplyBottomBorder(toolbar, shadedBorder: true);

            toolbar.OverflowButton.Name = "Print Library View Options";
            toolbar.Padding             = theme.ToolbarPadding;

            toolbar.ExtendOverflowMenu = (popupMenu) => LibraryWidget.CreateSortingMenu(popupMenu, libraryView);

            allControls.AddChild(toolbar);

            toolbar.AddChild(new HorizontalSpacer());

            toolbar.AddChild(LibraryWidget.CreateViewOptionsMenuButton(theme,
                                                                       libraryView,
                                                                       (show) => ShowContainers = show,
                                                                       () => ShowContainers));

            breadCrumbWidget = new FolderBreadCrumbWidget(workspace.LibraryView, theme);
            navBar.AddChild(breadCrumbWidget);

            var searchPanel = new TextEditWithInlineCancel(theme)
            {
                Visible = false,
                Margin  = new BorderDouble(10, 0, 5, 0),
            };

            searchPanel.TextEditWidget.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                this.PerformSearch();
            };
            searchPanel.ResetButton.Click += (s, e) =>
            {
                breadCrumbWidget.Visible = true;
                searchPanel.Visible      = false;

                searchPanel.TextEditWidget.Text = "";

                this.ClearSearch();
            };

            // Store a reference to the input field
            this.searchInput = searchPanel.TextEditWidget;

            navBar.AddChild(searchPanel);

            searchButton         = theme.CreateSearchButton();
            searchButton.Enabled = false;
            searchButton.Name    = "Search Library Button";
            searchButton.Click  += (s, e) =>
            {
                if (searchPanel.Visible)
                {
                    PerformSearch();
                }
                else
                {
                    searchContainer = libraryView.ActiveContainer;

                    breadCrumbWidget.Visible = false;
                    searchPanel.Visible      = true;
                    searchInput.Focus();
                }
            };
            navBar.AddChild(searchButton);

            allControls.AddChild(libraryView);

            buttonPanel = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                Padding = theme.ToolbarPadding,
            };
            AddLibraryButtonElements();
            allControls.AddChild(buttonPanel);

            allControls.AnchorAll();

            this.AddChild(allControls);

            // Register listeners
            libraryView.SelectedItems.CollectionChanged += SelectedItems_CollectionChanged;
            libraryContext.ContainerChanged             += Library_ContainerChanged;
        }