/* * 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 . */ #include #include #include #include #include #include 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& 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; } } } }