| 2638 | } |
| 2639 | |
| 2640 | void App::loadDiffFromMemory( const std::string& content, const std::string& originalFilePath ) { |
| 2641 | if ( UIDiffView::isMultiFileDiff( content ) ) { |
| 2642 | auto diffViewTitle = i18n( "diff_viewer", "Diff Viewer" ) + ": " + originalFilePath; |
| 2643 | UIIcon* icon = getUISceneNode()->findIcon( "filetype-diff" ); |
| 2644 | if ( !icon ) |
| 2645 | icon = getUISceneNode()->findIcon( "file" ); |
| 2646 | |
| 2647 | auto scrollView = UIDiffView::NewMultiFileDiffViewer( content ); |
| 2648 | auto [tab, iv] = getSplitter()->createWidget( scrollView, diffViewTitle ); |
| 2649 | if ( icon ) |
| 2650 | tab->setIcon( icon->getSize( getMenuIconSize() ) ); |
| 2651 | tab->setText( diffViewTitle ); |
| 2652 | |
| 2653 | auto diffView = scrollView->getFirstChild()->asType<UILinearLayout>()->getFirstChild(); |
| 2654 | |
| 2655 | while ( diffView ) { |
| 2656 | if ( diffView->isType( UI_TYPE_DIFF_VIEW ) ) |
| 2657 | diffView->asType<UIDiffView>()->setSyntaxColorScheme( *getCurrentColorScheme() ); |
| 2658 | diffView = diffView->getNextNode(); |
| 2659 | } |
| 2660 | return; |
| 2661 | } |
| 2662 | |
| 2663 | auto diffViewTitle = i18n( "diff_viewer", "Diff Viewer" ); |
| 2664 | auto* diffView = Tools::UIDiffView::New(); |
| 2665 | auto [tab, iv] = getSplitter()->createWidget( diffView, diffViewTitle ); |
| 2666 | if ( !originalFilePath.empty() ) { |
| 2667 | std::string fileName = FileSystem::fileNameFromPath( originalFilePath ); |
| 2668 | tab->setText( diffViewTitle + ": " + fileName ); |
| 2669 | tab->setTooltipText( originalFilePath ); |
| 2670 | } else { |
| 2671 | tab->setText( diffViewTitle ); |
| 2672 | } |
| 2673 | UIIcon* icon = getUISceneNode()->findIcon( "filetype-diff" ); |
| 2674 | if ( !icon ) |
| 2675 | icon = getUISceneNode()->findIcon( "file" ); |
| 2676 | if ( icon ) |
| 2677 | tab->setIcon( icon->getSize( getMenuIconSize() ) ); |
| 2678 | diffView->setHeadersVisible( true ); |
| 2679 | diffView->loadFromPatch( content, originalFilePath ); |
| 2680 | diffView->setSyntaxColorScheme( *getCurrentColorScheme() ); |
| 2681 | registerUnlockedCommands( *diffView ); |
| 2682 | } |
| 2683 | |
| 2684 | void App::loadDiffFromPath( const std::string& path ) { |
| 2685 | std::string content; |
no test coverage detected