Пример #1
0
        public void OnTeamCollectionBookStatusChange_TeamCollection_GivenCheckedOutByOther_WhenCheckedOutByNone_RemovesIcon()
        {
            // Setup //
            var collectionFolder = new TemporaryFolder("LibraryListViewTests");

            Book.BookCollectionTests.AddBook(collectionFolder, "book1");

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder), new BookSelection(), new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            var primaryCollectionFlow = new FlowLayoutPanel();
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);

            obj.SetField("_primaryCollectionFlow", primaryCollectionFlow);
            _view.LoadPrimaryCollectionButtons();
            _view.OnTeamCollectionBookStatusChange(new BookStatusChangeEventArgs("book1", CheckedOutBy.Other));
            var button = primaryCollectionFlow.Controls.OfType <Button>().First();

            Assert.AreEqual(1, button.Controls.OfType <Label>().Count(), "Test was not set up properly. Wrong number of labels.");

            // System Under Test //
            _view.OnTeamCollectionBookStatusChange(new BookStatusChangeEventArgs("book1", CheckedOutBy.None));

            // Verification //
            var labelOfButton = button.Controls.OfType <Label>().FirstOrDefault();

            Assert.IsNull(labelOfButton);
        }
Пример #2
0
 public static void CreateMenuActions(LibraryListView libraryView, List <LibraryAction> menuActions, ILibraryContext libraryContext, MainViewWidget mainViewWidget, ThemeConfig theme, bool allowPrint)
 {
     menuActions.Add(new LibraryAction(ActionScope.ListView)
     {
         Icon        = StaticData.Instance.LoadIcon("cube.png", 16, 16, ApplicationController.Instance.MenuTheme.InvertIcons),
         Title       = "Add".Localize(),
         ToolTipText = "Add an.stl, .obj, .amf, .gcode or.zip file to the Library".Localize(),
         Action      = (selectedLibraryItems, listView) =>
         {
             UiThread.RunOnIdle(() =>
             {
                 AggContext.FileDialogs.OpenFileDialog(
                     new OpenFileDialogParams(ApplicationSettings.OpenPrintableFileParams, multiSelect: true),
                     (openParams) =>
                 {
                     if (openParams.FileNames != null)
                     {
                         if (libraryView.ActiveContainer is ILibraryWritableContainer writableContainer &&
                             openParams.FileNames.Length > 0)
                         {
                             writableContainer.Add(openParams.FileNames.Select(f => new FileSystemFileItem(f)));
                         }
                     }
                 });
             });
Пример #3
0
        public LibraryBrowserPage(Action <string, ILibraryWritableContainer> acceptCallback, string acceptButtonText)
        {
            FolderBreadCrumbWidget breadCrumbWidget = null;

            this.WindowSize = new Vector2(480, 500);

            contentRow.Padding = 0;

            // Create a new library context for the SaveAs view
            libraryNavContext = new LibraryConfig()
            {
                ActiveContainer = ApplicationController.Instance.Library.RootLibaryContainer
            };
            libraryNavContext.ContainerChanged += (s, e) =>
            {
                acceptButton.Enabled = libraryNavContext.ActiveContainer is ILibraryWritableContainer;
                breadCrumbWidget.SetContainer(libraryNavContext.ActiveContainer);
            };

            librarySelectorWidget = new LibraryListView(libraryNavContext, new IconListView(theme, 75), theme)
            {
                BackgroundColor = theme.MinimalShade,
                ShowItems       = true,
                ContainerFilter = (container) => !container.IsReadOnly,
            };

            // put in the bread crumb widget
            breadCrumbWidget = new FolderBreadCrumbWidget(libraryNavContext, theme);
            breadCrumbWidget.BackgroundColor = theme.MinimalShade;
            contentRow.AddChild(breadCrumbWidget);
            contentRow.BackgroundColor = Color.Transparent;

            contentRow.AddChild(librarySelectorWidget);

            acceptButton      = theme.CreateDialogButton(acceptButtonText);
            acceptButton.Name = "Accept Button";
            // Disable the save as button until the user actually selects a provider
            acceptButton.Enabled = false;
            acceptButton.Cursor  = Cursors.Hand;
            acceptButton.Click  += (s, e) =>
            {
                if (librarySelectorWidget.ActiveContainer is ILibraryWritableContainer writableContainer)
                {
                    acceptCallback(
                        itemNameWidget?.ActualTextEditWidget.Text ?? "none",
                        writableContainer);
                }

                this.DialogWindow.CloseOnIdle();
            };

            this.AddPageAction(acceptButton);
        }
Пример #4
0
        public static PopupMenu CreateSortingMenu(PopupMenu popupMenu, LibraryListView libraryView)
        {
            var siblingList = new List <GuiWidget>();

            popupMenu.CreateBoolMenuItem(
                "Date Created".Localize(),
                () => libraryView.ActiveSort.HasFlag(SortKey.CreatedDate),
                (v) => libraryView.ActiveSort = SortKey.CreatedDate,
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            popupMenu.CreateBoolMenuItem(
                "Date Modified".Localize(),
                () => libraryView.ActiveSort.HasFlag(SortKey.ModifiedDate),
                (v) => libraryView.ActiveSort = SortKey.ModifiedDate,
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            popupMenu.CreateBoolMenuItem(
                "Name".Localize(),
                () => libraryView.ActiveSort.HasFlag(SortKey.Name),
                (v) => libraryView.ActiveSort = SortKey.Name,
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            popupMenu.CreateSeparator();

            siblingList = new List <GuiWidget>();

            popupMenu.CreateBoolMenuItem(
                "Ascending".Localize(),
                () => libraryView.Ascending,
                (v) => libraryView.Ascending = true,
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            popupMenu.CreateBoolMenuItem(
                "Descending".Localize(),
                () => !libraryView.Ascending,
                (v) => libraryView.Ascending = false,
                useRadioStyle: true,
                siblingRadioButtonList: siblingList);

            return(popupMenu);
        }
Пример #5
0
        public static GuiWidget CreateSortingMenuButton(ThemeConfig theme, LibraryListView libraryView)
        {
            var viewOptionsButton = new PopupMenuButton(
                new ImageWidget(StaticData.Instance.LoadIcon("fa-sort_16.png", 32, 32, theme.InvertIcons)), theme)
            {
                AlignToRightEdge = true,
                Name             = "Print Library View Options",
                ToolTipText      = "Sorting".Localize()
            };

            viewOptionsButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(theme);
                CreateSortingMenu(popupMenu, libraryView);
                return(popupMenu);
            };

            return(viewOptionsButton);
        }
Пример #6
0
        public void LoadPrimaryCollectionButtons_BookTitleHasAmpersand_ButtonUsesNonEscapedForm()
        {
            // Setup //
            var collectionFolder = new TemporaryFolder("LibraryListViewTests");

            Book.BookCollectionTests.AddBook(collectionFolder, "A&B Book");

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder), new BookSelection(), new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            // System Under Test //
            _view.LoadPrimaryCollectionButtons();

            // Verification //
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);
            var primaryCollectionFlow = (FlowLayoutPanel)(obj.GetFieldOrProperty("_primaryCollectionFlow"));
            var firstBookButton       = primaryCollectionFlow.Controls.OfType <Button>().First();

            Assert.AreEqual("A&B Book", firstBookButton.Text, "Text");                  // Not escaped because the button has UseMnemonic = false
            Assert.AreEqual(false, firstBookButton.UseMnemonic, "UseMnemonic");
        }
Пример #7
0
        /// <summary>
        /// Invoked when this page is about to be displayed in a Frame.
        /// </summary>
        /// <param name="e">Event data that describes how this page was reached.
        /// This parameter is typically used to configure the page.</param>
        async protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            //set which items are visible

            BottomBar.Visibility           = Visibility.Collapsed;
            RecentReadsListView.Visibility = Visibility.Collapsed;
            LibraryListView.Visibility     = Visibility.Visible;
            //set which buttons are currently chosen
            RecentReadsBorder.BorderThickness = new Thickness(0);
            LibraryBorder.BorderThickness     = new Thickness(3);
            _isRecentReads = false;
            //open data
            await RetrieveLibrary();

            LibrarySource.SortByBookNameAscending();
            LibraryListView.Focus(FocusState.Programmatic);
            //make no item currently selected
            LibraryListView.SelectedItem = null;
            //set a MainPage for other pages to access this
            Current = this;
        }
Пример #8
0
        public void LoadPrimaryCollectionButtons_CollectionNameHasAmpersand_IsEscaped()
        {
            // Setup //
            var collectionFolder          = new TemporaryFolder("LibraryListViewTests");
            var collectionSettings        = new CollectionSettings();
            var privateCollectionSettings = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(collectionSettings);

            privateCollectionSettings.SetFieldOrProperty("CollectionName", "A&B");

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder, collectionSettings), new BookSelection(), new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            // System Under Test //
            _view.LoadPrimaryCollectionButtons();

            // Verification //
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);
            var primaryCollectionFlow = (FlowLayoutPanel)(obj.GetFieldOrProperty("_primaryCollectionFlow"));
            var listHeader            = primaryCollectionFlow.Controls.OfType <ListHeader>().First();

            Assert.AreEqual("A&&B", listHeader.Label.Text);
        }
Пример #9
0
        public void LoadOneCollection_NonEditableCollection_BookNotSelected()
        {
            // Setup //
            var collectionFolder = new TemporaryFolder("LibraryListViewTests");
            var collection       = new BookCollection(collectionFolder.Path, BookCollection.CollectionType.SourceCollection, new BookSelection());

            BloomTests.Book.BookCollectionTests.AddBook(collectionFolder, "book1");

            BookSelection bookSelection = new BookSelection();

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder), bookSelection, new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            Bloom.Properties.Settings.Default.CurrentBookPath = Path.Combine(collectionFolder.Path, "book1");

            // System Under Test //
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);

            obj.Invoke("LoadOneCollection", collection, new System.Windows.Forms.FlowLayoutPanel());

            // Verification //
            Assert.IsNull(bookSelection.CurrentSelection);
        }
