Skip to content

Commit

Permalink
qmlui: add Script Editor method insertion popup
Browse files Browse the repository at this point in the history
  • Loading branch information
mcallegari committed Jul 5, 2018
1 parent f601ffa commit 022494d
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 1 deletion.
1 change: 0 additions & 1 deletion engine/src/scriptv4.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ bool Script::setData(const QString& str)
return false;

m_data = str;
syntaxErrorsLines(); // TODO remove from here

Doc* doc = qobject_cast<Doc*> (parent());
Q_ASSERT(doc != NULL);
Expand Down
97 changes: 97 additions & 0 deletions qmlui/qml/fixturesfunctions/ScriptEditor.qml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ Rectangle
requestView(prevID, functionManager.getEditorResource(prevID))
}

IconButton
{
id: addButton
width: height
height: UISettings.iconSizeMedium
imgSource: "qrc:/add.svg"
tooltip: qsTr("Add a method call at cursor position")
onClicked: addMethodMenu.open()
}

IconButton
{
id: functionTreeButton
Expand Down Expand Up @@ -235,4 +245,91 @@ Rectangle
}
} // Column
} // SplitView

FileDialog
{
id: selectFileDialog
visible: false
onAccepted:
{
// strip "file://" and add single quotes
var str = "'" + fileUrl.toString().slice(7) + "'"
scriptEdit.insert(scriptEdit.cursorPosition, str)
addMethodMenu.close()
}
}

Popup
{
id: addMethodMenu
x: (addButton.x + addButton.width) - width
y: addButton.y + addButton.height
padding: 0

background:
Rectangle
{
color: UISettings.bgStrong
border.color: UISettings.bgStronger
}

function insertMethod(str)
{
scriptEdit.insert(scriptEdit.cursorPosition, str + "\n")
scriptEdit.cursorPosition -= 3
addMethodMenu.close()
}

Column
{
ContextMenuEntry
{
imgSource: "qrc:/play.svg"
entryText: qsTr("Start function")
onClicked: addMethodMenu.insertMethod("Engine.startFunction();")
}
ContextMenuEntry
{
imgSource: "qrc:/stop.svg"
entryText: qsTr("Stop function")
onClicked: addMethodMenu.insertMethod("Engine.stopFunction();")
}
ContextMenuEntry
{
imgSource: "qrc:/sliders.svg"
entryText: qsTr("Set fixture channel")
onClicked: addMethodMenu.insertMethod("Engine.setFixture();")
}
ContextMenuEntry
{
imgSource: "qrc:/clock.svg"
entryText: qsTr("Wait time")
onClicked: addMethodMenu.insertMethod("Engine.waitTime();")
}
ContextMenuEntry
{
imgSource: "qrc:/random.svg"
entryText: qsTr("Random number")
onClicked: addMethodMenu.insertMethod("Engine.random();")
}
ContextMenuEntry
{
imgSource: "qrc:/blackout.svg"
entryText: qsTr("Blackout")
onClicked: addMethodMenu.insertMethod("Engine.setBlackout();")
}
ContextMenuEntry
{
imgSource: "qrc:/script.svg"
entryText: qsTr("System command")
onClicked: addMethodMenu.insertMethod("Engine.systemCommand();")
}
ContextMenuEntry
{
imgSource: "qrc:/fileopen.svg"
entryText: qsTr("File path")
onClicked: selectFileDialog.open()
}
}
}
}

0 comments on commit 022494d

Please sign in to comment.