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 "kateglobal.h"
12#include "macros.h"
13#include "mappings.h"
14#include "registers.h"
15
16#include <KConfigGroup>
17
18using namespace KateVi;
19
20GlobalState::GlobalState()
21{
22 m_macros = new Macros();
23 m_mappings = new Mappings();
24 m_registers = new Registers();
25 m_searchHistory = new History();
26 m_replaceHistory = new History();
27 m_commandHistory = new History();
28
29 readConfig(config: config().data());
30}
31
32GlobalState::~GlobalState()
33{
34 writeConfig(config: config().data());
35 config().data()->sync();
36
37 delete m_searchHistory;
38 delete m_replaceHistory;
39 delete m_commandHistory;
40 delete m_macros;
41 delete m_mappings;
42 delete m_registers;
43}
44
45void GlobalState::writeConfig(KConfig *configFile) const
46{
47 // FIXME: use own groups instead of one big group!
48 KConfigGroup config(configFile, QStringLiteral("Kate Vi Input Mode Settings"));
49 m_macros->writeConfig(config);
50 m_mappings->writeConfig(config);
51 m_registers->writeConfig(config);
52}
53
54void GlobalState::readConfig(const KConfig *configFile)
55{
56 // FIXME: use own groups instead of one big group!
57 const KConfigGroup config(configFile, QStringLiteral("Kate Vi Input Mode Settings"));
58
59 m_macros->readConfig(config);
60 m_mappings->readConfig(config);
61 m_registers->readConfig(config);
62}
63
64KSharedConfigPtr GlobalState::config()
65{
66 // use dummy config for unit tests!
67 return KTextEditor::EditorPrivate::unitTestMode()
68 ? KSharedConfig::openConfig(QStringLiteral("katevirc-unittest"), mode: KConfig::SimpleConfig, type: QStandardPaths::TempLocation)
69 : KSharedConfig::openConfig(QStringLiteral("katevirc"));
70}
71

source code of ktexteditor/src/vimode/globalstate.cpp