KiCad PCB EDA Suite
Loading...
Searching...
No Matches
dialog_text_diff.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
21
23#include <kiplatform/ui.h>
24#include <widgets/ui_common.h>
25
26#include <wx/settings.h>
27#include <wx/stc/stc.h>
28
29static constexpr int STYLE_ADDED = 1;
30static constexpr int STYLE_REMOVED = 2;
31
32
33void FillTextDiffControl( wxStyledTextCtrl* aCtrl, const std::vector<KIGIT::TEXT_DIFF_LINE>& aLines )
34{
35 wxStyledTextCtrl* stc = aCtrl;
36
37 stc->SetReadOnly( false );
38 stc->ClearAll();
39 stc->StyleSetFont( wxSTC_STYLE_DEFAULT, KIUI::GetMonospacedUIFont() );
40
41 // Scintilla ignores the desktop theme, and StyleClearAll copies the default style onto
42 // every other one, so these have to come before it.
43 stc->StyleSetForeground( wxSTC_STYLE_DEFAULT, wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT ) );
44 stc->StyleSetBackground( wxSTC_STYLE_DEFAULT, wxSystemSettings::GetColour( wxSYS_COLOUR_LISTBOX ) );
45 stc->StyleClearAll();
46 stc->SetMarginWidth( 1, 0 );
47
49
50 stc->StyleSetForeground( STYLE_ADDED, theme.added.ToColour() );
51 stc->StyleSetForeground( STYLE_REMOVED, theme.removed.ToColour() );
52
53 for( const KIGIT::TEXT_DIFF_LINE& line : aLines )
54 {
55 int start = stc->GetLength();
56
57 switch( line.kind )
58 {
59 case KIGIT::TEXT_DIFF_KIND::ADDED: stc->AppendText( wxS( "+ " ) + line.text + wxS( "\n" ) ); break;
60 case KIGIT::TEXT_DIFF_KIND::REMOVED: stc->AppendText( wxS( "- " ) + line.text + wxS( "\n" ) ); break;
61 case KIGIT::TEXT_DIFF_KIND::CONTEXT: stc->AppendText( wxS( " " ) + line.text + wxS( "\n" ) ); break;
62 }
63
64 if( line.kind != KIGIT::TEXT_DIFF_KIND::CONTEXT )
65 {
66 stc->StartStyling( start );
67 stc->SetStyling( stc->GetLength() - start,
69 }
70 }
71
72 stc->SetReadOnly( true );
73}
74
75
76DIALOG_TEXT_DIFF::DIALOG_TEXT_DIFF( wxWindow* aParent, const wxString& aTitle,
77 const std::vector<KIGIT::TEXT_DIFF_LINE>& aLines ) :
78 DIALOG_TEXT_DIFF_BASE( aParent, wxID_ANY, aTitle )
79{
80 FillTextDiffControl( m_diff, aLines );
81
84}
void SetupStandardButtons(std::map< int, wxString > aLabels={})
void finishDialogSettings()
In all dialogs, we must call the same functions to fix minimal dlg size, the default position and per...
DIALOG_TEXT_DIFF_BASE(wxWindow *parent, wxWindowID id=wxID_ANY, const wxString &title=wxEmptyString, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxSize(780, 560), long style=wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER)
DIALOG_TEXT_DIFF(wxWindow *aParent, const wxString &aTitle, const std::vector< KIGIT::TEXT_DIFF_LINE > &aLines)
wxColour ToColour() const
Definition color4d.cpp:221
static constexpr int STYLE_ADDED
void FillTextDiffControl(wxStyledTextCtrl *aCtrl, const std::vector< KIGIT::TEXT_DIFF_LINE > &aLines)
Fill aCtrl with a line diff, added and removed lines in the diff colours, and make it read only.
static constexpr int STYLE_REMOVED
void FillTextDiffControl(wxStyledTextCtrl *aCtrl, const std::vector< KIGIT::TEXT_DIFF_LINE > &aLines)
Fill aCtrl with a line diff, added and removed lines in the diff colours, and make it read only.
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:54
KICOMMON_API wxFont GetMonospacedUIFont(int aRelativeSize=0)
Definition ui_common.cpp:94
Diff colors with defaults for light backgrounds.
Definition diff_scene.h:275
static DIFF_COLOR_THEME ForText(bool aDarkTheme)
Resolve change colors for UI text. Pass the desktop theme captured on the UI thread.
Functions to provide common constants and other functions to assist in making a consistent UI.