Skip to content

Commit

Permalink
A couple of nits in image preview.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpartanJ committed Nov 25, 2024
1 parent ca25c6e commit 4b21d02
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions src/tools/ecode/ecode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,24 +801,26 @@ void App::onFileDropped( std::string file ) {

if ( !node )
node = widget;

bool willLoadAnImage =
Image::isImageExtension( file ) && FileSystem::fileExtension( file ) != "svg";
if ( node && node->isType( UI_TYPE_CODEEDITOR ) ) {
codeEditor = node->asType<UICodeEditor>();
if ( ( codeEditor->getDocument().isLoading() || !codeEditor->getDocument().isEmpty() ) &&
( !Image::isImageExtension( file ) || FileSystem::fileExtension( file ) == "svg" ) ) {
!willLoadAnImage ) {
auto d = mSplitter->createCodeEditorInTabWidget(
mSplitter->tabWidgetFromEditor( codeEditor ) );
codeEditor = d.second;
tab = d.first;
}
} else if ( widget && widget->isType( UI_TYPE_TERMINAL ) ) {
if ( !Image::isImageExtension( file ) &&
( !Image::isImageExtension( file ) || FileSystem::fileExtension( file ) == "svg" ) ) {
if ( !Image::isImageExtension( file ) && !willLoadAnImage ) {
auto d =
mSplitter->createCodeEditorInTabWidget( mSplitter->tabWidgetFromWidget( widget ) );
codeEditor = d.second;
tab = d.first;
}
} else {
} else if ( !willLoadAnImage ) {
auto d = mSplitter->createEditorInNewTab();
codeEditor = d.second;
tab = d.first;
Expand Down Expand Up @@ -3002,14 +3004,20 @@ void App::initProjectTreeView( std::string path, bool openClean ) {
}

void App::initImageView() {
const auto onCloseImage = [this]( const Event* ) {
mImageLayout->on( Event::MouseClick, [this]( const Event* ) {
mImageLayout->findByType<UIImage>( UI_TYPE_IMAGE )->setDrawable( nullptr );
mImageLayout->setEnabled( false )->setVisible( false );
if ( mSplitter->getCurWidget() )
mSplitter->getCurWidget()->setFocus();
};
mImageLayout->on( Event::MouseClick, onCloseImage );
mImageLayout->on( Event::KeyDown, onCloseImage );
} );
mImageLayout->on( Event::KeyDown, [this]( const Event* event ) {
if ( event->asKeyEvent()->getKeyCode() == KEY_ESCAPE ) {
mImageLayout->findByType<UIImage>( UI_TYPE_IMAGE )->setDrawable( nullptr );
mImageLayout->setEnabled( false )->setVisible( false );
if ( mSplitter->getCurWidget() )
mSplitter->getCurWidget()->setFocus();
}
} );
}

bool App::isFileVisibleInTreeView( const std::string& filePath ) {
Expand Down

0 comments on commit 4b21d02

Please sign in to comment.