Explorar o código

Make 'remove' toolbar buttons query for removal

jp9000 %!s(int64=11) %!d(string=hai) anos
pai
achega
66c3c862e4
Modificáronse 2 ficheiros con 39 adicións e 22 borrados
  1. 35 21
      obs/window-basic-main.cpp
  2. 4 1
      obs/window-basic-main.hpp

+ 35 - 21
obs/window-basic-main.cpp

@@ -92,7 +92,7 @@ OBSBasic::OBSBasic(QWidget *parent)
 	removeItemAction = new QAction(QTStr("Remove"), this);
 	removeItemAction->setShortcut(QKeySequence(Qt::Key_Delete));
 	connect(removeItemAction, SIGNAL(triggered()),
-			this, SLOT(RemoveSelectedItem()));
+			this, SLOT(RemoveSelectedSceneItem()));
 	addAction(removeItemAction);
 }
 
@@ -792,21 +792,36 @@ void OBSBasic::DeactivateAudioSource(OBSSource source)
 	}
 }
 
-void OBSBasic::RemoveSelectedItem()
+bool OBSBasic::QueryRemoveSource(obs_source_t source)
 {
-	OBSSceneItem item = GetCurrentSceneItem();
-	if (item) {
-		obs_source_t source = obs_sceneitem_getsource(item);
-		const char   *name  = obs_source_getname(source);
+	const char *name  = obs_source_getname(source);
+
+	QString text = QTStr("ConfirmRemove.Text");
+	text.replace("$1", QT_UTF8(name));
+
+	QMessageBox::StandardButton button;
+	button = QMessageBox::question(this,
+			QTStr("ConfirmRemove.Remove"), text);
 
-		QString text = QTStr("ConfirmRemove.Text");
-		text.replace("$1", QT_UTF8(name));
+	return button == QMessageBox::Yes;
+}
 
-		QMessageBox::StandardButton button;
-		button = QMessageBox::question(this,
-				QTStr("ConfirmRemove.Remove"), text);
+void OBSBasic::RemoveSelectedScene()
+{
+	OBSScene scene = GetCurrentScene();
+	if (scene) {
+		obs_source_t source = obs_scene_getsource(scene);
+		if (QueryRemoveSource(source))
+			obs_source_remove(source);
+	}
+}
 
-		if (button == QMessageBox::Yes)
+void OBSBasic::RemoveSelectedSceneItem()
+{
+	OBSSceneItem item = GetCurrentSceneItem();
+	if (item) {
+		obs_source_t source = obs_sceneitem_getsource(item);
+		if (QueryRemoveSource(source))
 			obs_sceneitem_remove(item);
 	}
 }
@@ -1297,14 +1312,11 @@ void OBSBasic::on_actionAddScene_triggered()
 
 void OBSBasic::on_actionRemoveScene_triggered()
 {
-	QListWidgetItem *item = ui->scenes->currentItem();
-	if (!item)
-		return;
-
-	QVariant userData = item->data(Qt::UserRole);
-	obs_scene_t scene = userData.value<OBSScene>();
+	OBSScene     scene  = GetCurrentScene();
 	obs_source_t source = obs_scene_getsource(scene);
-	obs_source_remove(source);
+
+	if (source && QueryRemoveSource(source))
+		obs_source_remove(source);
 }
 
 void OBSBasic::on_actionSceneProperties_triggered()
@@ -1445,8 +1457,10 @@ void OBSBasic::on_actionAddSource_triggered()
 
 void OBSBasic::on_actionRemoveSource_triggered()
 {
-	OBSSceneItem item = GetCurrentSceneItem();
-	if (item)
+	OBSSceneItem item   = GetCurrentSceneItem();
+	obs_source_t source = obs_sceneitem_getsource(item);
+
+	if (source && QueryRemoveSource(source))
 		obs_sceneitem_remove(item);
 }
 

+ 4 - 1
obs/window-basic-main.hpp

@@ -116,6 +116,8 @@ private:
 
 	OBSSceneItem  GetCurrentSceneItem();
 
+	bool          QueryRemoveSource(obs_source_t source);
+
 	void GetFPSCommon(uint32_t &num, uint32_t &den) const;
 	void GetFPSInteger(uint32_t &num, uint32_t &den) const;
 	void GetFPSFraction(uint32_t &num, uint32_t &den) const;
@@ -148,7 +150,8 @@ private slots:
 	void ActivateAudioSource(OBSSource source);
 	void DeactivateAudioSource(OBSSource source);
 
-	void RemoveSelectedItem();
+	void RemoveSelectedScene();
+	void RemoveSelectedSceneItem();
 
 private:
 	/* OBS Callbacks */