Skip to content

Commit

Permalink
Fix Codacy issues
Browse files Browse the repository at this point in the history
Fix Codacy issues
  • Loading branch information
timunie committed Feb 27, 2021
1 parent aa909cc commit 82fb357
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private void ToggleIconScaling(object obj)

public bool IsToggleSwitchVisible { get; set; }

public ObservableCollection<string> Animals { get; } = new ObservableCollection<string>()
public ObservableCollection<string> Animals { get; } = new ObservableCollection<string>
{
"African elephant",
"Ant",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public object CreateObjectFromString(string input, CultureInfo culture, string s
return null;
}

MetroDialogSettings dialogSettings = new MetroDialogSettings()
MetroDialogSettings dialogSettings = new MetroDialogSettings
{
AffirmativeButtonText = "Yes",
NegativeButtonText = "No",
Expand Down
19 changes: 16 additions & 3 deletions src/MahApps.Metro/Controls/Helper/BindingHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,12 @@ public static object Eval(object source, string expression, string format)
/// <returns></returns>
public static object Eval(Binding binding, object source)
{
if (binding is null) throw new ArgumentNullException(nameof(binding));
if (binding is null)
{
throw new ArgumentNullException(nameof(binding));
}

Binding newBinding = new Binding()
Binding newBinding = new Binding
{
Source = source,
AsyncState = binding.AsyncState,
Expand All @@ -91,7 +94,7 @@ public static object Eval(Binding binding, object source)
/// <param name="binding">The <see cref="Binding"/> to evaluate</param>
/// <param name="dependencyObject">optional: The <see cref="DependencyObject"/> to evalutate</param>
/// <returns>The resulting object</returns>
public static object Eval(Binding binding, DependencyObject dependencyObject = null)
public static object Eval(Binding binding, DependencyObject dependencyObject)
{
dependencyObject ??= new DependencyObject();

Expand All @@ -106,5 +109,15 @@ public static object Eval(Binding binding, DependencyObject dependencyObject = n
return dependencyObject.GetValue(DummyTextProperty);
}
}

/// <summary>
/// Evaluates a defined <see cref="Binding"/> on the given <see cref="DependencyObject"/>
/// </summary>
/// <param name="binding">The <see cref="Binding"/> to evaluate</param>
/// <returns>The resulting object</returns>
public static object Eval(Binding binding)
{
return Eval(binding, null);
}
}
}
2 changes: 2 additions & 0 deletions src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,8 @@ public static void ButtonClicked(object sender, RoutedEventArgs e)
case SelectionMode.Extended:
multiSelectionComboBox.SelectedItems.Clear();
break;
default:
throw new NotSupportedException("Unknown SelectionMode");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public interface ICompareObjectToString
[MarkupExtensionReturnType(typeof(DefaultObjectToStringComparer))]
public class DefaultObjectToStringComparer : MarkupExtension, ICompareObjectToString
{
static DefaultObjectToStringComparer _Instance;
private static DefaultObjectToStringComparer _Instance;

/// <inheritdoc/>
public bool CheckIfStringMatchesObject(string input, object objectToCompare, StringComparison stringComparison, string stringFormat)
Expand All @@ -48,7 +48,7 @@ public bool CheckIfStringMatchesObject(string input, object objectToCompare, Str
{
objectText = objectToCompare.ToString();
}
else if (stringFormat.Contains('{') && stringFormat.Contains('{'))
else if (stringFormat.Contains('{') && stringFormat.Contains('}'))
{
objectText = string.Format(stringFormat, objectToCompare);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,9 @@ public int SelectItemsFromTextInputDelay
private void UpdateEditableText()
{
if (PART_EditableTextBox is null || SelectedItems is null)
{
return;
}

var selectedItemsText = GetSelectedItemsText();

Expand Down Expand Up @@ -583,14 +585,13 @@ private void UpdateHasCustomText(string selectedItemsText)

private void UpdateDisplaySelectedItems(OrderSelectedItemsBy orderBy)
{
switch (orderBy)
if (orderBy == OrderSelectedItemsBy.SelectedOrder)
{
case OrderSelectedItemsBy.SelectedOrder:
SetCurrentValue(DisplaySelectedItemsProperty, SelectedItems);
break;
case OrderSelectedItemsBy.ItemsSourceOrder:
SetCurrentValue(DisplaySelectedItemsProperty, ((IEnumerable<object>)PART_PopupListBox.SelectedItems).OrderBy(o => Items.IndexOf(o)));
break;
SetCurrentValue(DisplaySelectedItemsProperty, SelectedItems);
}
else if (orderBy == OrderSelectedItemsBy.ItemsSourceOrder)
{
SetCurrentValue(DisplaySelectedItemsProperty, ((IEnumerable<object>)PART_PopupListBox.SelectedItems).OrderBy(o => Items.IndexOf(o)));
}
}

Expand Down Expand Up @@ -638,7 +639,7 @@ private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e)
SelectedItems.Clear();
break;
default:
break;
throw new NotSupportedException("Unknown SelectionMode");
}
return;
}
Expand Down Expand Up @@ -671,7 +672,7 @@ private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e)
case SelectionMode.Multiple:
case SelectionMode.Extended:

var strings = Text.Split(new string[] { Separator }, StringSplitOptions.RemoveEmptyEntries);
var strings = Text.Split(new [] { Separator }, StringSplitOptions.RemoveEmptyEntries);

SelectedItems.Clear();

Expand All @@ -698,7 +699,7 @@ private void UpdateSelectedItemsFromTextTimer_Tick(object sender, EventArgs e)
}
break;
default:
break;
throw new NotSupportedException("Unknown SelectionMode");
}


