Skip to content

Commit

Permalink
Allow to locate files from the universal locator.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Nov 25, 2024
1 parent 4b21d02 commit 5bf9b89
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 23 deletions.
3 changes: 3 additions & 0 deletions include/eepp/graphics/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> getImageExtensionsSupported();

/** @return The last failure image loading/info reason */
static std::string getLastFailureReason();

Expand Down
5 changes: 5 additions & 0 deletions src/eepp/graphics/image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,11 @@ bool Image::isImageExtension( const std::string& path ) {
ext == "pvr" || ext == "pkm" || ext == "svg" || ext == "qoi" );
}

std::vector<std::string> Image::getImageExtensionsSupported() {
return std::vector<std::string>{ "png", "tga", "bmp", "jpg", "gif", "jpeg", "dds",
"psd", "hdr", "pic", "pvr", "pkm", "svg", "qoi" };
}

std::string Image::getLastFailureReason() {
return std::string( stbi_failure_reason() );
}
Expand Down
1 change: 1 addition & 0 deletions src/eepp/ui/doc/syntaxdefinitionmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ std::vector<std::string> SyntaxDefinitionManager::getLanguageNames() const {

std::vector<std::string> SyntaxDefinitionManager::getExtensionsPatternsSupported() const {
std::vector<std::string> exts;
exts.reserve( mDefinitions.size() );
for ( auto& style : mDefinitions )
for ( auto& pattern : style.getFiles() )
exts.emplace_back( pattern );
Expand Down
11 changes: 10 additions & 1 deletion src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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(),
Expand All @@ -2605,7 +2614,7 @@ void App::loadDirTree( const std::string& path ) {
}
mFileSystemListener->setDirTree( mDirTree );
},
SyntaxDefinitionManager::instance()->getExtensionsPatternsSupported() );
supportedExts );
}

UIMessageBox* App::errorMsgBox( const String& msg ) {
Expand Down
42 changes: 28 additions & 14 deletions src/tools/ecode/projectdirectorytree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ ProjectDirectoryTree::~ProjectDirectoryTree() {
mRunning = false;
Lock l( mFilesMutex );
}
{ Lock l( mDoneMutex ); }
{
Lock l( mDoneMutex );
}
}

void ProjectDirectoryTree::scan( const ProjectDirectoryTree::ScanCompleteEvent& scanComplete,
Expand Down Expand Up @@ -126,7 +128,7 @@ ProjectDirectoryTree::fuzzyMatchTree( const std::vector<std::string>& matches, c
break;
}
}
auto model = std::make_shared<FileListModel>( files, names );
auto model = std::make_shared<FileListModel>( std::move( files ), std::move( names ) );
model->setBasePath( basePath );
return model;
}
Expand All @@ -151,7 +153,7 @@ ProjectDirectoryTree::fuzzyMatchTree( const std::string& match, const size_t& ma
break;
}
}
auto model = std::make_shared<FileListModel>( files, names );
auto model = std::make_shared<FileListModel>( std::move( files ), std::move( names ) );
model->setBasePath( basePath );
return model;
}
Expand All @@ -171,7 +173,7 @@ ProjectDirectoryTree::matchTree( const std::string& match, const size_t& max,
break;
}
}
auto model = std::make_shared<FileListModel>( files, names );
auto model = std::make_shared<FileListModel>( std::move( files ), std::move( names ) );
model->setBasePath( basePath );
return model;
}
Expand All @@ -196,7 +198,7 @@ ProjectDirectoryTree::globMatchTree( const std::string& match, const size_t& max
break;
}
}
auto model = std::make_shared<FileListModel>( files, names );
auto model = std::make_shared<FileListModel>( std::move( files ), std::move( names ) );
model->setBasePath( basePath );
return model;
}
Expand All @@ -223,13 +225,23 @@ void ProjectDirectoryTree::asyncMatchTree( MatchType type, const std::string& ma

std::shared_ptr<FileListModel>
ProjectDirectoryTree::asModel( const size_t& max, const std::vector<CommandInfo>& prependCommands,
const std::string& basePath ) const {
size_t rmax = eemin( mNames.size(), max );
std::vector<std::string> files( rmax );
std::vector<std::string> 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<std::string>& skipExtensions ) const {
size_t namesSize = mNames.size();
size_t rmax = eemin( namesSize, max );
std::vector<std::string> files;
std::vector<std::string> 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;
Expand All @@ -239,7 +251,7 @@ ProjectDirectoryTree::asModel( const size_t& max, const std::vector<CommandInfo>
count++;
}
}
auto model = std::make_shared<FileListModel>( files, names );
auto model = std::make_shared<FileListModel>( std::move( files ), std::move( names ) );
model->setBasePath( basePath );

if ( !prependCommands.empty() ) {
Expand All @@ -256,14 +268,16 @@ ProjectDirectoryTree::emptyModel( const std::vector<CommandInfo>& prependCommand
std::vector<std::string> files;
std::vector<std::string> 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 );
files.insert( files.begin() + count, cmd.desc );
count++;
}
}
auto model = std::make_shared<FileListModel>( files, names );
auto model = std::make_shared<FileListModel>( std::move( files ), std::move( names ) );
model->setBasePath( basePath );

if ( !prependCommands.empty() ) {
Expand Down
9 changes: 5 additions & 4 deletions src/tools/ecode/projectdirectorytree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace ecode {

class FileListModel : public Model {
public:
FileListModel( const std::vector<std::string>& files, const std::vector<std::string>& names ) :
FileListModel( std::vector<std::string>&& files, std::vector<std::string>&& names ) :
mFiles( files ), mNames( names ), mIcons( mNames.size(), nullptr ) {}

virtual size_t rowCount( const ModelIndex& ) const { return mNames.size(); }
Expand Down Expand Up @@ -140,9 +140,10 @@ class ProjectDirectoryTree {
UIIcon* icon{ nullptr };
};

std::shared_ptr<FileListModel> asModel( const size_t& max,
const std::vector<CommandInfo>& prependCommands = {},
const std::string& basePath = "" ) const;
std::shared_ptr<FileListModel>
asModel( const size_t& max, const std::vector<CommandInfo>& prependCommands = {},
const std::string& basePath = "",
const std::vector<std::string>& skipExtensions = {} ) const;

static std::shared_ptr<FileListModel>
emptyModel( const std::vector<CommandInfo>& prependCommands = {},
Expand Down
14 changes: 10 additions & 4 deletions src/tools/ecode/universallocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -727,14 +729,16 @@ std::shared_ptr<FileListModel> UniversalLocator::openDocumentsModel( const std::

std::vector<std::string> files;
std::vector<std::string> names;
files.reserve( docs.size() );
names.reserve( docs.size() );

for ( const auto& doc : docs ) {
names.emplace_back( FileSystem::fileNameFromPath( doc ) );
files.emplace_back( std::move( doc ) );
}

if ( match.empty() )
return std::make_shared<FileListModel>( files, names );
return std::make_shared<FileListModel>( std::move( files ), std::move( names ) );

std::multimap<int, int, std::greater<int>> matchesMap;

Expand All @@ -746,13 +750,15 @@ std::shared_ptr<FileListModel> UniversalLocator::openDocumentsModel( const std::

std::vector<std::string> ffiles;
std::vector<std::string> 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<FileListModel>( ffiles, fnames );
return std::make_shared<FileListModel>( std::move( ffiles ), std::move( fnames ) );
}

void UniversalLocator::focusOrLoadFile( const std::string& path, const TextRange& range ) {
Expand Down

0 comments on commit 5bf9b89

Please sign in to comment.