diff --git a/src/ui/form/prog/programeditdialog.cpp b/src/ui/form/prog/programeditdialog.cpp index 032745ff..8e95306c 100644 --- a/src/ui/form/prog/programeditdialog.cpp +++ b/src/ui/form/prog/programeditdialog.cpp @@ -74,25 +74,7 @@ void ProgramEditDialog::initialize(const AppRow &appRow, const QVector & m_appRow = appRow; m_appIdList = appIdList; - const bool isSingleSelection = (appIdList.size() <= 1); - const bool isPathEditable = isSingleSelection && (appRow.appId == 0 || appRow.isWildcard); - - m_editPath->setText(isSingleSelection && !isWildcard() ? appRow.appOriginPath : QString()); - m_editPath->setReadOnly(!isPathEditable); - m_editPath->setClearButtonEnabled(isPathEditable); - m_editPath->setEnabled(isSingleSelection); - m_editPath->setVisible(!isWildcard()); - - m_editWildcard->setText(isSingleSelection && isWildcard() ? appRow.appOriginPath : QString()); - m_editWildcard->setReadOnly(!isPathEditable); - m_editWildcard->setEnabled(isSingleSelection); - m_editWildcard->setVisible(isWildcard()); - - m_btSelectFile->setEnabled(isPathEditable); - m_editName->setText(isSingleSelection ? appRow.appName : QString()); - m_editName->setEnabled(isSingleSelection); - m_editName->setClearButtonEnabled(isSingleSelection); - m_btGetName->setEnabled(isSingleSelection); + initializePathNameFields(); m_comboAppGroup->setCurrentIndex(appRow.groupIndex); m_cbUseGroupPerm->setChecked(appRow.useGroupPerm); @@ -116,11 +98,43 @@ void ProgramEditDialog::initialize(const AppRow &appRow, const QVector & m_dteBlockAppAt->setMinimumDateTime(QDateTime::currentDateTime()); m_cbBlockAppNone->setChecked(appRow.endTime.isNull()); - if (isSingleSelection && appRow.appName.isEmpty()) { + retranslateUi(); +} + +void ProgramEditDialog::initializePathNameFields() +{ + const bool isSingleSelection = (m_appIdList.size() <= 1); + const bool isPathEditable = isSingleSelection && (m_appRow.appId == 0 || isWildcard()); + + initializePathField(isSingleSelection, isPathEditable); + initializeNameField(isSingleSelection, isPathEditable); + + if (isSingleSelection && m_appRow.appName.isEmpty()) { fillEditName(); // Auto-fill the name } +} - retranslateUi(); +void ProgramEditDialog::initializePathField(bool isSingleSelection, bool isPathEditable) +{ + m_editPath->setText(isSingleSelection && !isWildcard() ? m_appRow.appOriginPath : QString()); + m_editPath->setReadOnly(!isPathEditable); + m_editPath->setClearButtonEnabled(isPathEditable); + m_editPath->setEnabled(isSingleSelection); + m_editPath->setVisible(!isWildcard()); + + m_editWildcard->setText(isSingleSelection && isWildcard() ? m_appRow.appOriginPath : QString()); + m_editWildcard->setReadOnly(!isPathEditable); + m_editWildcard->setEnabled(isSingleSelection); + m_editWildcard->setVisible(isWildcard()); +} + +void ProgramEditDialog::initializeNameField(bool isSingleSelection, bool isPathEditable) +{ + m_btSelectFile->setEnabled(isPathEditable); + m_editName->setText(isSingleSelection ? m_appRow.appName : QString()); + m_editName->setEnabled(isSingleSelection); + m_editName->setClearButtonEnabled(isSingleSelection); + m_btGetName->setEnabled(isSingleSelection); } void ProgramEditDialog::activate() @@ -180,7 +194,7 @@ void ProgramEditDialog::retranslateUi() void ProgramEditDialog::retranslatePathPlaceholderText() { - if (!isWildcard()) + if (!(isWildcard() && m_editWildcard->isEnabled())) return; const auto placeholderText = tr("# Examples:") + '\n' diff --git a/src/ui/form/prog/programeditdialog.h b/src/ui/form/prog/programeditdialog.h index ecf5baf7..e36a48fa 100644 --- a/src/ui/form/prog/programeditdialog.h +++ b/src/ui/form/prog/programeditdialog.h @@ -42,6 +42,10 @@ public: void activate(); private: + void initializePathNameFields(); + void initializePathField(bool isSingleSelection, bool isPathEditable); + void initializeNameField(bool isSingleSelection, bool isPathEditable); + void setupController(); void retranslateUi();