Skip to content

Commit f730063

Browse files
Warchamp7RytoEX
authored andcommitted
frontend: Adjustments to Add Source window
1 parent 6750a6e commit f730063

4 files changed

Lines changed: 187 additions & 188 deletions

File tree

frontend/data/locale/en-US.ini

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -644,13 +644,15 @@ Basic.Main.PreviewDisabled="Preview is currently disabled"
644644
Basic.SourceSelect="Add Source"
645645
Basic.SourceSelect.SelectType="Source Type"
646646
Basic.SourceSelect.Recent="Recently Created"
647-
Basic.SourceSelect.NewSource="Create a New Source"
648-
Basic.SourceSelect.Existing="Add an Existing Source"
647+
Basic.SourceSelect.Description="Select which source(s) to add to your current scene."
648+
Basic.SourceSelect.NewSource="Add a new %1"
649+
Basic.SourceSelect.AddExisting="Add %1 existing"
650+
Basic.SourceSelect.NoSelection="Add existing"
649651
Basic.SourceSelect.CreateButton="Create New"
650652
Basic.SourceSelect.AddVisible="Make source visible"
651-
Basic.SourceSelect.NoExisting="No existing %1 sources"
653+
Basic.SourceSelect.NoExisting="You have no existing %1 sources yet."
652654
Basic.SourceSelect.Accessible.SourceName="Source Name"
653-
Basic.SourceSelect.Accessible.Existing="Add an Existing Source"
655+
Basic.SourceSelect.Accessible.Existing="Add an existing source"
654656
Basic.SourceSelect.Deprecated.Create="This source type is marked as deprecated and may be removed in the future."
655657

656658
# source box

frontend/data/themes/Yami.obt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2437,6 +2437,16 @@ OBSBasicAdvAudio #scrollAreaWidgetContents {
24372437
}
24382438

