| 101 | } |
| 102 | |
| 103 | void 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" |
nothing calls this directly
no test coverage detected