mirror of
https://gitlab.com/kicad/code/kicad.git
synced 2025-09-14 02:03:12 +02:00
Merge branch 'feature-revert-all-settings-defaults-7273' into 'master'
Add option to restore the default settings on startup. Closes #7273 See merge request kicad/code/kicad!2079
This commit is contained in:
commit
025a459696
@ -214,6 +214,7 @@ set( KICOMMON_SRCS
|
||||
trace_helpers.cpp
|
||||
wildcards_and_files_ext.cpp
|
||||
wx_filename.cpp
|
||||
startup_key_handler.cpp
|
||||
|
||||
singleton.cpp
|
||||
pgm_base.cpp
|
||||
|
120
common/startup_key_handler.cpp
Normal file
120
common/startup_key_handler.cpp
Normal file
@ -0,0 +1,120 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The 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/>.
|
||||
*/
|
||||
|
||||
#include <functional>
|
||||
|
||||
#include <startup_key_handler.h>
|
||||
#include <wx/msgdlg.h>
|
||||
#include <gestfich.h>
|
||||
#include <paths.h>
|
||||
#include <confirm.h>
|
||||
|
||||
|
||||
StartupKeyHandler::StartupKeyHandler()
|
||||
{
|
||||
//Setup Keys and required actions to perform
|
||||
m_keyActions[{ WXK_CONTROL }] = { KEY_ACTION::RESET_TO_FACTORY_DEFAULTS };
|
||||
}
|
||||
|
||||
|
||||
StartupKeyHandler::~StartupKeyHandler()
|
||||
{
|
||||
m_keyActions.clear();
|
||||
}
|
||||
|
||||
|
||||
void StartupKeyHandler::CheckStartupKeys()
|
||||
{
|
||||
for( const auto& [keySequence, actions] : m_keyActions )
|
||||
{
|
||||
// We can request multiple combinations of modifying keys
|
||||
if( std::all_of( keySequence.begin(), keySequence.end(),
|
||||
[]( wxKeyCode keyCode )
|
||||
{
|
||||
return isKeyActionRequested( keyCode );
|
||||
} ) )
|
||||
{
|
||||
performKeyActions( actions );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool StartupKeyHandler::isKeyActionRequested( wxKeyCode aKeyCode )
|
||||
{
|
||||
return wxGetKeyState( aKeyCode );
|
||||
}
|
||||
|
||||
|
||||
void StartupKeyHandler::performKeyActions( const std::vector<KEY_ACTION>& aActions )
|
||||
{
|
||||
for( const KEY_ACTION& action : aActions )
|
||||
{
|
||||
switch( action )
|
||||
{
|
||||
case KEY_ACTION::RESET_TO_FACTORY_DEFAULTS:
|
||||
resetToFactoryDefaults();
|
||||
break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void StartupKeyHandler::resetToFactoryDefaults()
|
||||
{
|
||||
wxString errors;
|
||||
|
||||
if( IsOK( nullptr, _( "Reset settings to default?" ) ) )
|
||||
{
|
||||
wxString sourcePath = PATHS::GetUserSettingsPath();
|
||||
wxString destPath = sourcePath + ".backup";
|
||||
|
||||
// Remove existing backup if exists
|
||||
if( !RmDirRecursive( destPath, &errors ) )
|
||||
{
|
||||
if( !errors.empty() )
|
||||
{
|
||||
DisplayErrorMessage( nullptr, errors );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// Create backup before deleting
|
||||
if( !CopyDirectory( sourcePath, destPath, errors ) )
|
||||
{
|
||||
if( !errors.empty() )
|
||||
{
|
||||
DisplayErrorMessage( nullptr, errors );
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//delete
|
||||
if( !RmDirRecursive( sourcePath, &errors ) )
|
||||
{
|
||||
if( !errors.empty() )
|
||||
{
|
||||
DisplayErrorMessage( nullptr, errors );
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
63
include/startup_key_handler.h
Normal file
63
include/startup_key_handler.h
Normal file
@ -0,0 +1,63 @@
|
||||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright The 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 STARTUP_KEY_HANDLER_H
|
||||
#define STARTUP_KEY_HANDLER_H
|
||||
|
||||
#include <kicommon.h>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <wx/wx.h>
|
||||
|
||||
|
||||
// A class to handle key press detection and execute multiple actions at startup
|
||||
class KICOMMON_API StartupKeyHandler
|
||||
{
|
||||
public:
|
||||
// Enum to define actions for key presses
|
||||
enum class KEY_ACTION
|
||||
{
|
||||
RESET_TO_FACTORY_DEFAULTS
|
||||
};
|
||||
|
||||
// Constructor to initialize key-action mappings
|
||||
StartupKeyHandler();
|
||||
|
||||
~StartupKeyHandler();
|
||||
|
||||
// Function to handle the startup key check
|
||||
void CheckStartupKeys();
|
||||
|
||||
private:
|
||||
// Function to check if a ctrl key is pressed
|
||||
static bool isKeyActionRequested( wxKeyCode aKeyCode );
|
||||
|
||||
// Function to perform actions if ctrl key pressed
|
||||
void performKeyActions( const std::vector<KEY_ACTION>& aActions );
|
||||
|
||||
// Resets all user-configurable settings to their original factory default values.
|
||||
// This operation will erase any customized settings or preferences.
|
||||
void resetToFactoryDefaults();
|
||||
|
||||
private:
|
||||
// A map to store the combination of keys and their corresponding list of actions
|
||||
std::map<std::vector<wxKeyCode>, std::vector<KEY_ACTION>> m_keyActions;
|
||||
};
|
||||
|
||||
#endif // STARTUP_KEY_HANDLER_H
|
@ -63,6 +63,8 @@
|
||||
#include <api/api_server.h>
|
||||
#endif
|
||||
|
||||
#include "startup_key_handler.h"
|
||||
|
||||
// a dummy to quiet linking with EDA_BASE_FRAME::config();
|
||||
#include <kiface_base.h>
|
||||
KIFACE_BASE& Kiface()
|
||||
@ -86,6 +88,9 @@ PGM_KICAD& PgmTop()
|
||||
|
||||
bool PGM_KICAD::OnPgmInit()
|
||||
{
|
||||
StartupKeyHandler keyHandler;
|
||||
keyHandler.CheckStartupKeys();
|
||||
|
||||
App().SetAppDisplayName( wxT( "KiCad" ) );
|
||||
|
||||
#if defined(DEBUG)
|
||||
|
Loading…
x
Reference in New Issue
Block a user