Changeset View
Changeset View
Standalone View
Standalone View
kate/katepluginmanager.cpp
Show First 20 Lines • Show All 95 Lines • ▼ Show 20 Line(s) | 83 | for (const auto &pluginMetaData : plugins) { | |||
---|---|---|---|---|---|
96 | unique.insert (info.saveName()); | 96 | unique.insert (info.saveName()); | ||
97 | } | 97 | } | ||
98 | 98 | | |||
99 | // sort to ensure some deterministic plugin load order, this is important for tool-view creation order | 99 | // sort to ensure some deterministic plugin load order, this is important for tool-view creation order | ||
100 | std::sort(m_pluginList.begin(), m_pluginList.end()); | 100 | std::sort(m_pluginList.begin(), m_pluginList.end()); | ||
101 | 101 | | |||
102 | // construct fast lookup map, do this after vector has final size, resize will invalidate the pointers! | 102 | // construct fast lookup map, do this after vector has final size, resize will invalidate the pointers! | ||
103 | m_name2Plugin.clear(); | 103 | m_name2Plugin.clear(); | ||
104 | for (int i = 0; i < m_pluginList.size(); ++i) { | 104 | for (auto& pluginInfo : m_pluginList) { | ||
105 | m_name2Plugin[m_pluginList[i].saveName()] = &(m_pluginList[i]); | 105 | m_name2Plugin[pluginInfo.saveName()] = &pluginInfo; | ||
106 | } | 106 | } | ||
107 | } | 107 | } | ||
108 | 108 | | |||
109 | void KatePluginManager::loadConfig(KConfig *config) | 109 | void KatePluginManager::loadConfig(KConfig *config) | ||
110 | { | 110 | { | ||
111 | // first: unload the plugins | 111 | // first: unload the plugins | ||
112 | unloadAllPlugins(); | 112 | unloadAllPlugins(); | ||
113 | 113 | | |||
114 | /** | 114 | /** | ||
115 | * ask config object | 115 | * ask config object | ||
116 | */ | 116 | */ | ||
117 | if (config) { | 117 | if (config) { | ||
118 | KConfigGroup cg = KConfigGroup(config, QStringLiteral("Kate Plugins")); | 118 | KConfigGroup cg = KConfigGroup(config, QStringLiteral("Kate Plugins")); | ||
119 | 119 | | |||
120 | // disable all plugin if no config, beside the ones marked as default load | 120 | // disable all plugin if no config, beside the ones marked as default load | ||
121 | for (int i = 0; i < m_pluginList.size(); ++i) { | 121 | for (auto& pluginInfo: m_pluginList) { | ||
122 | m_pluginList[i].load = cg.readEntry(m_pluginList[i].saveName(), m_pluginList[i].defaultLoad); | 122 | pluginInfo.load = cg.readEntry(pluginInfo.saveName(), pluginInfo.defaultLoad); | ||
123 | } | 123 | } | ||
124 | } | 124 | } | ||
125 | 125 | | |||
126 | /** | 126 | /** | ||
127 | * load plugins | 127 | * load plugins | ||
128 | */ | 128 | */ | ||
129 | for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { | 129 | for (auto& pluginInfo : m_pluginList) { | ||
130 | if (it->load) { | 130 | if (pluginInfo.load) { | ||
131 | /** | 131 | /** | ||
132 | * load plugin + trigger update of GUI for already existing main windows | 132 | * load plugin + trigger update of GUI for already existing main windows | ||
133 | */ | 133 | */ | ||
134 | loadPlugin(&(*it)); | 134 | loadPlugin(&pluginInfo); | ||
135 | enablePluginGUI(&(*it)); | 135 | enablePluginGUI(&pluginInfo); | ||
136 | 136 | | |||
137 | // restore config | 137 | // restore config | ||
138 | if (auto interface = qobject_cast<KTextEditor::SessionConfigInterface *> (it->plugin)) { | 138 | if (auto interface = qobject_cast<KTextEditor::SessionConfigInterface *> (pluginInfo.plugin)) { | ||
139 | KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(it->saveName())); | 139 | KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(pluginInfo.saveName())); | ||
140 | interface->readSessionConfig(group); | 140 | interface->readSessionConfig(group); | ||
141 | } | 141 | } | ||
142 | } | 142 | } | ||
143 | } | 143 | } | ||
144 | } | 144 | } | ||
145 | 145 | | |||
146 | void KatePluginManager::writeConfig(KConfig *config) | 146 | void KatePluginManager::writeConfig(KConfig *config) | ||
147 | { | 147 | { | ||
Show All 10 Lines | 157 | if (auto interface = qobject_cast<KTextEditor::SessionConfigInterface *> (plugin.plugin)) { | |||
158 | KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(saveName)); | 158 | KConfigGroup group(config, QStringLiteral("Plugin:%1:").arg(saveName)); | ||
159 | interface->writeSessionConfig(group); | 159 | interface->writeSessionConfig(group); | ||
160 | } | 160 | } | ||
161 | } | 161 | } | ||
162 | } | 162 | } | ||
163 | 163 | | |||
164 | void KatePluginManager::unloadAllPlugins() | 164 | void KatePluginManager::unloadAllPlugins() | ||
165 | { | 165 | { | ||
166 | for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { | 166 | for (auto& pluginInfo : m_pluginList) { | ||
167 | if (it->plugin) { | 167 | if (pluginInfo.plugin) { | ||
168 | unloadPlugin(&(*it)); | 168 | unloadPlugin(&pluginInfo); | ||
169 | } | 169 | } | ||
170 | } | 170 | } | ||
171 | } | 171 | } | ||
172 | 172 | | |||
173 | void KatePluginManager::enableAllPluginsGUI(KateMainWindow *win, KConfigBase *config) | 173 | void KatePluginManager::enableAllPluginsGUI(KateMainWindow *win, KConfigBase *config) | ||
174 | { | 174 | { | ||
175 | for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { | 175 | for (auto& pluginInfo : m_pluginList) { | ||
176 | if (it->plugin) { | 176 | if (pluginInfo.plugin) { | ||
177 | enablePluginGUI(&(*it), win, config); | 177 | enablePluginGUI(&pluginInfo, win, config); | ||
178 | } | 178 | } | ||
179 | } | 179 | } | ||
180 | } | 180 | } | ||
181 | 181 | | |||
182 | void KatePluginManager::disableAllPluginsGUI(KateMainWindow *win) | 182 | void KatePluginManager::disableAllPluginsGUI(KateMainWindow *win) | ||
183 | { | 183 | { | ||
184 | for (KatePluginList::iterator it = m_pluginList.begin(); it != m_pluginList.end(); ++it) { | 184 | for (auto& pluginInfo : m_pluginList) { | ||
185 | if (it->plugin) { | 185 | if (pluginInfo.plugin) { | ||
186 | disablePluginGUI(&(*it), win); | 186 | disablePluginGUI(&pluginInfo, win); | ||
187 | } | 187 | } | ||
188 | } | 188 | } | ||
189 | } | 189 | } | ||
190 | 190 | | |||
191 | bool KatePluginManager::loadPlugin(KatePluginInfo *item) | 191 | bool KatePluginManager::loadPlugin(KatePluginInfo *item) | ||
192 | { | 192 | { | ||
193 | /** | 193 | /** | ||
194 | * try to load the plugin | 194 | * try to load the plugin | ||
▲ Show 20 Lines • Show All 166 Lines • Show Last 20 Lines |