6 #include <unordered_map>
48 using std::make_unique;
50 using std::unique_ptr;
51 using std::unordered_map;
90 #define AVOID_NULLPTR_STRING(arg) (arg == nullptr?"":arg)
142 if (fileName.empty() ==
true)
throw ExceptionBase(
"Could not save file. No filename known");
144 Tools::getPathName(fileName),
145 Tools::getFileName(fileName)
154 class OnTextSave:
public virtual Action
157 void performAction()
override {
159 textEditorTabController->view->saveFile(
160 textEditorTabController->popUps->getFileDialogScreenController()->getPathName(),
161 textEditorTabController->popUps->getFileDialogScreenController()->getFileName()
164 textEditorTabController->showInfoPopUp(
"Warning",
string(exception.what()));
166 textEditorTabController->popUps->getFileDialogScreenController()->close();
173 OnTextSave(
TextEditorTabController* textEditorTabController): textEditorTabController(textEditorTabController) {
181 vector<string> extensions = {
185 Tools::getPathName(fileName),
188 Tools::getFileName(fileName),
201 class FindAction:
public virtual Action
204 void performAction()
override {
205 if (textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText().empty() ==
true) {
206 textEditorTabController->showInfoPopUp(
"Find",
"No find string given.");
208 if (textEditorTabController->view->find(
209 textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText(),
210 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isMatchCase(),
211 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isWholeWordOnly(),
212 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isInSelectionOnly(),
213 textEditorTabController->firstSearch,
214 textEditorTabController->searchIndex
216 textEditorTabController->showInfoPopUp(
"Find",
"Text not found.");
218 textEditorTabController->firstSearch =
false;
221 FindAction(
TextEditorTabController* textEditorTabController): textEditorTabController(textEditorTabController) {
227 class CountAction:
public virtual Action
230 void performAction()
override {
231 if (textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText().empty() ==
true) {
232 textEditorTabController->showInfoPopUp(
"Count",
"No find string given.");
234 auto count = textEditorTabController->view->count(
235 textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText(),
236 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isMatchCase(),
237 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isWholeWordOnly(),
238 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isInSelectionOnly()
240 textEditorTabController->showInfoPopUp(
"Count",
"The text occurred " + to_string(count) +
" times.");
243 CountAction(
TextEditorTabController* textEditorTabController): textEditorTabController(textEditorTabController) {
249 class ReplaceAction:
public virtual Action
252 void performAction()
override {
253 if (textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText().empty() ==
true) {
254 textEditorTabController->showInfoPopUp(
"Replace",
"No find string given.");
256 if (textEditorTabController->view->replace(
257 textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText(),
258 textEditorTabController->popUps->getFindReplaceDialogScreenController()->getReplaceText(),
259 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isMatchCase(),
260 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isWholeWordOnly(),
261 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isInSelectionOnly(),
262 textEditorTabController->searchIndex
264 textEditorTabController->showInfoPopUp(
"Replace",
"Text not found.");
268 ReplaceAction(
TextEditorTabController* textEditorTabController): textEditorTabController(textEditorTabController) {
274 class ReplaceAllAction:
public virtual Action
277 void performAction()
override {
278 if (textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText().empty() ==
true) {
279 textEditorTabController->showInfoPopUp(
"Replace All",
"No find string given.");
281 if (textEditorTabController->view->replaceAll(
282 textEditorTabController->popUps->getFindReplaceDialogScreenController()->getFindText(),
283 textEditorTabController->popUps->getFindReplaceDialogScreenController()->getReplaceText(),
284 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isMatchCase(),
285 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isWholeWordOnly(),
286 textEditorTabController->popUps->getFindReplaceDialogScreenController()->isInSelectionOnly()
288 textEditorTabController->showInfoPopUp(
"Replace All",
"Text not found.");
292 ReplaceAllAction(
TextEditorTabController* textEditorTabController): textEditorTabController(textEditorTabController) {
298 class CompleteAction:
public virtual Action
301 void performAction()
override {
302 textEditorTabController->view->cancelFind();
303 textEditorTabController->popUps->getFindReplaceDialogScreenController()->close();
305 CompleteAction(
TextEditorTabController* textEditorTabController): textEditorTabController(textEditorTabController) {
312 new FindAction(
this),
313 new CountAction(
this),
314 new ReplaceAction(
this),
315 new ReplaceAllAction(
this),
316 new CompleteAction(
this)
321 showInfoPopUp(
"Warning",
"This command is not supported yet");
337 if (node->
getId() ==
"selectbox_outliner") {
339 if (StringTools::startsWith(outlinerNode,
"miniscript.script.") ==
true) {
340 auto scriptIdx = Integer::parse(StringTools::substring(outlinerNode,
string(
"miniscript.script.").size()));
350 if (visual ==
true) {
366 Engine::getInstance()->getGUI()->invalidateFocussedNode();
372 Console::println(
"TextEditorTabController::onFocus(): Unknown screen node");
386 if (StringTools::startsWith(nodeValue,
"node_") ==
true) {
400 int tooltipLeft, tooltipTop;
412 xml+=
"<selectbox-parent-option image=\"resources/engine/images/folder.png\" text=\"EngineMiniScript\" value=\"miniscript.script." + to_string(-1) +
"\">\n";
415 xml+=
"<selectbox-option text=\"" + GUIParser::escape(miniScriptSyntaxTree.name) +
"\" value=\"miniscript.script." + to_string(scriptIdx) +
"\" />\n";
418 xml+=
"</selectbox-parent-option>\n";
430 vector<string> scriptAsStringArray;
432 FileSystem::getInstance()->getContentAsStringArray(Tools::getPathName(scriptFileName), Tools::getFileName(scriptFileName), scriptAsStringArray);
444 scriptInstance = unique_ptr<EngineMiniScript>(EngineMiniScript::loadScript(Tools::getPathName(scriptFileName), Tools::getFileName(scriptFileName)));
453 showInfoPopUp(
"Warning",
"Could not load script. Script not valid!");
459 unordered_map<string, string> methodOperatorMap;
461 methodOperatorMap[operatorMethod->getMethodName()] = EngineMiniScript::getOperatorAsString(operatorMethod->getOperator());
470 string argumentsString;
471 switch(script.scriptType) {
472 case EngineMiniScript::Script::SCRIPTTYPE_FUNCTION: {
473 for (
const auto& argument: script.arguments) {
474 if (argumentsString.empty() ==
false) argumentsString+=
", ";
475 if (argument.reference ==
true) argumentsString+=
"=";
476 argumentsString+= argument.name;
478 argumentsString =
"(" + argumentsString +
")";
479 name+=
"function: ";
break;
481 case EngineMiniScript::Script::SCRIPTTYPE_ON: name+=
"on: ";
break;
482 case EngineMiniScript::Script::SCRIPTTYPE_ONENABLED: name+=
"on-enabled: ";
break;
484 if (script.name.empty() ==
false) {
487 if (script.condition.empty() ==
false)
488 name+= script.condition + (argumentsString.empty() ==
false?
": " + argumentsString:
"");
492 .type = script.scriptType,
493 .condition = script.condition,
495 .conditionSyntaxTree = script.conditionSyntaxTree,
496 .syntaxTree = script.syntaxTree
void invalidateFocussedNode()
Invalidate focussed node.
const string & getValue()
GUI node controller base class.
virtual const MutableString & getValue()=0
const string & getToolTip()
GUINodeController * getController()
GUIScreenNode * getScreenNode()
GUI parent node base class thats supporting child nodes.
GUI screen node that represents a screen that can be rendered via GUI system.
void addChangeListener(GUIChangeListener *listener)
Add change listener.
void removeFocusListener(GUIFocusListener *listener)
Remove focus listener.
void addActionListener(GUIActionListener *listener)
Add action listener.
void addFocusListener(GUIFocusListener *listener)
Add focus listener.
File system singleton class.
Text editor tab controller.
void onContextMenuRequest(GUIElementNode *node, int mouseX, int mouseY) override
On context menu request.
void onDrop(const string &payload, int mouseX, int mouseY) override
On drop.
void dispose() override
Dispose.
void setOutlinerAddDropDownContent()
Set outliner add drop down content.
void closeFindReplaceWindow()
Close find/replace window.
unique_ptr< EngineMiniScript > scriptInstance
vector< MiniScriptScriptSyntaxTree > miniScriptSyntaxTrees
void onChange(GUIElementNode *node) override
On change.
void onCommand(TabControllerCommand command) override
On command.
virtual ~TextEditorTabController()
Destructor.
void onUnfocus(GUIElementNode *node) override
On unfocus.
ContextMenuType contextMenuType
void onTooltipCloseRequest() override
On tooltip close request.
GUIScreenNode * screenNode
void onFocus(GUIElementNode *node) override
On focus.
void initialize(GUIScreenNode *screenNode) override
Init.
void updateMiniScriptSyntaxTree(int miniScriptScriptIdx)
Update EngineMiniScript syntax tree.
void showInfoPopUp(const string &caption, const string &message)
Show the information pop up / modal.
void onAction(GUIActionListenerType type, GUIElementNode *node) override
void setOutlinerContent()
Set outliner content.
void onTooltipShowRequest(GUINode *node, int mouseX, int mouseY) override
On tooltip show request.
void saveFile(const string &pathName, const string &fileName)
Save file.
void setVisualEditor()
Set visual editor.
const string & getFileName()
void setCodeEditor()
Set code editor.
void setMiniScriptMethodOperatorMap(const unordered_map< string, string > &methodOperatorMap)
Set method -> operator map.
Engine * getEngine() override
const string & getTabId() override
const string & getExtension()
EditorView * getEditorView()
void selectAll()
Select all.
void updateMiniScriptSyntaxTree(int miniScriptScriptIdx)
Update miniscript syntax tree.
GUIScreenNode * getTabScreenNode()
int getMiniScriptScriptIdx()
bool equals(const string &s2) const
Equals.
An attribute is a name-value pair.
Always the top level node.
The element is a container class.
std::exception Exception
Exception base class.