LUAEditorFindDialog.hxx 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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_FINDDIALOG_H
  9. #define LUAEDITOR_FINDDIALOG_H
  10. #if !defined(Q_MOC_RUN)
  11. #include <AzCore/std/parallel/thread.h>
  12. #include <AzCore/std/parallel/semaphore.h>
  13. #include <AzCore/Component/Component.h>
  14. #include "LUAEditorView.hxx"
  15. #include <QDialog>
  16. #endif
  17. #pragma once
  18. class LUAEditorMainWindow;
  19. class QListWidget;
  20. namespace Ui
  21. {
  22. class LUAEditorFindDialog;
  23. }
  24. namespace LUAEditor
  25. {
  26. class LUAEditorMainWindow;
  27. class FindResults;
  28. // mode controls the main find process loops, that are now consolidated
  29. enum mode
  30. {
  31. CurrentDoc,
  32. AllOpenDocs,
  33. AllLUAAssets,
  34. };
  35. //////////////////////////////////////////////////////////////////////////
  36. // Find Dialog
  37. class LUAEditorFindDialog
  38. : public QDialog
  39. , public LUAViewMessages::Handler
  40. {
  41. Q_OBJECT
  42. public:
  43. AZ_CLASS_ALLOCATOR(LUAEditorFindDialog, AZ::SystemAllocator);
  44. LUAEditorFindDialog(QWidget *parent = 0);
  45. ~LUAEditorFindDialog();
  46. void SetAnyDocumentsOpen(bool value);
  47. void SetToFindInAllOpen( bool findInAny );
  48. void SetNewSearchStarting( bool bOverride = false, bool bSearchForwards = true );
  49. void ResetSearch();
  50. virtual void showEvent( QShowEvent * event );
  51. static void Reflect(AZ::ReflectContext* reflection);
  52. void SaveState();
  53. private:
  54. LUAViewWidget::FindOperation m_findOperation;
  55. bool m_bFoundFirst;
  56. bool m_bLastForward;
  57. bool m_bLastWrap;
  58. bool m_bAnyDocumentsOpen;
  59. bool m_bWasFindInAll;
  60. // prep for deeper search options
  61. int m_WrapLine;
  62. int m_WrapIndex;
  63. LUAViewWidget* m_WrapWidget;
  64. LUAEditorMainWindow* pLUAEditorMainWindow;
  65. int m_lastSearchWhere;
  66. QString m_lastSearchText;
  67. void FindInView(LUAViewWidget* pLUAViewWidget, QListWidget* pCurrentFindListView);
  68. int ReplaceInView(LUAViewWidget* pLUAViewWidget);
  69. void BusyOn();
  70. void PostProcessOn();
  71. void PostReplaceOn();
  72. void BusyOff();
  73. //////////////////////////////////////////////////////////////////////////
  74. //LUAViewMessages::Bus
  75. void OnDataLoadedAndSet(const DocumentInfo& info, LUAViewWidget* pLUAViewWidget);
  76. //////////////////////////////////////////////////////////////////////////
  77. //stored dialog state for find/replace threads
  78. QString m_SearchText;
  79. bool m_bCaseSensitiveIsChecked;
  80. bool m_bWholeWordIsChecked;
  81. bool m_bRegExIsChecked;
  82. AZStd::vector<AZStd::string> m_dOpenView;
  83. //find in files thread stuff
  84. void FindInFilesSetUp(int theMode, FindResults* resultsWidget);
  85. AZStd::vector<AZStd::string> m_dFindAllLUAAssetsInfo;
  86. bool m_bFindThreadRunning;
  87. bool m_bCancelFindSignal;
  88. void ProcessFindItems();
  89. struct ResultEntry
  90. {
  91. QString m_lineText;
  92. int m_lineNumber;
  93. AZStd::vector<AZStd::pair<int, int>> m_matches; //position and length within line
  94. };
  95. struct ResultDocument
  96. {
  97. AZStd::string m_assetId;
  98. AZStd::vector<ResultEntry> m_entries;
  99. };
  100. QHash<QString, ResultDocument> m_resultList;
  101. //replace in files thread stuff
  102. bool m_bReplaceThreadRunning;
  103. bool m_bCancelReplaceSignal;
  104. void ReplaceInFilesSetUp();
  105. //utility
  106. LUAViewWidget* GetViewFromParent();
  107. struct FIFData
  108. {
  109. int m_TotalMatchesFound;
  110. QString m_SearchText;
  111. bool m_bCaseSensitiveIsChecked;
  112. bool m_bWholeWordIsChecked;
  113. bool m_bRegExIsChecked;
  114. FindResults* m_resultsWidget;
  115. AZStd::vector<LUAViewWidget*> m_OpenView;
  116. AZStd::vector<AZStd::string> m_dOpenView;
  117. AZStd::vector<LUAViewWidget*>::iterator m_openViewIter;
  118. AZStd::vector< AZStd::string>::iterator m_assetInfoIter;
  119. };
  120. FIFData m_FIFData;
  121. struct RIFData
  122. {
  123. int m_TotalMatchesFound;
  124. QString m_SearchText;
  125. bool m_bCaseSensitiveIsChecked;
  126. bool m_bWholeWordIsChecked;
  127. bool m_bRegExIsChecked;
  128. QListWidget* m_pCurrentFindListView;
  129. AZStd::vector<LUAViewWidget*> m_OpenView;
  130. AZStd::vector<AZStd::string> m_dOpenView;
  131. AZStd::vector</*EditorFramework::EditorAsset*/AZStd::string>::iterator m_assetInfoIter; // fix this
  132. AZStd::vector</*EditorFramework::EditorAsset*/AZStd::string> m_dReplaceAllLUAAssetsInfo; // fix this
  133. AZStd::vector<AZStd::string> m_dReplaceProcessList;
  134. AZStd::unordered_set<AZStd::string> m_waitingForOpenToComplete;
  135. };
  136. RIFData m_RIFData;
  137. AZStd::vector<LUAViewWidget*> m_PendingReplaceInViewOperations;
  138. signals:
  139. void triggerFindInFilesNext( int theMode );
  140. void triggerReplaceInFilesNext();
  141. void triggerFindNextInView(LUAViewWidget::FindOperation* operation, LUAViewWidget* pLUAViewWidget, QListWidget* pCurrentFindListView);
  142. public slots:
  143. void OnReplaceAll();
  144. void OnReplace();
  145. void OnCancel();
  146. void OnFindNext();
  147. void OnFindAll();
  148. void OnSearchWhereChanged( int index );
  149. void FindInFilesNext( int theMode );
  150. void ReplaceInFilesNext();
  151. void ProcessReplaceItems();
  152. void OnReplaceInViewIterate();
  153. void FindNextInView(LUAViewWidget::FindOperation* operation, LUAViewWidget* pLUAViewWidget, QListWidget* pCurrentFindListView);
  154. private:
  155. Ui::LUAEditorFindDialog* m_gui;
  156. };
  157. }
  158. #endif //LUAEDITOR_FINDDIALOG_H