UIProjectFrame.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743
  1. // Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
  2. // Please see LICENSE.md in repository root for license information
  3. // https://github.com/AtomicGameEngine/AtomicGameEngine
  4. #include "AtomicEditor.h"
  5. #include <TurboBadger/tb_select.h>
  6. #include <Atomic/Core/Context.h>
  7. #include <Atomic/IO/Log.h>
  8. #include <Atomic/IO/FileSystem.h>
  9. #include <Atomic/Resource/ResourceEvents.h>
  10. #include <Atomic/UI/UI.h>
  11. #include "../AEEditor.h"
  12. #include "../Project/AEProject.h"
  13. #include "UIListView.h"
  14. #include "UIProjectFrame.h"
  15. #include "../Project/ProjectUtils.h"
  16. #include "UI/Modal/UIModalOps.h"
  17. using namespace tb;
  18. namespace AtomicEditor
  19. {
  20. ProjectFrame::ProjectFrame(Context* context) :
  21. AEWidget(context)
  22. {
  23. UI* tbui = GetSubsystem<UI>();
  24. tbui->LoadResourceFile(delegate_, "AtomicEditor/editor/ui/projectframe.tb.txt");
  25. delegate_->SetID(TBIDC("projectframe_delegate"));
  26. delegate_->SetGravity(WIDGET_GRAVITY_TOP_BOTTOM);
  27. // folders
  28. TBLayout* foldercontainer = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("foldercontainer"));
  29. assert(foldercontainer);
  30. folderList_ = new ListView(context_, "folderList_");
  31. folderList_->GetRootList()->SetGravity(WIDGET_GRAVITY_ALL);
  32. TBWidgetDelegate* folderListWD = folderList_->GetWidgetDelegate();
  33. folderListWD->SetID(TBIDC("folerList_delegate"));
  34. folderListWD->SetGravity(WIDGET_GRAVITY_ALL);
  35. foldercontainer->AddChild(folderListWD);
  36. SubscribeToEvent(E_FILECHANGED, HANDLER(ProjectFrame, HandleFileChanged));
  37. InitializeMenuSources();
  38. }
  39. ProjectFrame::~ProjectFrame()
  40. {
  41. }
  42. void ProjectFrame::InitializeMenuSources()
  43. {
  44. MenubarItem* item;
  45. item = new MenubarItem("Folder", TBIDC("create_folder"));
  46. item->SetSkinImage(TBIDC("Folder.icon"));
  47. menuCreateSource.AddItem(item);
  48. menuCreateSource.AddItem(new MenubarItem("-"));
  49. item = new MenubarItem("Component", TBIDC("create_component"));
  50. item->SetSkinImage(TBIDC("JavascriptBitmap"));
  51. menuCreateSource.AddItem(item);
  52. item = new MenubarItem("Script", TBIDC("create_script"));
  53. item->SetSkinImage(TBIDC("JavascriptBitmap"));
  54. menuCreateSource.AddItem(item);
  55. item = new MenubarItem("Module", TBIDC("create_module"));
  56. item->SetSkinImage(TBIDC("JavascriptBitmap"));
  57. menuCreateSource.AddItem(item);
  58. menuCreateSource.AddItem(new MenubarItem("-"));
  59. item = new MenubarItem("2D Level", TBIDC("create_2d_level"));
  60. item->SetSkinImage(TBIDC("2DLevelBitmap"));
  61. menuCreateSource.AddItem(item);
  62. }
  63. void ProjectFrame::Refresh()
  64. {
  65. String cfolder = currentContentFolder_;
  66. currentContentFolder_ = "";
  67. RefreshFolders();
  68. SelectCurrentContentFolder(cfolder);
  69. }
  70. void ProjectFrame::HandleFileChanged(StringHash eventType, VariantMap& eventData)
  71. {
  72. // Don't currently do anything here
  73. /*
  74. using namespace FileChanged;
  75. const String& fileName = eventData[P_FILENAME].GetString();
  76. const String& resourceName = eventData[P_RESOURCENAME].GetString();
  77. */
  78. }
  79. void ProjectFrame::ScanDirForFolders(Vector<String>& dirs, const String& fullPath)
  80. {
  81. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  82. Vector<String> _dirs;
  83. fileSystem->ScanDir(_dirs, fullPath, "", SCAN_DIRS, false);
  84. for (unsigned i = 0; i < _dirs.Size(); i++)
  85. {
  86. const String& dir = _dirs[i];
  87. if (dir == "." || dir == ".." || dir.EndsWith("/..") || dir.EndsWith("/."))
  88. continue;
  89. dirs.Push(dir);
  90. }
  91. }
  92. void ProjectFrame::RecursiveAddFolder(ListViewItem* parent, const String& fullpath, const String& folderName)
  93. {
  94. TBID id = TBIDC(fullpath.CString());
  95. tbidToFolder_[id] = fullpath;
  96. ListViewItem* child = parent->AddChild(folderName.CString(), "Folder.icon", TBIDC(fullpath.CString()));
  97. Vector<String> dirs;
  98. ScanDirForFolders(dirs, fullpath);
  99. for (unsigned i = 0; i < dirs.Size(); i++)
  100. {
  101. const String& dir = dirs[i];
  102. RecursiveAddFolder(child, AddTrailingSlash(fullpath + dir), dir);
  103. }
  104. }
  105. void ProjectFrame::Clear()
  106. {
  107. currentContentFolder_ = "";
  108. tbidToContent_.Clear();
  109. tbidToContentFolder_.Clear();
  110. tbidToFolder_.Clear();
  111. TBLayout* container = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("contentcontainer"));
  112. assert(container);
  113. folderList_->DeleteAllItems();
  114. container->DeleteAllChildren();
  115. }
  116. void ProjectFrame::RefreshFolders()
  117. {
  118. Editor* editor = GetSubsystem<Editor>();
  119. Project* project = editor->GetProject();
  120. tbidToFolder_.Clear();
  121. String resourcePath = project->GetResourcePath();
  122. currentContentFolder_ = resourcePath;
  123. TBID id = TBID(resourcePath.CString());
  124. tbidToFolder_[id] = resourcePath;
  125. folderList_->DeleteAllItems();
  126. ListViewItem* resources = folderList_->AddItem("Resources", "Folder.icon", id);
  127. Vector<String> dirs;
  128. ScanDirForFolders(dirs, resourcePath);
  129. for (unsigned i = 0; i < dirs.Size(); i++)
  130. {
  131. const String& dir = dirs[i];
  132. RecursiveAddFolder(resources, AddTrailingSlash(resourcePath + dir), dir);
  133. }
  134. resources->SetExpanded(true);
  135. RefreshContent(resourcePath);
  136. folderList_->GetRootList()->SetValue(0);
  137. }
  138. void ProjectFrame::ScanContentDirForContent(Vector<String>& folders, Vector<String>& content, const String& fullPath)
  139. {
  140. FileSystem* fileSystem = GetSubsystem<FileSystem>();
  141. folders.Clear();
  142. content.Clear();
  143. Vector<String> _folders;
  144. fileSystem->ScanDir(_folders, fullPath, "", SCAN_DIRS, false);
  145. for (unsigned i = 0; i < _folders.Size(); i++)
  146. {
  147. const String& dir = _folders[i];
  148. if (dir == "." || dir == ".." || dir.EndsWith("/..") || dir.EndsWith("/."))
  149. continue;
  150. folders.Push(dir);
  151. }
  152. fileSystem->ScanDir(content, fullPath, "", SCAN_FILES, false);
  153. }
  154. TBLayout* ProjectFrame::CreateButtonLayout(const String& fullpath, const String& text)
  155. {
  156. Editor* editor = GetSubsystem<Editor>();
  157. Project* project = editor->GetProject();
  158. FileSystem* fs = GetSubsystem<FileSystem>();
  159. String pathName, fileName, extension;
  160. SplitPath(fullpath, pathName, fileName, extension);
  161. TBID bitmapID = TBIDC("Folder.icon");
  162. if (fs->FileExists(fullpath))
  163. bitmapID = TBIDC("FileBitmap");
  164. if (extension.Length())
  165. {
  166. if (extension == ".js")
  167. {
  168. if (project->IsComponentsDirOrFile(fullpath))
  169. {
  170. bitmapID = TBIDC("ComponentBitmap");
  171. }
  172. else
  173. {
  174. bitmapID = TBIDC("JavascriptBitmap");
  175. }
  176. }
  177. }
  178. TBLayout* blayout = new TBLayout();
  179. TBWidget* spacer = new TBWidget();
  180. spacer->SetRect(TBRect(0, 0, 8, 8));
  181. blayout->AddChild(spacer);
  182. TBButton* button = new TBButton();
  183. LayoutParams lp;
  184. lp.SetHeight(20);
  185. TBFontDescription fd;
  186. fd.SetID(TBIDC("Vera"));
  187. fd.SetSize(11);
  188. button->SetGravity(WIDGET_GRAVITY_LEFT);
  189. TBSkinImage* image = new TBSkinImage(bitmapID);
  190. image->SetRect(TBRect(0, 0, 12, 12));
  191. image->SetGravity(WIDGET_GRAVITY_RIGHT);
  192. blayout->AddChild(image);
  193. button->SetID(TBIDC(fullpath.CString()));
  194. button->SetLayoutParams(lp);
  195. button->SetFontDescription(fd);
  196. button->SetText(text.CString());
  197. button->SetSkinBg(TBIDC("TBButton.flat"));
  198. blayout->AddChild(button);
  199. return blayout;
  200. }
  201. void ProjectFrame::RefreshContent(const String& fullpath)
  202. {
  203. Editor* editor = GetSubsystem<Editor>();
  204. Project* project = editor->GetProject();
  205. currentContentFolder_ = fullpath;
  206. tbidToContent_.Clear();
  207. tbidToContentFolder_.Clear();
  208. Vector<String> folders;
  209. Vector<String> content;
  210. ScanContentDirForContent(folders, content, fullpath);
  211. TBLayout* container = delegate_->GetWidgetByIDAndType<TBLayout>(TBIDC("contentcontainer"));
  212. assert(container);
  213. container->DeleteAllChildren();
  214. if (fullpath != project->GetResourcePath())
  215. {
  216. LayoutParams lp;
  217. lp.SetHeight(20);
  218. TBFontDescription fd;
  219. fd.SetID(TBIDC("Vera"));
  220. fd.SetSize(11);
  221. TBButton* button = new TBButton();
  222. button->SetGravity(WIDGET_GRAVITY_LEFT);
  223. button->SetText(".. ");
  224. button->SetID(TBIDC(".."));
  225. button->SetSkinBg(TBIDC("TBButton.flat"));
  226. button->SetLayoutParams(lp);
  227. button->SetFontDescription(fd);
  228. container->AddChild(button);
  229. }
  230. for (unsigned i = 0; i < folders.Size(); i++)
  231. {
  232. String contentID = AddTrailingSlash(fullpath + folders[i]);
  233. container->AddChild(CreateButtonLayout(contentID, folders[i]));
  234. tbidToContentFolder_[TBIDC(contentID.CString())] = contentID;
  235. }
  236. for (unsigned i = 0; i < content.Size(); i++)
  237. {
  238. String contentID = fullpath + content[i];
  239. container->AddChild(CreateButtonLayout(contentID, content[i]));
  240. tbidToContent_[TBIDC(contentID.CString())] = contentID;
  241. }
  242. }
  243. bool ProjectFrame::HandlePopMenuEvent(const TBWidgetEvent &ev)
  244. {
  245. if (ev.type == EVENT_TYPE_CLICK)
  246. {
  247. if (ev.target->GetID() == TBIDC("create popup"))
  248. {
  249. UIModalOps* ops = GetSubsystem<UIModalOps>();
  250. String resourcePath = GetCurrentContentFolder();
  251. if (resourcePath.Length())
  252. {
  253. if (ev.ref_id == TBIDC("create_component"))
  254. {
  255. if (CheckResourceCreatePath(resourcePath, "Component"))
  256. ops->ShowCreateComponent(resourcePath);
  257. }
  258. else if (ev.ref_id == TBIDC("create_script"))
  259. {
  260. if (CheckResourceCreatePath(resourcePath, "Script"))
  261. ops->ShowCreateScript(resourcePath);
  262. }
  263. else if (ev.ref_id == TBIDC("create_module"))
  264. {
  265. if (CheckResourceCreatePath(resourcePath, "Module"))
  266. ops->ShowCreateModule(resourcePath);
  267. }
  268. else if (ev.ref_id == TBIDC("create_2d_level"))
  269. {
  270. ops->ShowCreate2DLevel(resourcePath);
  271. }
  272. else if (ev.ref_id == TBIDC("create_folder"))
  273. {
  274. ops->ShowNewFolder(resourcePath);
  275. }
  276. }
  277. return true;
  278. }
  279. }
  280. return false;
  281. }
  282. bool ProjectFrame::OnEvent(const TBWidgetEvent &ev)
  283. {
  284. if (!ev.target)
  285. return false;
  286. if (HandlePopMenuEvent(ev))
  287. return true;
  288. if (ev.type == EVENT_TYPE_CLICK)
  289. {
  290. if (ev.target->GetID() == TBIDC("menu create"))
  291. {
  292. UI* tbui = GetSubsystem<UI>();
  293. if (!tbui->GetRootWidget()->GetWidgetByID(TBIDC("create popup")))
  294. if (TBMenuWindow *menu = new TBMenuWindow(ev.target, TBIDC("create popup")))
  295. menu->Show(&menuCreateSource, TBPopupAlignment());
  296. return true;
  297. }
  298. // context menu
  299. if (ev.target->GetID() == TBIDC("contextmenu"))
  300. {
  301. return OnContextMenuEvent(ev);
  302. }
  303. // we clicked the folder list
  304. if (ev.target->GetID() == TBID("folderList_"))
  305. {
  306. TBSelectList* list = (TBSelectList*) ev.target;
  307. TBID tbid = list->GetSelectedItemID();
  308. if (tbidToFolder_.Contains(tbid))
  309. {
  310. SelectCurrentContentFolder(tbidToFolder_[tbid]);
  311. }
  312. }
  313. else
  314. {
  315. if (ev.target->GetID() == TBIDC(".."))
  316. {
  317. String parentPath = GetParentPath(currentContentFolder_);
  318. SelectCurrentContentFolder(parentPath);
  319. return true;
  320. }
  321. // see if we clicked a folder in the content area
  322. else if (tbidToContentFolder_.Contains(ev.target->GetID()))
  323. {
  324. String path = tbidToContentFolder_[ev.target->GetID()];
  325. SelectCurrentContentFolder(path);
  326. }
  327. else if (tbidToContent_.Contains(ev.target->GetID()))
  328. {
  329. // we clicked some content
  330. String contentPath = tbidToContent_[ev.target->GetID()];
  331. Editor* editor = GetSubsystem<Editor>();
  332. editor->EditResource(contentPath);
  333. }
  334. }
  335. return false;
  336. }
  337. if (ev.type == EVENT_TYPE_RIGHT_POINTER_UP)
  338. {
  339. TBPoint pos_in_root(ev.target_x, ev.target_y);
  340. if (tbidToFolder_.Contains(ev.target->GetID()))
  341. {
  342. // right click folder
  343. String folder = tbidToFolder_[ev.target->GetID()];
  344. CreateFolderContextMenu(AddTrailingSlash(folder), pos_in_root.x, pos_in_root.y);
  345. }
  346. else if (tbidToContent_.Contains(ev.target->GetID()))
  347. {
  348. // right click content
  349. String content = tbidToContent_[ev.target->GetID()];
  350. CreateContentContextMenu(content, pos_in_root.x, pos_in_root.y);
  351. }
  352. else
  353. {
  354. if (folderList_->GetRootList()->IsAncestorOf(ev.target))
  355. {
  356. // right click in folder area
  357. CreateFolderContainerContextMenu(pos_in_root.x, pos_in_root.y);
  358. }
  359. else
  360. {
  361. TBScrollContainer* container = delegate_->GetWidgetByIDAndType<TBScrollContainer>(TBIDC("contentcontainerscroll"));
  362. if (container->IsAncestorOf(ev.target))
  363. {
  364. CreateContentContainerContextMenu(pos_in_root.x, pos_in_root.y);
  365. }
  366. }
  367. }
  368. return true;
  369. }
  370. return false;
  371. }
  372. void ProjectFrame::SelectCurrentContentFolder(const String& folder)
  373. {
  374. folderList_->SelectItemByID(TBIDC(folder.CString()));
  375. if (currentContentFolder_ != folder)
  376. RefreshContent(folder);
  377. }
  378. bool ProjectFrame::CheckResourceCreatePath(const String& path, const String& resourceType)
  379. {
  380. Editor* editor = GetSubsystem<Editor>();
  381. Project* project = editor->GetProject();
  382. if (resourceType == "Script")
  383. {
  384. if (!project->IsScriptsDirOrFile(path))
  385. {
  386. editor->PostModalError("Create Script Error", "Scripts must reside in or in a subfolder of the Scripts folder");
  387. return false;
  388. }
  389. }
  390. if (resourceType == "Module")
  391. {
  392. if (!project->IsModulesDirOrFile(path))
  393. {
  394. editor->PostModalError("Create Module Error", "Modules must reside in or in a subfolder of the Modules folder");
  395. return false;
  396. }
  397. }
  398. if (resourceType == "Component")
  399. {
  400. if (!project->IsComponentsDirOrFile(path))
  401. {
  402. editor->PostModalError("Create Component Error", "Components must reside in or in a subfolder of the Components folder");
  403. return false;
  404. }
  405. }
  406. return true;
  407. }
  408. // Context Menus
  409. bool ProjectFrame::OnContextMenuEvent(const TBWidgetEvent &ev)
  410. {
  411. UIModalOps* ops = GetSubsystem<UIModalOps>();
  412. if (ev.ref_id == TBIDC("reveal_in_finder"))
  413. {
  414. ProjectUtils* utils = GetSubsystem<ProjectUtils>();
  415. utils->RevealInFinder(contextMenuPath_);
  416. }
  417. else if (ev.ref_id == TBIDC("create_component"))
  418. {
  419. ops->ShowCreateComponent(contextMenuPath_);
  420. }
  421. else if (ev.ref_id == TBIDC("create_script"))
  422. {
  423. ops->ShowCreateScript(contextMenuPath_);
  424. }
  425. else if (ev.ref_id == TBIDC("create_module"))
  426. {
  427. ops->ShowCreateModule(contextMenuPath_);
  428. }
  429. else if (ev.ref_id == TBIDC("create_2d_level"))
  430. {
  431. ops->ShowCreate2DLevel(contextMenuPath_);
  432. }
  433. else if (ev.ref_id == TBIDC("new_folder"))
  434. {
  435. ops->ShowNewFolder(contextMenuPath_);
  436. }
  437. else if (ev.ref_id == TBIDC("delete"))
  438. {
  439. ops->ShowResourceDelete(contextMenuPath_);
  440. }
  441. return true;
  442. }
  443. String ProjectFrame::GetCurrentContentFolder()
  444. {
  445. if (currentContentFolder_.Length())
  446. return currentContentFolder_;
  447. Editor* editor = GetSubsystem<Editor>();
  448. Project* project = editor->GetProject();
  449. if (project)
  450. return project->GetResourcePath();
  451. return "";
  452. }
  453. void ProjectFrame::CreateFolderContextMenu(const String& folder, int x, int y)
  454. {
  455. contextMenuPath_ = "";
  456. Editor* editor = GetSubsystem<Editor>();
  457. Project* project = editor->GetProject();
  458. TBMenuWindow *menu = new TBMenuWindow(delegate_, TBIDC("contextmenu"));
  459. TBGenericStringItemSource *source = menu->GetList()->GetDefaultSource();
  460. TBGenericStringItem* item = new TBGenericStringItem("Create Folder", TBIDC("new_folder"));
  461. item->SetSkinImage(TBIDC("FolderCreateBitmap"));
  462. source->AddItem(item);
  463. bool isJS = false;
  464. if (project->IsComponentsDirOrFile(folder))
  465. {
  466. isJS = true;
  467. source->AddItem(new TBGenericStringItem("-"));
  468. item = new TBGenericStringItem("Create Component", TBIDC("create_component"));
  469. item->SetSkinImage(TBIDC("ComponentBitmap"));
  470. source->AddItem(item);
  471. }
  472. else if (project->IsScriptsDirOrFile(folder))
  473. {
  474. isJS = true;
  475. source->AddItem(new TBGenericStringItem("-"));
  476. item = new TBGenericStringItem("Create Script", TBIDC("create_script"));
  477. item->SetSkinImage(TBIDC("JavascriptBitmap"));
  478. source->AddItem(item);
  479. }
  480. else if (project->IsModulesDirOrFile(folder))
  481. {
  482. isJS = true;
  483. source->AddItem(new TBGenericStringItem("-"));
  484. item = new TBGenericStringItem("Create Module", TBIDC("create_module"));
  485. item->SetSkinImage(TBIDC("JavascriptBitmap"));
  486. source->AddItem(item);
  487. }
  488. if (!isJS)
  489. {
  490. item = new TBGenericStringItem("Create 2D Level", TBIDC("create_2d_level"));
  491. item->SetSkinImage(TBIDC("2DLevelBitmap"));
  492. source->AddItem(item);
  493. }
  494. source->AddItem(new TBGenericStringItem("-"));
  495. item = new TBGenericStringItem("Reveal in Finder", TBIDC("reveal_in_finder"));
  496. item->SetSkinImage(TBIDC("MagnifierBitmap"));
  497. source->AddItem(item);
  498. source->AddItem(new TBGenericStringItem("-"));
  499. item = new TBGenericStringItem("Delete Folder", TBIDC("delete"));
  500. item->SetSkinImage(TBIDC("FolderDeleteBitmap"));
  501. source->AddItem(item);
  502. menu->Show(source, TBPopupAlignment(TBPoint(x, y)), -1);
  503. contextMenuPath_ = folder;
  504. }
  505. void ProjectFrame::CreateContentContextMenu(const String& content, int x, int y)
  506. {
  507. contextMenuPath_ = "";
  508. TBMenuWindow *menu = new TBMenuWindow(delegate_, TBIDC("contextmenu"));
  509. TBGenericStringItemSource *source = menu->GetList()->GetDefaultSource();
  510. source->AddItem(new TBGenericStringItem("Delete", TBIDC("delete")));
  511. source->AddItem(new TBGenericStringItem("-"));
  512. source->AddItem(new TBGenericStringItem("Reveal in Finder", TBIDC("reveal_in_finder")));
  513. menu->Show(source, TBPopupAlignment(TBPoint(x, y)), -1);
  514. contextMenuPath_ = content;
  515. }
  516. void ProjectFrame::CreateFolderContainerContextMenu(int x, int y)
  517. {
  518. contextMenuPath_ = "";
  519. TBMenuWindow *menu = new TBMenuWindow(delegate_, TBIDC("contextmenu"));
  520. TBGenericStringItemSource *source = menu->GetList()->GetDefaultSource();
  521. source->AddItem(new TBGenericStringItem("Create Folder", TBIDC("new_folder")));
  522. source->AddItem(new TBGenericStringItem("-"));
  523. source->AddItem(new TBGenericStringItem("Reveal in Finder", TBIDC("reveal_in_finder")));
  524. menu->Show(source, TBPopupAlignment(TBPoint(x, y)), -1);
  525. contextMenuPath_ = currentContentFolder_;
  526. }
  527. void ProjectFrame::CreateContentContainerContextMenu(int x, int y)
  528. {
  529. contextMenuPath_ = "";
  530. Editor* editor = GetSubsystem<Editor>();
  531. Project* project = editor->GetProject();
  532. TBMenuWindow *menu = new TBMenuWindow(delegate_, TBIDC("contextmenu"));
  533. TBGenericStringItemSource *source = menu->GetList()->GetDefaultSource();
  534. TBGenericStringItem* item = new TBGenericStringItem("Create Folder", TBIDC("new_folder"));
  535. item->SetSkinImage(TBIDC("Folder.icon"));
  536. source->AddItem(item);
  537. bool isJS = false;
  538. if (project->IsComponentsDirOrFile(currentContentFolder_))
  539. {
  540. isJS = true;
  541. source->AddItem(new TBGenericStringItem("-"));
  542. item = new TBGenericStringItem("Create Component", TBIDC("create_component"));
  543. item->SetSkinImage(TBIDC("ComponentBitmap"));
  544. source->AddItem(item);
  545. }
  546. else if (project->IsScriptsDirOrFile(currentContentFolder_))
  547. {
  548. isJS = true;
  549. source->AddItem(new TBGenericStringItem("-"));
  550. item = new TBGenericStringItem("Create Script", TBIDC("create_script"));
  551. item->SetSkinImage(TBIDC("JavascriptBitmap"));
  552. source->AddItem(item);
  553. }
  554. else if (project->IsModulesDirOrFile(currentContentFolder_))
  555. {
  556. isJS = true;
  557. source->AddItem(new TBGenericStringItem("-"));
  558. item = new TBGenericStringItem("Create Module", TBIDC("create_module"));
  559. item->SetSkinImage(TBIDC("JavascriptBitmap"));
  560. source->AddItem(item);
  561. }
  562. if (!isJS)
  563. {
  564. item = new TBGenericStringItem("Create 2D Level", TBIDC("create_2d_level"));
  565. item->SetSkinImage(TBIDC("2DLevelBitmap"));
  566. source->AddItem(item);
  567. }
  568. source->AddItem(new TBGenericStringItem("-"));
  569. source->AddItem(new TBGenericStringItem("Reveal in Finder", TBIDC("reveal_in_finder")));
  570. menu->Show(source, TBPopupAlignment(TBPoint(x, y)), -1);
  571. contextMenuPath_ = currentContentFolder_;
  572. }
  573. }