Пример #10
0
        public void OnTeamCollectionBookStatusChange_TeamCollection_CheckedOutBySelf()
        {
            // Setup //
            var collectionFolder = new TemporaryFolder("LibraryListViewTests");

            Book.BookCollectionTests.AddBook(collectionFolder, "book1");

            _view = new LibraryListView(new FakeLibraryModel(collectionFolder), new BookSelection(), new SelectedTabChangedEvent(), new LocalizationChangedEvent(), new BookStatusChangeEvent(), null);

            var primaryCollectionFlow = new FlowLayoutPanel();
            var obj = new Microsoft.VisualStudio.TestTools.UnitTesting.PrivateObject(_view);

            obj.SetField("_primaryCollectionFlow", primaryCollectionFlow);
            _view.LoadPrimaryCollectionButtons();

            // System Under Test //
            _view.OnTeamCollectionBookStatusChange(new BookStatusChangeEventArgs("book1", CheckedOutBy.Self));

            // Verification //
            var button        = primaryCollectionFlow.Controls.OfType <Button>().First();
            var labelOfButton = button.Controls.OfType <Label>().First();

            AssertImageCenterIsColor(labelOfButton.Image, Palette.BloomYellow);
        }
Пример #11
0
        public PrintLibraryWidget(MainViewWidget mainViewWidget, PartWorkspace workspace, ThemeConfig theme, 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) => UserSettings.Instance.ShowContainers,
                BackgroundColor = theme.BackgroundColor,
                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(AggContext.StaticData.LoadIcon("fa-sort_16.png", 32, 32, theme.InvertIcons), theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Name    = "Folders Toolbar"
            };

            theme.ApplyBottomBorder(toolbar, shadedBorder: true);

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

            toolbar.ExtendOverflowMenu = (popupMenu) =>
            {
                var siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "Date Created".Localize(),
                    () => libraryView.ActiveSort == LibraryListView.SortKey.CreatedDate,
                    (v) => libraryView.ActiveSort = LibraryListView.SortKey.CreatedDate,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Date Modified".Localize(),
                    () => libraryView.ActiveSort == LibraryListView.SortKey.ModifiedDate,
                    (v) => libraryView.ActiveSort = LibraryListView.SortKey.ModifiedDate,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Name".Localize(),
                    () => libraryView.ActiveSort == LibraryListView.SortKey.Name,
                    (v) => libraryView.ActiveSort = LibraryListView.SortKey.Name,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateSeparator();

                siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "Ascending".Localize(),
                    () => libraryView.Ascending,
                    (v) => libraryView.Ascending = true,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Descending".Localize(),
                    () => !libraryView.Ascending,
                    (v) => libraryView.Ascending = false,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
            };

            allControls.AddChild(toolbar);

            var showFolders = new ExpandCheckboxButton("Folders".Localize(), theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit | VAnchor.Center,
                Margin  = theme.ButtonSpacing,
                Name    = "Show Folders Toggle",
                Checked = UserSettings.Instance.ShowContainers,
            };

            showFolders.SetIconMargin(theme.ButtonSpacing);
            showFolders.CheckedStateChanged += async(s, e) =>
            {
                UserSettings.Instance.set(UserSettingsKey.ShowContainers, showFolders.Checked ? "1" : "0");
                await libraryView.Reload();
            };
            toolbar.AddChild(showFolders);

            PopupMenuButton viewMenuButton;

            toolbar.AddChild(
                viewMenuButton = new PopupMenuButton(
                    new ImageWidget(AggContext.StaticData.LoadIcon("mi-view-list_10.png", 32, 32, theme.InvertIcons))
            {
                //VAnchor = VAnchor.Center
            },
                    theme)
            {
                AlignToRightEdge = true
            });

            viewMenuButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var listView = this.libraryView;

                var siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "View List".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.RowListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.RowListView;
                    listView.ListContentView = new RowListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#if DEBUG
                popupMenu.CreateBoolMenuItem(
                    "View XSmall Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView18,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView18;
                    listView.ListContentView = new IconListView(theme, 18);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Small Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView70,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView70;
                    listView.ListContentView = new IconListView(theme, 70);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#endif
                popupMenu.CreateBoolMenuItem(
                    "View Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView;
                    listView.ListContentView = new IconListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Large Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView256,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView256;
                    listView.ListContentView = new IconListView(theme, 256);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                return(popupMenu);
            };

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

            var searchPanel = new SearchInputBox(theme)
            {
                Visible = false,
                Margin  = new BorderDouble(10, 0, 5, 0),
            };
            searchPanel.searchInput.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                this.PerformSearch();
            };
            searchPanel.ResetButton.Click += (s, e) =>
            {
                breadCrumbWidget.Visible = true;
                searchPanel.Visible      = false;

                searchPanel.searchInput.Text = "";

                this.ClearSearch();
            };

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

            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;
        }
