Tig 9 mesiacov pred
rodič
commit
0b353037ba

+ 5 - 0
Terminal.Gui/Application/Application.Initialization.cs

@@ -99,7 +99,12 @@ public static partial class Application // Initialization (Init/Shutdown)
         // valid after a Driver is loaded. In this case we need just
         // `Settings` so we can determine which driver to use.
         // Don't reset, so we can inherit the theme from the previous run.
+        string previousTheme = Themes?.Theme ?? string.Empty;
         Load ();
+        if (Themes is { } && !string.IsNullOrEmpty (previousTheme) && previousTheme != "Default")
+        {
+            ThemeManager.SelectedTheme = previousTheme;
+        }
         Apply ();
 
         AddApplicationKeyBindings ();

+ 12 - 4
Terminal.Gui/Configuration/ConfigurationManager.cs

@@ -197,10 +197,18 @@ public static class ConfigurationManager
 
         try
         {
-            settings = Settings?.Apply () ?? false;
-
-            themes = !string.IsNullOrEmpty (ThemeManager.SelectedTheme)
-                     && (ThemeManager.Themes? [ThemeManager.SelectedTheme]?.Apply () ?? false);
+            if (string.IsNullOrEmpty (ThemeManager.SelectedTheme))
+            {
+                settings = Settings?.Apply () ?? false;
+                themes = !string.IsNullOrEmpty (ThemeManager.SelectedTheme)
+                         && (ThemeManager.Themes? [ThemeManager.SelectedTheme]?.Apply () ?? false);
+            }
+            else
+            {
+                themes = !string.IsNullOrEmpty (ThemeManager.SelectedTheme)
+                         && (ThemeManager.Themes? [ThemeManager.SelectedTheme]?.Apply () ?? false);
+                settings = Settings?.Apply () ?? false;
+            }
             appSettings = AppSettings?.Apply () ?? false;
         }
         catch (JsonException e)

+ 1 - 1
Terminal.Gui/Configuration/ThemeManager.cs

@@ -110,7 +110,7 @@ public class ThemeManager : IDictionary<string, ThemeScope>
             string oldTheme = _theme;
             _theme = value;
 
-            if (oldTheme != _theme && Settings! ["Themes"]?.PropertyValue is Dictionary<string, ThemeScope> themes && themes.ContainsKey (_theme))
+            if ((oldTheme != _theme || oldTheme != Settings! ["Theme"].PropertyValue as string) && Settings! ["Themes"]?.PropertyValue is Dictionary<string, ThemeScope> themes && themes.ContainsKey (_theme))
             {
                 Settings! ["Theme"].PropertyValue = _theme;
                 Instance.OnThemeChanged (oldTheme);

+ 42 - 0
Terminal.Gui/View/Layout/DimAuto.cs

@@ -408,6 +408,48 @@ public record DimAuto (Dim? MaximumContentDim, Dim? MinimumContentDim, DimAutoSt
                 }
 
                 #endregion DimView
+
+                #region DimAuto
+                // [ ] DimAuto      - Dimension is internally calculated
+
+                List<View> dimAutoSubViews;
+
+                if (dimension == Dimension.Width && us.GetType ().Name == "Bar" && us.Subviews.Count == 3)
+                {
+
+                }
+
+                if (dimension == Dimension.Width)
+                {
+                    dimAutoSubViews = includedSubviews.Where (v => v.Width is { } && v.Width.Has<DimAuto> (out _)).ToList ();
+                }
+                else
+                {
+                    dimAutoSubViews = includedSubviews.Where (v => v.Height is { } && v.Height.Has<DimAuto> (out _)).ToList ();
+                }
+
+                for (var i = 0; i < dimAutoSubViews.Count; i++)
+                {
+                    View v = dimAutoSubViews [i];
+
+                    if (dimension == Dimension.Width)
+                    {
+                        v.SetRelativeLayout (new (maxCalculatedSize, 0));
+                    }
+                    else
+                    {
+                        v.SetRelativeLayout (new (0, maxCalculatedSize));
+                    }
+
+                    int maxDimAuto= dimension == Dimension.Width ? v.Frame.X + v.Frame.Width : v.Frame.Y + v.Frame.Height;
+
+                    if (maxDimAuto > maxCalculatedSize)
+                    {
+                        maxCalculatedSize = maxDimAuto;
+                    }
+                }
+
+                #endregion
             }
         }
 

+ 11 - 11
Terminal.Gui/Views/Bar.cs

@@ -77,7 +77,11 @@ public class Bar : View, IOrientation, IDesignable
         }
     }
 
