LUAEditorMainWindow.hxx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #ifndef LUAEDITOR_LUAEDITORMAINWINDOW_H
  9. #define LUAEDITOR_LUAEDITORMAINWINDOW_H
  10. #if !defined(Q_MOC_RUN)
  11. #include <AzCore/base.h>
  12. #include <AzCore/Memory/SystemAllocator.h>
  13. #include <AzCore/std/containers/map.h>
  14. #include <AzToolsFramework/AssetBrowser/Search/Filter.h>
  15. #include <AzToolsFramework/UI/LegacyFramework/UIFrameworkAPI.h>
  16. #include <AzToolsFramework/UI/LegacyFramework/MainWindowSavedState.h>
  17. #include <AzToolsFramework/UI/Logging/LogPanel_Panel.h>
  18. #include <Source/LUA/LUAEditorFindResults.hxx>
  19. #include "LUAEditorContextInterface.h"
  20. #include "LUAEditorViewMessages.h"
  21. #include "LUAEditorView.hxx"
  22. #include "LUAEditorFindDialog.hxx"
  23. #pragma once
  24. class QMenu;
  25. class QAction;
  26. class QToolbar;
  27. class QDockWidget;
  28. class QSettings;
  29. class QStandardItemModel;
  30. namespace Ui
  31. {
  32. class LUAEditorMainWindow;
  33. }
  34. namespace AzToolsFramework
  35. {
  36. class TargetSelectorButtonAction;
  37. namespace AssetBrowser
  38. {
  39. class AssetBrowserFilterModel;
  40. }
  41. }
  42. namespace LUA
  43. {
  44. class TargetContextButtonAction;
  45. }
  46. class ClassReferenceFilterModel;
  47. #include <QtWidgets/QMainWindow>
  48. #endif
  49. namespace LUAEditor
  50. {
  51. // Structure used for storing/retrieving compilation error data
  52. struct CompilationErrorData
  53. {
  54. AZStd::string m_filename;
  55. int m_lineNumber = 0;
  56. };
  57. //forwards
  58. class LUAViewWidget;
  59. class LUAEditorSettingsDialog;
  60. class DebugAttachmentButtonAction;
  61. class AssetDatabaseLocationListener;
  62. //////////////////////////////////////////////////////////////////////////
  63. //Main Window
  64. class LUAEditorMainWindow
  65. : public QMainWindow
  66. , public LUAEditorMainWindowMessages::Handler
  67. , private LUAEditor::LUABreakpointTrackerMessages::Bus::Handler
  68. , public LUAViewMessages::Handler
  69. {
  70. Q_OBJECT;
  71. public:
  72. AZ_CLASS_ALLOCATOR(LUAEditorMainWindow,AZ::SystemAllocator,0);
  73. LUAEditorMainWindow(QStandardItemModel* dataModel, bool connectedState, QWidget* parent = NULL, Qt::WindowFlags flags = Qt::WindowFlags());
  74. virtual ~LUAEditorMainWindow();
  75. bool OnGetPermissionToShutDown();
  76. //////////////////////////////////////////////////////////////////////////
  77. // Qt Events
  78. private:
  79. void closeEvent(QCloseEvent* event) override;
  80. Ui::LUAEditorMainWindow* m_gui;
  81. AzToolsFramework::TargetSelectorButtonAction* m_pTargetButton;
  82. LUA::TargetContextButtonAction* m_pContextButton;
  83. DebugAttachmentButtonAction* m_pDebugAttachmentButton;
  84. bool m_bAutocompleteEnabled;
  85. int m_SkinChoice;
  86. Q_SIGNALS:
  87. void OnReferenceDataChanged();
  88. //////////////////////////////////////////////////////////////////////////
  89. // Qt Slots
  90. public slots:
  91. void RestoreWindowState();
  92. void OnMenuCloseCurrentWindow();
  93. //file menu
  94. void OnFileMenuOpen();
  95. void OnFileMenuNew();
  96. void OnFileMenuSave();
  97. void OnFileMenuSaveAs();
  98. void OnFileMenuSaveAll();
  99. void OnFileMenuReload();
  100. void OnFileMenuClose();
  101. void OnFileMenuCloseAll();
  102. void OnFileMenuCloseAllExcept();
  103. //edit menu
  104. void OnEditMenuUndo();
  105. void OnEditMenuRedo();
  106. void OnEditMenuCut();
  107. void OnEditMenuCopy();
  108. void OnEditMenuPaste();
  109. void OnEditMenuFind();
  110. void OnEditMenuFindNext();
  111. void OnEditMenuFindInAllOpen();
  112. void OnEditMenuFindLocal();
  113. void OnEditMenuFindLocalReverse();
  114. void OnEditMenuGoToLine();
  115. void OnEditMenuFoldAll();
  116. void OnEditMenuUnfoldAll();
  117. void OnEditMenuReplace();
  118. void OnEditMenuReplaceInAllOpen();
  119. void OnEditMenuSelectAll();
  120. void OnEditMenuSelectToBrace();
  121. void OnCommentSelectedBlock();
  122. void OnUnCommentSelectedBlock();
  123. void OnEditMenuTransposeUp();
  124. void OnEditMenuTransposeDn();
  125. void OnTabForwards();
  126. void OnTabBackwards();
  127. //view menu
  128. void OnViewMenuBreakpoints();
  129. void OnViewMenuStack();
  130. void OnViewMenuLocals();
  131. void OnViewMenuWatch();
  132. void OnViewMenuReference();
  133. void OnViewMenuFind1();
  134. void OnViewMenuFind2();
  135. void OnViewMenuFind3();
  136. void OnViewMenuFind4();
  137. void OnViewMenuResetZoom();
  138. // options Menu
  139. void OnAutocompleteChanged(bool change);
  140. void OnSettings();
  141. // help menu
  142. void OnLuaDocumentation();
  143. void OnDebugExecute();
  144. void OnDebugExecuteOnTarget();
  145. // execution control
  146. void OnDebugToggleBreakpoint();
  147. void OnDebugContinueRunning();
  148. void OnDebugStepOver();
  149. void OnDebugStepIn();
  150. void OnDebugStepOut();
  151. //source control
  152. void OnSourceControlMenuCheckOut();
  153. //tools menu
  154. // panels
  155. void luaClassFilterTextChanged( const QString& );
  156. //find
  157. void OnFindResultClicked(FindResultsBlockInfo result);
  158. void showTabContextMenu(const AZStd::string& assetId, const QPoint&);
  159. void closeAllTabsExceptThisTabContextMenu();
  160. // user closed all tabs in the log control
  161. void OnLogTabsReset();
  162. void AddMessageToLog(AzToolsFramework::Logging::LogLine::LogType type, const char* window, const char* message, void* data);
  163. private:
  164. AZStd::string m_currentTabContextMenuUUID;
  165. AZStd::string m_lastOpenFilePath;
  166. AZStd::vector<FindResultsBlockInfo> m_dProcessFindListClicked;
  167. void OnDataLoadedAndSet(const DocumentInfo& info, LUAViewWidget* pLUAViewWidget) override;
  168. AzToolsFramework::AssetBrowser::AssetBrowserFilterModel* m_filterModel;
  169. QSharedPointer<AzToolsFramework::AssetBrowser::CompositeFilter> CreateFilter();
  170. QAction* m_actionClearRecentFiles;
  171. void LogLineSelectionChanged(const AzToolsFramework::Logging::LogLine& logLine);
  172. void OnOptionsMenuRequested();
  173. void UpdateOpenRecentMenu();
  174. public:
  175. void SetupLuaFilesPanel();
  176. void ResetSearchClicks();
  177. bool NeedsCheckout();
  178. //////////////////////////////////////////////////////////////////////////
  179. //ClientInterface Messages
  180. private:
  181. //////////////////////////////////////////////////////////////////////////
  182. AssetDatabaseLocationListener* m_assetDatabaseListener = nullptr;
  183. public:
  184. void OnOpenLUAView(const DocumentInfo& docInfo);
  185. void OnOpenWatchView();
  186. void OnOpenBreakpointsView();
  187. void OnOpenStackView();
  188. void OnOpenLocalsView();
  189. void OnOpenFindView(int watchIndex); //this is not the page index this is the watch window index
  190. void OnOpenReferenceView();
  191. void MoveProgramCursor(const AZStd::string& assetId, int lineNumber);
  192. void MoveEditCursor(const AZStd::string& assetId, int lineNumber, bool withSelection = false);
  193. //////////////////////////////////////////////////////////////////////////
  194. // LUAEditorMainWindow Messages.
  195. public:
  196. virtual void OnCloseView(const AZStd::string& assetId);
  197. void OnFocusInEvent(const AZStd::string& assetId) override;
  198. void OnFocusOutEvent(const AZStd::string& assetId) override;
  199. void OnRequestCheckOut(const AZStd::string& assetId) override;
  200. void OnConnectedToTarget() override;
  201. void OnDisconnectedFromTarget() override;
  202. void OnConnectedToDebugger() override;
  203. void OnDisconnectedFromDebugger() override;
  204. void Repaint() override;
  205. //////////////////////////////////////////////////////////////////////////
  206. void dragEnterEvent(QDragEnterEvent *pEvent) override;
  207. void dropEvent(QDropEvent *pEvent) override;
  208. void IgnoreFocusEvents(bool ignore) { m_bIgnoreFocusRequests = ignore; }
  209. // specifically pass by value
  210. bool RequestCloseDocument(const AZStd::string assetId);
  211. void OnDockWidgetLocationChanged(const AZStd::string assetId);
  212. void OnDocumentInfoUpdated(const DocumentInfo& newInfo);
  213. bool OnRequestFocusView(const AZStd::string& assetId);
  214. bool OnFileSaveDialog(const AZStd::string& assetName, AZStd::string& newAssetName);
  215. bool OnFileSaveAsDialog(const AZStd::string& assetName, AZStd::string& newAssetName);
  216. //window state
  217. void SaveWindowState();
  218. // send new data to context.
  219. bool SyncDocumentToContext(const AZStd::string& assetId);
  220. private:
  221. //////////////////////////////////////////////////////////////////////////
  222. // Find Dialog
  223. LUAEditorFindDialog *m_ptrFindDialog;
  224. //////////////////////////////////////////////////////////////////////////
  225. LUAEditorSettingsDialog* m_settingsDialog;
  226. QTabBar* ResolveDockWidgetToTabBarAndIndex(LUADockWidget* pDockWidget, int& tabIndex);
  227. AZ::Uuid ResolveTabBarAndIndexToDocumentID(QTabBar* pBar, int tabIndex);
  228. QTabBar* FindMyDock(QWidget *source);
  229. //////////////////////////////////////////////////////////////////////////
  230. //View Tracking
  231. private:
  232. //LUA Views
  233. class TrackedLUAView
  234. {
  235. public:
  236. TrackedLUAView( LUADockWidget* pLUADockWidget,
  237. LUAViewWidget* pLUAViewWidget,
  238. AZStd::string assetId)
  239. : m_pLUADockWidget(pLUADockWidget)
  240. , m_pLUAViewWidget(pLUAViewWidget)
  241. , m_assetId(assetId){}
  242. ~TrackedLUAView(){};
  243. LUADockWidget* luaDockWidget(){ return m_pLUADockWidget;}
  244. LUAViewWidget* luaViewWidget(){ return m_pLUAViewWidget;}
  245. AZStd::string assetId(){ return m_assetId; }
  246. private:
  247. LUADockWidget* m_pLUADockWidget;
  248. LUAViewWidget* m_pLUAViewWidget;
  249. AZStd::string m_assetId;
  250. };//class TrackedLUAView
  251. typedef AZStd::unordered_map<AZStd::string, TrackedLUAView> TrackedLUAViewMap;
  252. TrackedLUAViewMap m_dOpenLUAView;
  253. //this will track the last focused document
  254. //this will get set on the focus event
  255. //Note this is only valid if the m_dOpenLUAView is not empty
  256. AZStd::string m_lastFocusedAssetId;
  257. QAction *actionTabForwards;
  258. QAction *actionTabBackwards;
  259. QLabel *m_ptrPerforceStatusWidget;
  260. // support for windows-ish Ctrl+Tab cycling through documents via the above Tab actions
  261. typedef AZStd::list<AZStd::string> TrackedLUACtrlTabOrder;
  262. TrackedLUACtrlTabOrder m_CtrlTabOrder;
  263. bool eventFilter(QObject *obj, QEvent *event) override;
  264. AZStd::string m_StoredTabAssetId;
  265. bool m_bIgnoreFocusRequests;
  266. // this tracks where the program cursor was last:
  267. AZStd::string m_lastProgramCounterAssetId;
  268. //////////////////////////////////////////////////////////////////////////
  269. //////////////////////////////////////////////////////////////////////////
  270. //Debugger Messages, from the LUAEditor::LUABreakpointTrackerMessages::Bus
  271. void BreakpointsUpdate(const LUAEditor::BreakpointMap& uniqueBreakpoints) override;
  272. void BreakpointHit(const LUAEditor::Breakpoint& breakpoint) override;
  273. void BreakpointResume() override;
  274. void OnExecuteScriptResult(bool success) override;
  275. //////////////////////////////////////////////////////////////////////////
  276. // track activity and synchronize the appropriate widgets' states to match
  277. void SetDebugControlsToInitial();
  278. void SetDebugControlsToRunning();
  279. void SetDebugControlsToAtBreak();
  280. void SetEditContolsToNoFilesOpen();
  281. void SetEditContolsToAtLeastOneFileOpen();
  282. //////////////////////////////////////////////////////////////////////////
  283. // LUA class reference panel support
  284. ClassReferenceFilterModel *m_ClassReferenceFilter;
  285. //////////////////////////////////////////////////////////////////////////
  286. // Internal state tracking to consolidate button/GUI handling
  287. struct StateTrack
  288. {
  289. StateTrack()
  290. : targetConnected(false)
  291. , debuggerAttached(false)
  292. , atLeastOneFileOpen(false)
  293. , scriptRunning(false)
  294. , atBreak(false)
  295. , hasExecuted(false)
  296. {}
  297. void Init()
  298. {
  299. targetConnected = false;
  300. debuggerAttached = false;
  301. atLeastOneFileOpen = false;
  302. scriptRunning = false;
  303. atBreak = false;
  304. hasExecuted = false;
  305. }
  306. bool targetConnected;
  307. bool debuggerAttached;
  308. bool atLeastOneFileOpen;
  309. bool scriptRunning;
  310. bool atBreak;
  311. bool hasExecuted;
  312. } m_StateTrack;
  313. void SetGUIToMatch( StateTrack & );
  314. //////////////////////////////////////////////////////////////////////////
  315. // Debugging
  316. private:
  317. void ExecuteScript(bool locally);
  318. //////////////////////////////////////////////////////////////////////////
  319. //finding
  320. public:
  321. QTabWidget* GetFindTabWidget();
  322. FindResults* GetFindResultsWidget(int index);
  323. void SetCurrentFindListWidget(int index);
  324. LUAViewWidget* GetCurrentView();
  325. AZStd::vector<LUAViewWidget*> GetAllViews();
  326. bool HasAtLeastOneFileOpen() const;
  327. };
  328. class LUAEditorMainWindowLayout : public QLayout
  329. {
  330. Q_OBJECT;
  331. public:
  332. AZ_CLASS_ALLOCATOR(LUAEditorMainWindowLayout, AZ::SystemAllocator);
  333. LUAEditorMainWindowLayout(QWidget *pParent);
  334. virtual ~LUAEditorMainWindowLayout();
  335. virtual void addItem(QLayoutItem *);
  336. virtual QLayoutItem *itemAt(int index) const ;
  337. virtual QLayoutItem *takeAt(int index) ;
  338. virtual int count() const;
  339. virtual void setGeometry ( const QRect & r );
  340. virtual QSize sizeHint() const;
  341. virtual QSize minimumSize() const;
  342. // this layout can only have two children:
  343. AZStd::vector<QLayoutItem *> children;
  344. virtual Qt::Orientations expandingDirections() const;
  345. };
  346. class LUAEditorMainWindowSavedState : public AzToolsFramework::MainWindowSavedState
  347. {
  348. public:
  349. AZ_RTTI(LUAEditorMainWindowSavedState, "{AEB8E5D6-4F2F-49A2-BB09-795614ABAAFF}", AzToolsFramework::MainWindowSavedState);
  350. AZ_CLASS_ALLOCATOR(LUAEditorMainWindowSavedState, AZ::SystemAllocator);
  351. AZStd::vector<AZStd::string> m_openAssetIds;
  352. bool m_bAutocompleteEnabled;
  353. bool m_bAutoReloadUnmodifiedFiles = false;
  354. LUAEditorMainWindowSavedState() {}
  355. void Init(const QByteArray& windowState,const QByteArray& windowGeom) override
  356. {
  357. AzToolsFramework::MainWindowSavedState::Init(windowState, windowGeom);
  358. }
  359. static void Reflect(AZ::ReflectContext* reflection);
  360. };
  361. }
  362. #endif //LUAEDITOR_LUAEDITORMAINWINDOW_H