From bfb2201e002018f57e8391160b780f9814b05076 Mon Sep 17 00:00:00 2001 From: Jakub Mandula Date: Wed, 26 Nov 2025 16:36:21 +0100 Subject: [PATCH 1/3] Added a basic Left/Right Only File view with < > hot keys --- diff-pdf.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 3 deletions(-) diff --git a/diff-pdf.cpp b/diff-pdf.cpp index f95b638..0b335ab 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -42,6 +42,14 @@ #include #include + +enum DisplayMode +{ + SHOW_DIFF_DOCUMENT, + SHOW_LEFT_DOCUMENT, + SHOW_RIGHT_DOCUMENT +}; + // ------------------------------------------------------------------------ // PDF rendering functions // ------------------------------------------------------------------------ @@ -537,6 +545,9 @@ const int ID_OFFSET_RIGHT = wxNewId(); const int ID_OFFSET_UP = wxNewId(); const int ID_OFFSET_DOWN = wxNewId(); const int ID_GUTTER = wxNewId(); +const int ID_LEFT_DOC = wxNewId(); +const int ID_RIGHT_DOC = wxNewId(); +const int ID_DIFF_DOC = wxNewId(); #define BMP_ARTPROV(id) wxArtProvider::GetBitmap(id, wxART_TOOLBAR) @@ -597,11 +608,17 @@ class DiffFrame : public wxFrame "Offset one of the pages up (Ctrl up)"); toolbar->AddTool(ID_OFFSET_DOWN, "", BMP_OFFSET_DOWN, "Offset one of the pages down (Ctrl down)"); + toolbar->AddTool(ID_LEFT_DOC, "Left document", BMP_ARTPROV(wxART_GO_BACK), + "Show left document (Ctrl <)"); + toolbar->AddTool(ID_DIFF_DOC, "Diff document", BMP_ARTPROV(wxART_REDO), + "Show diff document (Ctrl d)"); + toolbar->AddTool(ID_RIGHT_DOC, "Right document", BMP_ARTPROV(wxART_GO_FORWARD), + "Show right document (Ctrl >)"); toolbar->Realize(); SetToolBar(toolbar); - wxAcceleratorEntry accels[8]; + wxAcceleratorEntry accels[11]; accels[0].Set(wxACCEL_NORMAL, WXK_PAGEUP, ID_PREV_PAGE); accels[1].Set(wxACCEL_NORMAL, WXK_PAGEDOWN, ID_NEXT_PAGE); accels[2].Set(wxACCEL_CTRL, (int)'=', ID_ZOOM_IN); @@ -610,8 +627,11 @@ class DiffFrame : public wxFrame accels[5].Set(wxACCEL_CTRL, WXK_RIGHT, ID_OFFSET_RIGHT); accels[6].Set(wxACCEL_CTRL, WXK_UP, ID_OFFSET_UP); accels[7].Set(wxACCEL_CTRL, WXK_DOWN, ID_OFFSET_DOWN); + accels[8].Set(wxACCEL_CTRL, (int)',', ID_LEFT_DOC); + accels[9].Set(wxACCEL_CTRL, (int)'.', ID_RIGHT_DOC); + accels[10].Set(wxACCEL_CTRL, (int)'d', ID_DIFF_DOC); - wxAcceleratorTable accel_table(8, accels); + wxAcceleratorTable accel_table(11, accels); SetAcceleratorTable(accel_table); m_gutter = new Gutter(this, ID_GUTTER); @@ -695,8 +715,32 @@ class DiffFrame : public wxFrame m_offset.x, m_offset.y, &thumbnail, Gutter::WIDTH ); + // Render page according to the current display mode + switch ( m_display_mode ) + { + case SHOW_LEFT_DOCUMENT: + // + if ( img1 ) + m_viewer->Set(img1); + else if ( img2 ) + m_viewer->Set(img2); + else + m_viewer->Set(NULL); + break; + + case SHOW_RIGHT_DOCUMENT: + if ( img2 ) + m_viewer->Set(img2); + else if ( img1 ) + m_viewer->Set(img1); + else + m_viewer->Set(NULL); + break; - m_viewer->Set(diff ? diff : img1); + case SHOW_DIFF_DOCUMENT: + default: + m_viewer->Set(diff ? diff : img1); + } // Always update the diff map. It will be all-white if there were // no differences. @@ -788,6 +832,27 @@ class DiffFrame : public wxFrame DoUpdatePage(); } + void OnShowLeftDocument(wxCommandEvent&) + { + m_display_mode = SHOW_LEFT_DOCUMENT; + m_offset = wxPoint(0, 0); + DoUpdatePage(); + } + + void OnShowDiffDocument(wxCommandEvent&) + { + m_display_mode = SHOW_DIFF_DOCUMENT; + m_offset = wxPoint(0, 0); + DoUpdatePage(); + } + + void OnShowRightDocument(wxCommandEvent&) + { + m_display_mode = SHOW_RIGHT_DOCUMENT; + m_offset = wxPoint(0, 0); + DoUpdatePage(); + } + void OnOffsetLeft(wxCommandEvent&) { DoOffset(-1, 0); } void OnOffsetRight(wxCommandEvent&) { DoOffset(1, 0); } void OnOffsetUp(wxCommandEvent&) { DoOffset(0, -1); } @@ -803,6 +868,7 @@ class DiffFrame : public wxFrame int m_diff_count; int m_cur_page; wxPoint m_offset; + DisplayMode m_display_mode; }; BEGIN_EVENT_TABLE(DiffFrame, wxFrame) @@ -817,6 +883,9 @@ BEGIN_EVENT_TABLE(DiffFrame, wxFrame) EVT_TOOL (ID_OFFSET_RIGHT, DiffFrame::OnOffsetRight) EVT_TOOL (ID_OFFSET_UP, DiffFrame::OnOffsetUp) EVT_TOOL (ID_OFFSET_DOWN, DiffFrame::OnOffsetDown) + EVT_TOOL (ID_LEFT_DOC, DiffFrame::OnShowLeftDocument) + EVT_TOOL (ID_DIFF_DOC, DiffFrame::OnShowDiffDocument) + EVT_TOOL (ID_RIGHT_DOC, DiffFrame::OnShowRightDocument) END_EVENT_TABLE() From 11654e8b9e4f20c02ae13c4fbbed60a9dce72f22 Mon Sep 17 00:00:00 2001 From: Jakub Mandula Date: Wed, 26 Nov 2025 16:56:57 +0100 Subject: [PATCH 2/3] Update Readme with Left/Right view instructions --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 29e452e..ac1e518 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,8 @@ This opens a window that lets you view the files' pages and zoom in on details. It is also possible to shift the two pages relatively to each other using Ctrl-arrows (Cmd-arrows on MacOS). This is useful for identifying translation-only differences. +You can also use Ctrl < and Ctrl > (Cmd < and Cmd > on MacOS) show the left and right documents respecively. Ctrl d to return back to the diff view. + See the output of `$ diff-pdf --help` for complete list of options. From b39e57b2c2e0c835272ccf204e4c023e22cdd477 Mon Sep 17 00:00:00 2001 From: Jakub Mandula Date: Thu, 8 Jan 2026 12:23:42 +0100 Subject: [PATCH 3/3] Make requested changes to PR --- README.md | 2 +- diff-pdf.cpp | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index ac1e518..66d11d4 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ This opens a window that lets you view the files' pages and zoom in on details. It is also possible to shift the two pages relatively to each other using Ctrl-arrows (Cmd-arrows on MacOS). This is useful for identifying translation-only differences. -You can also use Ctrl < and Ctrl > (Cmd < and Cmd > on MacOS) show the left and right documents respecively. Ctrl d to return back to the diff view. +You can also use `Ctrl+<` and `Ctrl+>` (`Cmd+<` and `Cmd+>` on MacOS) show the left and right documents respecively. `Ctrl+D` to return back to the diff view. See the output of `$ diff-pdf --help` for complete list of options. diff --git a/diff-pdf.cpp b/diff-pdf.cpp index 0b335ab..0c24358 100644 --- a/diff-pdf.cpp +++ b/diff-pdf.cpp @@ -559,6 +559,10 @@ const int ID_DIFF_DOC = wxNewId(); #define BMP_OFFSET_UP BMP_ARTPROV(wxART_GO_UP) #define BMP_OFFSET_DOWN BMP_ARTPROV(wxART_GO_DOWN) +#define BMP_LEFT_DOC BMP_ARTPROV(wxART_GO_BACK) +#define BMP_RIGHT_DOC BMP_ARTPROV(wxART_GO_FORWARD) +#define BMP_DIFF_DOC BMP_ARTPROV(wxART_REDO) + #ifdef __WXGTK__ #define BMP_ZOOM_IN BMP_ARTPROV("gtk-zoom-in") #define BMP_ZOOM_OUT BMP_ARTPROV("gtk-zoom-out") @@ -608,12 +612,12 @@ class DiffFrame : public wxFrame "Offset one of the pages up (Ctrl up)"); toolbar->AddTool(ID_OFFSET_DOWN, "", BMP_OFFSET_DOWN, "Offset one of the pages down (Ctrl down)"); - toolbar->AddTool(ID_LEFT_DOC, "Left document", BMP_ARTPROV(wxART_GO_BACK), - "Show left document (Ctrl <)"); - toolbar->AddTool(ID_DIFF_DOC, "Diff document", BMP_ARTPROV(wxART_REDO), - "Show diff document (Ctrl d)"); - toolbar->AddTool(ID_RIGHT_DOC, "Right document", BMP_ARTPROV(wxART_GO_FORWARD), - "Show right document (Ctrl >)"); + toolbar->AddTool(ID_LEFT_DOC, "Left document", BMP_LEFT_DOC, + "Show left document (Ctrl+<)"); + toolbar->AddTool(ID_DIFF_DOC, "Diff document", BMP_DIFF_DOC, + "Show diff document (Ctrl+d)"); + toolbar->AddTool(ID_RIGHT_DOC, "Right document", BMP_RIGHT_DOC, + "Show right document (Ctrl+>)"); toolbar->Realize(); SetToolBar(toolbar); @@ -719,7 +723,7 @@ class DiffFrame : public wxFrame switch ( m_display_mode ) { case SHOW_LEFT_DOCUMENT: - // + // Try showing the left document; if not available, fall back if ( img1 ) m_viewer->Set(img1); else if ( img2 ) @@ -729,6 +733,7 @@ class DiffFrame : public wxFrame break; case SHOW_RIGHT_DOCUMENT: + // Try showing the right document; if not available, fall back if ( img2 ) m_viewer->Set(img2); else if ( img1 ) @@ -832,24 +837,27 @@ class DiffFrame : public wxFrame DoUpdatePage(); } + void ResetOffset() + { + m_offset = wxPoint(0, 0); + DoUpdatePage(); + } + void OnShowLeftDocument(wxCommandEvent&) { m_display_mode = SHOW_LEFT_DOCUMENT; - m_offset = wxPoint(0, 0); DoUpdatePage(); } void OnShowDiffDocument(wxCommandEvent&) { m_display_mode = SHOW_DIFF_DOCUMENT; - m_offset = wxPoint(0, 0); DoUpdatePage(); } void OnShowRightDocument(wxCommandEvent&) { m_display_mode = SHOW_RIGHT_DOCUMENT; - m_offset = wxPoint(0, 0); DoUpdatePage(); } @@ -883,9 +891,9 @@ BEGIN_EVENT_TABLE(DiffFrame, wxFrame) EVT_TOOL (ID_OFFSET_RIGHT, DiffFrame::OnOffsetRight) EVT_TOOL (ID_OFFSET_UP, DiffFrame::OnOffsetUp) EVT_TOOL (ID_OFFSET_DOWN, DiffFrame::OnOffsetDown) - EVT_TOOL (ID_LEFT_DOC, DiffFrame::OnShowLeftDocument) - EVT_TOOL (ID_DIFF_DOC, DiffFrame::OnShowDiffDocument) - EVT_TOOL (ID_RIGHT_DOC, DiffFrame::OnShowRightDocument) + EVT_TOOL (ID_LEFT_DOC, DiffFrame::OnShowLeftDocument) + EVT_TOOL (ID_DIFF_DOC, DiffFrame::OnShowDiffDocument) + EVT_TOOL (ID_RIGHT_DOC, DiffFrame::OnShowRightDocument) END_EVENT_TABLE()