From 7f6568cfb0abc5276bc2e3737db97f90b068f4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mart=C3=ADn=20Lucas=20Golini?= Date: Wed, 26 Aug 2026 17:43:57 -0300 Subject: [PATCH] Allow to configure the default diff view (Unified vs Side by side) --- bin/assets/i18n/de.xml | 4 ++++ bin/assets/i18n/en.xml | 4 ++++ bin/assets/i18n/fr.xml | 4 ++++ bin/assets/i18n/zh.xml | 4 ++++ src/tools/ecode/appconfig.cpp | 6 ++++++ src/tools/ecode/appconfig.hpp | 2 ++ src/tools/ecode/ecode.cpp | 17 +++++++++++++++-- src/tools/ecode/ecode.hpp | 1 + src/tools/ecode/settingspanel.cpp | 19 +++++++++++++++++++ 9 files changed, 59 insertions(+), 2 deletions(-) diff --git a/bin/assets/i18n/de.xml b/bin/assets/i18n/de.xml index 0ba0dc4f4..7bda84bf5 100644 --- a/bin/assets/i18n/de.xml +++ b/bin/assets/i18n/de.xml @@ -1210,4 +1210,8 @@ Für sichtbare Änderung ecode neu starten. Update the matching tag automatically while editing. Highlight Matching Tags Highlight the matching XML or HTML tag at the cursor. + Default Diff View + Choose the initial layout used when opening text diffs. + Side by Side + Unified diff --git a/bin/assets/i18n/en.xml b/bin/assets/i18n/en.xml index c09492c19..aea2406f1 100644 --- a/bin/assets/i18n/en.xml +++ b/bin/assets/i18n/en.xml @@ -1195,4 +1195,8 @@ Restart ecode to see the changes. Update the matching tag automatically while editing. Highlight Matching Tags Highlight the matching XML or HTML tag at the cursor. + Default Diff View + Choose the initial layout used when opening text diffs. + Side by Side + Unified diff --git a/bin/assets/i18n/fr.xml b/bin/assets/i18n/fr.xml index 361ec2ee8..20d4ddc0b 100644 --- a/bin/assets/i18n/fr.xml +++ b/bin/assets/i18n/fr.xml @@ -1194,4 +1194,8 @@ Redémarrer ecode pour voir les changements. Update the matching tag automatically while editing. Highlight Matching Tags Highlight the matching XML or HTML tag at the cursor. + Default Diff View + Choose the initial layout used when opening text diffs. + Side by Side + Unified diff --git a/bin/assets/i18n/zh.xml b/bin/assets/i18n/zh.xml index 83ed008c4..0528df4bd 100644 --- a/bin/assets/i18n/zh.xml +++ b/bin/assets/i18n/zh.xml @@ -999,4 +999,8 @@ file in the directory tree. Update the matching tag automatically while editing. Highlight Matching Tags Highlight the matching XML or HTML tag at the cursor. + Default Diff View + Choose the initial layout used when opening text diffs. + Side by Side + Unified diff --git a/src/tools/ecode/appconfig.cpp b/src/tools/ecode/appconfig.cpp index 3740ef2dc..22d0b0436 100644 --- a/src/tools/ecode/appconfig.cpp +++ b/src/tools/ecode/appconfig.cpp @@ -214,6 +214,9 @@ void AppConfig::load( const std::string& confPath, std::string& keybindingsPath, ini.getValueB( "editor", "restore_editor_selection_on_focus", true ); editor.tabJumpMode = UITabWidget::tabJumpModefromString( ini.getValue( "editor", "tab_jump_mode", "linear" ) ); + editor.diffViewMode = ini.getValue( "editor", "diff_view_mode", "unified" ) == "side_by_side" + ? UIDiffView::ViewMode::SideBySide + : UIDiffView::ViewMode::Unified; editor.singleClickNavigation = ini.getValueB( "editor", "single_click_tree_navigation", false ); editor.syncProjectTreeWithEditor = @@ -419,6 +422,9 @@ void AppConfig::save( const std::vector& recentFiles, UITabWidget::tabJumpModeToString( editor.tabJumpMode ) ); ini.setValue( "editor", "new_tab_position", NewTabPosition::toString( editor.newTabPosition ) ); ini.setValue( "editor", "custom_date_format", editor.customDateFormat ); + ini.setValue( "editor", "diff_view_mode", + editor.diffViewMode == UIDiffView::ViewMode::SideBySide ? "side_by_side" + : "unified" ); ini.setValueB( "editor", "single_click_tree_navigation", editor.singleClickNavigation ); ini.setValueB( "editor", "sync_project_tree_with_editor", editor.syncProjectTreeWithEditor ); ini.setValueB( "editor", "auto_close_xml_tags", editor.autoCloseXMLTags ); diff --git a/src/tools/ecode/appconfig.hpp b/src/tools/ecode/appconfig.hpp index d8e647f23..df40d3d25 100644 --- a/src/tools/ecode/appconfig.hpp +++ b/src/tools/ecode/appconfig.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -131,6 +132,7 @@ struct CodeEditorConfig { UITabWidget::TabJumpMode tabJumpMode{ UITabWidget::TabJumpMode::Linear }; NewTabPosition::Position newTabPosition{ NewTabPosition::Last }; std::string customDateFormat{ "%d.%m.%Y %H:%M:%S" }; + UIDiffView::ViewMode diffViewMode{ UIDiffView::ViewMode::Unified }; bool singleClickNavigation{ false }; bool syncProjectTreeWithEditor{ true }; diff --git a/src/tools/ecode/ecode.cpp b/src/tools/ecode/ecode.cpp index 6b1411588..bc17e12f2 100644 --- a/src/tools/ecode/ecode.cpp +++ b/src/tools/ecode/ecode.cpp @@ -2617,8 +2617,10 @@ void App::loadDiffFromMemory( const std::string& content, const std::string& ori auto diffView = scrollView->getFirstChild()->asType()->getFirstChild(); while ( diffView ) { - if ( diffView->isType( UI_TYPE_DIFF_VIEW ) ) + if ( diffView->isType( UI_TYPE_DIFF_VIEW ) ) { + configureDiffView( diffView->asType() ); diffView->asType()->setSyntaxColorScheme( *getCurrentColorScheme() ); + } diffView = diffView->getNextNode(); } return; @@ -2626,6 +2628,7 @@ void App::loadDiffFromMemory( const std::string& content, const std::string& ori auto diffViewTitle = i18n( "diff_viewer", "Diff Viewer" ); auto* diffView = Tools::UIDiffView::New(); + configureDiffView( diffView ); diffView->setAutoDeleteOldTempImage( true ); auto [tab, iv] = getSplitter()->createWidget( diffView, diffViewTitle ); if ( !tab ) @@ -2669,8 +2672,10 @@ void App::loadDiffFromPath( const std::string& path ) { auto diffView = scrollView->getFirstChild()->asType()->getFirstChild(); while ( diffView ) { - if ( diffView->isType( UI_TYPE_DIFF_VIEW ) ) + if ( diffView->isType( UI_TYPE_DIFF_VIEW ) ) { + configureDiffView( diffView->asType() ); diffView->asType()->setSyntaxColorScheme( *getCurrentColorScheme() ); + } diffView = diffView->getNextNode(); } return; @@ -2678,6 +2683,7 @@ void App::loadDiffFromPath( const std::string& path ) { auto diffViewTitle = i18n( "diff_viewer", "Diff Viewer" ); auto* diffView = Tools::UIDiffView::New(); + configureDiffView( diffView ); auto [tab, iv] = mSplitter->createWidget( diffView, i18n( "diff_viewer", "Diff Viewer" ) ); if ( !path.empty() ) { std::string fileName = FileSystem::fileNameFromPath( path ); @@ -2698,6 +2704,7 @@ void App::loadDiffFromPath( const std::string& path ) { void App::loadDiffFromPaths( const std::string& oldPath, const std::string& newPath ) { auto diffViewTitle = i18n( "diff_viewer", "Diff Viewer" ); auto* diffView = Tools::UIDiffView::New(); + configureDiffView( diffView ); auto [tab, iv] = mSplitter->createWidget( diffView, i18n( "diff_viewer", "Diff Viewer" ) ); if ( !newPath.empty() ) { std::string fileName = FileSystem::fileNameFromPath( newPath ); @@ -2718,6 +2725,7 @@ void App::loadDiffFromPaths( const std::string& oldPath, const std::string& newP void App::loadDiffFromStrings( const std::string& str, const std::string& otherStr ) { auto diffViewTitle = i18n( "diff_viewer", "Diff Viewer" ); auto* diffView = Tools::UIDiffView::New(); + configureDiffView( diffView ); auto [tab, iv] = mSplitter->createWidget( diffView, i18n( "diff_viewer", "Diff Viewer" ) ); tab->setText( diffViewTitle ); auto icon = findIcon( "filetype-diff" ); @@ -2728,6 +2736,11 @@ void App::loadDiffFromStrings( const std::string& str, const std::string& otherS registerUnlockedCommands( *diffView ); } +void App::configureDiffView( UIDiffView* diffView ) { + if ( diffView ) + diffView->setViewMode( mConfig.editor.diffViewMode ); +} + void App::openFileFromPath( const std::string& path ) { std::string ext = FileSystem::fileExtension( path ); if ( !Image::isImageExtension( path ) && !SoundFileFactory::isKnownFileExtension( path ) && diff --git a/src/tools/ecode/ecode.hpp b/src/tools/ecode/ecode.hpp index a79eb2e0a..38681e930 100644 --- a/src/tools/ecode/ecode.hpp +++ b/src/tools/ecode/ecode.hpp @@ -584,6 +584,7 @@ class App : public UICodeEditorSplitter::Client, public PluginContextProvider { const std::string& repoPath = "" ); void loadDiffFromStrings( const std::string& str, const std::string& otherStr ); + void configureDiffView( UIDiffView* diffView ); void createAndShowRecentFolderPopUpMenu( Node* recentFoldersBut ); diff --git a/src/tools/ecode/settingspanel.cpp b/src/tools/ecode/settingspanel.cpp index 7401c7ccc..e376a4339 100644 --- a/src/tools/ecode/settingspanel.cpp +++ b/src/tools/ecode/settingspanel.cpp @@ -903,6 +903,25 @@ void SettingsPanel::addUserSettings( PanelState& panel ) { mApp->getSplitter()->setColorScheme( editorSchemeIds[std::min( selected, editorSchemeIds.size() - 1 )] ); } ); + addChoice( + panel, + { "defaultDiffView", "editor.appearance", + mApp->i18n( "default_diff_view", "Default Diff View" ), + mApp->i18n( "default_diff_view_desc", + "Choose the initial layout used when opening text diffs." ) }, + { mApp->i18n( "diff_view_unified", "Unified" ), + mApp->i18n( "diff_view_side_by_side", "Side by Side" ) }, + [this] { + return mApp->getConfig().editor.diffViewMode == UIDiffView::ViewMode::Unified ? 0 : 1; + }, + [this]( size_t selected ) { + auto mode = + selected == 0 ? UIDiffView::ViewMode::Unified : UIDiffView::ViewMode::SideBySide; + mApp->getConfig().editor.diffViewMode = mode; + mApp->getSplitter()->forEachWidgetType( UI_TYPE_DIFF_VIEW, [mode]( UIWidget* widget ) { + widget->asType()->setViewMode( mode ); + } ); + } ); auto addEditorBool = [this, &panel]( std::string id, const char* nameKey, const char* name, const char* descriptionKey, const char* description, bool CodeEditorConfig::* member, auto apply ) {