KTextEditor

globalstate.cpp
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
17using namespace KateVi;
18
19GlobalState::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().data());
29}
30
31GlobalState::~GlobalState()
32{
33 writeConfig(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
44void 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
53void 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
63KSharedConfigPtr GlobalState::config()
64{
65 // use dummy config for unit tests!
66 return QStandardPaths::isTestModeEnabled()
68 : KSharedConfig::openConfig(QStringLiteral("katevirc"));
69}
static KSharedConfig::Ptr openConfig(const QString &fileName=QString(), OpenFlags mode=FullConfig, QStandardPaths::StandardLocation type=QStandardPaths::GenericConfigLocation)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jun 21 2024 12:02:52 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.