diff --git a/src/CosmosDbExplorer.Core/Helpers/FoldFinder.cs b/src/CosmosDbExplorer.Core/Helpers/FoldFinder.cs index 58153a5..0a88508 100644 --- a/src/CosmosDbExplorer.Core/Helpers/FoldFinder.cs +++ b/src/CosmosDbExplorer.Core/Helpers/FoldFinder.cs @@ -12,19 +12,20 @@ namespace CosmosDbExplorer.Core.Helpers /// public class FoldFinder { - private readonly bool _foldableRoot; private readonly IList _delimiters; private readonly Regex _scanner; public FoldFinder(IList delimiters, bool foldableRoot = true) { - _foldableRoot = foldableRoot; + FoldableRoot = foldableRoot; _delimiters = delimiters; _scanner = RegexifyDelimiters(delimiters); } public int FirstErrorOffset { get; private set; } = -1; + public bool FoldableRoot { get; set; } + public IList Scan(string code, int start = 0, int end = -1, bool throwOnError = true) { FirstErrorOffset = -1; @@ -37,9 +38,9 @@ public IList Scan(string code, int start = 0, int end = -1, bool thro Delimiter matchedDelimiter; var currentItem = default(FoldStackItem); - foreach (Match match in _scanner.Matches(code, start)) + foreach (var match in _scanner.Matches(code, start).Cast()) { - if (!_foldableRoot && match.Index == 0) + if (!FoldableRoot && match.Index == 0) { continue; } @@ -152,14 +153,17 @@ private static Regex RegexifyDelimiters(IList delimiters) string.Format("((\\{0})|(\\{1}))", d.Start, d.End))), RegexOptions.Compiled | RegexOptions.Multiline); } - private class FoldStackItem + private struct FoldStackItem { public FoldMatch Position; public Delimiter Delimter; } + + + } - public class FoldMatch + public struct FoldMatch { public int Start; public int End; @@ -167,7 +171,14 @@ public class FoldMatch public class Delimiter { - public string Start; - public string End; + public Delimiter(string start, string end) + { + Start = start; + End = end; + } + + public string Start { get; private set; } + public string End { get; private set; } } + } diff --git a/src/CosmosDbExplorer/App.config b/src/CosmosDbExplorer/App.config new file mode 100644 index 0000000..2234c4e --- /dev/null +++ b/src/CosmosDbExplorer/App.config @@ -0,0 +1,55 @@ + + + + +
+ + +
+ + + + + + Consolas + + + 11 + + + Default + + + + + + 50 + + + Metro + + + F5 + + + True + + + False + + + True + + + True + + + + + + + https://www.bruttin.com/CosmosDbExplorer/autoupdate.json + + + + \ No newline at end of file diff --git a/src/CosmosDbExplorer/AvalonEdit/BraceFoldingStrategy.cs b/src/CosmosDbExplorer/AvalonEdit/BraceFoldingStrategy.cs index e91bc35..952862a 100644 --- a/src/CosmosDbExplorer/AvalonEdit/BraceFoldingStrategy.cs +++ b/src/CosmosDbExplorer/AvalonEdit/BraceFoldingStrategy.cs @@ -12,22 +12,25 @@ namespace CosmosDbExplorer.AvalonEdit public class BraceFoldingStrategy { private readonly FoldFinder _foldFinder; + /// /// Creates a new BraceFoldingStrategy. /// - public BraceFoldingStrategy() + public BraceFoldingStrategy(bool foldRoot) { _foldFinder = new FoldFinder(new List { //Json Object Delimiters - new Delimiter { Start = "{", End = "}" }, + new Delimiter( start: "{", end: "}" ), //Json Array Delimiters - new Delimiter { Start = "[", End = "]" } - }, false); + new Delimiter( start: "[", end: "]" ) + }, foldRoot); } + public bool FoldRootElement { get => _foldFinder.FoldableRoot; set => _foldFinder.FoldableRoot = value; } + public void UpdateFoldings(FoldingManager manager, TextDocument document) { - var newFoldings = CreateNewFoldings(document, out int firstErrorOffset); + var newFoldings = CreateNewFoldings(document, out var firstErrorOffset); manager.UpdateFoldings(newFoldings, firstErrorOffset); } diff --git a/src/CosmosDbExplorer/Behaviors/AvalonTextEditorBraceFoldingBehavior.cs b/src/CosmosDbExplorer/Behaviors/AvalonTextEditorBraceFoldingBehavior.cs index 8952d9e..dd77bcf 100644 --- a/src/CosmosDbExplorer/Behaviors/AvalonTextEditorBraceFoldingBehavior.cs +++ b/src/CosmosDbExplorer/Behaviors/AvalonTextEditorBraceFoldingBehavior.cs @@ -3,6 +3,8 @@ using System.Windows.Threading; using CosmosDbExplorer.AvalonEdit; using CosmosDbExplorer.Core.Helpers; +using CosmosDbExplorer.Properties; + using ICSharpCode.AvalonEdit; using ICSharpCode.AvalonEdit.Folding; using Microsoft.Xaml.Behaviors; @@ -11,16 +13,20 @@ namespace CosmosDbExplorer.Behaviors { public class AvalonTextEditorBraceFoldingBehavior : Behavior { - private readonly BraceFoldingStrategy _foldingStrategy = new(); + private readonly BraceFoldingStrategy _foldingStrategy = new(Settings.Default.FoldingRootElement); private FoldingManager? _foldingManager; private readonly TimedDebounce _timer = new() { WaitingMilliSeconds = 500 }; protected override void OnAttached() { base.OnAttached(); + + OnUseFoldingChanged(); + _timer.Idled += OnTextChangedIdle; AssociatedObject.TextChanged += OnTextChanged; } + protected override void OnDetaching() { _timer.Idled -= OnTextChangedIdle; @@ -86,11 +92,41 @@ private void OnUseFoldingChanged() } } + public bool FoldRootElement + { + get { return (bool)GetValue(FoldRootElementProperty); } + set { SetValue(FoldRootElementProperty, value); } + } + + // Using a DependencyProperty as the backing store for FoldRootElement. This enables animation, styling, binding, etc... + public static readonly DependencyProperty FoldRootElementProperty = + DependencyProperty.Register( + "FoldRootElement", + typeof(bool), + typeof(AvalonTextEditorBraceFoldingBehavior), + new PropertyMetadata(true, OnFoldRootElementPropertyChanged)); + + private static void OnFoldRootElementPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is AvalonTextEditorBraceFoldingBehavior behavior) + { + behavior.OnFoldRootElementChanged(); + } + } + + private void OnFoldRootElementChanged() + { + _foldingStrategy.FoldRootElement = FoldRootElement; + + OnTextChangedIdle(null, new EventArgs()); + } + private void InitFoldingManager() { if (_foldingManager is null && AssociatedObject?.TextArea is not null) { _foldingManager = FoldingManager.Install(AssociatedObject.TextArea); + OnTextChangedIdle(null, new EventArgs()); } } diff --git a/src/CosmosDbExplorer/Properties/Settings.Designer.cs b/src/CosmosDbExplorer/Properties/Settings.Designer.cs index af4fb8d..6738fe6 100644 --- a/src/CosmosDbExplorer/Properties/Settings.Designer.cs +++ b/src/CosmosDbExplorer/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace CosmosDbExplorer.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.2.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.3.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -139,5 +139,29 @@ public string AutoUpdaterUrl { return ((string)(this["AutoUpdaterUrl"])); } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool EnableFolding { + get { + return ((bool)(this["EnableFolding"])); + } + set { + this["EnableFolding"] = value; + } + } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool FoldingRootElement { + get { + return ((bool)(this["FoldingRootElement"])); + } + set { + this["FoldingRootElement"] = value; + } + } } } diff --git a/src/CosmosDbExplorer/Properties/Settings.settings b/src/CosmosDbExplorer/Properties/Settings.settings index 82dd608..9dbf914 100644 --- a/src/CosmosDbExplorer/Properties/Settings.settings +++ b/src/CosmosDbExplorer/Properties/Settings.settings @@ -32,5 +32,11 @@ https://www.bruttin.com/CosmosDbExplorer/autoupdate.json + + True + + + True + \ No newline at end of file diff --git a/src/CosmosDbExplorer/Styles/CosmosDbExplorerThemeProvider.cs b/src/CosmosDbExplorer/Styles/CosmosDbExplorerThemeProvider.cs index ccf94cd..fec7d90 100644 --- a/src/CosmosDbExplorer/Styles/CosmosDbExplorerThemeProvider.cs +++ b/src/CosmosDbExplorer/Styles/CosmosDbExplorerThemeProvider.cs @@ -13,7 +13,7 @@ namespace CosmosDbExplorer.Styles { public class CosmosDbExplorerThemeProvider : /*MahAppsLibraryThemeProvider*/LibraryThemeProvider { - public static readonly CosmosDbExplorerThemeProvider DefaultInstance = new CosmosDbExplorerThemeProvider(); + public static readonly CosmosDbExplorerThemeProvider DefaultInstance = new(); public CosmosDbExplorerThemeProvider() : base(true) @@ -34,7 +34,7 @@ public override void FillColorSchemeValues(Dictionary values, Ru throw new ArgumentNullException(nameof(colorValues)); } - bool isDarkMode = colorValues.Options.BaseColorScheme.Name == ThemeManager.BaseColorDark; + //var isDarkMode = colorValues.Options.BaseColorScheme.Name == ThemeManager.BaseColorDark; //values.Add("CosmosDbExplorer.AvalonEdit.LinkTextForegroundBrush", isDarkMode ? Color.FromRgb(155, 109, 90).ToString() : Colors.CornflowerBlue.ToString()); diff --git a/src/CosmosDbExplorer/ViewModels/AboutViewModel.cs b/src/CosmosDbExplorer/ViewModels/AboutViewModel.cs index 1bd196b..d5effb9 100644 --- a/src/CosmosDbExplorer/ViewModels/AboutViewModel.cs +++ b/src/CosmosDbExplorer/ViewModels/AboutViewModel.cs @@ -52,7 +52,12 @@ public AboutViewModel(ISystemService systemService) public string Title { get; set; } - public static List Authors => new() { new Author("Sacha Bruttin", "sachabruttin"), new Author("savbace", "savbace") }; + public static List Authors => new() + { + new Author("Sacha Bruttin", "sachabruttin"), + new Author("savbace", "savbace"), + new Author("Curlack", "Curlack") + }; public static string LicenseUrl => "https://github.com/sachabruttin/CosmosDbExplorer/blob/master/LICENSE"; diff --git a/src/CosmosDbExplorer/ViewModels/DocumentsTabViewModel.cs b/src/CosmosDbExplorer/ViewModels/DocumentsTabViewModel.cs index 338fddf..d669240 100644 --- a/src/CosmosDbExplorer/ViewModels/DocumentsTabViewModel.cs +++ b/src/CosmosDbExplorer/ViewModels/DocumentsTabViewModel.cs @@ -54,7 +54,7 @@ public class DocumentsTabViewModel : PaneWithZoomViewModel>>(selectedDocuments.Count()); + var tasks = new List>>(selectedDocuments.Count); foreach (var document in selectedDocuments) { diff --git a/src/CosmosDbExplorer/Views/DocumentsTabView.xaml b/src/CosmosDbExplorer/Views/DocumentsTabView.xaml index b819126..c10133a 100644 --- a/src/CosmosDbExplorer/Views/DocumentsTabView.xaml +++ b/src/CosmosDbExplorer/Views/DocumentsTabView.xaml @@ -7,6 +7,7 @@ xmlns:controls="clr-namespace:CosmosDbExplorer.Controls" xmlns:viewmodel="clr-namespace:CosmosDbExplorer.ViewModels" xmlns:template="clr-namespace:CosmosDbExplorer.TemplateSelectors" + xmlns:properties="clr-namespace:CosmosDbExplorer.Properties" xmlns:mah="http://metro.mahapps.com/winfx/xaml/controls" d:DataContext="{d:DesignInstance Type=viewmodel:DocumentsTabViewModel}" mc:Ignorable="d" @@ -172,7 +173,7 @@ diff --git a/src/CosmosDbExplorer/Views/ImportDocumentView.xaml b/src/CosmosDbExplorer/Views/ImportDocumentView.xaml index dbf1a27..3f3af03 100644 --- a/src/CosmosDbExplorer/Views/ImportDocumentView.xaml +++ b/src/CosmosDbExplorer/Views/ImportDocumentView.xaml @@ -7,6 +7,7 @@ xmlns:avalonEdit="http://icsharpcode.net/sharpdevelop/avalonedit" xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:behaviors="clr-namespace:CosmosDbExplorer.Behaviors" + xmlns:properties="clr-namespace:CosmosDbExplorer.Properties" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> @@ -14,7 +15,10 @@ Style="{StaticResource CosmosEditor}" IsModified="{Binding IsDirty, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"> - + diff --git a/src/CosmosDbExplorer/Views/JsonEditorView.xaml b/src/CosmosDbExplorer/Views/JsonEditorView.xaml index 16a8b64..d9d800b 100644 --- a/src/CosmosDbExplorer/Views/JsonEditorView.xaml +++ b/src/CosmosDbExplorer/Views/JsonEditorView.xaml @@ -8,6 +8,7 @@ xmlns:i="http://schemas.microsoft.com/xaml/behaviors" xmlns:behaviors="clr-namespace:CosmosDbExplorer.Behaviors" xmlns:viewmodel="clr-namespace:CosmosDbExplorer.ViewModels" + xmlns:properties="clr-namespace:CosmosDbExplorer.Properties" d:DataContext="{d:DesignInstance Type=viewmodel:JsonViewerViewModel}" mc:Ignorable="d" d:DesignHeight="450" d:DesignWidth="800"> @@ -19,7 +20,10 @@ ContextMenu="{StaticResource JsonEditorContextMenu}" HorizontalScrollBarVisibility="Auto" > - + diff --git a/src/CosmosDbExplorer/Views/JsonEditorView.xaml.cs b/src/CosmosDbExplorer/Views/JsonEditorView.xaml.cs index 0c34450..da179c6 100644 --- a/src/CosmosDbExplorer/Views/JsonEditorView.xaml.cs +++ b/src/CosmosDbExplorer/Views/JsonEditorView.xaml.cs @@ -37,13 +37,6 @@ public bool UseFolding // Using a DependencyProperty as the backing store for UseFolding. This enables animation, styling, binding, etc... public static readonly DependencyProperty UseFoldingProperty = - DependencyProperty.Register("UseFolding", typeof(bool), typeof(JsonEditorView), new PropertyMetadata(false, OnUseFoldingChanged)); - - private static void OnUseFoldingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var value = (bool)e.NewValue; - var target = (JsonEditorView)d; - target.foldingBehavior.UseFolding = value; - } + DependencyProperty.Register("UseFolding", typeof(bool), typeof(JsonEditorView), new PropertyMetadata(false)); } } diff --git a/src/CosmosDbExplorer/Views/SettingsPage.xaml b/src/CosmosDbExplorer/Views/SettingsPage.xaml index ab7fdd7..3bbb790 100644 --- a/src/CosmosDbExplorer/Views/SettingsPage.xaml +++ b/src/CosmosDbExplorer/Views/SettingsPage.xaml @@ -156,6 +156,13 @@ IsOn="{Binding Source={x:Static properties:Settings.Default}, Path=ShowLineNumbers, Mode=TwoWay}" /> + + + diff --git a/src/CosmosDbExplorer/Views/ShellWindow.xaml b/src/CosmosDbExplorer/Views/ShellWindow.xaml index 7e706ac..868df9d 100644 --- a/src/CosmosDbExplorer/Views/ShellWindow.xaml +++ b/src/CosmosDbExplorer/Views/ShellWindow.xaml @@ -492,6 +492,9 @@ + + + @@ -500,6 +503,9 @@ + + +