| 2566 | } |
| 2567 | |
| 2568 | void App::loadImageFromMedium( const std::string& path, bool isMemory, bool forcePreview, |
| 2569 | bool forceTab ) { |
| 2570 | if ( ( isMemory && !Image::isImage( reinterpret_cast<const unsigned char*>( path.data() ), |
| 2571 | path.size() ) ) || |
| 2572 | ( !isMemory && ( !FileSystem::fileExists( path ) || !Image::isImage( path ) ) ) ) |
| 2573 | return; |
| 2574 | |
| 2575 | if ( !forceTab && ( mConfig.ui.imagesQuickPreview || forcePreview ) ) { |
| 2576 | UIImageViewer* imageView = mImageLayout->findByType<UIImageViewer>( UI_TYPE_IMAGE_VIEWER ); |
| 2577 | |
| 2578 | if ( imageView ) { |
| 2579 | mImageLayout->setEnabled( true )->setVisible( true ); |
| 2580 | if ( !imageView->hasEventsOfType( Event::OnResourceLoaded ) ) { |
| 2581 | imageView->on( Event::OnResourceLoaded, [this, imageView]( auto ) { |
| 2582 | if ( mImageLayout->isVisible() ) { |
| 2583 | mImageLayout->getFirstChild()->setFocus(); |
| 2584 | } else { |
| 2585 | imageView->reset(); |
| 2586 | } |
| 2587 | } ); |
| 2588 | } |
| 2589 | imageView->loadImageAsync( path, isMemory, true ); |
| 2590 | } |
| 2591 | } else { |
| 2592 | UIImageViewer* imageView = UIImageViewer::New(); |
| 2593 | auto [tab, iv] = |
| 2594 | mSplitter->createWidget( imageView, i18n( "image_viewer", "Image Viewer" ) ); |
| 2595 | |
| 2596 | imageView->on( Event::OnResourceLoaded, [tab, imageView, this]( auto ) { |
| 2597 | tab->setText( imageView->getImageName().empty() ? i18n( "image_viewer", "Image Viewer" ) |
| 2598 | : String( imageView->getImageName() ) ); |
| 2599 | std::string path( imageView->getImagePath() ); |
| 2600 | std::string ext( FileSystem::fileExtension( path ) ); |
| 2601 | String::toLowerInPlace( ext ); |
| 2602 | tab->setTooltipText( path ); |
| 2603 | auto icon = findIcon( "filetype-" + ext ); |
| 2604 | tab->setIcon( icon ? icon : findIcon( "file" ) ); |
| 2605 | if ( mProjectTreeView && mConfig.editor.syncProjectTreeWithEditor ) { |
| 2606 | mProjectTreeView->setFocusOnSelection( false ); |
| 2607 | if ( !mCurrentProject.empty() && String::startsWith( path, mCurrentProject ) ) { |
| 2608 | mProjectTreeView->openRowWithPath( path.substr( mCurrentProject.size() ) ); |
| 2609 | } else { |
| 2610 | mProjectTreeView->openRowWithPath( FileSystem::fileNameFromPath( path ) ); |
| 2611 | } |
| 2612 | mProjectTreeView->setFocusOnSelection( true ); |
| 2613 | } |
| 2614 | } ); |
| 2615 | imageView->loadImageAsync( path, isMemory, true ); |
| 2616 | } |
| 2617 | } |
| 2618 | |
| 2619 | void App::loadImageFromMemory( const std::string& content ) { |
| 2620 | loadImageFromMedium( content, true, true ); |
no test coverage detected