1// SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd.
2//
3// SPDX-License-Identifier: GPL-3.0-or-later
4
5#include "texteditkeeper.h"
6
7TextEdit *TextEditKeeper::create(const QString &language, QString *err)
8{
9 return instance()->editFactory.create(language, err);
10}
11
12void TextEditKeeper::setAnalysedLanguage(const QString &lang)
13{
14 instance()->analysedLanguage = lang;
15}
16
17QString TextEditKeeper::getAnalysedLanguage()
18{
19 return instance()->analysedLanguage;
20}
21
22void TextEditKeeper::setAnalysedWorkspace(const QString &workspace)
23{
24 instance()->analysedWorkspace = workspace;
25}
26
27QString TextEditKeeper::getAnalysedWorkspace()
28{
29 return instance()->analysedWorkspace;
30}
31
32void TextEditKeeper::setAnalysedStorage(const QString &storage)
33{
34 instance()->analysedStorage = storage;
35}
36
37QString TextEditKeeper::getAnalysedStorage()
38{
39 return instance()->analysedStorage;
40}
41
42void TextEditKeeper::setAnalysedData(const AnalysedData &data)
43{
44 instance()->data = data;
45}
46
47void TextEditKeeper::cleanAnalysedData()
48{
49 instance()->data.rules.clear();
50 instance()->data.tokenMaps.clear();
51}
52
53QString TextEditKeeper::userActionAnalyseTitle()
54{
55 return "User Action Analyse"; // can't translation this, crashed
56}
57
58QString TextEditKeeper::getTokenTypeAnnLine(const QString &tokenType, const QString &displayText)
59{
60 QString result;
61 auto data = instance()->data;
62 auto rules = data.rules;
63 for(auto tokenMap: data.tokenMaps) {
64 if (tokenType.toStdString() != tokenMap.semanticTokenType
65 || tokenMap.result.empty())
66 continue;
67 for (size_t idx = 0; idx < rules.size(); idx++) {
68 if (!result.isEmpty()) result += " ";
69 result += QString::fromStdString(data.rules[idx]);
70 if (!result.isEmpty()) result += ": ";
71 result += QString::number(tokenMap.result[idx]*100) + "%";
72 }
73 }
74 if (!result.isEmpty()) {
75 QString textInfo;
76 if (!displayText.isEmpty()) {
77 textInfo += "\"" + displayText + "\"";
78 }
79 if (!textInfo.isEmpty())
80 result = tokenType + " " + textInfo + " " + result;
81 }
82 return result;
83}
84
85AnalysedData TextEditKeeper::analysedData()
86{
87 return instance()->data;
88}
89
90dpfservice::ProjectInfo TextEditKeeper::projectInfo()
91{
92 return instance()->proInfo;
93}
94
95void TextEditKeeper::saveProjectInfo(const dpfservice::ProjectInfo &info)
96{
97 instance()->proInfo = info;
98}
99
100void TextEditKeeper::removeProjectInfo(const dpfservice::ProjectInfo &info)
101{
102 if (instance()->proInfo.workspaceFolder() == info.workspaceFolder()) {
103 instance()->proInfo = dpfservice::ProjectInfo();
104 }
105}
106