Browse Source

Fixed CanExecute DependsOn and scroll on linux

flabbet 6 months ago
parent
commit
af1a62a6e9

+ 0 - 1
src/PixiEditor/Initialization/ClassicDesktopEntry.cs

@@ -59,7 +59,6 @@ internal class ClassicDesktopEntry
         StartupArgs.Args = e.Args.ToList();
         string arguments = string.Join(' ', e.Args);
 
-        Dispatcher dispatcher = Dispatcher.UIThread;
         InitOperatingSystem();
 
         if (ParseArgument("--crash (\"?)([A-z0-9:\\/\\ -_.]+)\\1", arguments, out Group[] groups))

+ 6 - 4
src/PixiEditor/Models/Commands/Attributes/Evaluators/CanExecuteAttribute.cs

@@ -1,20 +1,22 @@
-namespace PixiEditor.Models.Commands.Attributes.Evaluators;
+using PixiEditor.ViewModels.Document;
+
+namespace PixiEditor.Models.Commands.Attributes.Evaluators;
 
 internal partial class Evaluator
 {
     [AttributeUsage(AttributeTargets.Property | AttributeTargets.Method, AllowMultiple = true)]
     internal class CanExecuteAttribute : EvaluatorAttribute
     {
-        //public string[] DependentOn { get; }
+        public string[] DependentOn { get; }
 
         public CanExecuteAttribute([InternalName] string name) : base(name)
         {
-            //DependentOn = new[] { nameof(DocumentManagerViewModel.ActiveDocument) }; // ActiveDocument will be required 99% of the time, so we'll just add it by default
+            DependentOn = new[] { nameof(DocumentManagerViewModel.ActiveDocument) }; // ActiveDocument will be required 99% of the time, so we'll just add it by default
         }
 
         public CanExecuteAttribute([InternalName] string name, params string[] dependentOn) : base(name)
         {
-            //DependentOn = dependentOn;
+            DependentOn = dependentOn;
         }
     }
 }

+ 1 - 1
src/PixiEditor/Models/Commands/CommandController.cs

@@ -602,7 +602,7 @@ internal class CommandController
                                     evaluateFunction => new CanExecuteEvaluator()
                                     {
                                         Name = attribute.Name, Evaluate = evaluateFunction.Invoke,
-                                        /*DependentOn = canExecuteAttribute.DependentOn*/
+                                        DependentOn = canExecuteAttribute.DependentOn
                                     });
                                 break;
                             }

+ 1 - 1
src/PixiEditor/Models/Commands/Evaluators/CanExecuteEvaluator.cs

@@ -7,7 +7,7 @@ internal class CanExecuteEvaluator : Evaluator<bool>
     public static CanExecuteEvaluator AlwaysTrue { get; } = new StaticValueEvaluator(true);
 
     public static CanExecuteEvaluator AlwaysFalse { get; } = new StaticValueEvaluator(false);
-    public string[]? DependentOn { get; set; } // TODO: It is used in CanExecuteChanged event, but it's commented out because it might not impact performance
+    public string[]? DependentOn { get; set; }
 
     private class StaticValueEvaluator : CanExecuteEvaluator
     {

+ 21 - 4
src/PixiEditor/Views/Input/NumberInput.cs

@@ -135,6 +135,8 @@ internal partial class NumberInput : TextBox
     private double _pressedValue;
     private double _pressedRelativeX;
 
+    private double scrollBuildup;
+
     static NumberInput()
     {
         ValueProperty.Changed.Subscribe(OnValueChanged);
@@ -347,15 +349,29 @@ internal partial class NumberInput : TextBox
             return;
         }
 
-        int step = (int)e.Delta.Y;
+        e.Handled = true;
+        double requiredBuildup = 1;
+        
+        if(Decimals == 0 && e.KeyModifiers.HasFlag(KeyModifiers.Control))
+        {
+            requiredBuildup = 2;
+        }
+        
+        if (Math.Abs(scrollBuildup) < requiredBuildup)
+        {
+            scrollBuildup += e.Delta.Y;
+            return;
+        }
+
+        double step = Math.Sign(e.Delta.Y);
 
         double newValue = Value;
-        if (e.KeyModifiers.HasFlag(KeyModifiers.Shift))
+        if (e.KeyModifiers.HasFlag(KeyModifiers.Shift) && Min - double.NegativeInfinity > 0.1f && Max - double.PositiveInfinity > 0.1f)
         {
             double multiplier = (Max - Min) * 0.1f;
             newValue += step * multiplier;
         }
-        else if (e.KeyModifiers.HasFlag(KeyModifiers.Control))
+        else if (e.KeyModifiers.HasFlag(KeyModifiers.Control) && Decimals > 0)
         {
             newValue += step / 2f;
         }
@@ -365,7 +381,8 @@ internal partial class NumberInput : TextBox
         }
 
         Value = (float)Math.Round(Math.Clamp(newValue, Min, Max), Decimals);
-
+        
+        scrollBuildup = 0;
         OnScrollAction?.Invoke();
     }