2020-10-04 10:57:55 -07:00
/ *
Copyright ( c ) 2020 , Kevin Pope , John Lewin , Lars Brubaker
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 ;
using System.Collections.Generic ;
using System.Linq ;
using Markdig.Agg ;
using MatterHackers.Agg ;
2020-10-25 23:11:59 -07:00
using MatterHackers.Agg.Platform ;
2020-10-04 10:57:55 -07:00
using MatterHackers.Agg.UI ;
2021-05-21 15:23:25 -07:00
using MatterHackers.ImageProcessing ;
2020-10-04 10:57:55 -07:00
using MatterHackers.Localizations ;
using MatterHackers.MatterControl.DataStorage ;
using MatterHackers.MatterControl.PartPreviewWindow ;
2020-10-26 16:40:36 -07:00
using MatterHackers.MatterControl.SlicerConfiguration ;
2020-10-04 10:57:55 -07:00
using MatterHackers.VectorMath ;
namespace MatterHackers.MatterControl.PrintHistory
{
public class PrintHistoryEditor
{
2020-10-25 15:45:51 -07:00
private readonly PrinterConfig printer ;
2020-10-25 08:48:43 -07:00
private readonly ThemeConfig theme ;
private readonly PrintTask printTask ;
private readonly IEnumerable < PrintTask > printTasks ;
2020-10-04 10:57:55 -07:00
2020-10-25 15:45:51 -07:00
public PrintHistoryEditor ( PrinterConfig printer , ThemeConfig theme , PrintTask printTask , IEnumerable < PrintTask > printTasks )
2020-10-04 10:57:55 -07:00
{
2020-10-25 15:45:51 -07:00
this . printer = printer ;
2020-10-04 10:57:55 -07:00
this . theme = theme ;
this . printTask = printTask ;
this . printTasks = printTasks ;
}
public static readonly string [ ] QualityNames = new string [ ]
{
"Failed" . Localize ( ) ,
"Terrible" . Localize ( ) ,
"Bad" . Localize ( ) ,
"Good" . Localize ( ) ,
"Great" . Localize ( ) ,
} ;
public void AddNotesMenu ( PopupMenu popupMenu , IEnumerable < PrintTask > printTasks , Action notesChanged )
{
2020-10-26 11:25:18 -07:00
var addNote = popupMenu . CreateMenuItem ( string . IsNullOrEmpty ( printTask . Note ) ? "Add Note..." . Localize ( ) : "Edit Note..." . Localize ( ) ) ;
addNote . Enabled = printTasks . Any ( ) ;
addNote . Click + = ( s , e ) = >
2020-10-04 10:57:55 -07:00
{
var inputBoxPage = new InputBoxPage (
"Print History Note" . Localize ( ) ,
2020-10-26 16:40:36 -07:00
"" ,
2020-10-25 08:48:43 -07:00
printTask . Note ? ? "" ,
2020-10-04 10:57:55 -07:00
"Enter Note Here" . Localize ( ) ,
string . IsNullOrEmpty ( printTask . Note ) ? "Add Note" . Localize ( ) : "Update" . Localize ( ) ,
( newNote ) = >
{
printTask . Note = newNote ;
2020-10-23 16:57:26 -07:00
printTask . CommitAndPushToServer ( ) ;
2020-10-04 10:57:55 -07:00
popupMenu . Unfocus ( ) ;
notesChanged ( ) ;
} )
{
AllowEmpty = true ,
} ;
2020-11-08 18:39:16 -08:00
inputBoxPage . ContentRow . AddChild ( CreateDefaultOptions ( inputBoxPage . TextEditWidget , theme , null ) , 0 ) ;
2020-10-04 10:57:55 -07:00
DialogWindow . Show ( inputBoxPage ) ;
inputBoxPage . Parent . Height + = 40 * GuiWidget . DeviceScale ;
} ;
}
2020-10-06 22:00:28 -07:00
public static GuiWidget GetQualityWidget ( ThemeConfig theme , PrintTask printTask , Action clicked , double buttonFontSize )
2020-10-04 10:57:55 -07:00
{
var content = new FlowLayoutWidget ( )
{
HAnchor = HAnchor . Fit | HAnchor . Stretch
} ;
2020-10-30 07:48:25 -07:00
var siblings = new List < GuiWidget > ( ) ;
2020-10-04 10:57:55 -07:00
2020-10-25 15:45:51 -07:00
var textWidget = new TextWidget ( "Print Quality" . Localize ( ) + ":" , pointSize : theme . DefaultFontSize , textColor : theme . TextColor )
{
VAnchor = VAnchor . Center
} ;
2020-10-04 10:57:55 -07:00
content . AddChild ( textWidget ) ;
2020-10-25 23:11:59 -07:00
var size = ( int ) ( buttonFontSize * GuiWidget . DeviceScale ) ;
2021-05-21 15:23:25 -07:00
var star = StaticData . Instance . LoadIcon ( "star.png" , size , size ) . SetToColor ( theme . TextColor ) ;
var openStar = StaticData . Instance . LoadIcon ( "open_star.png" , size , size ) . SetToColor ( theme . TextColor ) ;
var failure = StaticData . Instance . LoadIcon ( "failure.png" , size , size ) . SetToColor ( theme . TextColor ) ;
2020-10-25 23:11:59 -07:00
content . AddChild ( new GuiWidget ( size , 1 ) ) ;
2020-10-04 10:57:55 -07:00
2020-10-30 07:48:25 -07:00
content . MouseLeaveBounds + = ( s , e ) = >
{
SetStarState ( theme , siblings , printTask ) ;
} ;
2020-10-04 10:57:55 -07:00
for ( int i = 0 ; i < QualityNames . Length ; i + + )
{
2020-10-30 07:48:25 -07:00
var buttonIndex = i ;
GuiWidget buttonContent ;
if ( i = = 0 )
{
buttonContent = new ImageWidget ( failure ) ;
}
else
{
buttonContent = new GuiWidget ( )
{
HAnchor = HAnchor . Fit ,
VAnchor = VAnchor . Fit
} ;
buttonContent . AddChild ( new ImageWidget ( openStar )
{
Name = "open"
} ) ;
buttonContent . AddChild ( new ImageWidget ( star )
{
Name = "closed" ,
Visible = false
} ) ;
}
var button = new RadioButton ( buttonContent )
2020-10-04 10:57:55 -07:00
{
Enabled = printTask . PrintComplete ,
Checked = printTask . QualityWasSet & & printTask . PrintQuality = = i ,
ToolTipText = QualityNames [ i ] ,
Margin = 0 ,
Padding = 5 ,
HAnchor = HAnchor . Fit ,
VAnchor = VAnchor . Fit ,
} ;
button . MouseEnterBounds + = ( s , e ) = >
{
2020-10-30 07:48:25 -07:00
// set the correct filled stars for the hover
for ( int j = 0 ; j < siblings . Count ; j + + )
{
var open = siblings [ j ] . Descendants ( ) . Where ( d = > d . Name = = "open" ) . FirstOrDefault ( ) ;
var closed = siblings [ j ] . Descendants ( ) . Where ( d = > d . Name = = "closed" ) . FirstOrDefault ( ) ;
2020-10-04 10:57:55 -07:00
2020-10-30 07:48:25 -07:00
if ( j = = 0 )
{
if ( buttonIndex = = 0 )
{
siblings [ j ] . BackgroundColor = theme . AccentMimimalOverlay ;
}
else
{
siblings [ j ] . BackgroundColor = Color . Transparent ;
}
}
else if ( j < = buttonIndex )
{
siblings [ j ] . BackgroundColor = theme . AccentMimimalOverlay ;
}
else
{
siblings [ j ] . BackgroundColor = Color . Transparent ;
}
if ( j < = buttonIndex )
{
if ( open ! = null )
{
open . Visible = false ;
closed . Visible = true ;
}
}
else
{
if ( open ! = null )
{
open . Visible = true ;
closed . Visible = false ;
}
}
}
2020-10-04 10:57:55 -07:00
} ;
siblings . Add ( button ) ;
button . SiblingRadioButtonList = siblings ;
content . AddChild ( button ) ;
button . Click + = ( s , e ) = >
{
printTask . PrintQuality = siblings . IndexOf ( ( GuiWidget ) s ) ;
printTask . QualityWasSet = true ;
2020-10-23 16:57:26 -07:00
printTask . CommitAndPushToServer ( ) ;
2020-10-04 22:21:17 -07:00
clicked ( ) ;
2020-10-04 10:57:55 -07:00
} ;
}
2020-10-30 07:48:25 -07:00
SetStarState ( theme , siblings , printTask ) ;
2020-10-04 22:21:17 -07:00
return content ;
2020-10-04 10:57:55 -07:00
}
2020-10-30 07:48:25 -07:00
private static void SetStarState ( ThemeConfig theme , List < GuiWidget > siblings , PrintTask printTask )
{
var checkedButton = - 1 ;
if ( printTask . QualityWasSet )
{
checkedButton = printTask . PrintQuality ;
}
for ( int j = 0 ; j < siblings . Count ; j + + )
{
var open = siblings [ j ] . Descendants ( ) . Where ( d = > d . Name = = "open" ) . FirstOrDefault ( ) ;
var closed = siblings [ j ] . Descendants ( ) . Where ( d = > d . Name = = "closed" ) . FirstOrDefault ( ) ;
if ( j = = 0 )
{
if ( checkedButton = = 0 )
{
siblings [ j ] . BackgroundColor = theme . AccentMimimalOverlay ;
}
else
{
siblings [ j ] . BackgroundColor = Color . Transparent ;
}
}
else if ( j < = checkedButton )
{
siblings [ j ] . BackgroundColor = theme . AccentMimimalOverlay ;
}
else
{
siblings [ j ] . BackgroundColor = Color . Transparent ;
}
if ( j < = checkedButton )
{
if ( open ! = null )
{
open . Visible = false ;
closed . Visible = true ;
}
}
else
{
if ( open ! = null )
{
open . Visible = true ;
closed . Visible = false ;
}
}
}
}
2020-11-08 18:39:16 -08:00
public static GuiWidget CreateDefaultOptions ( GuiWidget textField , ThemeConfig theme , Action selectionChanged )
2020-10-04 10:57:55 -07:00
{
2020-11-08 18:39:16 -08:00
var selectString = "- " + "What went wrong?" . Localize ( ) + " -" ;
var menuButton = new PopupMenuButton ( selectString , theme ) ;
var menuButtonText = menuButton . Descendants < TextWidget > ( ) . First ( ) ;
menuButtonText . AutoExpandBoundsToText = true ;
2020-10-04 10:57:55 -07:00
2021-07-23 18:19:57 -07:00
void AddSelection ( PopupMenu menu , string text , string helpUrl = "" , bool other = false )
2020-10-04 10:57:55 -07:00
{
2020-11-08 18:39:16 -08:00
var menuItem = menu . CreateMenuItem ( text ) ;
2020-10-04 10:57:55 -07:00
2020-11-08 18:39:16 -08:00
menuItem . Click + = ( s , e ) = >
2020-10-04 10:57:55 -07:00
{
2021-07-23 18:19:57 -07:00
textField . Name = helpUrl ;
var markdownWidget = textField . Parents < SystemWindow > ( ) . First ( ) . Descendants < MarkdownWidget > ( ) . LastOrDefault ( ) ;
if ( markdownWidget ! = null )
{
markdownWidget . Markdown = textField . Name ;
markdownWidget . Visible = ! string . IsNullOrEmpty ( markdownWidget . Markdown ) ;
}
2020-11-08 18:39:16 -08:00
if ( other )
2020-10-26 16:40:36 -07:00
{
textField . Text = "" ;
textField . Visible = true ;
UiThread . RunOnIdle ( textField . Focus ) ;
2020-11-08 18:39:16 -08:00
menuButtonText . Text = "Other" . Localize ( ) + "..." ;
2020-10-26 16:40:36 -07:00
}
else
{
2020-11-08 18:39:16 -08:00
textField . Text = text ;
2020-10-26 16:40:36 -07:00
textField . Visible = false ;
2020-11-08 18:39:16 -08:00
menuButtonText . Text = textField . Text ;
2020-10-26 16:40:36 -07:00
}
2020-11-08 18:39:16 -08:00
selectionChanged ? . Invoke ( ) ;
2020-10-04 10:57:55 -07:00
} ;
}
2021-07-23 18:19:57 -07:00
string TroubleShooting ( string type , int issue )
{
return $"For help with {type} and other issues, please read MatterHackers [Troubleshooting Guide](https://www.matterhackers.com/articles/3d-printer-troubleshooting-guide#Issue{issue})" ;
}
2020-11-08 18:39:16 -08:00
menuButton . DynamicPopupContent = ( ) = >
{
var popupMenu = new PopupMenu ( ApplicationController . Instance . MenuTheme ) ;
popupMenu . CreateSubMenu ( "First Layer" . Localize ( ) ,
theme ,
( menu ) = >
{
2021-07-23 18:19:57 -07:00
AddSelection ( menu , "First Layer Bad Quality" . Localize ( ) , TroubleShooting ( "the first layer" , 1 ) ) ;
AddSelection ( menu , "Initial Z Height Incorrect" . Localize ( ) , TroubleShooting ( "initial Z height" , 1 ) ) ;
2020-11-08 18:39:16 -08:00
} ) ;
popupMenu . CreateSubMenu ( "Quality" . Localize ( ) ,
theme ,
( menu ) = >
{
2021-07-23 18:19:57 -07:00
AddSelection ( menu , "General Quality" . Localize ( ) , TroubleShooting ( "general quality" , 100 ) ) ;
2020-11-08 18:39:16 -08:00
AddSelection ( menu , "Rough Overhangs" . Localize ( ) ) ;
AddSelection ( menu , "Skipped Layers" . Localize ( ) ) ;
2021-07-23 18:19:57 -07:00
AddSelection ( menu , "Some Parts Lifted" . Localize ( ) , TroubleShooting ( "lifting" , 6 ) ) ;
AddSelection ( menu , "Stringing / Poor retractions" . Localize ( ) , TroubleShooting ( "stringing" , 9 ) ) ;
AddSelection ( menu , "Warping" . Localize ( ) , TroubleShooting ( "warping" , 6 ) ) ;
AddSelection ( menu , "Dislodged From Bed" . Localize ( ) , TroubleShooting ( "adhesion" , 2 ) ) ;
AddSelection ( menu , "Layer Shift" . Localize ( ) , TroubleShooting ( "layer shifting" , 8 ) ) ;
2020-11-08 18:39:16 -08:00
} ) ;
popupMenu . CreateSubMenu ( "Mechanical" . Localize ( ) ,
theme ,
( menu ) = >
{
AddSelection ( menu , "Bed Dislodged" . Localize ( ) ) ;
AddSelection ( menu , "Bowden Tube Popped Out" . Localize ( ) ) ;
2021-07-23 18:19:57 -07:00
AddSelection ( menu , "Extruder Slipping" . Localize ( ) , TroubleShooting ( "the extruder" , 13 ) ) ;
2020-11-08 18:39:16 -08:00
AddSelection ( menu , "Flooded Hot End" . Localize ( ) ) ;
AddSelection ( menu , "Power Outage" . Localize ( ) ) ;
} ) ;
2021-12-20 12:19:32 -08:00
popupMenu . CreateSubMenu ( "Computer / MatterControl" . Localize ( ) + " " ,
2020-11-08 18:39:16 -08:00
theme ,
( menu ) = >
{
AddSelection ( menu , "Computer Crashed" . Localize ( ) ) ;
AddSelection ( menu , "Computer Slow / Lagging" . Localize ( ) ) ;
AddSelection ( menu , "Couldn't Resume" . Localize ( ) ) ;
AddSelection ( menu , "Wouldn’ t Slice Correctly" . Localize ( ) ) ;
} ) ;
popupMenu . CreateSubMenu ( "Filament" . Localize ( ) ,
theme ,
( menu ) = >
{
AddSelection ( menu , "Filament Jam" . Localize ( ) ) ;
AddSelection ( menu , "Filament Runout" . Localize ( ) ) ;
AddSelection ( menu , "Filament Snapped" . Localize ( ) ) ;
} ) ;
popupMenu . CreateSubMenu ( "Heating" . Localize ( ) ,
theme ,
( menu ) = >
{
AddSelection ( menu , "Thermal Runaway - Bed" . Localize ( ) ) ;
AddSelection ( menu , "Thermal Runaway - Hot End" . Localize ( ) ) ;
AddSelection ( menu , "Heating" . Localize ( ) ) ;
AddSelection ( menu , "Took Too Long To Heat" . Localize ( ) ) ;
AddSelection ( menu , "Bad Thermistor" . Localize ( ) ) ;
AddSelection ( menu , "Bad Thermistor" . Localize ( ) ) ;
} ) ;
AddSelection ( popupMenu , "Test Print" . Localize ( ) ) ;
AddSelection ( popupMenu , "User Error" . Localize ( ) ) ;
2021-07-23 18:19:57 -07:00
AddSelection ( popupMenu , "Other" . Localize ( ) , "" , true ) ;
2020-11-08 18:39:16 -08:00
return popupMenu ;
} ;
textField . Visible = false ;
menuButton . VAnchor = VAnchor . Fit ;
return menuButton ;
2020-10-04 10:57:55 -07:00
}
2020-10-25 15:45:51 -07:00
private static string articles = @ "
- [ MatterControl Tutorials ] ( https : //www.matterhackers.com/store/l/mattercontrol/sk/MKZGTDW6#tutorials)
- [ Trick , Tips & Support Articles ] ( https : //www.matterhackers.com/topic/tips-and-tricks)
- [ MatterControl Articles ] ( https : //www.matterhackers.com/topic/mattercontrol)
2020-10-04 10:57:55 -07:00
- [ MatterControl Docs ] ( https : //www.matterhackers.com/mattercontrol/support)
- [ User Forum ] ( https : //forums.matterhackers.com/recent)";
2020-10-25 15:45:51 -07:00
public void CollectInfoPrintCanceled ( )
{
string markdownText = @"If you need help, here are some links that might be useful." + articles ;
2020-10-06 22:00:28 -07:00
new CollectPrintDetailsPage ( "Print Canceled" . Localize ( ) ,
2020-10-25 15:45:51 -07:00
printer ,
2020-10-25 08:48:43 -07:00
"Oops, looks like you canceled the print." ,
2020-10-04 22:21:17 -07:00
markdownText ,
2020-10-25 08:48:43 -07:00
printTask ,
false ) ;
2020-10-04 10:57:55 -07:00
}
public void CollectInfoPrintFinished ( )
{
// show a long running task asking about print feedback and up-selling more materials
// Ask about the print, offer help if needed.
// Let us know how your print came out.
string markdownText = @ "**Find more at MatterHackers**
Supplies and accessories :
2020-10-25 08:48:43 -07:00
[![Filament] ( https : //lh3.googleusercontent.com/2QmeGU_t2KKvAuXTSCYHq1EQTMHRurwreztY52jGdtRQStAEit7Yjsz_hW9l1akGjun7dVcaCGdHEHdGNIGkKykoMg=w100-h100)](https://www.matterhackers.com/store/c/3d-printer-filament) [](https://www.matterhackers.com/store/c/3d-printer-adhesive) [](https://www.matterhackers.com/store/c/printer-accessories)
2020-10-04 10:57:55 -07:00
2020-10-25 15:45:51 -07:00
Support and tutorials : " + articles;
2020-10-04 10:57:55 -07:00
2020-10-25 15:45:51 -07:00
new CollectPrintDetailsPage ( "Print Complete" . Localize ( ) ,
printer ,
2020-10-25 08:48:43 -07:00
"How did this print come out?" ,
2020-10-06 22:00:28 -07:00
markdownText ,
2020-10-25 08:48:43 -07:00
printTask ,
true ) ;
2020-10-04 10:57:55 -07:00
}
2020-10-25 08:48:43 -07:00
public class CollectPrintDetailsPage : DialogPage
2020-10-04 10:57:55 -07:00
{
2022-07-15 17:28:39 -07:00
private readonly ThemedTextEditWidget textEditWidget ;
2020-10-04 10:57:55 -07:00
2020-10-25 08:48:43 -07:00
public override string Text { get = > textEditWidget . Text ; set = > textEditWidget . Text = value ; }
public CollectPrintDetailsPage ( string windowTitle ,
2020-10-25 15:45:51 -07:00
PrinterConfig printer ,
2020-10-25 08:48:43 -07:00
string topMarkDown ,
string descriptionMarkdown ,
PrintTask printTask ,
bool collectQuality )
2020-10-25 15:45:51 -07:00
: base ( "Close" . Localize ( ) )
2020-10-04 10:57:55 -07:00
{
2020-10-25 08:48:43 -07:00
this . WindowTitle = windowTitle ;
2022-01-27 16:49:46 -08:00
this . HeaderText = printer . PrinterName + ": " + windowTitle ;
2020-10-26 16:40:36 -07:00
this . WindowSize = new Vector2 ( 500 * GuiWidget . DeviceScale , 440 * GuiWidget . DeviceScale ) ;
2020-10-06 22:00:28 -07:00
2020-10-25 08:48:43 -07:00
var scrollable = new ScrollableWidget ( autoScroll : true )
{
HAnchor = HAnchor . Stretch ,
VAnchor = VAnchor . Stretch ,
Margin = new BorderDouble ( bottom : 10 ) ,
} ;
2020-10-06 22:00:28 -07:00
2020-10-25 08:48:43 -07:00
scrollable . ScrollArea . HAnchor = HAnchor . Stretch ;
scrollable . ScrollArea . VAnchor = VAnchor . Fit ;
contentRow . AddChild ( scrollable ) ;
2020-10-04 10:57:55 -07:00
2020-10-25 08:48:43 -07:00
var topToBottom = scrollable . AddChild ( new FlowLayoutWidget ( FlowDirection . TopToBottom )
{
HAnchor = HAnchor . Stretch
} ) ;
2020-10-06 22:00:28 -07:00
2020-10-25 08:48:43 -07:00
topToBottom . AddChild ( new MarkdownWidget ( theme , false )
2020-10-06 22:00:28 -07:00
{
2020-10-25 08:48:43 -07:00
Markdown = topMarkDown ,
} ) ;
2020-10-06 22:00:28 -07:00
2020-10-25 08:48:43 -07:00
var reasonSection = new FlowLayoutWidget ( FlowDirection . TopToBottom )
{
HAnchor = HAnchor . Stretch ,
Visible = ! collectQuality
} ;
2020-10-06 22:00:28 -07:00
2020-10-25 08:48:43 -07:00
if ( collectQuality )
2020-10-06 22:00:28 -07:00
{
2020-10-25 08:48:43 -07:00
var qualityInput = GetQualityWidget ( theme ,
printTask ,
( ) = >
{
reasonSection . Visible = printTask . PrintQuality = = 0 ;
this . Descendants < ScrollableWidget > ( ) . First ( ) . ScrollPositionFromTop = new Vector2 ( 0 , 0 ) ;
} ,
16 ) ;
qualityInput . Margin = new BorderDouble ( 5 , 0 ) ;
qualityInput . HAnchor = HAnchor . Left ;
topToBottom . AddChild ( qualityInput ) ;
2020-10-06 22:00:28 -07:00
}
2020-10-25 08:48:43 -07:00
topToBottom . AddChild ( reasonSection ) ;
// Adds text box and check box to the above container
var emptyText = "What went wrong?" . Localize ( ) ;
var initialValue = printTask . Note ? ? "" ;
2022-07-15 17:28:39 -07:00
textEditWidget = new ThemedTextEditWidget ( initialValue , theme , pixelWidth : 300 , messageWhenEmptyAndNotSelected : emptyText )
2020-10-06 22:00:28 -07:00
{
2020-10-25 08:48:43 -07:00
Name = "InputBoxPage TextEditWidget" ,
HAnchor = HAnchor . Stretch ,
2020-10-26 16:40:36 -07:00
Margin = new BorderDouble ( 5 ) ,
2020-10-25 08:48:43 -07:00
} ;
2020-10-06 22:00:28 -07:00
2020-10-26 11:25:18 -07:00
textEditWidget . ActualTextEditWidget . EditComplete + = ( s , e ) = >
{
printTask . Note = textEditWidget . Text ;
printTask . CommitAndPushToServer ( ) ;
} ;
2020-11-08 18:39:16 -08:00
var dropDownList = CreateDefaultOptions ( textEditWidget , theme , ( ) = >
2020-10-26 11:25:18 -07:00
{
// Delay this so we wait for the text to be updated
UiThread . RunOnIdle ( ( ) = >
{
printTask . Note = textEditWidget . Text ;
printTask . CommitAndPushToServer ( ) ;
} ) ;
2020-11-08 18:39:16 -08:00
} ) ;
dropDownList . Margin = new BorderDouble ( 5 , 0 ) ;
dropDownList . HAnchor | = HAnchor . Left ;
reasonSection . AddChild ( dropDownList ) ;
reasonSection . AddChild ( textEditWidget ) ;
2020-10-04 10:57:55 -07:00
2020-10-25 08:48:43 -07:00
topToBottom . AddChild ( new HorizontalLine ( theme . BorderColor40 )
{
Margin = new BorderDouble ( 0 , 5 )
} ) ;
2020-10-04 10:57:55 -07:00
2020-10-25 08:48:43 -07:00
topToBottom . AddChild ( new MarkdownWidget ( theme , false )
{
Markdown = descriptionMarkdown ,
} ) ;
2020-10-26 11:25:18 -07:00
var collectHistoryHidden = UserSettings . Instance . get ( UserSettingsKey . CollectPrintHistoryData ) = = "false" ;
if ( ! collectHistoryHidden )
2020-10-25 08:48:43 -07:00
{
UiThread . RunOnIdle ( ( ) = >
{
2020-11-02 18:24:19 -08:00
DialogWindow . Show ( this , printTask . Id ) ;
2020-10-25 08:48:43 -07:00
// this will cause a layout that fixes a display issue
2020-10-26 16:40:36 -07:00
scrollable . ScrollArea . BoundsChanged + = ( s , e ) = >
{
scrollable . ScrollPositionFromTop = new Vector2 ( 0 , 0 ) ;
} ;
scrollable . ScrollPositionFromTop = new Vector2 ( 0 , 0 ) ;
2020-10-25 08:48:43 -07:00
} ) ;
}
2020-10-25 15:45:51 -07:00
if ( printer ! = null )
{
var printAgainButton = PrintPopupMenu . CreateStartPrintButton ( "Print Again" , printer , theme , out _ ) ;
printAgainButton . Click + = ( s , e ) = > this . DialogWindow ? . ClosePage ( ) ;
AddPageAction ( printAgainButton ) ;
}
2020-10-25 08:48:43 -07:00
}
public bool AllowEmpty { get ; set ; }
public override void OnLoad ( EventArgs args )
2020-10-04 10:57:55 -07:00
{
2020-10-25 08:48:43 -07:00
UiThread . RunOnIdle ( ( ) = >
{
textEditWidget . Focus ( ) ;
textEditWidget . ActualTextEditWidget . InternalTextEditWidget . SelectAll ( ) ;
} ) ;
base . OnLoad ( args ) ;
}
2020-10-04 10:57:55 -07:00
}
}
}