MCPcopy Create free account
hub / github.com/KDE/kdevelop / formatFile

Method formatFile

kdevplatform/shell/sourceformatterjob.cpp:103–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

101}
102
103void SourceFormatterJob::formatFile(const QUrl& url)
104{
105 qCDebug(SHELL) << "Checking whether to format file" << url;
106 SourceFormatterController::FileFormatter ff(url);
107 if (!ff.readFormatterAndStyle(m_sourceFormatterController->formatters())) {
108 return; // unsupported MIME type or no configured formatter for it
109 }
110
111 // if the file is opened in the editor, format the text in the editor without saving it
112 auto doc = ICore::self()->documentController()->documentForUrl(url);
113 if (doc) {
114 qCDebug(SHELL) << "Processing file " << url << "opened in editor";
115 ff.formatDocument(*doc);
116 return;
117 }
118
119 qCDebug(SHELL) << "Processing file " << url;
120 auto getJob = KIO::storedGet(url);
121 // TODO: make also async and use start() and integrate using setError and setErrorString.
122 if (getJob->exec()) {
123 // TODO: really fromLocal8Bit/toLocal8Bit? no encoding detection? added in b8062f736a2bf2eec098af531a7fda6ebcdc7cde
124 QString text = QString::fromLocal8Bit(getJob->data());
125 text = ff.format(text);
126 text = ff.addModeline(text);
127
128 auto putJob = KIO::storedPut(text.toLocal8Bit(), url, -1, KIO::Overwrite);
129 // see getJob
130 if (!putJob->exec()) {
131 auto* message = new Sublime::Message(putJob->errorString(), Sublime::Message::Error);
132 ICore::self()->uiController()->postMessage(message);
133 }
134 } else {
135 auto* message = new Sublime::Message(getJob->errorString(), Sublime::Message::Error);
136 ICore::self()->uiController()->postMessage(message);
137 }
138}
139
140#include "moc_sourceformatterjob.cpp"

Callers

nothing calls this directly

Calls 12

readFormatterAndStyleMethod · 0.80
formattersMethod · 0.80
documentForUrlMethod · 0.80
documentControllerMethod · 0.80
formatDocumentMethod · 0.80
execMethod · 0.80
formatMethod · 0.80
addModelineMethod · 0.80
uiControllerMethod · 0.80
dataMethod · 0.45
errorStringMethod · 0.45
postMessageMethod · 0.45

Tested by

no test coverage detected