Commit a9f8fe4f authored by Alexander Lohnau's avatar Alexander Lohnau 💬
Browse files

clang-tidy: Force braces around statements

If you want git blame to ignore formatting revisions run:
git config blame.ignoreRevsFile .git-blame-ignore-revs
parent 5b08b307
......@@ -332,12 +332,13 @@ void KateBtConfigWidget::defaults()
void KateBtConfigWidget::add()
{
QDir url(edtUrl->lineEdit()->text());
if (url.exists())
if (url.exists()) {
if (lstFolders->findItems(url.absolutePath(), Qt::MatchExactly).empty()) {
lstFolders->addItem(url.absolutePath());
emit changed();
m_changed = true;
}
}
}
void KateBtConfigWidget::remove()
......
......@@ -165,8 +165,9 @@ void CloseExceptPluginView::updateMenu(const std::set<QUrl> &paths,
// Form a new one
appendActionsFrom(paths, actions, menu, closeFunction);
if (!masks.empty()) {
if (!paths.empty())
if (!paths.empty()) {
menu->addSeparator(); // Add separator between paths and file's ext filters
}
appendActionsFrom(masks, actions, menu, closeFunction);
}
// Append 'Show Confirmation' toggle menu item
......@@ -192,8 +193,9 @@ void CloseExceptPluginView::updateMenu()
paths_set_type_masks masks;
for (KTextEditor::Document *document : docs) {
const QString &ext = QFileInfo(document->url().path()).completeSuffix();
if (!ext.isEmpty())
if (!ext.isEmpty()) {
masks.insert(QStringLiteral("*.") + ext);
}
doc_paths.insert(KIO::upUrl(document->url()));
}
paths_set_type paths = doc_paths;
......@@ -202,9 +204,11 @@ void CloseExceptPluginView::updateMenu()
for (paths_set_type::iterator it = doc_paths.begin(), last = doc_paths.end(); it != last; ++it) {
for (QUrl url = *it; (!url.path().isEmpty()) && url.path() != QLatin1String("/"); url = KIO::upUrl(url)) {
paths_set_type::iterator not_it = it;
for (++not_it; not_it != last; ++not_it)
if (!not_it->path().startsWith(url.path()))
for (++not_it; not_it != last; ++not_it) {
if (!not_it->path().startsWith(url.path())) {
break;
}
}
if (not_it == last) {
paths.insert(url);
break;
......@@ -261,8 +265,9 @@ void CloseExceptPluginView::close(const QString &item, const bool close_if_match
void CloseExceptPluginView::displayMessage(const QString &title, const QString &msg, KTextEditor::Message::MessageType level)
{
KTextEditor::View *kv = m_mainWindow->activeView();
if (!kv)
if (!kv) {
return;
}
delete m_infoMessage;
m_infoMessage = new KTextEditor::Message(xi18nc("@info", "<title>%1</title><nl/>%2", title, msg), level);
......
......@@ -28,12 +28,15 @@ QString toString(KateExternalTool::SaveMode saveMode)
KateExternalTool::SaveMode toSaveMode(const QString &mode)
{
if (mode == QStringLiteral("None"))
if (mode == QStringLiteral("None")) {
return KateExternalTool::SaveMode::None;
if (mode == QStringLiteral("CurrentDocument"))
}
if (mode == QStringLiteral("CurrentDocument")) {
return KateExternalTool::SaveMode::CurrentDocument;
if (mode == QStringLiteral("AllDocuments"))
}
if (mode == QStringLiteral("AllDocuments")) {
return KateExternalTool::SaveMode::AllDocuments;
}
return KateExternalTool::SaveMode::None;
}
......@@ -63,22 +66,30 @@ QString toString(KateExternalTool::OutputMode outputMode)
KateExternalTool::OutputMode toOutputMode(const QString &mode)
{
if (mode == QStringLiteral("Ignore"))
if (mode == QStringLiteral("Ignore")) {
return KateExternalTool::OutputMode::Ignore;
if (mode == QStringLiteral("InsertAtCursor"))
}
if (mode == QStringLiteral("InsertAtCursor")) {
return KateExternalTool::OutputMode::InsertAtCursor;
if (mode == QStringLiteral("ReplaceSelectedText"))
}
if (mode == QStringLiteral("ReplaceSelectedText")) {
return KateExternalTool::OutputMode::ReplaceSelectedText;
if (mode == QStringLiteral("ReplaceCurrentDocument"))
}
if (mode == QStringLiteral("ReplaceCurrentDocument")) {
return KateExternalTool::OutputMode::ReplaceCurrentDocument;
if (mode == QStringLiteral("AppendToCurrentDocument"))
}
if (mode == QStringLiteral("AppendToCurrentDocument")) {
return KateExternalTool::OutputMode::AppendToCurrentDocument;
if (mode == QStringLiteral("InsertInNewDocument"))
}
if (mode == QStringLiteral("InsertInNewDocument")) {
return KateExternalTool::OutputMode::InsertInNewDocument;
if (mode == QStringLiteral("CopyToClipboard"))
}
if (mode == QStringLiteral("CopyToClipboard")) {
return KateExternalTool::OutputMode::CopyToClipboard;
if (mode == QStringLiteral("DisplayInPane"))
}
if (mode == QStringLiteral("DisplayInPane")) {
return KateExternalTool::OutputMode::DisplayInPane;
}
return KateExternalTool::OutputMode::Ignore;
}
}
......
......@@ -140,8 +140,9 @@ KateExternalToolServiceEditor::KateExternalToolServiceEditor(KateExternalTool *t
Q_ASSERT(m_tool != nullptr);
ui->edtName->setText(m_tool->translatedName());
if (!m_tool->icon.isEmpty())
if (!m_tool->icon.isEmpty()) {
ui->btnIcon->setIcon(m_tool->icon);
}
ui->edtExecutable->setText(m_tool->executable);
ui->edtArgs->setText(m_tool->arguments);
......@@ -320,8 +321,9 @@ void KateExternalToolsConfigWidget::reset()
void KateExternalToolsConfigWidget::apply()
{
if (!m_changed)
if (!m_changed) {
return;
}
m_changed = false;
// collect all KateExternalTool items
......
......@@ -54,8 +54,9 @@ void KateExternalToolsMenuAction::reload()
// clear action collection
bool needs_readd = (m_actionCollection->takeAction(this) != nullptr);
m_actionCollection->clear();
if (needs_readd)
if (needs_readd) {
m_actionCollection->addAction(QStringLiteral("tools_external"), this);
}
menu()->clear();
// create tool actions
......
......@@ -21,12 +21,14 @@ KateBookmarkHandler::KateBookmarkHandler(KateFileBrowser *parent, QMenu *kpopupm
, m_menu(kpopupmenu)
{
setObjectName(QStringLiteral("KateBookmarkHandler"));
if (!m_menu)
if (!m_menu) {
m_menu = new QMenu(parent);
}
QString file = QStandardPaths::locate(QStandardPaths::GenericDataLocation, QStringLiteral("kate/fsbookmarks.xml"));
if (file.isEmpty())
if (file.isEmpty()) {
file = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QStringLiteral("/kate/fsbookmarks.xml");
}
KBookmarkManager *manager = KBookmarkManager::managerForFile(file, QStringLiteral("kate"));
manager->setUpdate(true);
......
......@@ -134,9 +134,10 @@ void KateFileBrowser::setupToolbar()
{
KConfigGroup config(KSharedConfig::openConfig(), "filebrowser");
QStringList actions = config.readEntry("toolbar actions", QStringList());
if (actions.isEmpty()) // default toolbar
if (actions.isEmpty()) { // default toolbar
actions << QStringLiteral("back") << QStringLiteral("forward") << QStringLiteral("bookmarks") << QStringLiteral("sync_dir")
<< QStringLiteral("configure");
}
// remove all actions from the toolbar (there should be none)
m_toolbar->clear();
......@@ -144,15 +145,18 @@ void KateFileBrowser::setupToolbar()
// now add all actions to the toolbar
for (const QString &it : qAsConst(actions)) {
QAction *ac = nullptr;
if (it.isEmpty())
if (it.isEmpty()) {
continue;
if (it == QLatin1String("bookmarks") || it == QLatin1String("sync_dir") || it == QLatin1String("configure"))
}
if (it == QLatin1String("bookmarks") || it == QLatin1String("sync_dir") || it == QLatin1String("configure")) {
ac = actionCollection()->action(it);
else
} else {
ac = m_dirOperator->actionCollection()->action(it);
}
if (ac)
if (ac) {
m_toolbar->addAction(ac);
}
}
}
......@@ -196,8 +200,9 @@ void KateFileBrowser::slotFilterChange(const QString &nf)
bool kateFileSelectorIsReadable(const QUrl &url)
{
if (!url.isLocalFile())
if (!url.isLocalFile()) {
return true; // what else can we say?
}
QDir dir(url.toLocalFile());
return dir.exists();
......@@ -207,14 +212,16 @@ void KateFileBrowser::setDir(const QUrl &u)
{
QUrl newurl;
if (!u.isValid())
if (!u.isValid()) {
newurl = QUrl::fromLocalFile(QDir::homePath());
else
} else {
newurl = u;
}
QString path(newurl.path());
if (!path.endsWith(QLatin1Char('/')))
if (!path.endsWith(QLatin1Char('/'))) {
path += QLatin1Char('/');
}
newurl.setPath(path);
if (!kateFileSelectorIsReadable(newurl)) {
......@@ -311,8 +318,9 @@ void KateFileBrowser::openSelectedFiles()
if (list.count() > 20) {
if (KMessageBox::questionYesNo(this,
i18np("You are trying to open 1 file, are you sure?", "You are trying to open %1 files, are you sure?", list.count()))
== KMessageBox::No)
== KMessageBox::No) {
return;
}
}
for (const KFileItem &item : list) {
......@@ -335,8 +343,9 @@ void KateFileBrowser::updateUrlNavigator(const QUrl &u)
void KateFileBrowser::setActiveDocumentDir()
{
QUrl u = activeDocumentUrl();
if (!u.isEmpty())
if (!u.isEmpty()) {
setDir(KIO::upUrl(u));
}
}
void KateFileBrowser::autoSyncFolder()
......@@ -358,8 +367,9 @@ void KateFileBrowser::selectorViewChanged(QAbstractItemView *newView)
QUrl KateFileBrowser::activeDocumentUrl()
{
KTextEditor::View *v = m_mainWindow->activeView();
if (v)
if (v) {
return v->document()->url();
}
return QUrl();
}
......
......@@ -95,8 +95,9 @@ QIcon KateFileBrowserConfigPage::icon() const
void KateFileBrowserConfigPage::apply()
{
if (!m_changed)
if (!m_changed) {
return;
}
m_changed = false;
......@@ -125,8 +126,9 @@ void KateFileBrowserConfigPage::init()
KConfigGroup config(KSharedConfig::openConfig(), "filebrowser");
// toolbar
QStringList l = config.readEntry("toolbar actions", QStringList());
if (l.isEmpty()) // default toolbar
if (l.isEmpty()) { // default toolbar
l << QStringLiteral("back") << QStringLiteral("forward") << QStringLiteral("bookmarks") << QStringLiteral("sync_dir") << QStringLiteral("configure");
}
// actions from diroperator + two of our own
const QStringList allActions{QStringLiteral("up"),
......@@ -153,10 +155,11 @@ void KateFileBrowserConfigPage::init()
for (const auto &actionName : allActions) {
lb = l.contains(actionName) ? acSel->selectedListWidget() : acSel->availableListWidget();
if (actionName == QLatin1String("bookmarks") || actionName == QLatin1String("sync_dir") || actionName == QLatin1String("configure"))
if (actionName == QLatin1String("bookmarks") || actionName == QLatin1String("sync_dir") || actionName == QLatin1String("configure")) {
ac = fileBrowser->actionCollection()->action(actionName);
else
} else {
ac = fileBrowser->dirOperator()->actionCollection()->action(actionName);
}
if (ac) {
QString text = ac->text().remove(re);
......
......@@ -49,8 +49,9 @@ int KateFileBrowserPlugin::configPages() const
KTextEditor::ConfigPage *KateFileBrowserPlugin::configPage(int number, QWidget *parent)
{
if (number != 0)
if (number != 0) {
return nullptr;
}
return new KateFileBrowserConfigPage(parent, m_views[0]->m_fileBrowser);
}
// END KateFileBrowserPlugin
......
......@@ -72,8 +72,9 @@ const QStringList AdvancedGDBSettings::configs() const
if (u_soSearchPaths->count() > 0) {
QString paths = QStringLiteral("set solib-search-path ");
for (int i = 0; i < u_soSearchPaths->count(); ++i) {
if (i != 0)
if (i != 0) {
paths += pathSeparator;
}
paths += u_soSearchPaths->item(i)->text();
}
tmp << paths;
......@@ -84,8 +85,9 @@ const QStringList AdvancedGDBSettings::configs() const
if (u_srcPaths->count() > 0) {
QString paths = QStringLiteral("set directories ");
for (int i = 0; i < u_srcPaths->count(); ++i) {
if (i != 0)
if (i != 0) {
paths += pathSeparator;
}
paths += u_srcPaths->item(i)->text();
}
tmp << paths;
......@@ -112,13 +114,15 @@ void AdvancedGDBSettings::setConfigs(const QStringList &cfgs)
u_baudCombo->setCurrentIndex(0);
// GDB
if (cfgs.count() <= GDBIndex)
if (cfgs.count() <= GDBIndex) {
return;
}
u_gdbCmd->setText(cfgs[GDBIndex]);
// Local / Remote
if (cfgs.count() <= LocalRemoteIndex)
if (cfgs.count() <= LocalRemoteIndex) {
return;
}
int start;
int end;
......@@ -143,20 +147,23 @@ void AdvancedGDBSettings::setConfigs(const QStringList &cfgs)
}
// Solib absolute path
if (cfgs.count() <= SoAbsoluteIndex)
if (cfgs.count() <= SoAbsoluteIndex) {
return;
}
start = 26; // "set solib-absolute-prefix "
u_soAbsPrefix->setText(cfgs[SoAbsoluteIndex].mid(start));
// Solib search path
if (cfgs.count() <= SoRelativeIndex)
if (cfgs.count() <= SoRelativeIndex) {
return;
}
start = 22; // "set solib-search-path "
QString tmp = cfgs[SoRelativeIndex].mid(start);
u_soSearchPaths->addItems(tmp.split(pathSeparator));
if (cfgs.count() <= SrcPathsIndex)
if (cfgs.count() <= SrcPathsIndex) {
return;
}
start = 16; // "set directories "
tmp = cfgs[SrcPathsIndex].mid(start);
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
......@@ -183,8 +190,9 @@ void AdvancedGDBSettings::slotBrowseGDB()
void AdvancedGDBSettings::setComboText(QComboBox *combo, const QString &str)
{
if (!combo)
if (!combo) {
return;
}
for (int i = 0; i < combo->count(); i++) {
if (combo->itemText(i) == str) {
......@@ -200,8 +208,9 @@ void AdvancedGDBSettings::setComboText(QComboBox *combo, const QString &str)
void AdvancedGDBSettings::slotSetSoPrefix()
{
QString prefix = QFileDialog::getExistingDirectory(this);
if (prefix.isEmpty())
if (prefix.isEmpty()) {
return;
}
u_soAbsPrefix->setText(prefix);
}
......@@ -209,8 +218,9 @@ void AdvancedGDBSettings::slotSetSoPrefix()
void AdvancedGDBSettings::slotAddSoPath()
{
QString path = QFileDialog::getExistingDirectory(this);
if (path.isEmpty())
if (path.isEmpty()) {
return;
}
u_soSearchPaths->addItem(path);
}
......@@ -224,8 +234,9 @@ void AdvancedGDBSettings::slotDelSoPath()
void AdvancedGDBSettings::slotAddSrcPath()
{
QString path = QFileDialog::getExistingDirectory(this);
if (path.isEmpty())
if (path.isEmpty()) {
return;
}
u_srcPaths->addItem(path);
}
......
......@@ -145,8 +145,9 @@ void ConfigView::readConfig(const KConfigGroup &group)
for (int i = 0; i < targetCount; i++) {
targetConfStrs = group.readEntry(targetKey.arg(i), QStringList());
if (targetConfStrs.count() == 0)
if (targetConfStrs.count() == 0) {
continue;
}
if ((version == 1) && (targetConfStrs.count() == 3)) {
// valid old style config, translate it now; note the
......@@ -182,8 +183,9 @@ void ConfigView::readConfig(const KConfigGroup &group)
if (i > 0) {
// copy the firsts and change the arguments
targetConfStrs[0] = targetName.arg(targetConfStrs[0]).arg(i + 1);
if (targetConfStrs.count() > 3)
if (targetConfStrs.count() > 3) {
targetConfStrs[3] = argStr;
}
m_targetCombo->addItem(targetConfStrs[0], targetConfStrs);
}
}
......@@ -200,8 +202,9 @@ void ConfigView::readConfig(const KConfigGroup &group)
}
m_targetSelectAction->setItems(targetNames);
if (lastTarget < 0 || lastTarget >= m_targetCombo->count())
if (lastTarget < 0 || lastTarget >= m_targetCombo->count()) {
lastTarget = 0;
}
m_targetCombo->setCurrentIndex(lastTarget);
m_takeFocus->setChecked(group.readEntry("alwaysFocusOnInput", false));
......@@ -431,16 +434,18 @@ void ConfigView::setAdvancedOptions()
QStringList tmp = m_targetCombo->itemData(m_targetCombo->currentIndex()).toStringList();
// make sure we have enough strings;
while (tmp.count() < CustomStartIndex)
while (tmp.count() < CustomStartIndex) {
tmp << QString();
}
if (tmp[GDBIndex].isEmpty()) {
tmp[GDBIndex] = QStringLiteral("gdb");
}
// Remove the strings that are not part of the advanced settings
for (int i = 0; i < GDBIndex; i++)
for (int i = 0; i < GDBIndex; i++) {
tmp.takeFirst();
}
m_advanced->setConfigs(tmp);
}
......@@ -451,11 +456,13 @@ void ConfigView::slotAdvancedClicked()
QStringList newList = m_targetCombo->itemData(m_targetCombo->currentIndex()).toStringList();
// make sure we have enough strings;
while (newList.count() < GDBIndex)
while (newList.count() < GDBIndex) {
newList << QString();
}
// Remove old advanced settings
while (newList.count() > GDBIndex)
while (newList.count() > GDBIndex) {
newList.takeLast();
}
if (m_advanced->exec() == QDialog::Accepted) {
// save the new values
......@@ -503,8 +510,9 @@ void ConfigView::saveCurrentToIndex(int index)
QStringList tmp = m_targetCombo->itemData(index).toStringList();
// make sure we have enough strings. The custom init strings are set in slotAdvancedClicked().
while (tmp.count() < CustomStartIndex)
while (tmp.count() < CustomStartIndex) {
tmp << QString();
}
tmp[NameIndex] = m_targetCombo->itemText(index);
tmp[ExecIndex] = m_executable->text();
......@@ -522,8 +530,9 @@ void ConfigView::loadFromIndex(int index)
QStringList tmp = m_targetCombo->itemData(index).toStringList();
// make sure we have enough strings. The custom init strings are set in slotAdvancedClicked().
while (tmp.count() < CustomStartIndex)
while (tmp.count() < CustomStartIndex) {
tmp << QString();
}
m_executable->setText(tmp[ExecIndex]);
m_workingDirectory->setText(tmp[WorkDirIndex]);
......
......@@ -130,8 +130,9 @@ void DebugView::slotReadDebugStdOut()
// handle one line at a time
do {
end = m_outBuffer.indexOf(QLatin1Char('\n'));
if (end < 0)
if (end < 0) {
break;
}
processLine(m_outBuffer.mid(0, end));
m_outBuffer.remove(0, end + 1);
} while (1);
......@@ -149,8 +150,9 @@ void DebugView::slotReadDebugStdErr()
// add whole lines at a time to the error list
do {
end = m_errBuffer.indexOf(QLatin1Char('\n'));
if (end < 0)
if (end < 0) {
break;
}
m_errorList << m_errBuffer.mid(0, end);
m_errBuffer.remove(0, end + 1);
} while (1);
......@@ -265,8 +267,9 @@ static const QRegularExpression threadLine(QStringLiteral("\\A\\**\\s+(\\d+)\\s+
void DebugView::processLine(QString line)
{
if (line.isEmpty())
if (line.isEmpty()) {
return;
}
static QRegularExpressionMatch match;
switch (m_state) {
......
......@@ -81,18 +81,21 @@ void IOView::createFifos()
m_stderrFifo = createFifo(QStringLiteral("stdErrFifo"));
m_stdin.setFileName(m_stdinFifo);
if (!m_stdin.open(QIODevice::ReadWrite))
if (!m_stdin.open(QIODevice::ReadWrite)) {
return;
}
m_stdoutD.setFileName(m_stdoutFifo);
m_stdoutD.open(QIODevice::ReadWrite);
m_stdout.setFileName(m_stdoutFifo);
m_stdoutFD = ::open(m_stdoutFifo.toLocal8Bit().data(), O_RDWR | O_NONBLOCK);
if (m_stdoutFD == -1)
if (m_stdoutFD == -1) {
return;
if (!m_stdout.open(m_stdoutFD, QIODevice::ReadWrite))
}
if (!m_stdout.open(m_stdoutFD, QIODevice::ReadWrite)) {
return;
}
m_stdoutNotifier = new QSocketNotifier(m_stdoutFD, QSocketNotifier::Read, this);
connect(m_stdoutNotifier, &QSocketNotifier::activated, this, &IOView::readOutput);
......@@ -103,10 +106,12 @@ void IOView::createFifos()
m_stderr.setFileName(m_stderrFifo);