LUAEditorMainWindow.hxx 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447
  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. void LogLineSelectionChanged(const AzToolsFramework::Logging::LogLine& logLine);
  171. void OnOptionsMenuRequested();
  172. public:
  173. void SetupLuaFilesPanel();
  174. void ResetSearchClicks();
  175. bool NeedsCheckout();
  176. //////////////////////////////////////////////////////////////////////////
  177. //ClientInterface Messages
  178. private:
  179. //////////////////////////////////////////////////////////////////////////
  180. AssetDatabaseLocationListener* m_assetDatabaseListener = nullptr;
  181. public:
  182. void OnOpenLUAView(const DocumentInfo& docInfo);
  183. void OnOpenWatchView();
  184. void OnOpenBreakpointsView();
  185. void OnOpenStackView();
  186. void OnOpenLocalsView();
  187. void OnOpenFindView(int watchIndex); //this is not the page index this is the watch window index
  188. void OnOpenReferenceView();
  189. void MoveProgramCursor(const AZStd::string& assetId, int lineNumber);
  190. void MoveEditCursor(const AZStd::string& assetId, int lineNumber, bool withSelection = false);
  191. //////////////////////////////////////////////////////////////////////////
  192. // LUAEditorMainWindow Messages.
  193. public:
  194. virtual void OnCloseView(const AZStd::string& assetId);
  195. void OnFocusInEvent(const AZStd::string& assetId) override;
  196. void OnFocusOutEvent(const AZStd::string& assetId) override;
  197. void OnRequestCheckOut(const AZStd::string& assetId) override;
  198. void OnConnectedToTarget() override;
  199. void OnDisconnectedFromTarget() override;
  200. void OnConnectedToDebugger() override;
  201. void OnDisconnectedFromDebugger() override;
  202. void Repaint() override;
  203. //////////////////////////////////////////////////////////////////////////
  204. void dragEnterEvent(QDragEnterEvent *pEvent) override;
  205. void dropEvent(QDropEvent *pEvent) override;
  206. void IgnoreFocusEvents(bool ignore) { m_bIgnoreFocusRequests = ignore; }
  207. // specifically pass by value
  208. bool RequestCloseDocument(const AZStd::string assetId);
  209. void OnDockWidgetLocationChanged(const AZStd::string assetId);
  210. void OnDocumentInfoUpdated(const DocumentInfo& newInfo);
  211. bool OnRequestFocusView(const AZStd::string& assetId);
  212. bool OnFileSaveDialog(const AZStd::string& assetName, AZStd::string& newAssetName);
  213. bool OnFileSaveAsDialog(const AZStd::string& assetName, AZStd::string& newAssetName);
  214. //window state
  215. void SaveWindowState();
  216. // send new data to context.
  217. bool SyncDocumentToContext(const AZStd::string& assetId);
  218. private:
  219. //////////////////////////////////////////////////////////////////////////
  220. // Find Dialog
  221. LUAEditorFindDialog *m_ptrFindDialog;
  222. //////////////////////////////////////////////////////////////////////////
  223. LUAEditorSettingsDialog* m_settingsDialog;
  224. QTabBar* ResolveDockWidgetToTabBarAndIndex(LUADockWidget* pDockWidget, int& tabIndex);
  225. AZ::Uuid ResolveTabBarAndIndexToDocumentID(QTabBar* pBar, int tabIndex);
  226. QTabBar* FindMyDock(QWidget *source);
  227. //////////////////////////////////////////////////////////////////////////
  228. //View Tracking
  229. private:
  230. //LUA Views
  231. class TrackedLUAView
  232. {
  233. public:
  234. TrackedLUAView( LUADockWidget* pLUADockWidget,
  235. LUAViewWidget* pLUAViewWidget,
  236. AZStd::string assetId)
  237. : m_pLUADockWidget(pLUADockWidget)
  238. , m_pLUAViewWidget(pLUAViewWidget)
  239. , m_assetId(assetId){}
  240. ~TrackedLUAView(){};
  241. LUADockWidget* luaDockWidget(){ return m_pLUADockWidget;}
  242. LUAViewWidget* luaViewWidget(){ return m_pLUAViewWidget;}
  243. AZStd::string assetId(){ return m_assetId; }
  244. private:
  245. LUADockWidget* m_pLUADockWidget;
  246. LUAViewWidget* m_pLUAViewWidget;
  247. AZStd::string m_assetId;
  248. };//class TrackedLUAView
  249. typedef AZStd::unordered_map<AZStd::string, TrackedLUAView> TrackedLUAViewMap;
  250. TrackedLUAViewMap m_dOpenLUAView;
  251. //this will track the last focused document
  252. //this will get set on the focus event
  253. //Note this is only valid if the m_dOpenLUAView is not empty
  254. AZStd::string m_lastFocusedAssetId;
  255. QAction *actionTabForwards;
  256. QAction *actionTabBackwards;
  257. QLabel *m_ptrPerforceStatusWidget;
  258. // support for windows-ish Ctrl+Tab cycling through documents via the above Tab actions
  259. typedef AZStd::list<AZStd::string> TrackedLUACtrlTabOrder;
  260. TrackedLUACtrlTabOrder m_CtrlTabOrder;
  261. bool eventFilter(QObject *obj, QEvent *event) override;
  262. AZStd::string m_StoredTabAssetId;
  263. bool m_bIgnoreFocusRequests;
  264. // this tracks where the program cursor was last:
  265. AZStd::string m_lastProgramCounterAssetId;
  266. //////////////////////////////////////////////////////////////////////////
  267. //////////////////////////////////////////////////////////////////////////
  268. //Debugger Messages, from the LUAEditor::LUABreakpointTrackerMessages::Bus
  269. void BreakpointsUpdate(const LUAEditor::BreakpointMap& uniqueBreakpoints) override;
  270. void BreakpointHit(const LUAEditor::Breakpoint& breakpoint) override;
  271. void BreakpointResume() override;
  272. void OnExecuteScriptResult(bool success) override;
  273. //////////////////////////////////////////////////////////////////////////
  274. // track activity and synchronize the appropriate widgets' states to match
  275. void SetDebugControlsToInitial();
  276. void SetDebugControlsToRunning();
  277. void SetDebugControlsToAtBreak();
  278. void SetEditContolsToNoFilesOpen();
  279. void SetEditContolsToAtLeastOneFileOpen();
  280. //////////////////////////////////////////////////////////////////////////
  281. // LUA class reference panel support
  282. ClassReferenceFilterModel *m_ClassReferenceFilter;
  283. //////////////////////////////////////////////////////////////////////////
  284. // Internal state tracking to consolidate button/GUI handling
  285. struct StateTrack
  286. {
  287. StateTrack()
  288. : targetConnected(false)
  289. , debuggerAttached(false)
  290. , atLeastOneFileOpen(false)
  291. , scriptRunning(false)
  292. , atBreak(false)
  293. , hasExecuted(false)
  294. {}
  295. void Init()
  296. {
  297. targetConnected = false;
  298. debuggerAttached = false;
  299. atLeastOneFileOpen = false;
  300. scriptRunning = false;
  301. atBreak = false;
  302. hasExecuted = false;
  303. }
  304. bool targetConnected;
  305. bool debuggerAttached;
  306. bool atLeastOneFileOpen;
  307. bool scriptRunning;
  308. bool atBreak;
  309. bool hasExecuted;
  310. } m_StateTrack;
  311. void SetGUIToMatch( StateTrack & );
  312. //////////////////////////////////////////////////////////////////////////
  313. // Debugging
  314. private:
  315. void ExecuteScript(bool locally);
  316. //////////////////////////////////////////////////////////////////////////
  317. //finding
  318. public:
  319. QTabWidget* GetFindTabWidget();
  320. FindResults* GetFindResultsWidget(int index);
  321. void SetCurrentFindListWidget(int index);
  322. LUAViewWidget* GetCurrentView();
  323. AZStd::vector<LUAViewWidget*> GetAllViews();
  324. };
  325. class LUAEditorMainWindowLayout : public QLayout
  326. {
  327. Q_OBJECT;
  328. public:
  329. AZ_CLASS_ALLOCATOR(LUAEditorMainWindowLayout, AZ::SystemAllocator);
  330. LUAEditorMainWindowLayout(QWidget *pParent);
  331. virtual ~LUAEditorMainWindowLayout();
  332. virtual void addItem(QLayoutItem *);
  333. virtual QLayoutItem *itemAt(int index) const ;
  334. virtual QLayoutItem *takeAt(int index) ;
  335. virtual int count() const;
  336. virtual void setGeometry ( const QRect & r );
  337. virtual QSize sizeHint() const;
  338. virtual QSize minimumSize() const;
  339. // this layout can only have two children:
  340. AZStd::vector<QLayoutItem *> children;
  341. virtual Qt::Orientations expandingDirections() const;
  342. };
  343. class LUAEditorMainWindowSavedState : public AzToolsFramework::MainWindowSavedState
  344. {
  345. public:
  346. AZ_RTTI(LUAEditorMainWindowSavedState, "{AEB8E5D6-4F2F-49A2-BB09-795614ABAAFF}", AzToolsFramework::MainWindowSavedState);
  347. AZ_CLASS_ALLOCATOR(LUAEditorMainWindowSavedState, AZ::SystemAllocator);
  348. AZStd::vector<AZStd::string> m_openAssetIds;
  349. bool m_bAutocompleteEnabled;
  350. bool m_bAutoReloadUnmodifiedFiles = false;
  351. LUAEditorMainWindowSavedState() {}
  352. void Init(const QByteArray& windowState,const QByteArray& windowGeom) override
  353. {
  354. AzToolsFramework::MainWindowSavedState::Init(windowState, windowGeom);
  355. }
  356. static void Reflect(AZ::ReflectContext* reflection);
  357. };
  358. }
  359. #endif //LUAEDITOR_LUAEDITORMAINWINDOW_H