Fix commit 0a881e09, not working on wxWidgets 3.1.5/msys2

This commit is contained in:
jean-pierre charras 2022-12-08 15:39:10 +01:00
parent 0098dfa6dc
commit 966f7bfa4c
3 changed files with 36 additions and 2 deletions

View File

@ -31,6 +31,7 @@
#include <dialogs/html_message_box.h>
#include <functional>
#include <unordered_map>
#include "cli/cli_names.h"
// Set of dialogs that have been chosen not to be shown again
static std::unordered_map<unsigned long, int> doNotShowAgainDlgs;
@ -41,7 +42,12 @@ bool IsGUI()
#if wxCHECK_VERSION( 3, 1, 6 )
return wxTheApp->IsGUI();
#else
return dynamic_cast<wxAppBase*>( 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
}

24
include/cli/cli_names.h Normal file
View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef CLI_NAMES_H
#define CLI_NAMES_H
#define KICAD_CLI_APP_NAME wxT( "kicad_cli_app" )
#endif

View File

@ -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 <kiface_base.h>
@ -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();