Skip to content

Commit

Permalink
Cleanup and performance optimizations
Browse files Browse the repository at this point in the history
  • Loading branch information
mscrivo committed Dec 23, 2023
1 parent ade63d5 commit 12c32c3
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 35 deletions.
42 changes: 36 additions & 6 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ charset = utf-8-bom

# XML project files
[*.{csproj,vbproj,vcxproj,vcxproj.filters,proj,projitems,shproj}]
indent_size = 2
indent_size = 4

# XML config files
[*.{props,targets,ruleset,config,nuspec,resx,vsixmanifest,vsct}]
Expand Down Expand Up @@ -78,7 +78,7 @@ dotnet_naming_style.non_private_static_field_style.capitalization = pascal_case
# Non-private readonly fields are PascalCase
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.symbols = non_private_readonly_fields
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_readonly_field_style
dotnet_naming_rule.non_private_readonly_fields_should_be_pascal_case.style = non_private_static_field_style

dotnet_naming_symbols.non_private_readonly_fields.applicable_kinds = field
dotnet_naming_symbols.non_private_readonly_fields.applicable_accessibilities = public, protected, internal, protected_internal, private_protected
Expand All @@ -89,7 +89,7 @@ dotnet_naming_style.non_private_readonly_field_style.capitalization = pascal_cas
# Constants are PascalCase
dotnet_naming_rule.constants_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.constants_should_be_pascal_case.symbols = constants
dotnet_naming_rule.constants_should_be_pascal_case.style = constant_style
dotnet_naming_rule.constants_should_be_pascal_case.style = non_private_static_field_style

dotnet_naming_symbols.constants.applicable_kinds = field, local
dotnet_naming_symbols.constants.required_modifiers = const
Expand All @@ -99,7 +99,7 @@ dotnet_naming_style.constant_style.capitalization = pascal_case
# Static fields are camelCase and start with _
dotnet_naming_rule.static_fields_should_be_camel_case.severity = suggestion
dotnet_naming_rule.static_fields_should_be_camel_case.symbols = static_fields
dotnet_naming_rule.static_fields_should_be_camel_case.style = static_field_style
dotnet_naming_rule.static_fields_should_be_camel_case.style = instance_field_style

dotnet_naming_symbols.static_fields.applicable_kinds = field
dotnet_naming_symbols.static_fields.required_modifiers = static
Expand Down Expand Up @@ -129,7 +129,7 @@ dotnet_naming_style.camel_case_style.capitalization = camel_case
# Local functions are PascalCase
dotnet_naming_rule.local_functions_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.local_functions_should_be_pascal_case.symbols = local_functions
dotnet_naming_rule.local_functions_should_be_pascal_case.style = local_function_style
dotnet_naming_rule.local_functions_should_be_pascal_case.style = non_private_static_field_style

dotnet_naming_symbols.local_functions.applicable_kinds = local_function

Expand All @@ -138,7 +138,7 @@ dotnet_naming_style.local_function_style.capitalization = pascal_case
# By default, name items with PascalCase
dotnet_naming_rule.members_should_be_pascal_case.severity = suggestion
dotnet_naming_rule.members_should_be_pascal_case.symbols = all_members
dotnet_naming_rule.members_should_be_pascal_case.style = pascal_case_style
dotnet_naming_rule.members_should_be_pascal_case.style = non_private_static_field_style

dotnet_naming_symbols.all_members.applicable_kinds = *

Expand Down Expand Up @@ -175,6 +175,20 @@ dotnet_public_api_analyzer.require_api_files = true

# dotnet_style_allow_multiple_blank_lines_experimental
dotnet_diagnostic.IDE2000.severity = warning
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
dotnet_style_prefer_auto_properties = true:silent
dotnet_style_prefer_collection_expression = true:suggestion
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent
dotnet_style_prefer_inferred_tuple_names = true:suggestion
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion
dotnet_style_operator_placement_when_wrapping = beginning_of_line
tab_width = 4
end_of_line = crlf

# CSharp code style settings:
[*.cs]
Expand Down Expand Up @@ -256,6 +270,22 @@ csharp_preserve_single_line_statements = true

# IDE0060: Remove unused parameter
dotnet_diagnostic.IDE0060.severity = warning
csharp_using_directive_placement = outside_namespace:silent
csharp_prefer_simple_using_statement = true:suggestion
csharp_style_namespace_declarations = block_scoped:silent
csharp_style_prefer_method_group_conversion = true:silent
csharp_style_prefer_top_level_statements = true:silent
csharp_style_prefer_primary_constructors = true:suggestion
csharp_style_expression_bodied_lambdas = true:silent
csharp_style_expression_bodied_local_functions = false:silent
csharp_style_prefer_null_check_over_type_check = true:suggestion
csharp_prefer_simple_default_expression = true:suggestion
csharp_style_prefer_local_over_anonymous_function = true:suggestion
csharp_style_prefer_index_operator = true:suggestion
csharp_style_prefer_range_operator = true:suggestion
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
csharp_style_prefer_tuple_swap = true:suggestion
csharp_style_prefer_utf8_string_literals = true:suggestion

[src/{Compilers,ExpressionEvaluator,Scripting}/**Test**/*.{cs,vb}]

Expand Down
2 changes: 1 addition & 1 deletion NetSparkle
35 changes: 18 additions & 17 deletions OotD.Core/Forms/InstanceManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,14 @@ public void LoadInstances()

