File indexing completed on 2024-04-21 03:58:06

0001 /*
0002     SPDX-FileCopyrightText: 2008-2011 Erlend Hamberg <ehamberg@gmail.com>
0003     SPDX-FileCopyrightText: 2011 Svyatoslav Kuzmich <svatoslav1@gmail.com>
0004     SPDX-FileCopyrightText: 2012-2013 Simon St James <kdedevel@etotheipiplusone.com>
0005 
0006     SPDX-License-Identifier: LGPL-2.0-or-later
0007 */
0008 
0009 #include "globalstate.h"
0010 #include "history.h"
0011 #include "kateglobal.h"
0012 #include "macros.h"
0013 #include "mappings.h"
0014 #include "registers.h"
0015 
0016 #include <KConfigGroup>
0017 
0018 using namespace KateVi;
0019 
0020 GlobalState::GlobalState()
0021 {
0022     m_macros = new Macros();
0023     m_mappings = new Mappings();
0024     m_registers = new Registers();
0025     m_searchHistory = new History();
0026     m_replaceHistory = new History();
0027     m_commandHistory = new History();
0028 
0029     readConfig(config().data());
0030 }
0031 
0032 GlobalState::~GlobalState()
0033 {
0034     writeConfig(config().data());
0035     config().data()->sync();
0036 
0037     delete m_searchHistory;
0038     delete m_replaceHistory;
0039     delete m_commandHistory;
0040     delete m_macros;
0041     delete m_mappings;
0042     delete m_registers;
0043 }
0044 
0045 void GlobalState::writeConfig(KConfig *configFile) const
0046 {
0047     // FIXME: use own groups instead of one big group!
0048     KConfigGroup config(configFile, QStringLiteral("Kate Vi Input Mode Settings"));
0049     m_macros->writeConfig(config);
0050     m_mappings->writeConfig(config);
0051     m_registers->writeConfig(config);
0052 }
0053 
0054 void GlobalState::readConfig(const KConfig *configFile)
0055 {
0056     // FIXME: use own groups instead of one big group!
0057     const KConfigGroup config(configFile, QStringLiteral("Kate Vi Input Mode Settings"));
0058 
0059     m_macros->readConfig(config);
0060     m_mappings->readConfig(config);
0061     m_registers->readConfig(config);
0062 }
0063 
0064 KSharedConfigPtr GlobalState::config()
0065 {
0066     // use dummy config for unit tests!
0067     return KTextEditor::EditorPrivate::unitTestMode()
0068         ? KSharedConfig::openConfig(QStringLiteral("katevirc-unittest"), KConfig::SimpleConfig, QStandardPaths::TempLocation)
0069         : KSharedConfig::openConfig(QStringLiteral("katevirc"));
0070 }