24392439
/* Add Source Dialog */
2440+
.btn-create-new {
2441+
background: transparent;
2442+
padding: var(--padding_wide) var(--padding_large);
2443+
border-radius: var(--border_radius);
2444+
border: 2px dashed var(--grey3);
2445+
outline: none;
2446+
qproperty-icon: url(theme:Dark/plus.svg);
2447+
margin-bottom: var(--spacing_large);
2448+
}
2449+
24402450
SourceSelectButton {
24412451
background: var(--grey5);
24422452
padding: var(--padding_base) var(--padding_large);

frontend/dialogs/OBSBasicSourceSelect.cpp

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,9 @@ OBSBasicSourceSelect::OBSBasicSourceSelect(OBSBasic *parent, undo_stack &undo_s)
255255
connect(ui->existingScrollArea->horizontalScrollBar(), &QScrollBar::valueChanged, this,
256256
&OBSBasicSourceSelect::updateButtonVisibility);
257257

258-
ui->createNewFrame->setVisible(false);
259-
ui->deprecatedCreateLabel->setVisible(false);
260-
ui->deprecatedCreateLabel->setProperty("class", "text-muted");
258+
ui->createNewSource->setVisible(false);
259+
ui->noExistingLabel->setVisible(false);
260+
ui->deprecatedFrame->setVisible(false);
261261

262262
rebuildSourceTypeList();
263263
refreshSources();
@@ -272,16 +272,16 @@ OBSBasicSourceSelect::OBSBasicSourceSelect(OBSBasic *parent, undo_stack &undo_s)
272272

273273
connect(ui->sourceTypeList, &QListWidget::itemDoubleClicked, this, &OBSBasicSourceSelect::createNew);
274274
connect(ui->sourceTypeList, &QListWidget::currentItemChanged, this, &OBSBasicSourceSelect::sourceTypeSelected);
275-
connect(ui->newSourceName, &QLineEdit::returnPressed, this, &OBSBasicSourceSelect::createNew);
276275
connect(ui->buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject);
277276

278277
connect(ui->addExistingButton, &QAbstractButton::clicked, this, &OBSBasicSourceSelect::addSelectedSources);
279278
connect(this, &OBSBasicSourceSelect::selectedItemsChanged, this, [this]() {
280279
ui->addExistingButton->setEnabled(selectedItems.size() > 0);
281280
if (selectedItems.size() > 0) {
282-
ui->addExistingButton->setText(QTStr("Add %1 Existing").arg(selectedItems.size()));
281+
ui->addExistingButton->setText(
282+
QTStr("Basic.SourceSelect.AddExisting").arg(selectedItems.size()));
283283
} else {
284-
ui->addExistingButton->setText("Add Existing");
284+
ui->addExistingButton->setText(QTStr("Basic.SourceSelect.NoSelection"));
285285
}
286286
});
287287

@@ -537,6 +537,13 @@ void OBSBasicSourceSelect::rebuildSourceTypeList()
537537

538538
ui->sourceTypeList->sortItems();
539539

540+
auto *deprecatedTitle = new QListWidgetItem(ui->sourceTypeList);
541+
deprecatedTitle->setText(QTStr("Deprecated"));
542+
deprecatedTitle->setFlags(deprecatedTitle->flags() & ~Qt::ItemIsEnabled);
543+
deprecatedTitle->setFlags(deprecatedTitle->flags() & ~Qt::ItemIsSelectable);
544+
545+
ui->sourceTypeList->addItem(deprecatedTitle);
546+
540547
// Shift Deprecated sources to the bottom
541548
QList<QListWidgetItem *> deprecatedItems;
542549
for (int i = 0; i < ui->sourceTypeList->count(); ++i) {
@@ -732,10 +739,6 @@ void OBSBasicSourceSelect::createNew()
732739
{
733740
bool visible = ui->sourceVisible->isChecked();
734741

735-
if (ui->newSourceName->text().isEmpty()) {
736-
return;
737-
}
738-
739742
if (selectedTypeId.compare(kRecentTypeId) == 0) {
740743
return;
741744
}
@@ -746,7 +749,8 @@ void OBSBasicSourceSelect::createNew()
746749

747750
std::string sourceType = selectedTypeId.toStdString();
748751
const char *id = sourceType.c_str();
749-
std::string newName = ui->newSourceName->text().toStdString();
752+
QString placeholder = getDisplayNameForSourceType(selectedTypeId);
753+
std::string newName = getNewSourceName(placeholder.toStdString().c_str());
750754

751755
std::optional<OBSSource> createResult = setupNewSource(this, id, newName.c_str());
752756
if (!createResult.has_value()) {
@@ -779,7 +783,7 @@ void OBSBasicSourceSelect::createNew()
779783
OBSDataAutoRelease wrapper = obs_data_create();
780784
obs_data_set_string(wrapper, "id", id);
781785
obs_data_set_int(wrapper, "item_id", obs_sceneitem_get_id(item));
782-
obs_data_set_string(wrapper, "name", ui->newSourceName->text().toUtf8().constData());
786+
obs_data_set_string(wrapper, "name", newName.c_str());
783787
obs_data_set_bool(wrapper, "visible", visible);
784788

785789
auto redo = [sceneUuid](const std::string &data) {
@@ -808,7 +812,7 @@ void OBSBasicSourceSelect::createNew()
808812

809813
obs_sceneitem_set_id(item, static_cast<int64_t>(obs_data_get_int(dat, "item_id")));
810814
};
811-
undo_s.add_action(QTStr("Undo.Add").arg(ui->newSourceName->text()), undo, redo,
815+
undo_s.add_action(QTStr("Undo.Add").arg(QString::fromStdString(newName)), undo, redo,
812816
std::string(obs_source_get_uuid(newSource)), std::string(obs_data_get_json(wrapper)));
813817

814818
main->CreatePropertiesWindow(newSource);
@@ -910,9 +914,15 @@ void OBSBasicSourceSelect::sourceTypeSelected(QListWidgetItem *current, QListWid
910914
QVariant unversionedIdData = current->data(kUnversionedIdRole);
911915
QVariant deprecatedData = current->data(kDeprecatedRole);
912916

917+
bool isDeprecatedType = deprecatedData.toBool();
918+
ui->deprecatedFrame->setVisible(isDeprecatedType);
919+
913920
if (unversionedIdData.toString().compare(kRecentTypeId) == 0) {
921+
ui->sourceSelectTitle->setText(QTStr("Basic.SourceSelect.Recent"));
914922
selectedTypeId = kRecentTypeId.toString();
915-
ui->createNewFrame->setVisible(false);
923+
ui->noExistingLabel->setVisible(false);
924+
ui->existingScrollArea->setVisible(true);
925+
ui->createNewSource->setVisible(false);
916926
updateExistingSources(kRecentListLimit);
917927
return;
918928
}
@@ -922,31 +932,21 @@ void OBSBasicSourceSelect::sourceTypeSelected(QListWidgetItem *current, QListWid
922932
return;
923933
}
924934

925-
ui->createNewFrame->setVisible(true);
926-
927-
bool isDeprecatedType = deprecatedData.toBool();
928-
ui->deprecatedCreateLabel->setVisible(isDeprecatedType);
935+
ui->createNewSource->setVisible(type != "scene");
929936

930937
selectedTypeId = type;
931938

932939
QString placeHolderText{getDisplayNameForSourceType(selectedTypeId)};
933940

934-
QString text{placeHolderText};
935-
int i = 2;
936-
OBSSourceAutoRelease source = nullptr;
937-
while ((source = obs_get_source_by_name(QT_TO_UTF8(text)))) {
938-
text = QString("%1 %2").arg(placeHolderText).arg(i++);
939-
}
940-
941-
ui->newSourceName->setText(text);
941+
ui->createNewSource->setText(
942+
QTStr("Basic.SourceSelect.NewSource").arg(getDisplayNameForSourceType(selectedTypeId)));
943+
ui->sourceSelectTitle->setText(QString("%1").arg(getDisplayNameForSourceType(selectedTypeId)));
942944

943945
updateExistingSources();
944946

945-
if (existingFlowLayout->count() == 0) {
946-
QLabel *noExisting = new QLabel();
947-
noExisting->setText(
948-
QTStr("Basic.SourceSelect.NoExisting").arg(getDisplayNameForSourceType(selectedTypeId)));
949-
noExisting->setProperty("class", "text-muted");
950-
existingFlowLayout->addWidget(noExisting);
951-
}
947+
ui->noExistingLabel->setText(
948+
QTStr("Basic.SourceSelect.NoExisting").arg(getDisplayNameForSourceType(selectedTypeId)));
949+
950+
ui->existingScrollArea->setVisible(existingFlowLayout->count() != 0);
951+
ui->noExistingLabel->setVisible(existingFlowLayout->count() == 0);
952952
}

0 commit comments

Comments
 (0)