diff --git a/include/eepp/graphics/image.hpp b/include/eepp/graphics/image.hpp index fafc24ca5..06abfe994 100644 --- a/include/eepp/graphics/image.hpp +++ b/include/eepp/graphics/image.hpp @@ -172,6 +172,9 @@ class EE_API Image { */ static bool isImageExtension( const std::string& path ); + /** @return A list of all supported extensions by the decoder */ + static std::vector getImageExtensionsSupported(); + /** @return The last failure image loading/info reason */ static std::string getLastFailureReason(); diff --git a/src/eepp/graphics/image.cpp b/src/eepp/graphics/image.cpp index f2538a563..517e8ecf1 100644 --- a/src/eepp/graphics/image.cpp +++ b/src/eepp/graphics/image.cpp @@ -413,6 +413,11 @@ bool Image::isImageExtension( const std::string& path ) { ext == "pvr" || ext == "pkm" || ext == "svg" || ext == "qoi" ); } +std::vector Image::getImageExtensionsSupported() { + return std::vector{ "png", "tga", "bmp", "jpg", "gif", "jpeg", "dds", + "psd", "hdr", "pic", "pvr", "pkm", "svg", "qoi" }; +} + std::string Image::getLastFailureReason() { return std::string( stbi_failure_reason() ); } diff --git a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp index d1f3128ed..e74d72ed8 100644 --- a/src/eepp/ui/doc/syntaxdefinitionmanager.cpp +++ b/src/eepp/ui/doc/syntaxdefinitionmanager.cpp @@ -459,6 +459,7 @@ std::vector SyntaxDefinitionManager::getLanguageNames() const { std::vector SyntaxDefinitionManager::getExtensionsPatternsSupported() const { std::vector exts; + exts.reserve( mDefinitions.size() ); for ( auto& style : mDefinitions ) for ( auto& pattern : style.getFiles() ) exts.emplace_back( pattern ); diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index e58e7a152..ae365af50 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2584,6 +2584,15 @@ void App::loadDirTree( const std::string& path ) { path, mThreadPool, mPluginManager.get(), [this]( auto path ) { loadFileFromPathOrFocus( path ); } ); Log::info( "Loading DirTree: %s", path ); + std::vector supportedExts( + SyntaxDefinitionManager::instance()->getExtensionsPatternsSupported() ); + auto imgExts( Image::getImageExtensionsSupported() ); + supportedExts.reserve( supportedExts.size() + imgExts.size() ); + for ( auto& ext : imgExts ) { + ext.insert( 0, "%." ); + ext += "$"; + supportedExts.push_back( ext ); + } mDirTree->scan( [this, clock]( ProjectDirectoryTree& dirTree ) { Log::info( "DirTree read in: %s. Found %ld files.", clock.getElapsedTime().toString(), @@ -2605,7 +2614,7 @@ void App::loadDirTree( const std::string& path ) { } mFileSystemListener->setDirTree( mDirTree ); }, - SyntaxDefinitionManager::instance()->getExtensionsPatternsSupported() ); + supportedExts ); } UIMessageBox* App::errorMsgBox( const String& msg ) { diff --git a/src/tools/ecode/projectdirectorytree.cpp b/src/tools/ecode/projectdirectorytree.cpp index feba8c895..2afb70b2d 100644 --- a/src/tools/ecode/projectdirectorytree.cpp +++ b/src/tools/ecode/projectdirectorytree.cpp @@ -31,7 +31,9 @@ ProjectDirectoryTree::~ProjectDirectoryTree() { mRunning = false; Lock l( mFilesMutex ); } - { Lock l( mDoneMutex ); } + { + Lock l( mDoneMutex ); + } } void ProjectDirectoryTree::scan( const ProjectDirectoryTree::ScanCompleteEvent& scanComplete, @@ -126,7 +128,7 @@ ProjectDirectoryTree::fuzzyMatchTree( const std::vector& matches, c break; } } - auto model = std::make_shared( files, names ); + auto model = std::make_shared( std::move( files ), std::move( names ) ); model->setBasePath( basePath ); return model; } @@ -151,7 +153,7 @@ ProjectDirectoryTree::fuzzyMatchTree( const std::string& match, const size_t& ma break; } } - auto model = std::make_shared( files, names ); + auto model = std::make_shared( std::move( files ), std::move( names ) ); model->setBasePath( basePath ); return model; } @@ -171,7 +173,7 @@ ProjectDirectoryTree::matchTree( const std::string& match, const size_t& max, break; } } - auto model = std::make_shared( files, names ); + auto model = std::make_shared( std::move( files ), std::move( names ) ); model->setBasePath( basePath ); return model; } @@ -196,7 +198,7 @@ ProjectDirectoryTree::globMatchTree( const std::string& match, const size_t& max break; } } - auto model = std::make_shared( files, names ); + auto model = std::make_shared( std::move( files ), std::move( names ) ); model->setBasePath( basePath ); return model; } @@ -223,13 +225,23 @@ void ProjectDirectoryTree::asyncMatchTree( MatchType type, const std::string& ma std::shared_ptr ProjectDirectoryTree::asModel( const size_t& max, const std::vector& prependCommands, - const std::string& basePath ) const { - size_t rmax = eemin( mNames.size(), max ); - std::vector files( rmax ); - std::vector names( rmax ); - for ( size_t i = 0; i < rmax; i++ ) { - files[i] = mFiles[i]; - names[i] = mNames[i]; + const std::string& basePath, + const std::vector& skipExtensions ) const { + size_t namesSize = mNames.size(); + size_t rmax = eemin( namesSize, max ); + std::vector files; + std::vector names; + files.reserve( rmax + prependCommands.size() ); + names.reserve( rmax + prependCommands.size() ); + for ( size_t i = 0; i < namesSize; i++ ) { + if ( skipExtensions.empty() || + std::find( skipExtensions.begin(), skipExtensions.end(), + FileSystem::fileExtension( mFiles[i] ) ) == skipExtensions.end() ) { + files.emplace_back( mFiles[i] ); + names.emplace_back( mNames[i] ); + if ( files.size() >= rmax ) + break; + } } if ( !prependCommands.empty() ) { int count = 0; @@ -239,7 +251,7 @@ ProjectDirectoryTree::asModel( const size_t& max, const std::vector count++; } } - auto model = std::make_shared( files, names ); + auto model = std::make_shared( std::move( files ), std::move( names ) ); model->setBasePath( basePath ); if ( !prependCommands.empty() ) { @@ -256,6 +268,8 @@ ProjectDirectoryTree::emptyModel( const std::vector& prependCommand std::vector files; std::vector names; if ( !prependCommands.empty() ) { + files.reserve( prependCommands.size() ); + names.reserve( prependCommands.size() ); int count = 0; for ( const auto& cmd : prependCommands ) { names.insert( names.begin() + count, cmd.name ); @@ -263,7 +277,7 @@ ProjectDirectoryTree::emptyModel( const std::vector& prependCommand count++; } } - auto model = std::make_shared( files, names ); + auto model = std::make_shared( std::move( files ), std::move( names ) ); model->setBasePath( basePath ); if ( !prependCommands.empty() ) { diff --git a/src/tools/ecode/projectdirectorytree.hpp b/src/tools/ecode/projectdirectorytree.hpp index 1e2fc2402..aa4b1c540 100644 --- a/src/tools/ecode/projectdirectorytree.hpp +++ b/src/tools/ecode/projectdirectorytree.hpp @@ -24,7 +24,7 @@ namespace ecode { class FileListModel : public Model { public: - FileListModel( const std::vector& files, const std::vector& names ) : + FileListModel( std::vector&& files, std::vector&& names ) : mFiles( files ), mNames( names ), mIcons( mNames.size(), nullptr ) {} virtual size_t rowCount( const ModelIndex& ) const { return mNames.size(); } @@ -140,9 +140,10 @@ class ProjectDirectoryTree { UIIcon* icon{ nullptr }; }; - std::shared_ptr asModel( const size_t& max, - const std::vector& prependCommands = {}, - const std::string& basePath = "" ) const; + std::shared_ptr + asModel( const size_t& max, const std::vector& prependCommands = {}, + const std::string& basePath = "", + const std::vector& skipExtensions = {} ) const; static std::shared_ptr emptyModel( const std::vector& prependCommands = {}, diff --git a/src/tools/ecode/universallocator.cpp b/src/tools/ecode/universallocator.cpp index 04d2fc648..b9547496b 100644 --- a/src/tools/ecode/universallocator.cpp +++ b/src/tools/ecode/universallocator.cpp @@ -381,7 +381,8 @@ void UniversalLocator::updateFilesTable( bool useGlob ) { #endif } else { mLocateTable->setModel( mApp->getDirTree()->asModel( - LOCATEBAR_MAX_RESULTS, getLocatorCommands(), mApp->getCurrentProject() ) ); + LOCATEBAR_MAX_RESULTS, getLocatorCommands(), mApp->getCurrentProject(), + Image::getImageExtensionsSupported() ) ); mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) ); } } @@ -654,7 +655,8 @@ void UniversalLocator::showLocateBar( bool useGlob ) { if ( mApp->getDirTree() && !mLocateTable->getModel() ) { mLocateTable->setModel( mApp->getDirTree()->asModel( - LOCATEBAR_MAX_RESULTS, getLocatorCommands(), mApp->getCurrentProject() ) ); + LOCATEBAR_MAX_RESULTS, getLocatorCommands(), mApp->getCurrentProject(), + Image::getImageExtensionsSupported() ) ); mLocateTable->getSelection().set( mLocateTable->getModel()->index( 0 ) ); } else if ( !mLocateTable->getModel() ) { mLocateTable->setModel( @@ -727,6 +729,8 @@ std::shared_ptr UniversalLocator::openDocumentsModel( const std:: std::vector files; std::vector names; + files.reserve( docs.size() ); + names.reserve( docs.size() ); for ( const auto& doc : docs ) { names.emplace_back( FileSystem::fileNameFromPath( doc ) ); @@ -734,7 +738,7 @@ std::shared_ptr UniversalLocator::openDocumentsModel( const std:: } if ( match.empty() ) - return std::make_shared( files, names ); + return std::make_shared( std::move( files ), std::move( names ) ); std::multimap> matchesMap; @@ -746,13 +750,15 @@ std::shared_ptr UniversalLocator::openDocumentsModel( const std:: std::vector ffiles; std::vector fnames; + ffiles.reserve( matchesMap.size() ); + fnames.reserve( matchesMap.size() ); for ( auto& res : matchesMap ) { fnames.emplace_back( std::move( names[res.second] ) ); ffiles.emplace_back( std::move( files[res.second] ) ); } - return std::make_shared( ffiles, fnames ); + return std::make_shared( std::move( ffiles ), std::move( fnames ) ); } void UniversalLocator::focusOrLoadFile( const std::string& path, const TextRange& range ) {