KiCad PCB EDA Suite
Loading...
Searching...
No Matches
mergetool_frame.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,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/gpl-3.0.html
19 * or you may search the http://www.gnu.org website for the version 3 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include "mergetool_frame.h"
25
26#include <base_units.h>
28#include <cli/exit_codes.h>
30#include <kiway.h>
31#include <reporter.h>
33
34#include <wx/crt.h>
35#include <wx/filename.h>
36#include <wx/msgdlg.h>
37
38
39namespace
40{
42{
43 switch( aKind )
44 {
49 return true;
50
51 default:
52 return false;
53 }
54}
55} // namespace
56
57
58MERGETOOL_FRAME::MERGETOOL_FRAME( KIWAY* aKiway, wxWindow* aParent,
59 const MERGETOOL_PATHS& aPaths ) :
60 KIWAY_PLAYER( aKiway, aParent, FRAME_MERGETOOL,
61 _( "KiCad Merge Tool" ), wxDefaultPosition,
62 wxWindow::FromDIP( wxSize( 400, 120 ), nullptr ),
63 wxDEFAULT_FRAME_STYLE | wxFRAME_NO_TASKBAR,
64 wxT( "MergeToolFrame" ), unityScale ),
65 m_paths( aPaths )
66{
67}
68
69
71
72
74{
75 // No persistent state to flush; the JOB writes the merged output
76 // directly. The frame is just the modal-dialog host.
77}
78
79
81{
83
84 if( !supportsMergetoolKind( kind ) )
85 {
86 wxMessageBox( wxString::Format( _( "No mergetool handler for output '%s'.\n"
87 "Output extension must be .kicad_pcb, .kicad_sch, "
88 ".kicad_sym, or .kicad_mod." ),
89 m_paths.output ),
90 _( "KiCad Merge Tool" ), wxOK | wxICON_ERROR, this );
92 }
93
94 // Interactive: the merge opens DIALOG_KICAD_MERGE_3WAY for unresolved conflicts.
96 const bool singleFile = kind == KICAD_DIFF::DOC_KIND::FOOTPRINT;
97 int exitCode = KICAD_DIFF::DispatchMerge( Kiway(), kind, m_paths.ancestor,
98 m_paths.ours, m_paths.theirs,
99 m_paths.output, /* interactive */ true,
100 singleFile, &reporter );
101
102 if( reporter.HasMessage() )
103 {
104 // Surface the kiface's diagnostics to the terminal so a `git mergetool`
105 // invocation can see what happened even when the dialog was dismissed.
106 wxFprintf( stderr, wxT( "%s" ), reporter.GetMessages() );
107 }
108
109 return exitCode;
110}
111
constexpr EDA_IU_SCALE unityScale
Definition base_units.h:124
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
KIWAY_PLAYER(KIWAY *aKiway, wxWindow *aParent, FRAME_T aFrameType, const wxString &aTitle, const wxPoint &aPos, const wxSize &aSize, long aStyle, const wxString &aFrameName, const EDA_IU_SCALE &aIuScale)
A minimalistic software bus for communications between various DLLs/DSOs (DSOs) within the same KiCad...
Definition kiway.h:311
~MERGETOOL_FRAME() override
MERGETOOL_FRAME(KIWAY *aKiway, wxWindow *aParent, const MERGETOOL_PATHS &aPaths)
int RunMerge()
Run the merge synchronously.
void doCloseWindow() override
MERGETOOL_PATHS m_paths
A wrapper for reporting to a wxString object.
Definition reporter.h:189
static bool supportsMergetoolKind(KICAD_DIFF::DOC_KIND aKind)
#define _(s)
@ FRAME_MERGETOOL
Top-level host for the 3-way merge resolution dialog.
Definition frame_type.h:64
static const int ERR_ARGS
Definition exit_codes.h:31
int DispatchMerge(KIWAY &aKiway, DOC_KIND aKind, const wxString &aAncestor, const wxString &aOurs, const wxString &aTheirs, const wxString &aOutput, bool aInteractive, bool aSingleFile, REPORTER *aReporter)
Run a 3-way document/library merge by calling the owning kiface's KIFACE_MERGE_DOCUMENT function expo...
DOC_KIND DocKindFromExtension(const wxString &aPath)
Map a path's extension to a DOC_KIND (.kicad_pcb -> PCB, .kicad_sch -> SCH, .kicad_sym -> SYM_LIB,...
DOC_KIND
Document type a diff/merge entry point should route to, derived from a file path's extension.
Top-level host frame for the 3-way merge resolution dialog.
IbisParser parser & reporter
Definition of file extensions used in Kicad.