From 966f7bfa4c34ebb5230265664cffe3e887c1df73 Mon Sep 17 00:00:00 2001 From: jean-pierre charras Date: Thu, 8 Dec 2022 15:39:10 +0100 Subject: [PATCH] Fix commit 0a881e09, not working on wxWidgets 3.1.5/msys2 --- common/confirm.cpp | 8 +++++++- include/cli/cli_names.h | 24 ++++++++++++++++++++++++ kicad/kicad_cli.cpp | 6 +++++- 3 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 include/cli/cli_names.h diff --git a/common/confirm.cpp b/common/confirm.cpp index 5b594dcb81..d8da3bca1f 100644 --- a/common/confirm.cpp +++ b/common/confirm.cpp @@ -31,6 +31,7 @@ #include #include #include +#include "cli/cli_names.h" // Set of dialogs that have been chosen not to be shown again static std::unordered_map doNotShowAgainDlgs; @@ -41,7 +42,12 @@ bool IsGUI() #if wxCHECK_VERSION( 3, 1, 6 ) return wxTheApp->IsGUI(); #else - return dynamic_cast( wxTheApp ); + // wxWidgets older than version 3.1.6 do not have a way to know if the app + // has a GUI or is a console application. + // So the trick is to set the App class name when starting kicad-cli, and when + // the app class name is the kicad-cli class name the app is a console app + bool run_gui = wxTheApp->GetClassName() != KICAD_CLI_APP_NAME; + return run_gui; #endif } diff --git a/include/cli/cli_names.h b/include/cli/cli_names.h new file mode 100644 index 0000000000..f07017c4ad --- /dev/null +++ b/include/cli/cli_names.h @@ -0,0 +1,24 @@ +/* + * This program source code file is part of KiCad, a free EDA CAD application. + * + * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation, either version 3 of the License, or (at your + * option) any later version. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program. If not, see . + */ + +#ifndef CLI_NAMES_H +#define CLI_NAMES_H + +#define KICAD_CLI_APP_NAME wxT( "kicad_cli_app" ) +#endif \ No newline at end of file diff --git a/kicad/kicad_cli.cpp b/kicad/kicad_cli.cpp index a43ceecd2c..9c42e6d4fc 100644 --- a/kicad/kicad_cli.cpp +++ b/kicad/kicad_cli.cpp @@ -67,6 +67,7 @@ #include "cli/command_sym.h" #include "cli/command_sym_upgrade.h" #include "cli/exit_codes.h" +#include "cli/cli_names.h" // a dummy to quiet linking with EDA_BASE_FRAME::config(); #include @@ -218,7 +219,10 @@ static COMMAND_ENTRY* recurseArgParserSubCommandUsed( argparse::ArgumentParser& bool PGM_KICAD::OnPgmInit() { PGM_BASE::BuildArgvUtf8(); - App().SetAppDisplayName( wxT( "KiCad" ) ); + App().SetAppDisplayName( wxT( "KiCad-cli" ) ); + // App name can be used by internal code to know if this is a + // kicad CLI app or a GUI app that is running + App().SetClassName( KICAD_CLI_APP_NAME ); #if defined( DEBUG ) wxString absoluteArgv0 = wxStandardPaths::Get().GetExecutablePath();