-    private void Bar_Initialized (object? sender, EventArgs e) { ColorScheme = Colors.ColorSchemes ["Menu"]; }
+    private void Bar_Initialized (object? sender, EventArgs e)
+    {
+        ColorScheme = Colors.ColorSchemes ["Menu"];
+        LayoutBarItems (GetContentSize ());
+    }
 
     /// <inheritdoc/>
     public override void SetBorderStyle (LineStyle value)
@@ -192,6 +196,11 @@ public class Bar : View, IOrientation, IDesignable
     {
         base.OnLayoutStarted (args);
 
+        LayoutBarItems (args.OldContentSize);
+    }
+
+    private void LayoutBarItems (Size contentSize)
+    {
         View? prevBarItem = null;
 
         switch (Orientation)
@@ -204,8 +213,6 @@ public class Bar : View, IOrientation, IDesignable
                     barItem.ColorScheme = ColorScheme;
                     barItem.X = Pos.Align (Alignment.Start, AlignmentModes);
                     barItem.Y = 0; //Pos.Center ();
-                    // HACK: This should not be needed
-                    barItem.SetRelativeLayout (GetContentSize ());
                 }
                 break;
 
@@ -239,8 +246,6 @@ public class Bar : View, IOrientation, IDesignable
                     if (barItem is Shortcut scBarItem)
                     {
                         scBarItem.MinimumKeyTextSize = minKeyWidth;
-                        // HACK: This should not be needed
-                        scBarItem.SetRelativeLayout (GetContentSize ());
                         maxBarItemWidth = Math.Max (maxBarItemWidth, scBarItem.Frame.Width);
                     }
 
@@ -264,10 +269,6 @@ public class Bar : View, IOrientation, IDesignable
                 foreach (View barItem in Subviews)
                 {
                     barItem.Width = maxBarItemWidth;
-
-                    if (barItem is Line line)
-                    {
-                    }
                 }
 
                 Height = Dim.Auto (DimAutoStyle.Content, totalHeight);
@@ -276,7 +277,6 @@ public class Bar : View, IOrientation, IDesignable
         }
     }
 
-
     /// <inheritdoc />
     public bool EnableForDesign ()
     {
@@ -301,7 +301,7 @@ public class Bar : View, IOrientation, IDesignable
         shortcut = new Shortcut
         {
             Text = "Czech",
-            CommandView = new CheckBox()
+            CommandView = new CheckBox ()
             {
                 Title = "_Check"
             },

+ 0 - 1
UICatalog/Scenario.cs

@@ -82,7 +82,6 @@ namespace UICatalog;
 public class Scenario : IDisposable
 {
     private static int _maxScenarioNameLen = 30;
-    public string Theme = "Default";
     public string TopLevelColorScheme = "Base";
     private bool _disposedValue;
 

+ 1 - 1
UICatalog/Scenarios/Adornments.cs

@@ -36,7 +36,7 @@ public class Adornments : Scenario
 
             // X = Pos.Center (),
             Width = Dim.Percent (60),
-            Height = Dim.Percent (80)
+            Height = Dim.Percent (90)
         };
         app.Add (window);
 

+ 35 - 21
UICatalog/Scenarios/AllViewsTester.cs

@@ -50,7 +50,7 @@ public class AllViewsTester : Scenario
     {
         // Don't create a sub-win (Scenario.Win); just use Application.Top
         Application.Init ();
-        ConfigurationManager.Apply ();
+   //     ConfigurationManager.Apply ();
 
         var app = new Window
         {
@@ -88,18 +88,10 @@ public class AllViewsTester : Scenario
 
         _classListView.SelectedItemChanged += (s, args) =>
                                               {
-                                                  // Remove existing class, if any
-                                                  if (_curView != null)
-                                                  {
-                                                      _curView.LayoutComplete -= LayoutCompleteHandler;
-                                                      _hostPane.Remove (_curView);
-                                                      _curView.Dispose ();
-                                                      _curView = null;
-                                                  }
+                                                  // Dispose existing current View, if any
+                                                  DisposeCurrentView ();
 
-                                                  _curView = CreateClass (_viewClasses.Values.ToArray () [_classListView.SelectedItem]);
-                                                  // Add
-                                                  _hostPane.Add (_curView);
+                                                  CreateCurrentView (_viewClasses.Values.ToArray () [_classListView.SelectedItem]);
 
                                                   // Force ViewToEdit to be the view and not a subview
                                                   if (_adornmentsEditor is { })
@@ -326,6 +318,11 @@ public class AllViewsTester : Scenario
             ColorScheme = Colors.ColorSchemes ["Dialog"]
         };
 
+        _hostPane.LayoutStarted += (sender, args) =>
+                                   {
+
+                                   };
+
         app.Add (_leftPane, _adornmentsEditor, _settingsPane, _hostPane);
 
         _classListView.SelectedItem = 0;
@@ -345,8 +342,10 @@ public class AllViewsTester : Scenario
     private void OnXRadioGroupOnSelectedItemChanged (object s, SelectedItemChangedArgs selected) { DimPosChanged (_curView); }
 
     // TODO: Add Command.HotKey handler (pop a message box?)
-    private View CreateClass (Type type)
+    private void CreateCurrentView (Type type)
     {
+        Debug.Assert(_curView is null);
+
         // If we are to create a generic Type
         if (type.IsGenericType)
         {
@@ -386,9 +385,24 @@ public class AllViewsTester : Scenario
             _orientation.Enabled = false;
         }
 
-        view.Initialized += View_Initialized;
+        view.Initialized += CurrentView_Initialized;
+        view.LayoutComplete += CurrentView_LayoutComplete;
 
-        return view;
+        _curView = view;
+        _hostPane.Add (_curView);
+       // Application.Refresh();
+    }
+
+    private void DisposeCurrentView ()
+    {
+        if (_curView != null)
+        {
+            _curView.Initialized -= CurrentView_Initialized;
+            _curView.LayoutComplete -= CurrentView_LayoutComplete;
+            _hostPane.Remove (_curView);
+            _curView.Dispose ();
+            _curView = null;
+        }
     }
 
     private void DimPosChanged (View view)
@@ -463,7 +477,7 @@ public class AllViewsTester : Scenario
             _hText.Enabled = true;
         }
 
-        UpdateTitle (view);
+        UpdateHostTitle (view);
     }
 
     private List<Type> GetAllViewClassesCollection ()
@@ -484,10 +498,10 @@ public class AllViewsTester : Scenario
         return types;
     }
 
-    private void LayoutCompleteHandler (object sender, LayoutEventArgs args)
+    private void CurrentView_LayoutComplete (object sender, LayoutEventArgs args)
     {
         UpdateSettings (_curView);
-        UpdateTitle (_curView);
+        UpdateHostTitle (_curView);
     }
 
     private void UpdateSettings (View view)
@@ -537,9 +551,9 @@ public class AllViewsTester : Scenario
         }
     }
 
