ecode: Fixed load callback when loading a file from the GlobalSearchController.

This commit is contained in:
Martín Lucas Golini
2022-04-02 01:05:03 -03:00
parent cf83d8fbf3
commit 0ef95ec3d4
7 changed files with 35 additions and 29 deletions

View File

@@ -95,7 +95,7 @@ class EE_API Variant {
}
mType = Type::Invalid;
}
bool isValid() { return mType != Type::Invalid; }
bool isValid() const { return mType != Type::Invalid; }
std::string toString() const {
switch ( mType ) {

View File

@@ -11,8 +11,8 @@ ClipboardSDL::~ClipboardSDL() {}
void ClipboardSDL::init() {}
void ClipboardSDL::setText( const std::string& Text ) {
SDL_SetClipboardText( Text.c_str() );
void ClipboardSDL::setText( const std::string& text ) {
SDL_SetClipboardText( text.c_str() );
}
std::string ClipboardSDL::getText() {

View File

@@ -19,7 +19,7 @@ class EE_API ClipboardSDL : public Clipboard {
String getWideText();
void setText( const std::string& Text );
void setText( const std::string& text );
protected:
friend class WindowSDL;

View File

@@ -1295,7 +1295,9 @@ void App::createDocAlert( UICodeEditor* editor ) {
} );
}
void App::loadFileFromPath( const std::string& path, bool inNewTab, UICodeEditor* codeEditor ) {
void App::loadFileFromPath(
const std::string& path, bool inNewTab, UICodeEditor* codeEditor,
std::function<void( UICodeEditor* codeEditor, const std::string& path )> onLoaded ) {
if ( Image::isImageExtension( path ) && Image::isImage( path ) ) {
UIImage* imageView = mImageLayout->findByType<UIImage>( UI_TYPE_IMAGE );
UILoader* loaderView = mImageLayout->findByType<UILoader>( UI_TYPE_LOADER );
@@ -1324,19 +1326,11 @@ void App::loadFileFromPath( const std::string& path, bool inNewTab, UICodeEditor
#endif
}
} else {
#if EE_PLATFORM != EE_PLATFORM_EMSCRIPTEN || defined( __EMSCRIPTEN_PTHREADS__ )
if ( inNewTab ) {
mEditorSplitter->loadAsyncFileFromPathInNewTab( path, mThreadPool );
mEditorSplitter->loadAsyncFileFromPathInNewTab( path, mThreadPool, onLoaded );
} else {
mEditorSplitter->loadAsyncFileFromPath( path, mThreadPool, codeEditor );
mEditorSplitter->loadAsyncFileFromPath( path, mThreadPool, codeEditor, onLoaded );
}
#else
if ( inNewTab ) {
mEditorSplitter->loadFileFromPathInNewTab( path );
} else {
mEditorSplitter->loadFileFromPath( path, codeEditor );
}
#endif
}
}

View File

@@ -59,7 +59,9 @@ class App : public UICodeEditorSplitter::Client {
std::shared_ptr<ThreadPool> getThreadPool() const;
void loadFileFromPath( const std::string& path, bool inNewTab = true,
UICodeEditor* codeEditor = nullptr );
UICodeEditor* codeEditor = nullptr,
std::function<void( UICodeEditor*, const std::string& )> onLoaded =
std::function<void( UICodeEditor*, const std::string& )>() );
void hideGlobalSearchBar();

View File

@@ -411,6 +411,16 @@ void GlobalSearchController::doGlobalSearch( String text, bool caseSensitive, bo
}
}
void GlobalSearchController::onLoadDone( const Variant& lineNum, const Variant& colNum ) {
if ( mEditorSplitter->getCurEditor() && lineNum.isValid() && colNum.isValid() &&
lineNum.is( Variant::Type::Int64 ) && colNum.is( Variant::Type::Int64 ) ) {
TextPosition pos{ lineNum.asInt64(), colNum.asInt64() };
mEditorSplitter->getCurEditor()->getDocument().setSelection( pos );
mEditorSplitter->getCurEditor()->goToLine( pos );
hideGlobalSearchBar();
}
}
void GlobalSearchController::initGlobalSearchTree( UITreeViewGlobalSearch* searchTree ) {
searchTree->addClass( "search_tree" );
searchTree->setParent( mGlobalSearchLayout );
@@ -451,13 +461,6 @@ void GlobalSearchController::initGlobalSearchTree( UITreeViewGlobalSearch* searc
if ( vPath.isValid() && vPath.is( Variant::Type::cstr ) ) {
std::string path( vPath.asCStr() );
UITab* tab = mEditorSplitter->isDocumentOpen( path );
if ( !tab ) {
FileInfo fileInfo( path );
if ( fileInfo.exists() && fileInfo.isRegularFile() )
mApp->loadFileFromPath( path );
} else {
tab->getTabWidget()->setTabSelected( tab );
}
Variant lineNum(
model->data( model->index( modelEvent->getModelIndex().row(),
ProjectSearch::ResultModel::FileOrPosition,
@@ -467,12 +470,17 @@ void GlobalSearchController::initGlobalSearchTree( UITreeViewGlobalSearch* searc
ProjectSearch::ResultModel::ColumnStart,
modelEvent->getModelIndex().parent() ),
ModelRole::Custom ) );
if ( mEditorSplitter->getCurEditor() && lineNum.isValid() && colNum.isValid() &&
lineNum.is( Variant::Type::Int64 ) && colNum.is( Variant::Type::Int64 ) ) {
TextPosition pos{ lineNum.asInt64(), colNum.asInt64() };
mEditorSplitter->getCurEditor()->getDocument().setSelection( pos );
mEditorSplitter->getCurEditor()->goToLine( pos );
hideGlobalSearchBar();
if ( !tab ) {
FileInfo fileInfo( path );
if ( fileInfo.exists() && fileInfo.isRegularFile() )
mApp->loadFileFromPath(
path, true, nullptr,
[&, lineNum, colNum]( UICodeEditor*, const std::string& ) {
onLoadDone( lineNum, colNum );
} );
} else {
tab->getTabWidget()->setTabSelected( tab );
onLoadDone( lineNum, colNum );
}
}
}

View File

@@ -52,6 +52,8 @@ class GlobalSearchController {
Uint32 mGlobalSearchHistoryOnItemSelectedCb{ 0 };
std::deque<std::pair<std::string, std::shared_ptr<ProjectSearch::ResultModel>>>
mGlobalSearchHistory;
void onLoadDone( const Variant& lineNum, const Variant& colNum );
};
#endif // GLOBALSEARCHCONTROLLER_HPP