LUAEditorMainWindow.hxx 15 KB

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