-    private void UpdateTitle (View view) { _hostPane.Title = $"{view.GetType ().Name} - {view.X}, {view.Y}, {view.Width}, {view.Height}"; }
+    private void UpdateHostTitle (View view) { _hostPane.Title = $"_Demo of {view.GetType ().Name}"; }
 
-    private void View_Initialized (object sender, EventArgs e)
+    private void CurrentView_Initialized (object sender, EventArgs e)
     {
         if (sender is not View view)
         {
@@ -566,6 +580,6 @@ public class AllViewsTester : Scenario
         _hRadioGroup.SelectedItemChanged += OnHRadioGroupOnSelectedItemChanged;
         _wRadioGroup.SelectedItemChanged += OnWRadioGroupOnSelectedItemChanged;
 
-        UpdateTitle (view);
+        UpdateHostTitle (view);
     }
 }

+ 0 - 2
UICatalog/Scenarios/CombiningMarks.cs

@@ -9,8 +9,6 @@ public class CombiningMarks : Scenario
     public override void Main ()
     {
         Application.Init ();
-        ConfigurationManager.Themes!.Theme = Theme;
-        ConfigurationManager.Apply ();
         var top = new Toplevel { ColorScheme = Colors.ColorSchemes [TopLevelColorScheme] };
 
         top.DrawContentComplete += (s, e) =>

+ 0 - 2
UICatalog/UICatalog.cs

@@ -317,7 +317,6 @@ public class UICatalogApp
             _selectedScenario = (Scenario)Activator.CreateInstance (_scenarios [item].GetType ())!;
 
             Application.Init (driverName: _forceDriver);
-            _selectedScenario.Theme = _cachedTheme;
             _selectedScenario.TopLevelColorScheme = _topLevelColorScheme;
             _selectedScenario.Main ();
             _selectedScenario.Dispose ();
@@ -335,7 +334,6 @@ public class UICatalogApp
             VerifyObjectsWereDisposed ();
             Themes!.Theme = _cachedTheme!;
             Apply ();
-            scenario.Theme = _cachedTheme;
             scenario.TopLevelColorScheme = _topLevelColorScheme;
 
 #if DEBUG_IDISPOSABLE