Skip to content

Commit

Permalink
[ui] ScriptEditor: ScriptEditor gets new icons
Browse files Browse the repository at this point in the history
Updated Icons for ScriptEditor

Script Editor shows a confirmation dialog before clearing history
  • Loading branch information
waaake committed Dec 12, 2024
1 parent 89fe362 commit d0ecb8a
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 12 deletions.
1 change: 1 addition & 0 deletions meshroom/ui/qml/Application.qml
Original file line number Diff line number Diff line change
Expand Up @@ -1225,6 +1225,7 @@ Page {
ScriptEditor {
id: scriptEditor
anchors.fill: parent
rootApplication: root

visible: graphEditorPanel.currentTab === 2
}
Expand Down
52 changes: 40 additions & 12 deletions meshroom/ui/qml/GraphEditor/ScriptEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,26 @@ import ScriptEditor 1.0
Item {
id: root

// Defines the parent or the root Application of which this script editor is a part of
property var rootApplication: undefined;

Component {
id: clearConfirmationDialog

MessageDialog {
title: "Clear history"

preset: "Warning"
text: "This will clear all history of executed scripts."
helperText: "Are you sure you would like to continue?."

standardButtons: Dialog.Ok | Dialog.Cancel
onClosed: destroy()
}
}

function replace(text, string, replacement) {
/*
/**
* Replaces all occurences of the string in the text
* @param text - overall text
* @param string - the string to be replaced in the text
Expand All @@ -28,7 +46,7 @@ Item {
}

function formatInput(text) {
/*
/**
* Formats the text to be displayed as the input script executed
*/

Expand All @@ -37,14 +55,23 @@ Item {
}

function formatOutput(text) {
/*
/**
* Formats the text to be displayed as the result of the script executed
*/

// Replace the text to be RichText Supportive
return "<font color=#49a1f3>" + "Result: " + replace(text, "\n", "<br>") + "</font><br><br>"
}

function clearHistory() {
/**
* Clears all of the executed history from the script editor
*/
ScriptEditorManager.clearHistory()
input.clear()
output.clear()
}

function processScript(text = "") {
// Use either the provided/selected or the entire script
text = text || input.text
Expand Down Expand Up @@ -117,7 +144,7 @@ Item {

MaterialToolButton {
font.pointSize: 18
text: MaterialIcons.download
text: MaterialIcons.file_open
ToolTip.text: "Load Script"

onClicked: {
Expand All @@ -127,7 +154,7 @@ Item {

MaterialToolButton {
font.pointSize: 18
text: MaterialIcons.upload
text: MaterialIcons.save
ToolTip.text: "Save Script"

onClicked: {
Expand All @@ -142,7 +169,7 @@ Item {
MaterialToolButton {
id: executeButton
font.pointSize: 18
text: MaterialIcons.slideshow
text: MaterialIcons.play_arrow
ToolTip.text: "Execute Script"

onClicked: {
Expand All @@ -152,7 +179,7 @@ Item {

MaterialToolButton {
font.pointSize: 18
text: MaterialIcons.cancel_presentation
text: MaterialIcons.backspace
ToolTip.text: "Clear Output Window"

onClicked: {
Expand Down Expand Up @@ -196,13 +223,14 @@ Item {

MaterialToolButton {
font.pointSize: 18
text: MaterialIcons.backspace
text: MaterialIcons.delete_sweep
ToolTip.text: "Clear History"

onClicked: {
ScriptEditorManager.clearHistory()
input.clear()
output.clear()
// Confirm from the user before clearing out any history
const confirmationDialog = clearConfirmationDialog.createObject(rootApplication ? rootApplication : root);
confirmationDialog.accepted.connect(clearHistory);
confirmationDialog.open();
}
}

Expand Down Expand Up @@ -293,7 +321,7 @@ Item {
root.forceActiveFocus()
}

Keys.onPressed: {
Keys.onPressed: (event) => {
if ((event.key === Qt.Key_Enter || event.key === Qt.Key_Return) && event.modifiers === Qt.ControlModifier) {
processScript(input.selectedText)
}
Expand Down

0 comments on commit d0ecb8a

Please sign in to comment.