2017-08-23 23:59:45 -07:00
|
|
|
|
/*
|
2018-10-16 16:00:06 -07:00
|
|
|
|
Copyright (c) 2018, Lars Brubaker, John Lewin
|
2017-08-23 23:59:45 -07:00
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
|
|
modification, are permitted provided that the following conditions are met:
|
|
|
|
|
|
|
|
|
|
|
|
1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
|
|
list of conditions and the following disclaimer.
|
|
|
|
|
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
|
|
this list of conditions and the following disclaimer in the documentation
|
|
|
|
|
|
and/or other materials provided with the distribution.
|
|
|
|
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
|
|
|
|
|
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
|
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
|
|
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
|
|
|
|
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
|
|
|
|
|
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
|
|
|
|
|
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
|
|
|
|
|
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
|
|
|
|
|
|
|
The views and conclusions contained in the software and documentation are those
|
|
|
|
|
|
of the authors and should not be interpreted as representing official policies,
|
|
|
|
|
|
either expressed or implied, of the FreeBSD Project.
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
using System;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
using System.Collections.Generic;
|
2015-04-17 20:14:20 -07:00
|
|
|
|
using System.Linq;
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
using MatterHackers.Agg;
|
2017-08-20 02:34:39 -07:00
|
|
|
|
using MatterHackers.Agg.Platform;
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
using MatterHackers.Agg.UI;
|
|
|
|
|
|
using MatterHackers.Localizations;
|
2018-10-07 11:36:52 -07:00
|
|
|
|
using MatterHackers.MatterControl.CustomWidgets;
|
Move to new library model and view
- Add new listview control for library content
- Migrate library providers to containers
- Cloud, Sqlite, Directories, Queue, History
- Migrate SideBar components to containers
- Primatives, Text, Braille, ImageConverter
- Create new library container types
- Zip files, Calibration parts, Printer SDCards
- Reduce leftnav to Library, Settings, Controls, Options
- Add DragDrop support for image content
2017-05-19 22:33:55 -07:00
|
|
|
|
using MatterHackers.MatterControl.SettingsManagement;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
using MatterHackers.MatterControl.SlicerConfiguration;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
|
|
|
|
|
namespace MatterHackers.MatterControl.PrinterControls.PrinterConnections
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
//Normally step one of the setup process
|
2017-11-08 15:56:37 -08:00
|
|
|
|
public class SetupStepMakeModelName : DialogPage
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
private FlowLayoutWidget printerModelContainer;
|
|
|
|
|
|
private FlowLayoutWidget printerMakeContainer;
|
|
|
|
|
|
|
|
|
|
|
|
private MHTextEditWidget printerNameInput;
|
|
|
|
|
|
|
|
|
|
|
|
private TextWidget printerNameError;
|
|
|
|
|
|
|
2018-04-14 20:51:01 -07:00
|
|
|
|
private GuiWidget nextButton;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
|
|
|
|
|
private bool usingDefaultName;
|
|
|
|
|
|
|
2016-06-01 14:00:47 -07:00
|
|
|
|
private static BorderDouble elementMargin = new BorderDouble(top: 3);
|
|
|
|
|
|
|
|
|
|
|
|
private BoundDropList printerManufacturerSelector;
|
|
|
|
|
|
private BoundDropList printerModelSelector;
|
|
|
|
|
|
|
2016-06-14 11:28:13 -07:00
|
|
|
|
string activeMake;
|
|
|
|
|
|
string activeModel;
|
|
|
|
|
|
string activeName;
|
|
|
|
|
|
|
2018-10-13 17:40:59 -07:00
|
|
|
|
private RadioButton createPrinterRadioButton = null;
|
|
|
|
|
|
|
2016-06-07 15:45:50 -07:00
|
|
|
|
public SetupStepMakeModelName()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-10-13 17:40:59 -07:00
|
|
|
|
bool userIsLoggedIn = !ApplicationController.GuestUserActive?.Invoke() ?? false;
|
|
|
|
|
|
|
|
|
|
|
|
this.HeaderText = this.WindowTitle = "Printer Setup".Localize();
|
|
|
|
|
|
|
|
|
|
|
|
var addPrinterColumn = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Stretch,
|
|
|
|
|
|
VAnchor = VAnchor.Fit,
|
|
|
|
|
|
};
|
2017-10-18 14:56:10 -07:00
|
|
|
|
|
2018-07-12 09:22:28 -07:00
|
|
|
|
printerManufacturerSelector = new BoundDropList(string.Format("- {0} -", "Select Make".Localize()), theme, maxHeight: 200)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2016-06-01 14:00:47 -07:00
|
|
|
|
Margin = elementMargin,
|
|
|
|
|
|
Name = "Select Make",
|
2016-09-29 14:27:42 -07:00
|
|
|
|
ListSource = OemSettings.Instance.AllOems,
|
|
|
|
|
|
TabStop = true
|
2016-06-01 14:00:47 -07:00
|
|
|
|
};
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2016-06-01 14:00:47 -07:00
|
|
|
|
printerManufacturerSelector.SelectionChanged += ManufacturerDropList_SelectionChanged;
|
|
|
|
|
|
|
|
|
|
|
|
printerMakeContainer = CreateSelectionContainer(
|
|
|
|
|
|
"Make".Localize() + ":",
|
2018-06-19 15:13:54 -07:00
|
|
|
|
"Select the printer manufacturer".Localize(),
|
2016-06-01 14:00:47 -07:00
|
|
|
|
printerManufacturerSelector);
|
|
|
|
|
|
|
2018-07-12 09:22:28 -07:00
|
|
|
|
printerModelSelector = new BoundDropList(string.Format("- {0} -", "Select Model".Localize()), theme, maxHeight: 200)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-06-01 14:00:47 -07:00
|
|
|
|
Name = "Select Model",
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2016-06-01 14:00:47 -07:00
|
|
|
|
Margin = elementMargin,
|
2016-09-29 14:27:42 -07:00
|
|
|
|
TabStop = true
|
2016-06-01 14:00:47 -07:00
|
|
|
|
};
|
|
|
|
|
|
printerModelSelector.SelectionChanged += ModelDropList_SelectionChanged;
|
|
|
|
|
|
|
2018-10-13 17:40:59 -07:00
|
|
|
|
printerModelContainer = CreateSelectionContainer(
|
|
|
|
|
|
"Model".Localize() + ":",
|
|
|
|
|
|
"Select the printer model".Localize(),
|
|
|
|
|
|
printerModelSelector);
|
2016-06-01 14:00:47 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
//Add inputs to main container
|
2018-10-13 17:40:59 -07:00
|
|
|
|
addPrinterColumn.AddChild(printerMakeContainer);
|
|
|
|
|
|
addPrinterColumn.AddChild(printerModelContainer);
|
|
|
|
|
|
addPrinterColumn.AddChild(createPrinterNameContainer());
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-10-13 17:40:59 -07:00
|
|
|
|
RadioButton signInRadioButton = null;
|
|
|
|
|
|
|
|
|
|
|
|
if (userIsLoggedIn)
|
|
|
|
|
|
{
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.AddChild(addPrinterColumn);
|
2018-10-13 17:40:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2018-10-07 11:36:52 -07:00
|
|
|
|
{
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.Padding = 10;
|
2018-10-13 17:40:59 -07:00
|
|
|
|
addPrinterColumn.Margin = new BorderDouble(28, 15, 15, 5);
|
|
|
|
|
|
|
|
|
|
|
|
var commonMargin = new BorderDouble(4, 2);
|
|
|
|
|
|
|
|
|
|
|
|
// Create export button for each plugin
|
2018-11-03 09:13:07 -07:00
|
|
|
|
signInRadioButton = new RadioButton(new RadioButtonViewText("Sign in to access your existing printers".Localize(), theme.TextColor))
|
2018-10-07 11:36:52 -07:00
|
|
|
|
{
|
2018-10-13 17:40:59 -07:00
|
|
|
|
HAnchor = HAnchor.Left,
|
|
|
|
|
|
Margin = commonMargin.Clone(bottom: 10),
|
|
|
|
|
|
Cursor = Cursors.Hand,
|
|
|
|
|
|
Name = "Sign In Radio Button",
|
2018-10-07 11:36:52 -07:00
|
|
|
|
};
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.AddChild(signInRadioButton);
|
2018-10-07 11:36:52 -07:00
|
|
|
|
|
2018-11-03 09:13:07 -07:00
|
|
|
|
createPrinterRadioButton = new RadioButton(new RadioButtonViewText("Create a new printer", theme.TextColor))
|
2018-10-13 17:40:59 -07:00
|
|
|
|
{
|
|
|
|
|
|
HAnchor = HAnchor.Left,
|
|
|
|
|
|
Margin = commonMargin,
|
|
|
|
|
|
Cursor = Cursors.Hand,
|
|
|
|
|
|
Name = "Create Printer Radio Button",
|
|
|
|
|
|
Checked = true
|
|
|
|
|
|
};
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.AddChild(createPrinterRadioButton);
|
2018-10-07 11:36:52 -07:00
|
|
|
|
|
2018-10-13 17:40:59 -07:00
|
|
|
|
createPrinterRadioButton.CheckedStateChanged += (s, e) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
addPrinterColumn.Enabled = createPrinterRadioButton.Checked;
|
|
|
|
|
|
this.SetElementVisibility();
|
|
|
|
|
|
};
|
|
|
|
|
|
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.AddChild(addPrinterColumn);
|
2018-10-13 17:40:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nextButton = theme.CreateDialogButton("Next".Localize());
|
|
|
|
|
|
nextButton.Name = "Next Button";
|
|
|
|
|
|
nextButton.Click += (s, e) => UiThread.RunOnIdle(async () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if (signInRadioButton?.Checked == true)
|
2018-10-07 11:36:52 -07:00
|
|
|
|
{
|
2018-10-16 16:00:06 -07:00
|
|
|
|
var authContext = new AuthenticationContext();
|
|
|
|
|
|
authContext.SignInComplete += (s2, e2) =>
|
|
|
|
|
|
{
|
2018-11-12 08:30:03 -08:00
|
|
|
|
this.DialogWindow.ChangeToPage(new OpenPrinterPage("Finish".Localize()));
|
2018-10-16 16:00:06 -07:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
this.DialogWindow.ChangeToPage(ApplicationController.GetAuthPage(authContext));
|
2018-10-13 17:40:59 -07:00
|
|
|
|
}
|
|
|
|
|
|
else
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2018-10-13 17:40:59 -07:00
|
|
|
|
bool controlsValid = this.ValidateControls();
|
|
|
|
|
|
if (controlsValid)
|
2016-10-04 14:40:59 -07:00
|
|
|
|
{
|
2018-11-15 15:34:13 -08:00
|
|
|
|
var printer = await ProfileManager.CreatePrinterAsync(activeMake, activeModel, activeName);
|
2018-10-13 17:40:59 -07:00
|
|
|
|
if (printer == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.printerNameError.Text = "Error creating profile".Localize();
|
|
|
|
|
|
this.printerNameError.Visible = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2016-10-04 14:40:59 -07:00
|
|
|
|
|
2018-10-13 17:40:59 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
|
|
|
|
|
{
|
2018-12-15 08:53:46 -08:00
|
|
|
|
DialogWindow.ChangeToPage(AppContext.Platform.GetConnectDevicePage(printer) as DialogPage);
|
2018-10-13 17:40:59 -07:00
|
|
|
|
});
|
|
|
|
|
|
}
|
2016-04-18 11:31:31 -07:00
|
|
|
|
}
|
2018-10-13 17:40:59 -07:00
|
|
|
|
});
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2017-08-23 17:27:30 -07:00
|
|
|
|
this.AddPageAction(nextButton);
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2014-10-31 09:36:30 -07:00
|
|
|
|
usingDefaultName = true;
|
|
|
|
|
|
|
2016-11-28 15:56:17 -08:00
|
|
|
|
if (printerManufacturerSelector.MenuItems.Count == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
printerManufacturerSelector.SelectedIndex = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
SetElementVisibility();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-04-18 11:31:31 -07:00
|
|
|
|
private void SetElementVisibility()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2018-10-13 17:40:59 -07:00
|
|
|
|
nextButton.Enabled = createPrinterRadioButton == null
|
|
|
|
|
|
|| !createPrinterRadioButton.Checked
|
|
|
|
|
|
|| (createPrinterRadioButton.Checked && (activeModel != null && this.activeMake != null));
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
private FlowLayoutWidget createPrinterNameContainer()
|
|
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
TextWidget printerNameLabel = new TextWidget("Name".Localize() + ":", 0, 0, 12)
|
|
|
|
|
|
{
|
2018-11-03 09:13:07 -07:00
|
|
|
|
TextColor = theme.TextColor,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2016-09-22 16:34:06 -07:00
|
|
|
|
Margin = new BorderDouble(0, 4, 0, 1)
|
2016-04-18 11:31:31 -07:00
|
|
|
|
};
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2018-10-14 20:05:37 -07:00
|
|
|
|
printerNameInput = new MHTextEditWidget("", theme)
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2016-04-18 11:31:31 -07:00
|
|
|
|
};
|
|
|
|
|
|
printerNameInput.KeyPressed += (s, e) => this.usingDefaultName = false;
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-05-03 18:22:59 -07:00
|
|
|
|
printerNameError = new TextWidget("", 0, 0, 10)
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2018-11-03 09:13:07 -07:00
|
|
|
|
TextColor = theme.TextColor,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2016-04-18 11:31:31 -07:00
|
|
|
|
Margin = new BorderDouble(top: 3)
|
|
|
|
|
|
};
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2018-07-12 09:22:28 -07:00
|
|
|
|
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
|
|
|
|
|
{
|
|
|
|
|
|
Margin = new BorderDouble(0, 5),
|
|
|
|
|
|
HAnchor = HAnchor.Stretch
|
|
|
|
|
|
};
|
2015-04-08 15:20:10 -07:00
|
|
|
|
container.AddChild(printerNameLabel);
|
|
|
|
|
|
container.AddChild(printerNameInput);
|
|
|
|
|
|
container.AddChild(printerNameError);
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-07-12 09:22:28 -07:00
|
|
|
|
private FlowLayoutWidget CreateSelectionContainer(string labelText, string validationMessage, DropDownList selector)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-06-01 14:00:47 -07:00
|
|
|
|
var sectionLabel = new TextWidget(labelText, 0, 0, 12)
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2018-11-03 09:13:07 -07:00
|
|
|
|
TextColor = theme.TextColor,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2016-04-18 11:31:31 -07:00
|
|
|
|
Margin = elementMargin
|
|
|
|
|
|
};
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-06-01 14:00:47 -07:00
|
|
|
|
var validationTextWidget = new TextWidget(validationMessage, 0, 0, 10)
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2018-10-15 18:25:53 -07:00
|
|
|
|
TextColor = theme.PrimaryAccentColor,
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch,
|
2016-04-18 11:31:31 -07:00
|
|
|
|
Margin = elementMargin
|
|
|
|
|
|
};
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-06-01 14:00:47 -07:00
|
|
|
|
selector.SelectionChanged += (s, e) =>
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2016-06-01 14:00:47 -07:00
|
|
|
|
validationTextWidget.Visible = selector.SelectedLabel.StartsWith("-"); // The default values have "- Title -"
|
2016-04-18 11:31:31 -07:00
|
|
|
|
};
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-06-01 14:00:47 -07:00
|
|
|
|
var container = new FlowLayoutWidget(FlowDirection.TopToBottom)
|
2016-04-18 11:31:31 -07:00
|
|
|
|
{
|
2016-06-01 14:00:47 -07:00
|
|
|
|
Margin = new BorderDouble(0, 5),
|
2017-08-07 15:47:27 -07:00
|
|
|
|
HAnchor = HAnchor.Stretch
|
2016-04-18 11:31:31 -07:00
|
|
|
|
};
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2016-06-01 14:00:47 -07:00
|
|
|
|
container.AddChild(sectionLabel);
|
|
|
|
|
|
container.AddChild(selector);
|
|
|
|
|
|
container.AddChild(validationTextWidget);
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
return container;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ManufacturerDropList_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2016-07-29 13:47:58 -07:00
|
|
|
|
activeMake = ((DropDownList)sender).SelectedValue;
|
2016-06-14 11:28:13 -07:00
|
|
|
|
activeModel = null;
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2016-07-29 13:47:58 -07:00
|
|
|
|
// Select the dictionary containing the printerName->printerToken mappings for the current OEM
|
2016-09-01 17:24:09 -07:00
|
|
|
|
Dictionary<string, PublicDevice> printers;
|
2016-06-14 11:28:13 -07:00
|
|
|
|
if (!OemSettings.Instance.OemProfiles.TryGetValue(activeMake, out printers))
|
2016-06-02 14:19:24 -07:00
|
|
|
|
{
|
2016-07-29 13:47:58 -07:00
|
|
|
|
// Fall back to an empty dictionary if no match
|
2016-09-01 17:24:09 -07:00
|
|
|
|
printers = new Dictionary<string, PublicDevice>();
|
2016-06-02 14:19:24 -07:00
|
|
|
|
}
|
2016-06-01 14:00:47 -07:00
|
|
|
|
|
2016-07-29 13:47:58 -07:00
|
|
|
|
// Models - sort dictionary results by key and assign to .ListSource
|
2016-09-01 17:24:09 -07:00
|
|
|
|
printerModelSelector.ListSource = printers.OrderBy(p => p.Key).Select(p => new KeyValuePair<string, string>(p.Key, p.Value.ProfileToken)).ToList();
|
2016-07-15 17:15:25 -07:00
|
|
|
|
if (printerModelSelector.MenuItems.Count == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
printerModelSelector.SelectedIndex = 0;
|
|
|
|
|
|
}
|
2015-11-02 17:54:26 -08:00
|
|
|
|
|
2018-11-03 10:12:27 -07:00
|
|
|
|
contentRow.Invalidate();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
|
2016-06-01 14:00:47 -07:00
|
|
|
|
SetElementVisibility();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void ModelDropList_SelectionChanged(object sender, EventArgs e)
|
|
|
|
|
|
{
|
2015-06-11 12:06:40 -07:00
|
|
|
|
UiThread.RunOnIdle(() =>
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-06-03 18:11:51 -07:00
|
|
|
|
DropDownList dropList = (DropDownList) sender;
|
2016-06-14 11:28:13 -07:00
|
|
|
|
activeModel = dropList.SelectedLabel;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
|
|
|
|
|
SetElementVisibility();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
if (usingDefaultName)
|
|
|
|
|
|
{
|
2016-06-14 11:28:13 -07:00
|
|
|
|
// Use ManufacturerDropList.SelectedLabel instead of activeMake to ensure the mapped Unicode values are picked up
|
2016-06-01 14:00:47 -07:00
|
|
|
|
string mappedMakeText = printerManufacturerSelector.SelectedLabel;
|
2016-02-04 12:13:56 -08:00
|
|
|
|
|
2016-10-04 18:35:24 -07:00
|
|
|
|
var existingPrinterNames = ProfileManager.Instance.ActiveProfiles.Select(p => p.Name);
|
2017-12-06 16:29:31 -08:00
|
|
|
|
printerNameInput.Text = agg_basics.GetNonCollidingName($"{mappedMakeText} {activeModel}", existingPrinterNames);
|
2015-04-08 15:20:10 -07:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2014-01-29 19:09:30 -08:00
|
|
|
|
|
2016-10-04 14:40:59 -07:00
|
|
|
|
private bool ValidateControls()
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-04-18 11:31:31 -07:00
|
|
|
|
if (!string.IsNullOrEmpty(printerNameInput.Text))
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
2016-06-14 11:28:13 -07:00
|
|
|
|
activeName = printerNameInput.Text;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
2016-06-14 11:28:13 -07:00
|
|
|
|
if (this.activeMake == null || activeModel == null)
|
2015-04-08 15:20:10 -07:00
|
|
|
|
{
|
|
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2017-10-31 11:43:25 -07:00
|
|
|
|
this.printerNameError.TextColor = Color.Red;
|
2016-10-04 14:40:59 -07:00
|
|
|
|
this.printerNameError.Text = "Printer name cannot be blank".Localize();
|
2015-04-08 15:20:10 -07:00
|
|
|
|
this.printerNameError.Visible = true;
|
2016-04-18 11:31:31 -07:00
|
|
|
|
|
2015-04-08 15:20:10 -07:00
|
|
|
|
return false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|