Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit db1127ef authored by Laurent Montel's avatar Laurent Montel 😁

Minor optimization

parent 8e638883
......@@ -30,16 +30,17 @@ SnippetDialog::SnippetDialog(KActionCollection *actionCollection, bool inGroupMo
, mActionCollection(actionCollection)
{
mUi = new Ui::SnippetDialog;
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(mainWidget);
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel, this);
mOkButton = buttonBox->button(QDialogButtonBox::Ok);
mOkButton->setDefault(true);
mOkButton->setShortcut(Qt::CTRL | Qt::Key_Return);
connect(buttonBox, &QDialogButtonBox::accepted, this, &SnippetDialog::accept);
connect(buttonBox, &QDialogButtonBox::rejected, this, &SnippetDialog::reject);
QWidget *mainWidget = new QWidget(this);
QVBoxLayout *mainLayout = new QVBoxLayout(this);
mainLayout->addWidget(mainWidget);
mainLayout->addWidget(buttonBox);
mUi->setupUi(mainWidget);
......@@ -117,10 +118,12 @@ void SnippetDialog::slotTextChanged()
bool SnippetDialog::snippetIsValid() const
{
if (mUi->groupWidget->isVisible()) {
return !mUi->nameEdit->text().trimmed().isEmpty()
&& !mUi->groupBox->currentText().trimmed().isEmpty();
if (mUi->nameEdit->text().trimmed().isEmpty()) {
return false;
} else {
return !mUi->nameEdit->text().trimmed().isEmpty();
if (mUi->groupWidget->isVisible()) {
return !mUi->groupBox->currentText().trimmed().isEmpty();
}
}
return false;
}
......@@ -555,16 +555,18 @@ void SnippetsManager::Private::save()
const QModelIndex index = mModel->index(j, 0, groupIndex);
const QString snippetName = index.data(SnippetsModel::NameRole).toString();
const QString snippetText = index.data(SnippetsModel::TextRole).toString();
const QString snippetKeySequence = index.data(SnippetsModel::KeySequenceRole).toString();
if (!snippetName.isEmpty()) {
const QString snippetText = index.data(SnippetsModel::TextRole).toString();
const QString snippetKeySequence = index.data(SnippetsModel::KeySequenceRole).toString();
group.writeEntry(QStringLiteral("snippetName_%1").arg(j), snippetName);
if (!snippetText.isEmpty()) {
group.writeEntry(QStringLiteral("snippetText_%1").arg(j), snippetText);
}
if (!snippetKeySequence.isEmpty()) {
group.writeEntry(QStringLiteral("snippetKeySequence_%1").arg(j),
snippetKeySequence);
group.writeEntry(QStringLiteral("snippetName_%1").arg(j), snippetName);
if (!snippetText.isEmpty()) {
group.writeEntry(QStringLiteral("snippetText_%1").arg(j), snippetText);
}
if (!snippetKeySequence.isEmpty()) {
group.writeEntry(QStringLiteral("snippetKeySequence_%1").arg(j),
snippetKeySequence);
}
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment