Added option to reopen if the current level is the same. This contributes to stability for batched tests (#4043)

* Added option to reopen if the current level is the same. This contributes to stability for batched tests

Signed-off-by: AMZN-AlexOteiza <aljanru@amazon.co.uk>

* Addressed PR comments

* Addressed PR and cleaned Base level that had an entity by accident

Signed-off-by: AMZN-AlexOteiza <aljanru@amazon.co.uk>

* Cleaned up params

Signed-off-by: AMZN-AlexOteiza <aljanru@amazon.co.uk>

* Addressed PR comments
monroegm-disable-blank-issue-2
AMZN-AlexOteiza 4 years ago committed by GitHub
parent a1ee7b5a31
commit 38f9dcb8ca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -1,3 +1,3 @@
version https://git-lfs.github.com/spec/v1 version https://git-lfs.github.com/spec/v1
oid sha256:e4937547ca4c486ef59656314401933217e0e0401fec103e1fb91c25ec60a177 oid sha256:a5f9e27e0f22c31ca61d866fb594c6fde5b8ceb891e17dda075fa1e0033ec2b9
size 2806 size 1666

@ -287,21 +287,22 @@ bool CCryDocManager::DoPromptFileName(QString& fileName, [[maybe_unused]] UINT n
return false; return false;
} }
CCryEditDoc* CCryDocManager::OpenDocumentFile(const char* lpszFileName, bool bAddToMRU) CCryEditDoc* CCryDocManager::OpenDocumentFile(const char* filename, bool addToMostRecentFileList, COpenSameLevelOptions openSameLevelOptions)
{ {
assert(lpszFileName != nullptr); assert(filename != nullptr);
const bool reopenIfSame = openSameLevelOptions == COpenSameLevelOptions::ReopenLevelIfSame;
// find the highest confidence // find the highest confidence
auto pos = m_templateList.begin(); auto pos = m_templateList.begin();
CCrySingleDocTemplate::Confidence bestMatch = CCrySingleDocTemplate::noAttempt; CCrySingleDocTemplate::Confidence bestMatch = CCrySingleDocTemplate::noAttempt;
CCrySingleDocTemplate* pBestTemplate = nullptr; CCrySingleDocTemplate* pBestTemplate = nullptr;
CCryEditDoc* pOpenDocument = nullptr; CCryEditDoc* pOpenDocument = nullptr;
if (lpszFileName[0] == '\"') if (filename[0] == '\"')
{ {
++lpszFileName; ++filename;
} }
QString szPath = QString::fromUtf8(lpszFileName); QString szPath = QString::fromUtf8(filename);
if (szPath.endsWith('"')) if (szPath.endsWith('"'))
{ {
szPath.remove(szPath.length() - 1, 1); szPath.remove(szPath.length() - 1, 1);
@ -325,7 +326,7 @@ CCryEditDoc* CCryDocManager::OpenDocumentFile(const char* lpszFileName, bool bAd
} }
} }
if (pOpenDocument != nullptr) if (!reopenIfSame && pOpenDocument != nullptr)
{ {
return pOpenDocument; return pOpenDocument;
} }
@ -336,7 +337,7 @@ CCryEditDoc* CCryDocManager::OpenDocumentFile(const char* lpszFileName, bool bAd
return nullptr; return nullptr;
} }
return pBestTemplate->OpenDocumentFile(szPath.toUtf8().data(), bAddToMRU, false); return pBestTemplate->OpenDocumentFile(szPath.toUtf8().data(), addToMostRecentFileList, false);
} }
////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////
@ -818,7 +819,7 @@ CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(const char* lpszPathName, b
return OpenDocumentFile(lpszPathName, true, bMakeVisible); return OpenDocumentFile(lpszPathName, true, bMakeVisible);
} }
CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(const char* lpszPathName, bool bAddToMRU, [[maybe_unused]] bool bMakeVisible) CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(const char* lpszPathName, bool addToMostRecentFileList, [[maybe_unused]] bool bMakeVisible)
{ {
CCryEditDoc* pCurDoc = GetIEditor()->GetDocument(); CCryEditDoc* pCurDoc = GetIEditor()->GetDocument();
@ -848,7 +849,7 @@ CCryEditDoc* CCrySingleDocTemplate::OpenDocumentFile(const char* lpszPathName, b
{ {
pCurDoc->OnOpenDocument(lpszPathName); pCurDoc->OnOpenDocument(lpszPathName);
pCurDoc->SetPathName(lpszPathName); pCurDoc->SetPathName(lpszPathName);
if (bAddToMRU) if (addToMostRecentFileList)
{ {
CCryEditApp::instance()->AddToRecentFileList(lpszPathName); CCryEditApp::instance()->AddToRecentFileList(lpszPathName);
} }
@ -3365,7 +3366,7 @@ void CCryEditApp::OnOpenSlice()
} }
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
CCryEditDoc* CCryEditApp::OpenDocumentFile(const char* lpszFileName) CCryEditDoc* CCryEditApp::OpenDocumentFile(const char* filename, bool addToMostRecentFileList, COpenSameLevelOptions openSameLevelOptions)
{ {
if (m_openingLevel) if (m_openingLevel)
{ {
@ -3405,9 +3406,9 @@ CCryEditDoc* CCryEditApp::OpenDocumentFile(const char* lpszFileName)
openDocTraceHandler.SetShowWindow(false); openDocTraceHandler.SetShowWindow(false);
} }
// in this case, we set bAddToMRU to always be true because adding files to the MRU list // in this case, we set addToMostRecentFileList to always be true because adding files to the MRU list
// automatically culls duplicate and normalizes paths anyway // automatically culls duplicate and normalizes paths anyway
m_pDocManager->OpenDocumentFile(lpszFileName, true); m_pDocManager->OpenDocumentFile(filename, addToMostRecentFileList, openSameLevelOptions);
if (openDocTraceHandler.HasAnyErrors()) if (openDocTraceHandler.HasAnyErrors())
{ {

@ -85,6 +85,12 @@ public:
using EditorIdleProcessingBus = AZ::EBus<EditorIdleProcessing>; using EditorIdleProcessingBus = AZ::EBus<EditorIdleProcessing>;
enum class COpenSameLevelOptions
{
ReopenLevelIfSame,
NotReopenIfSame
};
AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING AZ_PUSH_DISABLE_DLL_EXPORT_BASECLASS_WARNING
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
class SANDBOX_API CCryEditApp class SANDBOX_API CCryEditApp
@ -174,7 +180,9 @@ public:
virtual bool InitInstance(); virtual bool InitInstance();
virtual int ExitInstance(int exitCode = 0); virtual int ExitInstance(int exitCode = 0);
virtual bool OnIdle(LONG lCount); virtual bool OnIdle(LONG lCount);
virtual CCryEditDoc* OpenDocumentFile(const char* lpszFileName); virtual CCryEditDoc* OpenDocumentFile(const char* filename,
bool addToMostRecentFileList=true,
COpenSameLevelOptions openSameLevelOptions = COpenSameLevelOptions::NotReopenIfSame);
CCryDocManager* GetDocManager() { return m_pDocManager; } CCryDocManager* GetDocManager() { return m_pDocManager; }
@ -448,7 +456,7 @@ public:
~CCrySingleDocTemplate() {}; ~CCrySingleDocTemplate() {};
// avoid creating another CMainFrame // avoid creating another CMainFrame
// close other type docs before opening any things // close other type docs before opening any things
virtual CCryEditDoc* OpenDocumentFile(const char* lpszPathName, bool bAddToMRU, bool bMakeVisible); virtual CCryEditDoc* OpenDocumentFile(const char* lpszPathName, bool addToMostRecentFileList, bool bMakeVisible);
virtual CCryEditDoc* OpenDocumentFile(const char* lpszPathName, bool bMakeVisible = TRUE); virtual CCryEditDoc* OpenDocumentFile(const char* lpszPathName, bool bMakeVisible = TRUE);
virtual Confidence MatchDocType(const char* lpszPathName, CCryEditDoc*& rpDocMatch); virtual Confidence MatchDocType(const char* lpszPathName, CCryEditDoc*& rpDocMatch);
@ -468,7 +476,7 @@ public:
virtual void OnFileNew(); virtual void OnFileNew();
virtual bool DoPromptFileName(QString& fileName, UINT nIDSTitle, virtual bool DoPromptFileName(QString& fileName, UINT nIDSTitle,
DWORD lFlags, bool bOpenFileDialog, CDocTemplate* pTemplate); DWORD lFlags, bool bOpenFileDialog, CDocTemplate* pTemplate);
virtual CCryEditDoc* OpenDocumentFile(const char* lpszFileName, bool bAddToMRU); virtual CCryEditDoc* OpenDocumentFile(const char* filename, bool addToMostRecentFileList, COpenSameLevelOptions openSameLevelOptions = COpenSameLevelOptions::NotReopenIfSame);
QVector<CCrySingleDocTemplate*> m_templateList; QVector<CCrySingleDocTemplate*> m_templateList;
}; };

@ -143,20 +143,11 @@ namespace
return false; return false;
} }
} }
const bool addToMostRecentFileList = false;
auto newDocument = CCryEditApp::instance()->OpenDocumentFile(levelPath.toUtf8().data(),
addToMostRecentFileList, COpenSameLevelOptions::ReopenLevelIfSame);
auto previousDocument = GetIEditor()->GetDocument(); return newDocument != nullptr && !newDocument->IsLevelLoadFailed();
QString previousPathName = (previousDocument != nullptr) ? previousDocument->GetLevelPathName() : "";
auto newDocument = CCryEditApp::instance()->OpenDocumentFile(levelPath.toUtf8().data());
// the underlying document pointer doesn't change, so we can't check that; use the path name's instead
bool result = true;
if (newDocument == nullptr || newDocument->IsLevelLoadFailed() || (newDocument->GetLevelPathName() == previousPathName))
{
result = false;
}
return result;
} }
bool PyOpenLevelNoPrompt(const char* pLevelName) bool PyOpenLevelNoPrompt(const char* pLevelName)

Loading…
Cancel
Save