TDME2  1.9.200
EmptyEditorTabController.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 #include <memory>
5 
6 #include <tdme/tdme.h>
12 #include <tdme/gui/GUI.h>
13 #include <tdme/gui/GUIParser.h>
24 #include <tdme/utilities/Action.h>
25 #include <tdme/utilities/Console.h>
29 
30 using std::make_unique;
31 using std::string;
32 using std::unique_ptr;
33 
35 
56 
57 EmptyEditorTabController::EmptyEditorTabController(EmptyEditorTabView* view)
58 {
59  this->view = view;
60  this->popUps = view->getPopUps();
61  this->basePropertiesSubController = make_unique<BasePropertiesSubController>(view->getEditorView(), "prototype");
62  this->prototypeScriptSubController = make_unique<PrototypeScriptSubController>(view->getEditorView());
63 }
64 
66 }
67 
69 {
70  this->screenNode = screenNode;
73 }
74 
76 {
77 }
78 
80 {
81  switch (command) {
82  case COMMAND_SAVE:
83  {
84  auto fileName = view->getPrototype() != nullptr?view->getPrototype()->getFileName():"";
85  try {
86  if (fileName.empty() == true) throw ExceptionBase("Could not save file. No filename known");
87  view->saveFile(
88  Tools::getPathName(fileName),
89  Tools::getFileName(fileName)
90  );
91  } catch (Exception& exception) {
92  showInfoPopUp("Warning", string(exception.what()));
93  }
94  }
95  break;
96  case COMMAND_SAVEAS:
97  {
98  class OnEmptySave: public virtual Action
99  {
100  public:
101  void performAction() override {
102  try {
103  emptyEditorTabController->view->saveFile(
104  emptyEditorTabController->popUps->getFileDialogScreenController()->getPathName(),
105  emptyEditorTabController->popUps->getFileDialogScreenController()->getFileName()
106  );
107  } catch (Exception& exception) {
108  emptyEditorTabController->showInfoPopUp("Warning", string(exception.what()));
109  }
110  emptyEditorTabController->popUps->getFileDialogScreenController()->close();
111  }
112  OnEmptySave(EmptyEditorTabController* emptyEditorTabController): emptyEditorTabController(emptyEditorTabController) {
113  }
114  private:
115  EmptyEditorTabController* emptyEditorTabController;
116  };
117 
118  auto fileName = view->getPrototype() != nullptr?view->getPrototype()->getFileName():"";
119  vector<string> extensions = {
120  "tempty"
121  };
123  fileName.empty() == false?Tools::getPathName(fileName):string(),
124  "Save to: ",
125  extensions,
126  Tools::getFileName(fileName),
127  false,
128  new OnEmptySave(this)
129  );
130  }
131  break;
132  default:
133  showInfoPopUp("Warning", "This command is not supported yet");
134  break;
135  }
136 }
137 
138 void EmptyEditorTabController::onDrop(const string& payload, int mouseX, int mouseY) {
139  if (prototypeScriptSubController->onDrop(payload, mouseX, mouseY, view->getPrototype()) == true) return;
140  showInfoPopUp("Warning", "You can not drop a file here");
141 }
142 
144 {
145  if (basePropertiesSubController->onChange(node, view->getPrototype(), view->getPrototype()) == true) return;
146  if (prototypeScriptSubController->onChange(node, view->getPrototype()) == true) return;
147 }
148 
150  if (basePropertiesSubController->onFocus(node, view->getPrototype()) == true) return;
151 }
152 
154  if (basePropertiesSubController->onUnfocus(node, view->getPrototype()) == true) return;
155 }
156 
158  basePropertiesSubController->onContextMenuRequest(node, mouseX, mouseY, view->getPrototype());
159 }
160 
161 void EmptyEditorTabController::onTooltipShowRequest(GUINode* node, int mouseX, int mouseY) {
162  int tooltipLeft, tooltipTop;
163  if (view->getEditorView()->getCurrentTabTooltipPosition(screenNode, mouseX, mouseY, tooltipLeft, tooltipTop) == false) return;
164  //
165  popUps->getTooltipScreenController()->show(tooltipLeft, tooltipTop, node->getToolTip());
166 }
167 
170 }
171 
173 {
174  auto prototype = view->getPrototype();
175  if (basePropertiesSubController->onAction(type, node, prototype) == true) return;
176  if (prototypeScriptSubController->onAction(type, node, prototype) == true) return;
177 }
178 
180  string xml;
181  xml+= "<selectbox-parent-option image=\"resources/engine/images/folder.png\" text=\"" + GUIParser::escape("Prototype") + "\" value=\"" + GUIParser::escape("prototype") + "\">\n";
182  auto prototype = view->getPrototype();
183  if (prototype != nullptr) {
184  basePropertiesSubController->createBasePropertiesXML(prototype, xml);
185  prototypeScriptSubController->createScriptXML(prototype, xml);
186  }
187  xml+= "</selectbox-parent-option>\n";
189 
192  string("<dropdown-option text=\"Property\" value=\"property\" />\n")
193  );
194 }
195 
196 void EmptyEditorTabController::updateDetails(const string& outlinerNode) {
197  view->getEditorView()->setDetailsContent(string());
198  basePropertiesSubController->updateDetails(view->getPrototype(), outlinerNode);
199  prototypeScriptSubController->updateDetails(view->getPrototype(), outlinerNode);
200 }
201 
203  required_dynamic_cast<GUITextNode*>(screenNode->getNodeById(view->getTabId() + "_tab_text_info"))->setText(text);
204 }
205 
206 void EmptyEditorTabController::showInfoPopUp(const string& caption, const string& message)
207 {
208  popUps->getInfoDialogScreenController()->show(caption, message);
209 }
Prototype definition.
Definition: Prototype.h:55
GUI parser.
Definition: GUIParser.h:40
GUI node base class.
Definition: GUINode.h:64
const string & getToolTip()
Definition: GUINode.h:346
GUI screen node that represents a screen that can be rendered via GUI system.
Definition: GUIScreenNode.h:72
GUINode * getNodeById(const string &nodeId)
Get GUI node by id.
void show(const string &cwd, const string &captionText, const vector< string > &extensions, const string &fileName, bool enableFilter, Action *applyAction, Action *cancelAction=nullptr, const string &settingsFileName=".filedialog.properties", const string &settingsPathName=string())
Shows the file dialog pop up.
void show(const string &caption, const string &message)
Shows the pop up.
void show(int mouseX, int mouseY, const string &tooltip)
Show tooltip.
Pop ups controller accessor class.
Definition: PopUps.h:29
FileDialogScreenController * getFileDialogScreenController()
Definition: PopUps.h:61
TooltipScreenController * getTooltipScreenController()
Definition: PopUps.h:131
InfoDialogScreenController * getInfoDialogScreenController()
Definition: PopUps.h:75
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 updateInfoText(const MutableString &text)
Update info text line.
void setOutlinerAddDropDownContent()
Set outliner add drop down content.
void onCommand(TabControllerCommand command) override
On command.
void updateDetails(const string &outlinerNode)
Update details panel.
unique_ptr< PrototypeScriptSubController > prototypeScriptSubController
void showInfoPopUp(const string &caption, const string &message)
Show the information pop up / modal.
void onAction(GUIActionListenerType type, GUIElementNode *node) override
unique_ptr< BasePropertiesSubController > basePropertiesSubController
void onTooltipShowRequest(GUINode *node, int mouseX, int mouseY) override
On tooltip show request.
void saveFile(const string &pathName, const string &fileName)
Saving prototype as tempty prototype.
void setOutlinerAddDropDownContent(const string &xml)
Set outliner add drop down content.
Definition: EditorView.cpp:400
void setOutlinerContent(const string &xml)
Set outliner content.
Definition: EditorView.cpp:396
void setDetailsContent(const string &xml)
Set details content.
Definition: EditorView.cpp:404
bool getCurrentTabTooltipPosition(GUIScreenNode *screenNode, int mouseX, int mouseY, int &tooltipLeft, int &tooltipTop)
Determine current tab tooltip position.
Definition: EditorView.cpp:439
Console class.
Definition: Console.h:29
Exception base class.
Definition: ExceptionBase.h:19
Mutable utf8 aware string class.
Definition: MutableString.h:23
std::exception Exception
Exception base class.
Definition: Exception.h:18
Tab controller, which connects UI with logic.
Definition: TabController.h:34
Action Interface.
Definition: Action.h:11