Example #1
0
        public LibraryWidget(MainViewWidget mainViewWidget, ThemeConfig theme)
        {
            this.theme          = theme;
            this.mainViewWidget = mainViewWidget;
            this.Padding        = 0;
            this.AnchorAll();

            var allControls = new FlowLayoutWidget(FlowDirection.TopToBottom);

            libraryContext = ApplicationController.Instance.LibraryTabContext;

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

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

            breadCrumbWidget = new FolderBreadCrumbWidget(libraryContext, 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 = libraryContext.ActiveContainer;

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

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

            navBar.AddChild(CreateSortingMenuButton(theme, libraryView));

            allControls.AddChild(navBar);

            var horizontalSplitter = new Splitter()
            {
                SplitterDistance   = UserSettings.Instance.LibraryViewWidth,
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };

            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = horizontalSplitter.SplitterDistance;
            };

            allControls.AddChild(horizontalSplitter);

            libraryTreeView = new TreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Margin  = 5
            };
            libraryTreeView.AfterSelect += async(s, e) =>
            {
                if (libraryTreeView.SelectedNode is ContainerTreeNode treeNode)
                {
                    if (!treeNode.ContainerAcquired)
                    {
                        await this.EnsureExpanded(treeNode.Tag as ILibraryItem, treeNode);
                    }

                    if (treeNode.ContainerAcquired)
                    {
                        libraryContext.ActiveContainer = treeNode.Container;
                    }
                }
            };
            horizontalSplitter.Panel1.AddChild(libraryTreeView);

            var rootColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Margin  = new BorderDouble(left: 10)
            };

            libraryTreeView.AddChild(rootColumn);

            if (AppContext.IsLoading)
            {
                ApplicationController.StartupActions.Add(new ApplicationController.StartupAction()
                {
                    Title    = "Initializing Library".Localize(),
                    Priority = 0,
                    Action   = () =>
                    {
                        this.LoadRootLibraryNodes(rootColumn);
                    }
                });
            }
            else
            {
                this.LoadRootLibraryNodes(rootColumn);
            }

            horizontalSplitter.Panel2.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;
        }
Example #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;
        }
Example #3
0
        public SearchableTreePanel(ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.theme      = theme;
            this.TreeLoaded = false;

            var searchIcon = StaticData.Instance.LoadIcon("icon_search_24x24.png", 16, 16).SetToColor(theme.TextColor).AjustAlpha(0.3);

            searchBox = new TextEditWithInlineCancel(theme)
            {
                Name    = "Search",
                HAnchor = HAnchor.Stretch,
                Margin  = new BorderDouble(6),
            };

            searchBox.ResetButton.Visible = false;

            var searchInput = searchBox.TextEditWidget;

            searchInput.BeforeDraw += (s, e) =>
            {
                if (!searchBox.ResetButton.Visible)
                {
                    e.Graphics2D.Render(
                        searchIcon,
                        searchInput.Width - searchIcon.Width - 5,
                        searchInput.LocalBounds.Bottom + searchInput.Height / 2 - searchIcon.Height / 2);
                }
            };

            searchBox.ResetButton.Click += (s, e) =>
            {
                this.ClearSearch();
            };

            searchBox.KeyDown += (s, e) =>
            {
                if (e.KeyCode == Keys.Escape)
                {
                    this.ClearSearch();
                    e.Handled = true;
                }
            };

            searchBox.TextEditWidget.ActualTextEditWidget.TextChanged += (s, e) =>
            {
                if (string.IsNullOrWhiteSpace(searchBox.Text))
                {
                    this.ClearSearch();
                }
                else
                {
                    this.PerformSearch(searchBox.Text);
                }
            };

            horizontalSplitter = new Splitter()
            {
                SplitterDistance   = Math.Max(UserSettings.Instance.LibraryViewWidth, 20),
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground
            };
            horizontalSplitter.AnchorAll();

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = Math.Max(horizontalSplitter.SplitterDistance, 20);
            };

            this.AddChild(horizontalSplitter);

            var leftPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            leftPanel.AddChild(searchBox);

            treeView = new TreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };
            leftPanel.AddChild(treeView);

            horizontalSplitter.Panel1.AddChild(leftPanel);

            contentPanel = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit,
                Margin  = new BorderDouble(left: 2)
            };
            treeView.AddChild(contentPanel);
        }