Esempio n. 1
0
        public static bool TryLoad(out VisualizerDialogSettings settings)
        {
            try
            {
                if (!File.Exists(_settingsFilePath))
                {
                    settings = null;
                    return(false);
                }

                var settingsByName = File
                                     .ReadAllText(_settingsFilePath)
                                     .Split(_newLines, StringSplitOptions.RemoveEmptyEntries)
                                     .Select(line => line.Split(_colons, count: 2))
                                     .ToDictionary(
                    keyValue => keyValue.FirstOrDefault()?.Trim(),
                    keyValue => keyValue.LastOrDefault()?.Substring(1));

                settings = new VisualizerDialogSettings
                {
                    Theme = new VisualizerDialogTheme(),
                    Font  = new VisualizerDialogFontSettings(),
                    Size  = new VisualizerDialogSizeSettings()
                };

                SetValues(settings, settingsByName);
                return(true);
            }
            catch
            {
                settings = null;
                return(false);
            }
        }
Esempio n. 2
0
        private static string Serialize(VisualizerDialogSettings settings)
        {
            var theme = settings.Theme;

            return($@"
{ThemeName}: {theme.Name}
{ThemeBackground}: {theme.Background}
{ThemeDefault}: {theme.Default}
{ThemeToolbar}: {theme.Toolbar}
{ThemeMenu}: {theme.Menu}
{ThemeMenuHighlight}: {theme.MenuHighlight}
{ThemeKeyword}: {theme.Keyword}
{ThemeVariable}: {theme.Variable}
{ThemeTypeName}: {theme.TypeName}
{ThemeInterfaceName}: {theme.InterfaceName}
{ThemeCommandStatement}: {theme.CommandStatement}
{ThemeText}: {theme.Text}
{ThemeNumeric}: {theme.Numeric}
{ThemeMethodName}: {theme.MethodName}
{ThemeComment}: {theme.Comment}
{FontName}: {settings.Font.Name}
{FontSize}: {settings.Font.Size}
{SizeResizeToCode}: {settings.Size.ResizeToMatchCode}
{SizeInitialWidth}: {settings.Size.InitialWidth}
{SizeInitialHeight}: {settings.Size.InitialHeight}
{nameof(settings.Indent)}: {settings.Indent}
{nameof(settings.UseFullyQualifiedTypeNames)}: {settings.UseFullyQualifiedTypeNames}
{nameof(settings.UseExplicitTypeNames)}: {settings.UseExplicitTypeNames}
{nameof(settings.UseExplicitGenericParameters)}: {settings.UseExplicitGenericParameters}
{nameof(settings.DeclareOutputParametersInline)}: {settings.DeclareOutputParametersInline}
{nameof(settings.ShowImplicitArrayTypes)}: {settings.ShowImplicitArrayTypes}
{nameof(settings.ShowLambdaParameterTypeNames)}: {settings.ShowLambdaParameterTypeNames}
{nameof(settings.ShowQuotedLambdaComments)}: {settings.ShowQuotedLambdaComments}".TrimStart());
        }
Esempio n. 3
0
        public static void Save(VisualizerDialogSettings settings)
        {
            var saveWorker = new BackgroundWorker();

            saveWorker.DoWork += Save;
            saveWorker.RunWorkerAsync(settings);
        }
Esempio n. 4
0
        static VisualizerDialogSettings()
        {
            _default = new VisualizerDialogSettings
            {
                Theme = VisualizerDialogTheme.Light,
                Font  = VisualizerDialogFontSettings.Monospace,
                Size  = new VisualizerDialogSizeSettings()
            };

            Instance = GetInstance();
        }
Esempio n. 5
0
        private static void SetFontValues(
            VisualizerDialogSettings settings,
            IDictionary <string, string> settingsByName)
        {
            if (settingsByName.TryGetValue(FontName, out var value))
            {
                settings.Font.Name = value.Trim();
            }

            if (settingsByName.TryGetValue(FontSize, out value) &&
                int.TryParse(value, out var fontSize))
            {
                settings.Font.Size = fontSize;
            }
        }
Esempio n. 6
0
        private static void SetValues(
            VisualizerDialogSettings settings,
            IDictionary <string, string> settingsByName)
        {
            SetThemeValues(settings, settingsByName);
            SetFontValues(settings, settingsByName);
            SetSizeValues(settings, settingsByName);

            if (settingsByName.TryGetValue(nameof(settings.Indent), out var value))
            {
                settings.Indent = value;
            }

            if (settingsByName.TryGetValue(nameof(settings.UseFullyQualifiedTypeNames), out value))
            {
                settings.UseFullyQualifiedTypeNames = IsTrue(value);
            }

            if (settingsByName.TryGetValue(nameof(settings.UseExplicitTypeNames), out value))
            {
                settings.UseExplicitTypeNames = IsTrue(value);
            }

            if (settingsByName.TryGetValue(nameof(settings.UseExplicitGenericParameters), out value))
            {
                settings.UseExplicitGenericParameters = IsTrue(value);
            }

            if (settingsByName.TryGetValue(nameof(settings.DeclareOutputParametersInline), out value))
            {
                settings.DeclareOutputParametersInline = IsTrue(value);
            }

            if (settingsByName.TryGetValue(nameof(settings.ShowImplicitArrayTypes), out value))
            {
                settings.ShowImplicitArrayTypes = IsTrue(value);
            }

            if (settingsByName.TryGetValue(nameof(settings.ShowLambdaParameterTypeNames), out value))
            {
                settings.ShowLambdaParameterTypeNames = IsTrue(value);
            }

            if (settingsByName.TryGetValue(nameof(settings.ShowQuotedLambdaComments), out value))
            {
                settings.ShowQuotedLambdaComments = IsTrue(value);
            }
        }
Esempio n. 7
0
        private static void SetSizeValues(
            VisualizerDialogSettings settings,
            IDictionary <string, string> settingsByName)
        {
            if (settingsByName.TryGetValue(SizeResizeToCode, out var value))
            {
                settings.Size.ResizeToMatchCode = IsTrue(value);
            }

            if (settingsByName.TryGetValue(SizeInitialWidth, out value) &&
                int.TryParse(value, out var width))
            {
                settings.Size.InitialWidth = width;
            }

            if (settingsByName.TryGetValue(SizeInitialHeight, out value) &&
                int.TryParse(value, out var height))
            {
                settings.Size.InitialHeight = height;
            }
        }
Esempio n. 8
0
        private static void SetThemeValues(
            VisualizerDialogSettings settings,
            IDictionary <string, string> settingsByName)
        {
            var defaultTheme = settings.Theme;

            if (settingsByName.TryGetValue(ThemeName, out var value))
            {
                settings.Theme.Name = value;

                switch (value)
                {
                case "Light":
                    defaultTheme = VisualizerDialogTheme.Light;
                    break;

                case "Dark":
                    defaultTheme = VisualizerDialogTheme.Dark;
                    break;
                }
            }

            settings.Theme.Background = settingsByName.TryGetValue(ThemeBackground, out value)
                ? value : defaultTheme.Background;

            settings.Theme.Default = settingsByName.TryGetValue(ThemeDefault, out value)
                ? value : defaultTheme.Default;

            settings.Theme.Toolbar = settingsByName.TryGetValue(ThemeToolbar, out value)
                ? value : defaultTheme.Toolbar;

            settings.Theme.Menu = settingsByName.TryGetValue(ThemeMenu, out value)
                ? value : defaultTheme.Menu;

            settings.Theme.MenuHighlight = settingsByName.TryGetValue(ThemeMenuHighlight, out value) ? value : defaultTheme.MenuHighlight;

            settings.Theme.Keyword = settingsByName.TryGetValue(ThemeKeyword, out value)
                ? value : defaultTheme.Keyword;

            settings.Theme.Variable = settingsByName.TryGetValue(ThemeVariable, out value)
                ? value : defaultTheme.Variable;

            settings.Theme.TypeName = settingsByName.TryGetValue(ThemeTypeName, out value)
                ? value : defaultTheme.TypeName;

            settings.Theme.InterfaceName = settingsByName.TryGetValue(ThemeInterfaceName, out value)
                ? value : defaultTheme.InterfaceName;

            settings.Theme.CommandStatement = settingsByName.TryGetValue(ThemeCommandStatement, out value)
                ? value : defaultTheme.CommandStatement;

            settings.Theme.Text = settingsByName.TryGetValue(ThemeText, out value)
                ? value : defaultTheme.Text;

            settings.Theme.Numeric = settingsByName.TryGetValue(ThemeNumeric, out value)
                ? value : defaultTheme.Numeric;

            settings.Theme.MethodName = settingsByName.TryGetValue(ThemeMethodName, out value)
                ? value : defaultTheme.MethodName;

            settings.Theme.Comment = settingsByName.TryGetValue(ThemeComment, out value)
                ? value : defaultTheme.Comment;
        }