Пример #12
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;
        }
 internal void SetInitialFocus()
 {
     LibraryListView.Focus();
 }
Пример #14
0
        public PartTabPage(PartWorkspace workspace, ThemeConfig theme, string tabTitle)
            : base(tabTitle)
        {
            this.sceneContext    = workspace.SceneContext;
            this.theme           = theme;
            this.BackgroundColor = theme.BackgroundColor;
            this.Padding         = 0;
            this.printer         = workspace.Printer;
            this.workspace       = workspace;

            bool isPrinterType = this is PrinterTabPage;

            var favoritesBarAndView3DWidget = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            viewControls3D = new ViewControls3D(workspace, theme, sceneContext.Scene.UndoBuffer, isPrinterType, !(this is PrinterTabPage))
            {
                VAnchor = VAnchor.Top | VAnchor.Fit,
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Visible = true,
            };
            theme.ApplyBottomBorder(viewControls3D, shadedBorder: (this is PrinterTabPage));             // Shade border if toolbar is secondary rather than primary

            viewControls3D.ResetView += (sender, e) =>
            {
                if (view3DWidget.Visible)
                {
                    this.view3DWidget.ResetView();
                }
            };
            viewControls3D.ExtendOverflowMenu  = this.GetViewControls3DOverflowMenu;
            viewControls3D.OverflowButton.Name = "View3D Overflow Menu";

            // The 3D model view
            view3DWidget = new View3DWidget(
                printer,
                sceneContext,
                viewControls3D,
                theme,
                this,
                editorType: (isPrinterType) ? InteractionLayer.EditorType.Printer : InteractionLayer.EditorType.Part);

            viewControls3D.SetView3DWidget(view3DWidget);

            this.AddChild(topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            });

            topToBottom.AddChild(leftToRight = new FlowLayoutWidget()
            {
                Name    = "View3DContainerParent",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            });

            view3DContainer = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

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

            toolbarAndView3DWidget.AddChild(viewControls3D);

            var favoritesBarContext = new LibraryConfig()
            {
                ActiveContainer = ApplicationController.Instance.Library.RootLibaryContainer
            };

            var leftBar = new GuiWidget()
            {
                VAnchor     = VAnchor.Stretch,
                HAnchor     = HAnchor.Fit,
                Border      = new BorderDouble(top: 1, right: 1),
                BorderColor = theme.BorderColor20,
            };

            favoritesBarAndView3DWidget.AddChild(leftBar);

            bool expanded = UserSettings.Instance.get(UserSettingsKey.FavoritesBarExpansion) != "0";

            favoritesBar = new LibraryListView(favoritesBarContext, theme)
            {
                Name = "LibraryView",
                // Drop containers
                ContainerFilter  = (container) => false,
                HAnchor          = HAnchor.Absolute,
                VAnchor          = VAnchor.Stretch,
                AllowContextMenu = false,

                // restore to state for favorites bar size
                Width           = expanded ? 55 : 33,
                ListContentView = new IconView(theme, expanded ? 48 : 24)
                {
                    VAnchor = VAnchor.Fit | VAnchor.Top
                },
            };
            leftBar.AddChild(favoritesBar);

            favoritesBar.ScrollArea.VAnchor = VAnchor.Fit;

            var expandedImage  = AggContext.StaticData.LoadIcon("expand.png", 16, 16, theme.InvertIcons);
            var collapsedImage = AggContext.StaticData.LoadIcon("collapse.png", 16, 16, theme.InvertIcons);

            var expandBarButton = new IconButton(expanded ? collapsedImage : expandedImage, theme)
            {
                HAnchor = HAnchor.Center,
                VAnchor = VAnchor.Absolute | VAnchor.Bottom,
                Margin  = new BorderDouble(bottom: 3, top: 3),
                Height  = theme.ButtonHeight - 6,
                Width   = theme.ButtonHeight - 6
            };

            expandBarButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                expanded = !expanded;

                UserSettings.Instance.set(UserSettingsKey.FavoritesBarExpansion, expanded ? "1" : "0");

                favoritesBar.ListContentView = new IconView(theme, expanded ? 48 : 24);
                favoritesBar.Width           = expanded ? 55 : 33;
                expandBarButton.SetIcon(expanded ? collapsedImage : expandedImage);
                expandBarButton.Invalidate();

                favoritesBar.Reload().ConfigureAwait(false);
            });
            leftBar.AddChild(expandBarButton);

            favoritesBar.Margin = new BorderDouble(bottom: expandBarButton.Height + expandBarButton.Margin.Height);

            favoritesBarAndView3DWidget.AddChild(view3DWidget);
            toolbarAndView3DWidget.AddChild(favoritesBarAndView3DWidget);

            view3DContainer.AddChild(toolbarAndView3DWidget);

            leftToRight.AddChild(view3DContainer);

            if (sceneContext.World.RotationMatrix == Matrix4X4.Identity)
            {
                this.view3DWidget.ResetView();
            }

            this.AnchorAll();
        }