// create our instance and set the context menu to one defined in the form instance.
var newlyAdded = false;
if (!_mainFormInstances.ContainsKey(instanceName))
if (!_mainFormInstances.TryGetValue(instanceName, out var value))
{
_mainFormInstances.Add(instanceName, new MainForm(instanceName));
value = new MainForm(instanceName);
_mainFormInstances.Add(instanceName, value);
newlyAdded = true;
}

trayIcon.ContextMenuStrip = _mainFormInstances[instanceName].TrayMenu;
trayIcon.ContextMenuStrip = value.TrayMenu;

// remove unnecessary menu items
while (trayIcon.ContextMenuStrip.Items.Count > 0 &&
Expand All @@ -277,29 +278,29 @@ public void LoadInstances()
trayIcon.ContextMenuStrip.Items["RemoveInstanceMenu"]!.Visible = false;
trayIcon.ContextMenuStrip.Items["RenameInstanceMenu"]!.Visible = false;

if (_mainFormInstances[instanceName].TrayMenu.Items.ContainsKey("AddInstanceMenu"))
if (value.TrayMenu.Items.ContainsKey("AddInstanceMenu"))
{
_mainFormInstances[instanceName].TrayMenu.Items["AddInstanceMenu"]!.Visible = true;
value.TrayMenu.Items["AddInstanceMenu"]!.Visible = true;
}

if (_mainFormInstances[instanceName].TrayMenu.Items.ContainsKey("AboutMenu"))
if (value.TrayMenu.Items.ContainsKey("AboutMenu"))
{
_mainFormInstances[instanceName].TrayMenu.Items["AboutMenu"]!.Visible = true;
value.TrayMenu.Items["AboutMenu"]!.Visible = true;
}

if (_mainFormInstances[instanceName].TrayMenu.Items.ContainsKey("StartWithWindows"))
if (value.TrayMenu.Items.ContainsKey("StartWithWindows"))
{
_mainFormInstances[instanceName].TrayMenu.Items["StartWithWindows"]!.Visible = true;
value.TrayMenu.Items["StartWithWindows"]!.Visible = true;
}

if (_mainFormInstances[instanceName].TrayMenu.Items.ContainsKey("LockPositionMenu"))
if (value.TrayMenu.Items.ContainsKey("LockPositionMenu"))
{
_mainFormInstances[instanceName].TrayMenu.Items["LockPositionMenu"]!.Visible = true;
value.TrayMenu.Items["LockPositionMenu"]!.Visible = true;
}

if (_mainFormInstances[instanceName].TrayMenu.Items.ContainsKey("CheckForUpdatesMenu"))
if (value.TrayMenu.Items.ContainsKey("CheckForUpdatesMenu"))
{
_mainFormInstances[instanceName].TrayMenu.Items["CheckForUpdatesMenu"]!.Visible = true;
value.TrayMenu.Items["CheckForUpdatesMenu"]!.Visible = true;
}

// add global menu items that don't apply to the instance.
Expand Down Expand Up @@ -338,13 +339,13 @@ public void LoadInstances()
new ToolStripMenuItem(Resources.About, null, AboutMenu_Click, "AboutMenu"));
}

_mainFormInstances[instanceName].TrayMenu.Items["Separator6"]!.Visible = true;
_mainFormInstances[instanceName].TrayMenu.Items["ExitMenu"]!.Visible = true;
value.TrayMenu.Items["Separator6"]!.Visible = true;
value.TrayMenu.Items["ExitMenu"]!.Visible = true;

if (newlyAdded)
{
_mainFormInstances[instanceName].Show();
UnsafeNativeMethods.SendWindowToBack(_mainFormInstances[instanceName]);
value.Show();
UnsafeNativeMethods.SendWindowToBack(value);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions OotD.Core/Forms/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ private void SetMAPIFolder()
private void UpdateOutlookViewsList()
{
OutlookViewsMenu.DropDownItems.Clear();
OutlookFolderViews = new List<View>();
OutlookFolderViews = [];

if (_outlookFolder == null)
{
Expand Down Expand Up @@ -426,8 +426,8 @@ private static string GetFolderNameFromFullPath(string? fullPath)
{
if (fullPath != null)
{
return fullPath.Substring(fullPath.LastIndexOf("\\", StringComparison.Ordinal) + 1,
fullPath.Length - fullPath.LastIndexOf("\\", StringComparison.Ordinal) - 1);
return fullPath.Substring(fullPath.LastIndexOf('\\') + 1,
fullPath.Length - fullPath.LastIndexOf('\\') - 1);
}

return string.Empty;
Expand Down Expand Up @@ -460,7 +460,7 @@ private static string GenerateFolderPathFromObject(MAPIFolder? oFolder)
}
}

if (fullFolderPath.EndsWith("\\"))
if (fullFolderPath.EndsWith('\\'))
{
fullFolderPath = fullFolderPath[..^1];
}
Expand Down
11 changes: 4 additions & 7 deletions OotD.Core/Utility/OutlookFolderDefinition.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,14 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Diagnostics.CodeAnalysis;

namespace OotD.Utility;

/// <summary>
/// Structure to hold the currently selected custom folder details
/// </summary>
[SuppressMessage("ReSharper", "InconsistentNaming")]
internal struct OutlookFolderDefinition
{
public string? OutlookFolderName;
public string? OutlookFolderStoreId;
public string? OutlookFolderEntryId;
}
public string? OutlookFolderStoreId { get; set; }
public string? OutlookFolderName { get; set; }
public string? OutlookFolderEntryId { get; set; }
}

0 comments on commit 12c32c3

Please sign in to comment.