@@ -14,8 +14,11 @@ import ScriptEditor 1.0
1414Item {
1515 id: root
1616
17+ // Defines the parent or the root Application of which this script editor is a part of
18+ property var rootApplication: undefined ;
19+
1720 function replace (text , string , replacement ) {
18- /*
21+ /**
1922 * Replaces all occurences of the string in the text
2023 * @param text - overall text
2124 * @param string - the string to be replaced in the text
2831 }
2932
3033 function formatInput (text ) {
31- /*
34+ /**
3235 * Formats the text to be displayed as the input script executed
3336 */
3437
@@ -37,14 +40,38 @@ Item {
3740 }
3841
3942 function formatOutput (text ) {
40- /*
43+ /**
4144 * Formats the text to be displayed as the result of the script executed
4245 */
4346
4447 // Replace the text to be RichText Supportive
4548 return " <font color=#49a1f3>" + " Result: " + replace (text, " \n " , " <br>" ) + " </font><br><br>"
4649 }
4750
51+ Component {
52+ id: clearConfirmationDialog
53+
54+ MessageDialog {
55+ title: " Clear history"
56+
57+ preset: " Warning"
58+ text: " This will clear all history of executed scripts."
59+ helperText: " Are you sure you would like to continue?."
60+
61+ standardButtons: Dialog .Ok | Dialog .Cancel
62+ onClosed: destroy ()
63+ }
64+ }
65+
66+ function clearHistory () {
67+ /**
68+ * Clears all of the executed history from the script editor
69+ */
70+ ScriptEditorManager .clearHistory ()
71+ input .clear ()
72+ output .clear ()
73+ }
74+
4875 function processScript (text = " " ) {
4976 // Use either the provided/selected or the entire script
5077 text = text || input .text
@@ -117,7 +144,7 @@ Item {
117144
118145 MaterialToolButton {
119146 font .pointSize : 18
120- text: MaterialIcons .download
147+ text: MaterialIcons .file_open
121148 ToolTip .text : " Load Script"
122149
123150 onClicked: {
@@ -127,7 +154,7 @@ Item {
127154
128155 MaterialToolButton {
129156 font .pointSize : 18
130- text: MaterialIcons .upload
157+ text: MaterialIcons .save
131158 ToolTip .text : " Save Script"
132159
133160 onClicked: {
@@ -142,7 +169,7 @@ Item {
142169 MaterialToolButton {
143170 id: executeButton
144171 font .pointSize : 18
145- text: MaterialIcons .slideshow
172+ text: MaterialIcons .play_arrow
146173 ToolTip .text : " Execute Script"
147174
148175 onClicked: {
@@ -152,7 +179,7 @@ Item {
152179
153180 MaterialToolButton {
154181 font .pointSize : 18
155- text: MaterialIcons .cancel_presentation
182+ text: MaterialIcons .backspace
156183 ToolTip .text : " Clear Output Window"
157184
158185 onClicked: {
@@ -196,13 +223,14 @@ Item {
196223
197224 MaterialToolButton {
198225 font .pointSize : 18
199- text: MaterialIcons .backspace
226+ text: MaterialIcons .delete_sweep
200227 ToolTip .text : " Clear History"
201228
202229 onClicked: {
203- ScriptEditorManager .clearHistory ()
204- input .clear ()
205- output .clear ()
230+ // Confirm from the user before clearing out any history
231+ const confirmationDialog = clearConfirmationDialog .createObject (rootApplication ? rootApplication : root);
232+ confirmationDialog .accepted .connect (clearHistory);
233+ confirmationDialog .open ();
206234 }
207235 }
208236
@@ -293,7 +321,7 @@ Item {
293321 root .forceActiveFocus ()
294322 }
295323
296- Keys .onPressed : {
324+ Keys .onPressed : ( event ) => {
297325 if ((event .key === Qt .Key_Enter || event .key === Qt .Key_Return ) && event .modifiers === Qt .ControlModifier ) {
298326 processScript (input .selectedText )
299327 }
0 commit comments