From 5c5e57f2be0692bc57276bd367cd17c5077ec45f Mon Sep 17 00:00:00 2001 From: John Lewin Date: Wed, 29 Oct 2014 09:40:50 -0700 Subject: [PATCH] Revise checkbox and selection behavior in Queue and Library views - Fixes #81695578 --- ControlElements/ConditionalClickWidget.cs | 70 +++++++++++++++++++++++ MatterControl.csproj | 1 + PrintLibrary/LibraryRowItem.cs | 5 +- PrintQueue/QueueRowItem.cs | 8 +++ 4 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 ControlElements/ConditionalClickWidget.cs diff --git a/ControlElements/ConditionalClickWidget.cs b/ControlElements/ConditionalClickWidget.cs new file mode 100644 index 000000000..5bef53d27 --- /dev/null +++ b/ControlElements/ConditionalClickWidget.cs @@ -0,0 +1,70 @@ +//----------------------------------------------------------------------- +// +// Copyright (c) 2014, Lars Brubaker +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// 1. Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// 2. Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +// ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND +// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +// +// The views and conclusions contained in the software and documentation are those +// of the authors and should not be interpreted as representing official policies, +// either expressed or implied, of the FreeBSD Project. +// +//----------------------------------------------------------------------- +namespace MatterHackers.MatterControl +{ + using System; + + /// + /// The ConditionalClickWidget provides a ClickWidget that conditionally appears on the control surface to capture mouse input + /// + public class ConditionalClickWidget : ClickWidget + { + /// + /// The delegate which provides the Enabled state + /// + private Func enabledCallback; + + /// + /// Initializes a new instance of the ConditionalClickWidget class. + /// + /// The delegate to + public ConditionalClickWidget(Func enabledCallback) + { + this.enabledCallback = enabledCallback; + } + + /// + /// Determines if the control is enabled + /// + public override bool Enabled + { + get + { + return this.enabledCallback(); + } + + set + { + throw new InvalidOperationException("Cannot set Enabled on ConditionalClickWidget"); + } + } + } +} diff --git a/MatterControl.csproj b/MatterControl.csproj index aa3236865..bce8cfc54 100644 --- a/MatterControl.csproj +++ b/MatterControl.csproj @@ -108,6 +108,7 @@ + diff --git a/PrintLibrary/LibraryRowItem.cs b/PrintLibrary/LibraryRowItem.cs index 9b0ae8d91..2b779a716 100644 --- a/PrintLibrary/LibraryRowItem.cs +++ b/PrintLibrary/LibraryRowItem.cs @@ -161,7 +161,8 @@ namespace MatterHackers.MatterControl.PrintLibrary primaryContainer.AddChild(primaryFlow); - primaryClickContainer = new ClickWidget(); + // The ConditionalClickWidget supplies a user driven Enabled property based on a delegate of your choosing + primaryClickContainer = new ConditionalClickWidget(() => libraryDataView.EditMode); primaryClickContainer.HAnchor = HAnchor.ParentLeftRight; primaryClickContainer.VAnchor = VAnchor.ParentBottomTop; @@ -178,7 +179,7 @@ namespace MatterHackers.MatterControl.PrintLibrary AddHandlers(); } - ClickWidget primaryClickContainer; + ConditionalClickWidget primaryClickContainer; SlideWidget getItemActionButtons() { diff --git a/PrintQueue/QueueRowItem.cs b/PrintQueue/QueueRowItem.cs index 196b806bc..a8c2676b7 100644 --- a/PrintQueue/QueueRowItem.cs +++ b/PrintQueue/QueueRowItem.cs @@ -86,6 +86,7 @@ namespace MatterHackers.MatterControl.PrintQueue SlideWidget actionButtonContainer; GuiWidget selectionCheckBoxContainer; public CheckBox selectionCheckBox; + ConditionalClickWidget conditionalClickContainer; public bool IsHoverItem { @@ -186,11 +187,18 @@ namespace MatterHackers.MatterControl.PrintQueue editControls.Visible = false; } + // The ConditionalClickWidget supplies a user driven Enabled property based on a delegate of your choosing + conditionalClickContainer = new ConditionalClickWidget(() => queueDataView.EditMode); + conditionalClickContainer.HAnchor = HAnchor.ParentLeftRight; + conditionalClickContainer.VAnchor = VAnchor.ParentBottomTop; + conditionalClickContainer.Click += onLibraryItemClick; + topToBottomLayout.AddChild(topContentsFlowLayout); this.AddChild(topToBottomLayout); actionButtonContainer = getItemActionButtons(); actionButtonContainer.Visible = false; + this.AddChild(conditionalClickContainer); this.AddChild(actionButtonContainer);