From 7c47a26f0291477504081c7e67d35ab8f88c708a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Sat, 11 Feb 2023 12:51:19 -0300 Subject: [PATCH] Closes SpartanJ/ecode#43. --- include/eepp/graphics/textureloader.hpp | 44 ++++----- src/eepp/graphics/textureloader.cpp | 89 ++----------------- src/eepp/system/process.cpp | 6 +- src/tools/ecode/filelocator.cpp | 15 +++- .../ecode/plugins/lsp/lspclientserver.cpp | 3 +- src/tools/ecode/settingsmenu.cpp | 12 +++ 6 files changed, 58 insertions(+), 111 deletions(-) diff --git a/include/eepp/graphics/textureloader.hpp b/include/eepp/graphics/textureloader.hpp index b949a55bf..121ea1117 100644 --- a/include/eepp/graphics/textureloader.hpp +++ b/include/eepp/graphics/textureloader.hpp @@ -111,37 +111,37 @@ class EE_API TextureLoader { void load(); protected: - Uint32 mLoadType; // From memory, from path, from pack - Uint8* mPixels; // Texture Info - Uint32 mTexId; - Int32 mImgWidth; - Int32 mImgHeight; + Uint32 mLoadType{ 0 }; // From memory, from path, from pack + Uint8* mPixels{ nullptr }; // Texture Info + Uint32 mTexId{ 0 }; + Int32 mImgWidth{ 0 }; + Int32 mImgHeight{ 0 }; std::string mFilepath; - unsigned int mWidth; - unsigned int mHeight; - bool mMipmap; - Int32 mChannels; - Texture::ClampMode mClampMode; - bool mCompressTexture; - bool mLocalCopy; - Pack* mPack; - IOStream* mStream; + unsigned int mWidth{ 0 }; + unsigned int mHeight{ 0 }; + bool mMipmap{ false }; + Int32 mChannels{ 0 }; + Texture::ClampMode mClampMode{ Texture::ClampMode::ClampToEdge }; + bool mCompressTexture{ false }; + bool mLocalCopy{ false }; + Pack* mPack{ nullptr }; + IOStream* mStream{ nullptr }; - const Uint8* mImagePtr; - Uint32 mSize; + const Uint8* mImagePtr{ nullptr }; + Uint32 mSize{ 0 }; - RGB* mColorKey; + RGB* mColorKey{ nullptr }; Image::FormatConfiguration mFormatConfiguration; void reset(); private: - bool mLoaded; - bool mTexLoaded; - bool mDirectUpload; - int mImgType; - int mIsCompressed; + bool mLoaded{ false }; + bool mTexLoaded{ false }; + bool mDirectUpload{ false }; + int mImgType{ 0 }; + int mIsCompressed{ 0 }; Clock mTE; diff --git a/src/eepp/graphics/textureloader.cpp b/src/eepp/graphics/textureloader.cpp index e4c845de7..f20253dc4 100644 --- a/src/eepp/graphics/textureloader.cpp +++ b/src/eepp/graphics/textureloader.cpp @@ -27,109 +27,43 @@ TextureLoader::TextureLoader( IOStream& Stream, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) : mLoadType( TEX_LT_STREAM ), - mPixels( NULL ), - mTexId( 0 ), - mImgWidth( 0 ), - mImgHeight( 0 ), - mFilepath( "" ), - mWidth( 0 ), - mHeight( 0 ), mMipmap( Mipmap ), - mChannels( 0 ), mClampMode( ClampMode ), mCompressTexture( CompressTexture ), mLocalCopy( KeepLocalCopy ), - mPack( NULL ), - mStream( &Stream ), - mImagePtr( NULL ), - mSize( 0 ), - mColorKey( NULL ), - mLoaded( false ), - mTexLoaded( false ), - mDirectUpload( false ), - mImgType( STBI_unknown ), - mIsCompressed( 0 ) {} + mStream( &Stream ) {} TextureLoader::TextureLoader( const std::string& Filepath, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) : mLoadType( TEX_LT_PATH ), - mPixels( NULL ), - mTexId( 0 ), - mImgWidth( 0 ), - mImgHeight( 0 ), mFilepath( Filepath ), - mWidth( 0 ), - mHeight( 0 ), mMipmap( Mipmap ), - mChannels( 0 ), mClampMode( ClampMode ), mCompressTexture( CompressTexture ), - mLocalCopy( KeepLocalCopy ), - mPack( NULL ), - mStream( NULL ), - mImagePtr( NULL ), - mSize( 0 ), - mColorKey( NULL ), - mLoaded( false ), - mTexLoaded( false ), - mDirectUpload( false ), - mImgType( STBI_unknown ), - mIsCompressed( 0 ) {} + mLocalCopy( KeepLocalCopy ) {} TextureLoader::TextureLoader( const unsigned char* ImagePtr, const unsigned int& Size, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) : mLoadType( TEX_LT_MEM ), - mPixels( NULL ), - mTexId( 0 ), - mImgWidth( 0 ), - mImgHeight( 0 ), - mFilepath( "" ), - mWidth( 0 ), - mHeight( 0 ), mMipmap( Mipmap ), - mChannels( 0 ), mClampMode( ClampMode ), mCompressTexture( CompressTexture ), mLocalCopy( KeepLocalCopy ), - mPack( NULL ), - mStream( NULL ), mImagePtr( ImagePtr ), - mSize( Size ), - mColorKey( NULL ), - mLoaded( false ), - mTexLoaded( false ), - mDirectUpload( false ), - mImgType( STBI_unknown ), - mIsCompressed( 0 ) {} + mSize( Size ) {} TextureLoader::TextureLoader( Pack* Pack, const std::string& FilePackPath, const bool& Mipmap, const Texture::ClampMode& ClampMode, const bool& CompressTexture, const bool& KeepLocalCopy ) : mLoadType( TEX_LT_PACK ), - mPixels( NULL ), - mTexId( 0 ), - mImgWidth( 0 ), - mImgHeight( 0 ), mFilepath( FilePackPath ), - mWidth( 0 ), - mHeight( 0 ), mMipmap( Mipmap ), - mChannels( 0 ), mClampMode( ClampMode ), mCompressTexture( CompressTexture ), mLocalCopy( KeepLocalCopy ), - mPack( Pack ), - mStream( NULL ), - mImagePtr( NULL ), - mSize( 0 ), - mColorKey( NULL ), - mLoaded( false ), - mTexLoaded( false ), - mDirectUpload( false ), - mImgType( STBI_unknown ), - mIsCompressed( 0 ) {} + mPack( Pack ) {} TextureLoader::TextureLoader( const unsigned char* Pixels, const unsigned int& Width, const unsigned int& Height, const unsigned int& Channels, @@ -138,27 +72,14 @@ TextureLoader::TextureLoader( const unsigned char* Pixels, const unsigned int& W const std::string& FileName ) : mLoadType( TEX_LT_PIXELS ), mPixels( const_cast( Pixels ) ), - mTexId( 0 ), mImgWidth( Width ), mImgHeight( Height ), mFilepath( FileName ), - mWidth( 0 ), - mHeight( 0 ), mMipmap( Mipmap ), mChannels( Channels ), mClampMode( ClampMode ), mCompressTexture( CompressTexture ), - mLocalCopy( KeepLocalCopy ), - mPack( NULL ), - mStream( NULL ), - mImagePtr( NULL ), - mSize( 0 ), - mColorKey( NULL ), - mLoaded( false ), - mTexLoaded( false ), - mDirectUpload( false ), - mImgType( STBI_unknown ), - mIsCompressed( 0 ) {} + mLocalCopy( KeepLocalCopy ) {} TextureLoader::~TextureLoader() { eeSAFE_DELETE( mColorKey ); diff --git a/src/eepp/system/process.cpp b/src/eepp/system/process.cpp index ffa9ec54f..becde59eb 100644 --- a/src/eepp/system/process.cpp +++ b/src/eepp/system/process.cpp @@ -230,7 +230,7 @@ void Process::startAsyncRead( ReadFn readStdOut, ReadFn readStdErr ) { if ( n < static_cast( mBufferSize - 1 ) ) buffer[n] = '\0'; - if ( !mShuttingDown ) + if ( !mShuttingDown ) mReadStdErrFn( buffer.c_str(), static_cast( n ) ); } } ); @@ -274,8 +274,8 @@ void Process::startAsyncRead( ReadFn readStdOut, ReadFn readStdErr ) { mReadStdOutFn( buffer.c_str(), static_cast( n ) ); else mReadStdErrFn( buffer.c_str(), static_cast( n ) ); - } else if ( n < 0 && errno != EINTR && errno != EAGAIN && - errno != EWOULDBLOCK ) { + } else if ( n == 0 || ( n < 0 && errno != EINTR && errno != EAGAIN && + errno != EWOULDBLOCK ) ) { pollfds[i].fd = -1; continue; } diff --git a/src/tools/ecode/filelocator.cpp b/src/tools/ecode/filelocator.cpp index dd75e158d..d4f9e87ee 100644 --- a/src/tools/ecode/filelocator.cpp +++ b/src/tools/ecode/filelocator.cpp @@ -205,7 +205,20 @@ void FileLocator::showBar() { mLocateBarLayout->setVisible( true ); mLocateInput->setFocus(); mLocateTable->setVisible( true ); - mLocateInput->getDocument().selectAll(); + const String& text = mLocateInput->getText(); + + if ( !text.empty() && text[0] == '>' ) { + Int64 selectFrom = 1; + if ( text.size() >= 2 && text[1] == ' ' ) + selectFrom = 2; + + mLocateInput->getDocument().setSelection( + { { 0, selectFrom }, + { 0, mLocateInput->getDocument().endOfLine( { 0, 0 } ).column() } } ); + } else { + mLocateInput->getDocument().selectAll(); + } + mLocateInput->addEventListener( Event::OnSizeChange, [&]( const Event* ) { updateLocateBar(); } ); } diff --git a/src/tools/ecode/plugins/lsp/lspclientserver.cpp b/src/tools/ecode/plugins/lsp/lspclientserver.cpp index 3290726ac..3a89b10dc 100644 --- a/src/tools/ecode/plugins/lsp/lspclientserver.cpp +++ b/src/tools/ecode/plugins/lsp/lspclientserver.cpp @@ -244,7 +244,8 @@ static void fromJson( LSPCompletionOptions& options, const json& json ) { options.provider = true; if ( json.contains( "resolveProvider" ) && !json["resolveProvider"].is_null() ) options.resolveProvider = json["resolveProvider"].get(); - fromJson( options.triggerCharacters, json["triggerCharacters"] ); + if ( json.contains( "triggerCharacters" ) && !json["triggerCharacters"].is_null() ) + fromJson( options.triggerCharacters, json["triggerCharacters"] ); } } diff --git a/src/tools/ecode/settingsmenu.cpp b/src/tools/ecode/settingsmenu.cpp index b4535b9f4..733f2a791 100644 --- a/src/tools/ecode/settingsmenu.cpp +++ b/src/tools/ecode/settingsmenu.cpp @@ -1472,6 +1472,7 @@ void SettingsMenu::createProjectTreeMenu( const FileInfo& file ) { if ( mProjectTreeMenu && mProjectTreeMenu->isVisible() ) mProjectTreeMenu->close(); mProjectTreeMenu = UIPopUpMenu::New(); + if ( file.isDirectory() ) { mProjectTreeMenu->add( i18n( "new_file", "New File..." ), findIcon( "file-add" ) ) ->setId( "new_file" ); @@ -1480,6 +1481,17 @@ void SettingsMenu::createProjectTreeMenu( const FileInfo& file ) { mProjectTreeMenu->add( i18n( "open_folder", "Open Folder..." ), findIcon( "folder-open" ) ) ->setId( "open_folder" ); } else { + if ( file.isRegularFile() ) { + auto curDir( mApp->getCurrentWorkingDir() ); + FileSystem::dirAddSlashAtEnd( curDir ); + if ( curDir == file.getDirectoryPath() ) { + mProjectTreeMenu + ->add( i18n( "new_file_in_file_folder", "New File in File Folder..." ), + findIcon( "file-add" ) ) + ->setId( "new_file" ); + } + } + mProjectTreeMenu->add( i18n( "open_folder", "Open File" ), findIcon( "document-open" ) ) ->setId( "open_file" ); mProjectTreeMenu