From 39c9adff2fcee5e6a9c0b254e636f2f0ae695f2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Mon, 16 Sep 2024 20:36:04 -0300 Subject: [PATCH] Fix for issue SpartanJ/ecode#330. --- include/eepp/ui/doc/textdocument.hpp | 4 ++-- projects/linux/ee.creator.user | 10 ++++----- src/eepp/ui/doc/textdocument.cpp | 32 ++++++++++++++++++++-------- 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/include/eepp/ui/doc/textdocument.hpp b/include/eepp/ui/doc/textdocument.hpp index 87ee4e86c..c24c47e5e 100644 --- a/include/eepp/ui/doc/textdocument.hpp +++ b/include/eepp/ui/doc/textdocument.hpp @@ -516,9 +516,9 @@ class EE_API TextDocument { void toLowerSelection(); - const std::string& getLoadingFilePath() const; + std::string getLoadingFilePath() const; - const URI& getLoadingFileURI() const; + URI getLoadingFileURI() const; void setSelection( const TextRanges& selection ); diff --git a/projects/linux/ee.creator.user b/projects/linux/ee.creator.user index 80bef86a6..917837d8c 100644 --- a/projects/linux/ee.creator.user +++ b/projects/linux/ee.creator.user @@ -1,6 +1,6 @@ - + EnvironmentId @@ -124,7 +124,7 @@ {388e5431-b31b-42b3-b9ad-9002d279d75d} 10 0 - 19 + 2 ../../make/linux @@ -1219,10 +1219,10 @@ eepp-empty-window-debug ProjectExplorer.CustomExecutableRunConfiguration - false - 1 + true + 0 false - 0 + 1 false false %{buildDir}../../../bin/ diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 221a05504..82f43a84f 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -57,6 +57,17 @@ TextDocument::~TextDocument() { mLoading = false; Lock l( mLoadingMutex ); } + + { + Lock l( mClientsMutex ); + } + + // Loading has been stopped + while ( mLoadingAsync ) { + mLoading = false; + Sys::sleep( Milliseconds( 0.1 ) ); + } + notifyDocumentClosed(); if ( mDeleteOnClose ) FileSystem::fileRemove( mFilePath ); @@ -484,12 +495,12 @@ void TextDocument::toLowerSelection() { } } -const std::string& TextDocument::getLoadingFilePath() const { +std::string TextDocument::getLoadingFilePath() const { Lock l( mLoadingFilePathMutex ); return mLoadingFilePath; } -const URI& TextDocument::getLoadingFileURI() const { +URI TextDocument::getLoadingFileURI() const { Lock l( mLoadingFilePathMutex ); return mLoadingFileURI; } @@ -534,8 +545,8 @@ bool TextDocument::loadAsyncFromFile( const std::string& path, std::shared_ptr onLoaded, const Http::Request::ProgressCallback& progressCallback ) { + mLoading = true; URI uri( url ); - if ( uri.getScheme().empty() || ( uri.getScheme() != "https" && uri.getScheme() != "http" ) ) + if ( uri.getScheme().empty() || ( uri.getScheme() != "https" && uri.getScheme() != "http" ) ) { + mLoading = false; return false; + } - mLoading = true; mLoadingAsync = true; Http::getAsync( @@ -617,8 +631,8 @@ bool TextDocument::loadAsyncFromURL( const std::string& url, onLoaded( this, false ); } mLoading = false; - mLoadingAsync = false; notifyDocumentLoaded(); + mLoadingAsync = false; }, uri, Seconds( 10 ), progressCallback, headers, "", true, Http::getEnvProxyURI() ); return true;