Skip to content

Commit

Permalink
Improved: drop-down menus behaviour and performance.
Browse files Browse the repository at this point in the history
Improved: general performance.
Changed: skip target plugin type if not found during upgrade (handles the 'deleted' type case).
  • Loading branch information
yagasoft committed Dec 18, 2021
1 parent 9472c97 commit 0adfa41
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 408 deletions.
153 changes: 78 additions & 75 deletions CrmCodeGenerator.VSPackage/Dialogs/Login.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
using Yagasoft.Libraries.Common;
using Application = System.Windows.Forms.Application;
using MultiSelectComboBoxClass = CrmCodeGenerator.Controls.MultiSelectComboBox;
using Task = System.Threading.Tasks.Task;

#endregion

Expand Down Expand Up @@ -269,7 +268,7 @@ private void InitActions(bool isClearCache = false)
CheckContext(isClearCache);

crmAssembly.Clear();
Dispatcher.Invoke(() => TextBoxFilterType.Clear());
Dispatcher.InvokeAsync(() => TextBoxFilterType.Clear());

try
{
Expand Down Expand Up @@ -322,7 +321,7 @@ private void RegisterEvents()
{
//UpdateStatus("-- Cancelled tool!", false);
StillOpen = false;
Dispatcher.Invoke(Close);
Dispatcher.InvokeAsync(Close);
}
break;
Expand Down Expand Up @@ -397,10 +396,7 @@ private void RegisterEvents()
(o, args) =>
{
ParseCrmAssembly();
// update UI
Dispatcher.Invoke(
() => { ListPluginTypes.ItemsSource = crmAssembly.Children; });
Dispatcher.InvokeAsync(() => { ListPluginTypes.ItemsSource = crmAssembly.Children; });
};

assemblyRegistration.RegLogEntryAdded +=
Expand All @@ -419,7 +415,7 @@ private void RegisterEvents()

private void PopException(Exception exception)
{
Dispatcher.Invoke(
Dispatcher.InvokeAsync(
() =>
{
var message = exception.Message
Expand All @@ -430,7 +426,7 @@ private void PopException(Exception exception)

private void ShowBusy(string message)
{
Dispatcher.Invoke(
Dispatcher.InvokeAsync(
() =>
{
BusyIndicator.IsBusy = true;
Expand All @@ -441,7 +437,7 @@ private void ShowBusy(string message)

private void HideBusy()
{
Dispatcher.Invoke(
Dispatcher.InvokeAsync(
() =>
{
BusyIndicator.IsBusy = false;
Expand All @@ -464,7 +460,7 @@ internal void UpdateStatus(string message, bool working, bool newLine = true)

if (!string.IsNullOrWhiteSpace(message))
{
Dispatcher.BeginInvoke(new Action(() => { Status.Update(message, newLine); }));
Dispatcher.InvokeAsync(() => Status.Update(message, newLine));
}

Application.DoEvents();
Expand Down Expand Up @@ -584,22 +580,23 @@ private void ButtonDelete_Click(object sender, RoutedEventArgs e)
if (DteHelper.IsConfirmed("Are you sure you want to UNregister this plugin?" +
" This means that the plugin and all its steps will be deleted!", "Unregistration"))
{
new Thread(() =>
{
try
{
assemblyRegistration.DeleteAssembly(assemblyRegistration.Id);
crmAssembly.Clear();
}
catch (Exception exception)
{
PopException(exception);
}
finally
{
UpdateStatus("", false);
}
}).Start();
new Thread(
() =>
{
try
{
assemblyRegistration.DeleteAssembly(assemblyRegistration.Id);
crmAssembly.Clear();
}
catch (Exception exception)
{
PopException(exception);
}
finally
{
UpdateStatus("", false);
}
}).Start();
}
}

Expand All @@ -612,7 +609,7 @@ protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Escape)
{
Dispatcher.Invoke(Close);
Dispatcher.InvokeAsync(Close);
}

base.OnKeyDown(e);
Expand All @@ -622,16 +619,17 @@ protected override void OnKeyDown(KeyEventArgs e)

private void ClearSelectionOnClickEmpty(object sender, MouseButtonEventArgs e)
{
Dispatcher.Invoke(() =>
{
var hitTestResult = VisualTreeHelper.HitTest((ListView)sender, e.GetPosition((ListView)sender));
var controlType = hitTestResult.VisualHit.DependencyObjectType.SystemType;
if (controlType == typeof(ScrollViewer))
{
((ListView)sender).SelectedItem = null;
}
});
Dispatcher.InvokeAsync(
() =>
{
var hitTestResult = VisualTreeHelper.HitTest((ListView)sender, e.GetPosition((ListView)sender));
var controlType = hitTestResult.VisualHit.DependencyObjectType.SystemType;
if (controlType == typeof(ScrollViewer))
{
((ListView)sender).SelectedItem = null;
}
});
}

#region Types
Expand Down Expand Up @@ -667,7 +665,7 @@ private void ListPluginTypes_SelectionChanged(object sender, SelectionChangedEve
// update UI
UpdateListBindingToEntityChildren(type, ListTypeSteps);
Dispatcher.Invoke(() => TextBoxFilterStep.Clear());
Dispatcher.InvokeAsync(() => TextBoxFilterStep.Clear());
}).Start();
}

Expand Down Expand Up @@ -716,7 +714,7 @@ private void ButtonAddStep_Click(object sender, RoutedEventArgs e)
assemblyRegistration.CreateTypeStep(newStep);
Dispatcher.Invoke(() => type.Children.Add(newStep));
Dispatcher.InvokeAsync(() => type.Children.Add(newStep));
}
catch (Exception exception)
{
Expand Down Expand Up @@ -759,11 +757,12 @@ private void ButtonEditStep_Click(object sender, RoutedEventArgs e)
TypeStep dialogue = null;
Dispatcher.Invoke(() =>
{
dialogue = new TypeStep(clone, connectionManager);
dialogue.ShowDialog();
});
Dispatcher.Invoke(
() =>
{
dialogue = new TypeStep(clone, connectionManager);
dialogue.ShowDialog();
});
try
{
Expand All @@ -785,11 +784,12 @@ private void ButtonEditStep_Click(object sender, RoutedEventArgs e)
assemblyRegistration.UpdateTypeStep(clone);
Dispatcher.Invoke(() =>
{
type.Children.Remove(step);
type.Children.Add(clone);
});
Dispatcher.InvokeAsync(
() =>
{
type.Children.Remove(step);
type.Children.Add(clone);
});
}
catch (Exception exception)
{
Expand Down Expand Up @@ -821,11 +821,12 @@ private void ButtonRemoveStep_Click(object sender, RoutedEventArgs e)
{
try
{
steps.ForEach(step =>
{
assemblyRegistration.DeleteTypeStep(step.Id);
Dispatcher.Invoke(() => type.Children.Remove(step));
});
steps.ForEach(
step =>
{
assemblyRegistration.DeleteTypeStep(step.Id);
Dispatcher.InvokeAsync(() => type.Children.Remove(step));
});
}
catch (Exception exception)
{
Expand Down Expand Up @@ -971,7 +972,7 @@ private void ButtonAddImage_Click(object sender, RoutedEventArgs e)
if (dialogue.IsUpdate)
{
assemblyRegistration.CreateStepImage(newImage);
Dispatcher.Invoke(() => step.Children.Add(newImage));
Dispatcher.InvokeAsync(() => step.Children.Add(newImage));
}
}
catch (Exception exception)
Expand Down Expand Up @@ -1019,22 +1020,24 @@ private void ButtonEditImage_Click(object sender, RoutedEventArgs e)
var clone = image.Clone<CrmStepImage>();
StepImage dialogue = null;
Dispatcher.Invoke(() =>
{
dialogue = new StepImage(clone);
dialogue.ShowDialog();
});
Dispatcher.Invoke(
() =>
{
dialogue = new StepImage(clone);
dialogue.ShowDialog();
});
try
{
if (dialogue.IsUpdate)
{
assemblyRegistration.UpdateStepImage(clone);
Dispatcher.Invoke(() =>
{
step.Children.Remove(image);
step.Children.Add(clone);
});
Dispatcher.InvokeAsync(
() =>
{
step.Children.Remove(image);
step.Children.Add(clone);
});
}
}
catch (Exception exception)
Expand Down Expand Up @@ -1070,7 +1073,7 @@ private void ButtonRemoveImage_Click(object sender, RoutedEventArgs e)
images.ForEach(image =>
{
assemblyRegistration.DeleteStepImage(image.Id);
Dispatcher.Invoke(() => step.Children.Remove(image));
Dispatcher.InvokeAsync(() => step.Children.Remove(image));
});
}
catch (Exception exception)
Expand Down Expand Up @@ -1221,18 +1224,18 @@ private void SelectEntitiesByRegex(TextBox textBoxFilter, FilterControl control)
switch (control)
{
case FilterControl.Type:
Dispatcher.Invoke(() => crmAssembly.Filter(text));
Dispatcher.InvokeAsync(() => crmAssembly.Filter(text));
break;
case FilterControl.Step:
Dispatcher.Invoke(() => ((CrmPluginType)ListPluginTypes.SelectedItem)?.Filter(text));
Dispatcher.InvokeAsync(() => ((CrmPluginType)ListPluginTypes.SelectedItem)?.Filter(text));
break;
default:
throw new ArgumentOutOfRangeException(nameof(control), control, null);
}
Dispatcher.Invoke(textBoxFilter.Focus);
Dispatcher.InvokeAsync(textBoxFilter.Focus);
HideBusy();
}
Expand Down Expand Up @@ -1261,11 +1264,11 @@ private void UpdateListBindingToEntityChildren(object source, ListView listView)
{
var binding =
new Binding
{
Source = source,
Mode = BindingMode.OneWay,
Path = new PropertyPath("Children")
};
{
Source = source,
Mode = BindingMode.OneWay,
Path = new PropertyPath("Children")
};
listView.SetBinding(ItemsControl.ItemsSourceProperty, binding);
});
Expand Down
Loading

0 comments on commit 0adfa41

Please sign in to comment.