Merge pull request #2848 from jlewin/design_tools

Remove Connect failed/troubleshoot UI from PrinterConnection
This commit is contained in:
johnlewin 2018-01-06 13:23:47 -08:00 committed by GitHub
commit b23ae8ca68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 28 additions and 13 deletions

View file

@ -179,7 +179,7 @@ namespace MatterHackers.MatterControl
{
UiThread.RunOnIdle(() =>
{
printer.Settings.printer.Connection.Connect(false);
printer.Settings.printer.Connection.Connect();
}, 2);
}

View file

@ -32,6 +32,7 @@ using MatterHackers.Agg.Platform;
using MatterHackers.Agg.UI;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.PrinterCommunication;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication.FrostedSerial;
@ -49,6 +50,9 @@ namespace MatterHackers.MatterControl.ActionBar
private EventHandler unregisterEvents;
private PrinterConfig printer;
private bool listenForConnectFailed = false;
private long connectStartMs;
public PrinterConnectButton(PrinterConfig printer, ThemeConfig theme)
{
this.printer = printer;
@ -77,6 +81,7 @@ namespace MatterHackers.MatterControl.ActionBar
cancelConnectButton.ToolTipText = "Stop trying to connect to the printer.".Localize();
cancelConnectButton.Click += (s, e) => UiThread.RunOnIdle(() =>
{
listenForConnectFailed = false;
ApplicationController.Instance.ConditionalCancelPrint();
cancelConnectButton.Enabled = false;
});
@ -121,6 +126,21 @@ namespace MatterHackers.MatterControl.ActionBar
printer.Connection.EnableChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents);
printer.Connection.CommunicationStateChanged.RegisterEvent((s, e) => SetVisibleStates(), ref unregisterEvents);
printer.Connection.ConnectionFailed.RegisterEvent((s, e) =>
{
#if !__ANDROID__
// TODO: Someday this functionality should be revised to an awaitable Connect() call in the Connect button that
// shows troubleshooting on failed attempts, rather than hooking the failed event and trying to determine if the
// Connect button started the task
if (listenForConnectFailed
&& UiThread.CurrentTimerMs - connectStartMs < 25000)
{
// User initiated connect attempt failed, show port selection dialog
DialogWindow.Show(new SetupStepComPortOne(printer));
}
#endif
listenForConnectFailed = false;
}, ref unregisterEvents);
this.SetVisibleStates();
}
@ -135,6 +155,9 @@ namespace MatterHackers.MatterControl.ActionBar
{
if (printer.Settings.PrinterSelected)
{
listenForConnectFailed = true;
connectStartMs = UiThread.CurrentTimerMs;
#if __ANDROID__
if (!printer.Settings.GetValue<bool>(SettingsKey.enable_network_printing)
&& !FrostedSerialPort.HasPermissionToDevice())
@ -146,7 +169,7 @@ namespace MatterHackers.MatterControl.ActionBar
#endif
{
printer.Connection.HaltConnectionThread();
printer.Connection.Connect(true);
printer.Connection.Connect();
}
}
}
@ -191,6 +214,7 @@ namespace MatterHackers.MatterControl.ActionBar
break;
default:
listenForConnectFailed = false;
SetChildVisible(disconnectButton, true);
break;
}

View file

@ -42,7 +42,6 @@ using MatterControl.Printing;
using MatterHackers.Agg;
using MatterHackers.MatterControl.DataStorage;
using MatterHackers.MatterControl.PrinterCommunication.Io;
using MatterHackers.MatterControl.PrinterControls.PrinterConnections;
using MatterHackers.MatterControl.SlicerConfiguration;
using MatterHackers.SerialPortCommunication;
using MatterHackers.SerialPortCommunication.FrostedSerial;
@ -854,7 +853,7 @@ namespace MatterHackers.MatterControl.PrinterCommunication
}
}
public void Connect(bool showHelpIfNoPort = false)
public void Connect()
{
// TODO: Consider adding any conditions that would results in a connection failure to this initial test
// Start the process of requesting permission and exit if permission is not currently granted
@ -1044,14 +1043,6 @@ namespace MatterHackers.MatterControl.PrinterCommunication
OnConnectionFailed(
ConnectionFailure.PortUnavailable,
$"{this.ComPort} is not available");
#if !__ANDROID__
// Only pop up the com port helper if the USER actually CLICKED the connect button.
if (showHelpIfNoPort)
{
DialogWindow.Show(new SetupStepComPortOne(printer));
}
#endif
}
}

View file

@ -142,7 +142,7 @@ namespace MatterHackers.MatterControl
void ConnectButton_Click(object sender, EventArgs mouseEvent)
{
ApplicationController.Instance.ActivePrinter.Connection.Connect(true);
ApplicationController.Instance.ActivePrinter.Connection.Connect();
}
void NextButton_Click(object sender, EventArgs mouseEvent)