KiCad PCB EDA Suite
Loading...
Searching...
No Matches
test_hotkey_store.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, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <boost/test/unit_test.hpp>
21
22#include <hotkey_store.h>
23#include <hotkeys_basic.h>
24#include <tool/tool_action.h>
25#include <tool/tool_event.h>
26
27BOOST_AUTO_TEST_SUITE( HotkeyStore )
28
29BOOST_AUTO_TEST_CASE( PersistenceAndDefaults )
30{
31 TOOL_ACTION action1( TOOL_ACTION_ARGS().Name( "common.test1" ).FriendlyName( "Test1" )
32 .Scope( AS_GLOBAL ).DefaultHotkey( 'A' ) );
33 TOOL_ACTION action2( TOOL_ACTION_ARGS().Name( "common.test2" ).FriendlyName( "Test2" )
34 .Scope( AS_GLOBAL ).DefaultHotkey( 'B' ) );
35
36 HOTKEY_STORE store;
37 store.Init( { &action1, &action2 }, false );
38
39 auto& sections = store.GetSections();
40 BOOST_REQUIRE( !sections.empty() );
41
42 HOTKEY& hk = sections[0].m_HotKeys[0];
43 hk.m_EditKeycode = 'C';
44 store.SaveAllHotkeys();
45 BOOST_CHECK_EQUAL( action1.GetHotKey(), 'C' );
46
48 BOOST_CHECK_EQUAL( sections[0].m_HotKeys[0].m_EditKeycode, action1.GetDefaultHotKey() );
49}
50
51BOOST_AUTO_TEST_CASE( DuplicateRegistration )
52{
53 TOOL_ACTION action1( TOOL_ACTION_ARGS().Name( "common.test1" ).FriendlyName( "Test1" )
54 .Scope( AS_GLOBAL ).DefaultHotkey( 'A' ) );
55 TOOL_ACTION action2( TOOL_ACTION_ARGS().Name( "common.test2" ).FriendlyName( "Test2" )
56 .Scope( AS_GLOBAL ).DefaultHotkey( 'B' ) );
57
58 HOTKEY_STORE store;
59 store.Init( { &action1, &action2 }, false );
60
61 HOTKEY* conflict = nullptr;
62 bool has = store.CheckKeyConflicts( &action1, action2.GetHotKey(), &conflict );
63 BOOST_CHECK( has );
64 BOOST_CHECK( conflict != nullptr );
65
66 has = store.CheckKeyConflicts( &action1, 'Z', &conflict );
67 BOOST_CHECK( !has );
68}
69
70BOOST_AUTO_TEST_CASE( KeycodeSerialization )
71{
72 int code = MD_CTRL + 'M';
73 wxString name = KeyNameFromKeyCode( code );
74 int round = KeyCodeFromKeyName( name );
75 BOOST_CHECK_EQUAL( code, round );
76}
77
79
const char * name
Definition: DXF_plotter.cpp:62
A class that contains a set of hotkeys, arranged into "sections" and provides some book-keeping funct...
Definition: hotkey_store.h:66
bool CheckKeyConflicts(TOOL_ACTION *aAction, long aKey, HOTKEY **aConflict)
Check whether the given key conflicts with anything in this store.
void ResetAllHotkeysToDefault()
Reset every hotkey in the store to the default values.
void Init(std::vector< TOOL_ACTION * > aActionsList, bool aIncludeReadOnlyCmds)
std::vector< HOTKEY_SECTION > & GetSections()
Get the list of sections managed by this store.
void SaveAllHotkeys()
Persist all changes to hotkeys in the store to the underlying data structures.
Build up the properties of a TOOL_ACTION in an incremental manner that is static-construction safe.
Definition: tool_action.h:118
Represent a single user action.
Definition: tool_action.h:304
int GetHotKey() const
Return the hotkey keycode which initiates the action.
Definition: tool_action.h:348
int GetDefaultHotKey() const
Return the default hotkey (if any) for the action.
Definition: tool_action.h:342
wxString KeyNameFromKeyCode(int aKeycode, bool *aIsFound)
Return the key name from the key code.
int KeyCodeFromKeyName(const wxString &keyname)
Return the key code from its user-friendly key name (ie: "Ctrl+M").
int m_EditKeycode
Definition: hotkey_store.h:37
BOOST_AUTO_TEST_SUITE(CadstarPartParser)
BOOST_CHECK_EQUAL(ret, c.m_exp_result)
BOOST_REQUIRE(intersection.has_value()==c.ExpectedIntersection.has_value())
BOOST_AUTO_TEST_SUITE_END()
BOOST_AUTO_TEST_CASE(PersistenceAndDefaults)
@ AS_GLOBAL
Global action (toolbar/main menu event, global shortcut)
Definition: tool_action.h:49
@ MD_CTRL
Definition: tool_event.h:144