Expand Down Expand Up @@ -771,6 +772,8 @@ private void ExecutedClearContentCommand(object sender, ExecutedRoutedEventArgs
case SelectionMode.Extended:
multiSelectionCombo.SelectedItems.Clear();
break;
default:
throw new NotSupportedException("Unknown SelectionMode");
}
}
}
Expand Down Expand Up @@ -889,7 +892,10 @@ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
}

// If we have the ItemsSource set, we need to exit here.
if (ReadLocalValue(ItemsSourceProperty) != DependencyProperty.UnsetValue) return;
if (ReadLocalValue(ItemsSourceProperty) != DependencyProperty.UnsetValue)
{
return;
}

switch (e.Action)
{
Expand All @@ -908,11 +914,7 @@ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
break;

case NotifyCollectionChangedAction.Replace:
// TODO Add Handler
break;
case NotifyCollectionChangedAction.Move:
// TODO Add Handler
break;
case NotifyCollectionChangedAction.Reset:
PART_PopupListBox.Items.Clear();
foreach (var item in Items)
Expand All @@ -921,7 +923,7 @@ protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e)
}
break;
default:
break;
throw new NotSupportedException("Unsupported NotifyCollectionChangedAction");
}
}

Expand Down Expand Up @@ -951,10 +953,16 @@ protected override void OnDropDownOpened(EventArgs e)

PART_PopupListBox.Focus();

if (PART_PopupListBox.Items.Count == 0) return;
if (PART_PopupListBox.Items.Count == 0)
{
return;
}

var index = PART_PopupListBox.SelectedIndex;
if (index < 0) index = 0;
if (index < 0)
{
index = 0;
}

Action action = () =>
{
Expand Down Expand Up @@ -1052,7 +1060,10 @@ private void MultiSelectionComboBox_Loaded(object sender, EventArgs e)
Loaded -= MultiSelectionComboBox_Loaded;

// If we have the ItemsSource set, we need to exit here.
if (ReadLocalValue(ItemsSourceProperty) != DependencyProperty.UnsetValue) return;
if (ReadLocalValue(ItemsSourceProperty) != DependencyProperty.UnsetValue)
{
return;
}

PART_PopupListBox.Items.Clear();
foreach (var item in Items)
Expand Down

0 comments on commit 82fb357

Please sign in to comment.