From 73a868db55168ba57270b66be132a62e9a7d1997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Thu, 29 Aug 2024 18:20:17 -0300 Subject: [PATCH] Allow to drag folder into the editor and it will load the folder (SpartanJ/ecode/314). Flag the document as modified until saved when changing it's line ending (SpartanJ/ecode/315). Avoid processing document symbols on huge files. Avoid matching brackets on huge files. --- include/eepp/ui/doc/textdocument.hpp | 2 ++ src/eepp/ui/doc/textdocument.cpp | 12 ++++++++++++ src/eepp/ui/uicodeeditor.cpp | 4 ++++ src/tools/ecode/ecode.cpp | 18 ++++++++++++------ src/tools/ecode/ecode.hpp | 2 +- .../autocomplete/autocompleteplugin.cpp | 3 +-- src/tools/ecode/projectbuild.cpp | 7 ++++++- src/tools/ecode/settingsmenu.cpp | 6 ++++-- 8 files changed, 42 insertions(+), 12 deletions(-) diff --git a/include/eepp/ui/doc/textdocument.hpp b/include/eepp/ui/doc/textdocument.hpp index 630352925..87ee4e86c 100644 --- a/include/eepp/ui/doc/textdocument.hpp +++ b/include/eepp/ui/doc/textdocument.hpp @@ -639,6 +639,8 @@ class EE_API TextDocument { void setDirtyUntilSave(); + bool isHuge() const; + protected: friend class TextUndoStack; friend class FoldRangeServive; diff --git a/src/eepp/ui/doc/textdocument.cpp b/src/eepp/ui/doc/textdocument.cpp index 6cb1c61e2..ead9f47f1 100644 --- a/src/eepp/ui/doc/textdocument.cpp +++ b/src/eepp/ui/doc/textdocument.cpp @@ -3023,6 +3023,18 @@ void TextDocument::setDirtyUntilSave() { notifySelectionChanged(); } +static size_t guessFileSize( const TextDocument* doc ) { + Int64 maxLines = std::min( 101ul, doc->linesCount() ); + Int64 totalSize = 0; + for ( Int64 i = 0; i < maxLines; i++ ) + totalSize += doc->line( i ).size(); + return totalSize; +} + +bool TextDocument::isHuge() const { + return linesCount() > 50000 || guessFileSize( this ) > EE_1MB * 10; +} + void TextDocument::changeFilePath( const std::string& filePath, bool notify ) { mFilePath = filePath; mFileURI = URI( "file://" + mFilePath ); diff --git a/src/eepp/ui/uicodeeditor.cpp b/src/eepp/ui/uicodeeditor.cpp index 0fce04cba..ba1367b7a 100644 --- a/src/eepp/ui/uicodeeditor.cpp +++ b/src/eepp/ui/uicodeeditor.cpp @@ -2763,6 +2763,10 @@ void UICodeEditor::checkMatchingBrackets() { pos.setColumn( pos.column() - 1 ); } } + + if ( ( isOpenIt == open.end() && isCloseIt == close.end() ) || mDoc->isHuge() ) + return; + if ( isOpenIt != open.end() ) { size_t index = std::distance( open.begin(), isOpenIt ); String::StringBaseType openBracket = open[index]; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index faffc73ec..a3c17f6b2 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -678,7 +678,7 @@ void App::mainLoop() { } } -void App::onFileDropped( String file ) { +void App::onFileDropped( std::string file ) { Vector2f mousePos( mUISceneNode->getEventDispatcher()->getMousePosf() ); Node* node = mUISceneNode->overFind( mousePos ); UIWidget* widget = mSplitter->getCurWidget(); @@ -695,8 +695,7 @@ void App::onFileDropped( String file ) { if ( node && node->isType( UI_TYPE_CODEEDITOR ) ) { codeEditor = node->asType(); if ( ( codeEditor->getDocument().isLoading() || !codeEditor->getDocument().isEmpty() ) && - ( !Image::isImageExtension( file ) || - FileSystem::fileExtension( file.toUtf8() ) == "svg" ) ) { + ( !Image::isImageExtension( file ) || FileSystem::fileExtension( file ) == "svg" ) ) { auto d = mSplitter->createCodeEditorInTabWidget( mSplitter->tabWidgetFromEditor( codeEditor ) ); codeEditor = d.second; @@ -704,8 +703,7 @@ void App::onFileDropped( String file ) { } } else if ( widget && widget->isType( UI_TYPE_TERMINAL ) ) { if ( !Image::isImageExtension( file ) && - ( !Image::isImageExtension( file ) || - FileSystem::fileExtension( file.toUtf8() ) == "svg" ) ) { + ( !Image::isImageExtension( file ) || FileSystem::fileExtension( file ) == "svg" ) ) { auto d = mSplitter->createCodeEditorInTabWidget( mSplitter->tabWidgetFromWidget( widget ) ); codeEditor = d.second; @@ -3455,6 +3453,9 @@ void App::loadFolder( const std::string& path ) { loadDirTree( rpath ); Clock projClock; + if ( mProjectBuildManager ) + mProjectBuildManager.reset(); + mProjectBuildManager = std::make_unique( rpath, mThreadPool, mSidePanel, this ); mConfig.loadProject( rpath, mSplitter, mConfigPath, mProjectDocConfig, this, @@ -3740,7 +3741,12 @@ void App::init( const LogLevel& logLevel, std::string file, const Float& pidelDe mWindow->getInput()->pushCallback( [this]( InputEvent* event ) { if ( event->Type == InputEvent::FileDropped ) { - onFileDropped( event->file.file ); + std::string file( event->file.file ); + + if ( FileSystem::isDirectory( file ) ) + loadFolder( file ); + else + onFileDropped( file ); } else if ( event->Type == InputEvent::TextDropped ) { onTextDropped( event->textdrop.text ); } diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index 755a2d3f3..1285c339e 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -574,7 +574,7 @@ class App : public UICodeEditorSplitter::Client { void showSidePanel( bool show ); - void onFileDropped( String file ); + void onFileDropped( std::string file ); void onTextDropped( String text ); diff --git a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp index c1af2e141..400084475 100644 --- a/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp +++ b/src/tools/ecode/plugins/autocomplete/autocompleteplugin.cpp @@ -1235,8 +1235,7 @@ void AutoCompletePlugin::resetSignatureHelp() { AutoCompletePlugin::SymbolsList AutoCompletePlugin::getDocumentSymbols( TextDocument* doc ) { LuaPattern pattern( mSymbolPattern ); AutoCompletePlugin::SymbolsList symbols; - Int64 lc = doc->linesCount(); - if ( lc == 0 || lc > 50000 || mShuttingDown ) + if ( doc->linesCount() == 0 || doc->isHuge() || mShuttingDown ) return symbols; std::string current( getPartialSymbol( doc ) ); TextPosition end = doc->getSelection().end(); diff --git a/src/tools/ecode/projectbuild.cpp b/src/tools/ecode/projectbuild.cpp index 322e03a37..f1db9f131 100644 --- a/src/tools/ecode/projectbuild.cpp +++ b/src/tools/ecode/projectbuild.cpp @@ -19,6 +19,8 @@ using namespace EE::Scene; namespace ecode { +static constexpr auto SidePanelLoadUniqueId = String::hash( "ProjectBuildManager::load::async" ); + static const char* VAR_PROJECT_ROOT = "${project_root}"; static const char* VAR_BUILD_TYPE = "${build_type}"; static const char* VAR_OS = "${os}"; @@ -307,6 +309,8 @@ void ProjectBuildManager::selectTab() { } ProjectBuildManager::~ProjectBuildManager() { + mSidePanel->removeActionsByTag( SidePanelLoadUniqueId ); + if ( mUISceneNode && !SceneManager::instance()->isShuttingDown() && mSidePanel && mTab ) { mSidePanel->removeTab( mTab ); } @@ -568,7 +572,8 @@ bool ProjectBuildManager::load() { [this]() { mLoading = false; if ( mSidePanel ) - mSidePanel->runOnMainThread( [this]() { buildSidePanelTab(); } ); + mSidePanel->runOnMainThread( [this]() { buildSidePanelTab(); }, + Time::Zero, SidePanelLoadUniqueId ); } ); mProjectFile = mProjectRoot + ".ecode/project_build.json"; diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index 02689abb7..86a2d268b 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -414,8 +414,10 @@ UIMenu* SettingsMenu::createDocumentMenu() { auto le = TextFormat::stringToLineEnding( event->getNode()->asType()->getId() ); if ( mSplitter->curEditorExistsAndFocused() ) { - mSplitter->getCurEditor()->getDocument().setLineEnding( le ); - mApp->updateDocInfo( mSplitter->getCurEditor()->getDocument() ); + TextDocument& doc = mSplitter->getCurEditor()->getDocument(); + doc.setLineEnding( le ); + doc.setDirtyUntilSave(); + mApp->updateDocInfo( doc ); } } );