Пример #15
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;
        }
Пример #16
0
        public static void CreateMenuActions(LibraryListView libraryView, List <LibraryAction> menuActions, ILibraryContext libraryContext, MainViewWidget mainViewWidget, ThemeConfig theme, bool allowPrint)
        {
            menuActions.Add(new LibraryAction(ActionScope.ListView)
            {
                Icon        = AggContext.StaticData.LoadIcon("cube.png", 16, 16, ApplicationController.Instance.MenuTheme.InvertIcons),
                Title       = "Add".Localize(),
                ToolTipText = "Add an.stl, .obj, .amf, .gcode or.zip file to the Library".Localize(),
                Action      = (selectedLibraryItems, listView) =>
                {
                    UiThread.RunOnIdle(() =>
                    {
                        AggContext.FileDialogs.OpenFileDialog(
                            new OpenFileDialogParams(ApplicationSettings.OpenPrintableFileParams, multiSelect: true),
                            (openParams) =>
                        {
                            if (openParams.FileNames != null)
                            {
                                var writableContainer = libraryView.ActiveContainer as ILibraryWritableContainer;
                                if (writableContainer != null &&
                                    openParams.FileNames.Length > 0)
                                {
                                    writableContainer.Add(openParams.FileNames.Select(f => new FileSystemFileItem(f)));
                                }
                            }
                        });
                    });
                },
                IsEnabled = (s, l) => libraryView.ActiveContainer is ILibraryWritableContainer
            });

            menuActions.Add(new LibraryAction(ActionScope.ListView)
            {
                Title  = "Create Folder".Localize(),
                Icon   = AggContext.StaticData.LoadIcon("fa-folder-new_16.png", 16, 16, ApplicationController.Instance.MenuTheme.InvertIcons),
                Action = (selectedLibraryItems, listView) =>
                {
                    DialogWindow.Show(
                        new InputBoxPage(
                            "Create Folder".Localize(),
                            "Folder Name".Localize(),
                            "",
                            "Enter New Name Here".Localize(),
                            "Create".Localize(),
                            (newName) =>
                    {
                        if (!string.IsNullOrEmpty(newName) &&
                            libraryView.ActiveContainer is ILibraryWritableContainer writableContainer)
                        {
                            writableContainer.Add(new[]
                            {
                                new CreateFolderItem()
                                {
                                    Name = newName
                                }
                            });
                        }
                    }));
                },
                IsEnabled = (s, l) =>
                {
                    return(libraryView.ActiveContainer is ILibraryWritableContainer writableContainer &&
                           writableContainer?.AllowAction(ContainerActions.AddContainers) == true);
                }
            });
Пример #17
0
        public static GuiWidget CreateViewOptionsMenuButton(ThemeConfig theme,
                                                            LibraryListView libraryView,
                                                            Action <bool> showContainers,
                                                            Func <bool> containersShown)
        {
            var viewMenuButton = new PopupMenuButton(
                new ImageWidget(StaticData.Instance.LoadIcon("mi-view-list_10.png", 32, 32, theme.InvertIcons))
            {
                // VAnchor = VAnchor.Center
            },
                theme)
            {
                AlignToRightEdge = true,
                ToolTipText      = "View Settings".Localize()
            };

            viewMenuButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var listView = libraryView;

                var siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "Show Folders".Localize(),
                    () => containersShown(),
                    (isChecked) =>
                {
                    showContainers(isChecked);
                    listView.Reload().ConfigureAwait(false);
                });

                popupMenu.CreateSeparator();

                popupMenu.CreateBoolMenuItem(
                    "View List".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.RowListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.RowListView;
                    listView.ListContentView = new RowListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#if DEBUG
                popupMenu.CreateBoolMenuItem(
                    "View XSmall Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView18,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView18;
                    listView.ListContentView = new IconListView(theme, 18);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Small Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView70,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView70;
                    listView.ListContentView = new IconListView(theme, 70);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#endif
                popupMenu.CreateBoolMenuItem(
                    "View Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView;
                    listView.ListContentView = new IconListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Large Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView256,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView256;
                    listView.ListContentView = new IconListView(theme, 256);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                return(popupMenu);
            };

            return(viewMenuButton);
        }
Пример #18
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) => UserSettings.Instance.ShowContainers,
                BackgroundColor   = theme.BackgroundColor,
                Border            = new BorderDouble(top: 1),
                DoubleClickAction = LibraryListView.DoubleClickActions.PreviewItem
            };

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

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

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

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

                searchPanel.searchInput.Text = "";

                this.ClearSearch();
            };

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

            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);

            PopupMenuButton viewOptionsButton;

            navBar.AddChild(
                viewOptionsButton = new PopupMenuButton(
                    new ImageWidget(AggContext.StaticData.LoadIcon("fa-sort_16.png", 32, 32, theme.InvertIcons))
            {
                //VAnchor = VAnchor.Center
            },
                    theme)
            {
                AlignToRightEdge = true,
                Name             = "Print Library View Options"
            });

            viewOptionsButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "Date Created".Localize(),
                    () => libraryView.ActiveSort.HasFlag(SortKey.CreatedDate),
                    (v) => libraryView.ActiveSort = SortKey.CreatedDate,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Date Modified".Localize(),
                    () => libraryView.ActiveSort.HasFlag(SortKey.ModifiedDate),
                    (v) => libraryView.ActiveSort = SortKey.ModifiedDate,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Name".Localize(),
                    () => libraryView.ActiveSort.HasFlag(SortKey.Name),
                    (v) => libraryView.ActiveSort = SortKey.Name,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateSeparator();

                siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "Ascending".Localize(),
                    () => libraryView.Ascending,
                    (v) => libraryView.Ascending = true,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "Descending".Localize(),
                    () => !libraryView.Ascending,
                    (v) => libraryView.Ascending = false,
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                return(popupMenu);
            };

            PopupMenuButton viewMenuButton;

            navBar.AddChild(
                viewMenuButton = new PopupMenuButton(
                    new ImageWidget(AggContext.StaticData.LoadIcon("mi-view-list_10.png", 32, 32, theme.InvertIcons))
            {
                //VAnchor = VAnchor.Center
            },
                    theme)
            {
                AlignToRightEdge = true
            });

            viewMenuButton.DynamicPopupContent = () =>
            {
                var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                var listView = this.libraryView;

                var siblingList = new List <GuiWidget>();

                popupMenu.CreateBoolMenuItem(
                    "View List".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.RowListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.RowListView;
                    listView.ListContentView = new RowListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#if DEBUG
                popupMenu.CreateBoolMenuItem(
                    "View XSmall Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView18,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView18;
                    listView.ListContentView = new IconListView(theme, 18);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Small Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView70,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView70;
                    listView.ListContentView = new IconListView(theme, 70);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);
#endif
                popupMenu.CreateBoolMenuItem(
                    "View Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView;
                    listView.ListContentView = new IconListView(theme);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                popupMenu.CreateBoolMenuItem(
                    "View Large Icons".Localize(),
                    () => ApplicationController.Instance.ViewState.LibraryViewMode == ListViewModes.IconListView256,
                    (isChecked) =>
                {
                    ApplicationController.Instance.ViewState.LibraryViewMode = ListViewModes.IconListView256;
                    listView.ListContentView = new IconListView(theme, 256);
                    listView.Reload().ConfigureAwait(false);
                },
                    useRadioStyle: true,
                    siblingRadioButtonList: siblingList);

                return(popupMenu);
            };

            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;
        }
Пример #19
0
        public PartTabPage(PartWorkspace workspace, ThemeConfig theme, string tabTitle)
            : base(tabTitle)
        {
            this.sceneContext    = workspace.SceneContext;
            this.theme           = theme;
            this.BackgroundColor = theme.BackgroundColor;
            this.Padding         = 0;
            this.Workspace       = workspace;

            bool isPrinterType = this is PrinterTabPage;

            var favoritesBarAndView3DWidget = new FlowLayoutWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            viewControls3D = new ViewControls3D(workspace, theme, sceneContext.Scene.UndoBuffer, isPrinterType, !(this is PrinterTabPage))
            {
                VAnchor = VAnchor.Top | VAnchor.Fit,
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Visible = true,
            };

            // Shade border if toolbar is secondary rather than primary
            theme.ApplyBottomBorder(viewControls3D, shadedBorder: this is PrinterTabPage);

            viewControls3D.ResetView += (sender, e) =>
            {
                if (view3DWidget.Visible)
                {
                    this.view3DWidget.ResetView();
                }
            };
            viewControls3D.ExtendOverflowMenu  = this.GetViewControls3DOverflowMenu;
            viewControls3D.OverflowButton.Name = "View3D Overflow Menu";

            // The 3D model view
            view3DWidget = new View3DWidget(
                Printer,
                sceneContext,
                viewControls3D,
                theme,
                this,
                editorType: isPrinterType ? Object3DControlsLayer.EditorType.Printer : Object3DControlsLayer.EditorType.Part);

            viewControls3D.SetView3DWidget(view3DWidget);

            this.AddChild(topToBottom = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            });

            topToBottom.AddChild(leftToRight = new FlowLayoutWidget()
            {
                Name    = "View3DContainerParent",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            });

            view3DContainer = new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

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

            toolbarAndView3DWidget.AddChild(viewControls3D);

            var favoritesBarContext = new LibraryConfig()
            {
                ActiveContainer = ApplicationController.Instance.Library.RootLibaryContainer
            };

            var leftBar = new GuiWidget()
            {
                VAnchor     = VAnchor.Stretch,
                HAnchor     = HAnchor.Fit,
                Border      = new BorderDouble(top: 1, right: 1),
                BorderColor = theme.BorderColor20,
            };

            favoritesBarAndView3DWidget.AddChild(leftBar);

            bool expanded = UserSettings.Instance.get(UserSettingsKey.FavoritesBarExpansion) != "0";

            favoritesBar = new LibraryListView(favoritesBarContext, theme)
            {
                Name = "LibraryView",
                // Drop containers
                ContainerFilter = (container) => false,
                // HAnchor = HAnchor.Fit,
                HAnchor          = HAnchor.Absolute,
                VAnchor          = VAnchor.Stretch,
                AllowContextMenu = false,
                ActiveSort       = SortKey.ModifiedDate,
                Ascending        = true,
                // restore to state for favorites bar size
                Width           = expanded ? 55 * GuiWidget.DeviceScale : 33 * GuiWidget.DeviceScale,
                ListContentView = new IconView(theme, expanded ? 48 * GuiWidget.DeviceScale : 24 * GuiWidget.DeviceScale)
                {
                    VAnchor = VAnchor.Fit | VAnchor.Top
                },
            };

            // favoritesBar.ScrollArea.HAnchor = HAnchor.Fit;
            favoritesBar.ListContentView.HAnchor = HAnchor.Fit;
            leftBar.AddChild(favoritesBar);

            void UpdateWidth(object s, EventArgs e)
            {
                if (s is GuiWidget widget)
                {
                    favoritesBar.Width = widget.Width;
                }
            }

            favoritesBar.ListContentView.BoundsChanged += UpdateWidth;

            favoritesBar.ScrollArea.VAnchor = VAnchor.Fit;

            favoritesBar.VerticalScrollBar.Show = ScrollBar.ShowState.Never;

            var expandedImage  = StaticData.Instance.LoadIcon("expand.png", 16, 16).SetToColor(theme.TextColor);
            var collapsedImage = StaticData.Instance.LoadIcon("collapse.png", 16, 16).SetToColor(theme.TextColor);

            var expandBarButton = new IconButton(expanded ? collapsedImage : expandedImage, theme)
            {
                HAnchor     = HAnchor.Center,
                VAnchor     = VAnchor.Absolute | VAnchor.Bottom,
                Margin      = new BorderDouble(bottom: 3, top: 3),
                Height      = theme.ButtonHeight - 6 * GuiWidget.DeviceScale,
                Width       = theme.ButtonHeight - 6 * GuiWidget.DeviceScale,
                ToolTipText = expanded ? "Reduced Width".Localize() : "Expand Width".Localize(),
            };

            expandBarButton.Click += (s, e) => UiThread.RunOnIdle(async() =>
            {
                expanded = !expanded;

                // remove from the one we are deleting
                favoritesBar.ListContentView.BoundsChanged -= UpdateWidth;
                UserSettings.Instance.set(UserSettingsKey.FavoritesBarExpansion, expanded ? "1" : "0");
                favoritesBar.ListContentView         = new IconView(theme, expanded ? 48 * GuiWidget.DeviceScale : 24 * GuiWidget.DeviceScale);
                favoritesBar.ListContentView.HAnchor = HAnchor.Fit;
                // add to the one we created
                favoritesBar.ListContentView.BoundsChanged += UpdateWidth;
                expandBarButton.SetIcon(expanded ? collapsedImage : expandedImage);
                expandBarButton.Invalidate();
                expandBarButton.ToolTipText = expanded ? "Reduced Width".Localize() : "Expand Width".Localize();

                await favoritesBar.Reload();
                UpdateWidth(favoritesBar.ListContentView, null);
            });
            leftBar.AddChild(expandBarButton);

            favoritesBar.Margin = new BorderDouble(bottom: expandBarButton.Height + expandBarButton.Margin.Height);

            favoritesBarAndView3DWidget.AddChild(view3DWidget);
            toolbarAndView3DWidget.AddChild(favoritesBarAndView3DWidget);

            view3DContainer.AddChild(toolbarAndView3DWidget);

            leftToRight.AddChild(view3DContainer);

            if (sceneContext.World.RotationMatrix == Matrix4X4.Identity)
            {
                this.view3DWidget.ResetView();
            }

            this.AnchorAll();
        }