1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2008-2011 Erlend Hamberg <ehamberg@gmail.com> |
3 | SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com> |
4 | SPDX-FileCopyrightText: 2012-2013 Simon St James <kdedevel@etotheipiplusone.com> |
5 | |
6 | SPDX-License-Identifier: LGPL-2.0-or-later |
7 | */ |
8 | |
9 | #include "globalstate.h" |
10 | #include "history.h" |
11 | #include "macros.h" |
12 | #include "mappings.h" |
13 | #include "registers.h" |
14 | |
15 | #include <KConfigGroup> |
16 | |
17 | using namespace KateVi; |
18 | |
19 | GlobalState::GlobalState() |
20 | { |
21 | m_macros = new Macros(); |
22 | m_mappings = new Mappings(); |
23 | m_registers = new Registers(); |
24 | m_searchHistory = new History(); |
25 | m_replaceHistory = new History(); |
26 | m_commandHistory = new History(); |
27 | |
28 | readConfig(config: config().data()); |
29 | } |
30 | |
31 | GlobalState::~GlobalState() |
32 | { |
33 | writeConfig(config: config().data()); |
34 | config().data()->sync(); |
35 | |
36 | delete m_searchHistory; |
37 | delete m_replaceHistory; |
38 | delete m_commandHistory; |
39 | delete m_macros; |
40 | delete m_mappings; |
41 | delete m_registers; |
42 | } |
43 | |
44 | void GlobalState::writeConfig(KConfig *configFile) const |
45 | { |
46 | // FIXME: use own groups instead of one big group! |
47 | KConfigGroup config(configFile, QStringLiteral("Kate Vi Input Mode Settings")); |
48 | m_macros->writeConfig(config); |
49 | m_mappings->writeConfig(config); |
50 | m_registers->writeConfig(config); |
51 | } |
52 | |
53 | void GlobalState::readConfig(const KConfig *configFile) |
54 | { |
55 | // FIXME: use own groups instead of one big group! |
56 | const KConfigGroup config(configFile, QStringLiteral("Kate Vi Input Mode Settings")); |
57 | |
58 | m_macros->readConfig(config); |
59 | m_mappings->readConfig(config); |
60 | m_registers->readConfig(config); |
61 | } |
62 | |
63 | KSharedConfigPtr GlobalState::config() |
64 | { |
65 | // use dummy config for unit tests! |
66 | return QStandardPaths::isTestModeEnabled() |
67 | ? KSharedConfig::openConfig(QStringLiteral("katevirc-unittest"), mode: KConfig::SimpleConfig, type: QStandardPaths::TempLocation) |
68 | : KSharedConfig::openConfig(QStringLiteral("katevirc")); |
69 | } |
70 |