use run on idle less

This commit is contained in:
LarsBrubaker 2019-06-29 08:33:24 -07:00 committed by jlewin
parent 3824583acd
commit 54d29b41f7
5 changed files with 85 additions and 103 deletions

View file

@ -192,7 +192,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
if (isDirty)
{
// doing this during draw will often result in a enumeration changed
UiThread.RunOnIdle(RebuildContentSection);
RebuildContentSection();
}
base.OnDraw(graphics2D);

View file

@ -273,7 +273,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
foreach (var childContainer in this.SortItems(containerItems))
{
var listViewItem = new ListViewItem(childContainer, this.ActiveContainer, this);
listViewItem.DoubleClick += listViewItem_DoubleClick;
listViewItem.DoubleClick += ListViewItem_DoubleClick;
items.Add(listViewItem);
listViewItem.ViewWidget = itemsContentView.AddItem(listViewItem);
@ -294,7 +294,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
foreach (var item in this.SortItems(filteredResults))
{
var listViewItem = new ListViewItem(item, this.ActiveContainer, this);
listViewItem.DoubleClick += listViewItem_DoubleClick;
listViewItem.DoubleClick += ListViewItem_DoubleClick;
items.Add(listViewItem);
listViewItem.ViewWidget = itemsContentView.AddItem(listViewItem);
@ -426,7 +426,7 @@ namespace MatterHackers.MatterControl.CustomWidgets
return destImage;
}
private void listViewItem_DoubleClick(object sender, MouseEventArgs e)
private void ListViewItem_DoubleClick(object sender, MouseEventArgs e)
{
UiThread.RunOnIdle(async () =>
{

View file

@ -243,11 +243,11 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
SetLinkButtonsVisibility(this, null);
updateAvailableButton.Click += (s, e) => UiThread.RunOnIdle(() =>
updateAvailableButton.Click += (s, e) =>
{
UpdateControlData.Instance.CheckForUpdate();
DialogWindow.Show<CheckForUpdatesPage>();
});
};
tabControl.TabBar.ActionArea.AddChild(updateAvailableButton);
@ -499,7 +499,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
updateAvailableButton.Visible = true;
UiThread.RunOnIdle(this.ShowUpdateAvailableAnimation);
this.ShowUpdateAvailableAnimation();
}
}
else

View file

@ -118,7 +118,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
{
if (!menuVisibileAtMouseDown)
{
UiThread.RunOnIdle(this.ShowPopup);
this.ShowPopup();
}
base.OnClick(mouseEvent);

View file

@ -188,24 +188,21 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (sourceEvent.Button == MouseButtons.Right)
{
UiThread.RunOnIdle(() =>
{
var menu = ApplicationController.Instance.GetActionMenuForSceneItem((IObject3D)treeView.SelectedNode.Tag, Scene, true, this);
var menu = ApplicationController.Instance.GetActionMenuForSceneItem((IObject3D)treeView.SelectedNode.Tag, Scene, true, this);
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
systemWindow.ShowPopup(
new MatePoint(clickedWidget)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
new MatePoint(menu)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Right, MateEdge.Top)
},
altBounds: new RectangleDouble(sourceEvent.X + 1, sourceEvent.Y + 1, sourceEvent.X + 1, sourceEvent.Y + 1));
});
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
systemWindow.ShowPopup(
new MatePoint(clickedWidget)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
new MatePoint(menu)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Right, MateEdge.Top)
},
altBounds: new RectangleDouble(sourceEvent.X + 1, sourceEvent.Y + 1, sourceEvent.X + 1, sourceEvent.Y + 1));
}
}
};
@ -527,18 +524,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
else if (ProfileManager.Instance.ActiveProfiles.Count() <= 0)
{
// If no printer profiles exist, show the printer setup wizard
UiThread.RunOnIdle(() =>
var window = DialogWindow.Show(new SetupStepMakeModelName());
window.Closed += (s2, e2) =>
{
var window = DialogWindow.Show(new SetupStepMakeModelName());
window.Closed += (s2, e2) =>
if (ApplicationController.Instance.ActivePrinters.FirstOrDefault() is PrinterConfig printer
&& printer.Settings.PrinterSelected)
{
if (ApplicationController.Instance.ActivePrinters.FirstOrDefault() is PrinterConfig printer
&& printer.Settings.PrinterSelected)
{
CopyPlateToPrinter(sceneContext, printer);
}
};
});
CopyPlateToPrinter(sceneContext, printer);
}
};
}
else if (ApplicationController.Instance.ActivePrinters.Count() is int printerCount && printerCount > 0)
{
@ -551,38 +545,32 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
else
{
// If multiple active printers exist, show select printer dialog
UiThread.RunOnIdle(() =>
{
DialogWindow.Show(
new OpenPrinterPage(
"Next".Localize(),
(selectedPrinter) =>
DialogWindow.Show(
new OpenPrinterPage(
"Next".Localize(),
(selectedPrinter) =>
{
if (selectedPrinter?.Settings.PrinterSelected == true)
{
if (selectedPrinter?.Settings.PrinterSelected == true)
{
CopyPlateToPrinter(sceneContext, selectedPrinter);
}
}));
});
CopyPlateToPrinter(sceneContext, selectedPrinter);
}
}));
}
}
else if (ProfileManager.Instance.ActiveProfiles.Any())
{
// If no active printer but profiles exist, show select printer
UiThread.RunOnIdle(() =>
{
DialogWindow.Show(
new OpenPrinterPage(
"Next".Localize(),
(loadedPrinter) =>
DialogWindow.Show(
new OpenPrinterPage(
"Next".Localize(),
(loadedPrinter) =>
{
if (loadedPrinter is PrinterConfig activePrinter
&& activePrinter.Settings.PrinterSelected)
{
if (loadedPrinter is PrinterConfig activePrinter
&& activePrinter.Settings.PrinterSelected)
{
CopyPlateToPrinter(sceneContext, activePrinter);
}
}));
});
CopyPlateToPrinter(sceneContext, activePrinter);
}
}));
}
}
@ -874,7 +862,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Scene.Invalidate(new InvalidateArgs(null, InvalidateType.Children));
// Set focus to View3DWidget after drag-drop
UiThread.RunOnIdle(this.Focus);
this.Focus();
}
}
@ -1542,37 +1530,32 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
private void ShowPartContextMenu(MouseEventArgs mouseEvent, IObject3D selectedItem)
{
UiThread.RunOnIdle(() =>
{
var menu = ApplicationController.Instance.GetActionMenuForSceneItem(selectedItem, Scene, true, this);
var menu = ApplicationController.Instance.GetActionMenuForSceneItem(selectedItem, Scene, true, this);
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
systemWindow.ShowPopup(
new MatePoint(this)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
new MatePoint(menu)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
altBounds: new RectangleDouble(mouseEvent.X + 1, mouseEvent.Y + 1, mouseEvent.X + 1, mouseEvent.Y + 1));
});
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
systemWindow.ShowPopup(
new MatePoint(this)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
new MatePoint(menu)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
altBounds: new RectangleDouble(mouseEvent.X + 1, mouseEvent.Y + 1, mouseEvent.X + 1, mouseEvent.Y + 1));
}
public void ShowBedContextMenu(Vector2 position)
{
// Workspace/plate context menu
UiThread.RunOnIdle(() =>
var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);
var workspaceActions = ApplicationController.Instance.GetWorkspaceActions(this);
var actions = new[]
{
var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);
var workspaceActions = ApplicationController.Instance.GetWorkspaceActions(this);
var actions = new[]
{
new ActionSeparator(),
new NamedAction()
{
@ -1593,24 +1576,23 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
workspaceActions["ClearBed"],
};
theme.CreateMenuItems(popupMenu, actions);
theme.CreateMenuItems(popupMenu, actions);
var popupBounds = new RectangleDouble(position.X + 1, position.Y + 1, position.X + 1, position.Y + 1);
var popupBounds = new RectangleDouble(position.X + 1, position.Y + 1, position.X + 1, position.Y + 1);
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
systemWindow.ShowPopup(
new MatePoint(this)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Bottom),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
new MatePoint(popupMenu)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
altBounds: popupBounds);
});
var systemWindow = this.Parents<SystemWindow>().FirstOrDefault();
systemWindow.ShowPopup(
new MatePoint(this)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Bottom),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
new MatePoint(popupMenu)
{
Mate = new MateOptions(MateEdge.Left, MateEdge.Top),
AltMate = new MateOptions(MateEdge.Left, MateEdge.Top)
},
altBounds: popupBounds);
}
// TODO: Consider if we should always allow DragDrop or if we should prevent during printer or other scenarios
@ -1630,7 +1612,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
&& !rebuildTreePending)
{
rebuildTreePending = true;
UiThread.RunOnIdle(this.RebuildTree);
this.RebuildTree();
}
if (e.InvalidateType.HasFlag(InvalidateType.Name))
@ -1640,7 +1622,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
if (!rebuildTreePending)
{
rebuildTreePending = true;
UiThread.RunOnIdle(this.RebuildTree);
this.RebuildTree();
}
Scene.SelectedItem = null;