KSyntaxHighlighting

contextswitch.cpp
1 /*
2  SPDX-FileCopyrightText: 2016 Volker Krause <[email protected]>
3 
4  SPDX-License-Identifier: MIT
5 */
6 
7 #include "contextswitch_p.h"
8 #include "definition.h"
9 #include "definition_p.h"
10 #include "highlightingdata_p.hpp"
11 #include "ksyntaxhighlighting_logging.h"
12 #include "repository.h"
13 
14 using namespace KSyntaxHighlighting;
15 
16 void ContextSwitch::resolve(DefinitionData &def, QStringView contextInstr)
17 {
18  HighlightingContextData::ContextSwitch ctx(contextInstr);
19 
20  m_popCount = ctx.popCount();
21  m_isStay = !m_popCount;
22 
23  auto contextName = ctx.contextName();
24  auto defName = ctx.defName();
25 
26  if (contextName.isEmpty() && defName.isEmpty()) {
27  return;
28  }
29 
30  if (defName.isEmpty()) {
31  m_context = def.contextByName(contextName);
32  } else {
33  auto d = def.repo->definitionForName(defName.toString());
34  if (d.isValid()) {
35  auto data = DefinitionData::get(d);
36  def.addImmediateIncludedDefinition(d);
37  data->load();
38  if (contextName.isEmpty()) {
39  m_context = data->initialContext();
40  } else {
41  m_context = data->contextByName(contextName);
42  }
43  }
44  }
45 
46  if (!m_context) {
47  qCWarning(Log) << "cannot find context" << contextName << "in" << def.name;
48  } else {
49  m_isStay = false;
50  }
51 }
virtual QVariant get(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Mar 26 2023 04:09:17 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.