| 211 | } |
| 212 | |
| 213 | SourceFormatterController::SourceFormatterController(QObject *parent) |
| 214 | : ISourceFormatterController(parent) |
| 215 | , d_ptr(new SourceFormatterControllerPrivate) |
| 216 | { |
| 217 | Q_D(SourceFormatterController); |
| 218 | |
| 219 | setObjectName(QStringLiteral("SourceFormatterController")); |
| 220 | setComponentName(QStringLiteral("kdevsourceformatter"), i18n("Source Formatter")); |
| 221 | setXMLFile(QStringLiteral("kdevsourceformatter.rc")); |
| 222 | |
| 223 | if (Core::self()->setupFlags() & Core::NoUi) return; |
| 224 | |
| 225 | d->formatTextAction = actionCollection()->addAction(QStringLiteral("edit_reformat_source")); |
| 226 | d->formatTextAction->setText(i18nc("@action", "&Reformat Source")); |
| 227 | connect(d->formatTextAction, &QAction::triggered, this, &SourceFormatterController::beautifySource); |
| 228 | |
| 229 | d->formatLine = actionCollection()->addAction(QStringLiteral("edit_reformat_line")); |
| 230 | d->formatLine->setText(i18nc("@action", "Reformat Line")); |
| 231 | connect(d->formatLine, &QAction::triggered, this, &SourceFormatterController::beautifyLine); |
| 232 | |
| 233 | d->formatFilesAction = actionCollection()->addAction(QStringLiteral("tools_astyle")); |
| 234 | d->formatFilesAction->setText(i18nc("@action", "Reformat Files...")); |
| 235 | d->formatFilesAction->setToolTip(i18nc("@info:tooltip", "Format file(s) using the configured source formatter(s)")); |
| 236 | d->formatFilesAction->setWhatsThis(i18nc("@info:whatsthis", |
| 237 | "Formatting functionality using the configured source formatter(s).")); |
| 238 | d->formatFilesAction->setEnabled(false); |
| 239 | connect(d->formatFilesAction, &QAction::triggered, |
| 240 | this, QOverload<>::of(&SourceFormatterController::formatFiles)); |
| 241 | |
| 242 | |
| 243 | connect(Core::self()->pluginController(), &IPluginController::pluginLoaded, |
| 244 | this, &SourceFormatterController::pluginLoaded); |
| 245 | connect(Core::self()->pluginController(), &IPluginController::unloadingPlugin, |
| 246 | this, &SourceFormatterController::unloadingPlugin); |
| 247 | |
| 248 | // connect to both documentActivated & documentClosed, |
| 249 | // otherwise we miss when the last document was closed |
| 250 | connect(Core::self()->documentController(), &IDocumentController::documentActivated, |
| 251 | this, &SourceFormatterController::updateFormatTextAction); |
| 252 | connect(Core::self()->documentController(), &IDocumentController::documentClosed, |
| 253 | this, &SourceFormatterController::updateFormatTextAction); |
| 254 | connect(Core::self()->documentController(), &IDocumentController::documentUrlChanged, this, |
| 255 | &SourceFormatterController::updateFormatTextAction); |
| 256 | |
| 257 | qRegisterMetaType<QPointer<KDevelop::TextDocument>>(); |
| 258 | connect(Core::self()->documentController(), &IDocumentController::documentLoaded, |
| 259 | // Use a queued connection, because otherwise the view is not yet fully set up |
| 260 | // but wrap the document in a smart pointer to guard against crashes when it |
| 261 | // gets deleted in the meantime |
| 262 | this, [this](IDocument *doc) { |
| 263 | const auto textDoc = QPointer<TextDocument>(dynamic_cast<TextDocument*>(doc)); |
| 264 | QMetaObject::invokeMethod(this, "documentLoaded", Qt::QueuedConnection, Q_ARG(QPointer<KDevelop::TextDocument>, textDoc)); |
| 265 | }); |
| 266 | connect(Core::self()->projectController(), &IProjectController::projectOpened, this, [d](const IProject* project) { |
| 267 | FileFormatter::projectOpened(*project, d->sourceFormatters); |
| 268 | }); |
| 269 | |
| 270 | updateFormatTextAction(); |
nothing calls this directly
no test coverage detected