浏览代码

UI: Fix preview right-click menu getting wrong source

When right-clicking items in the preview window and getting context
menus for them, it would often make the wrong scene item be associated
with the context menu because of the fact that it was using
QListWidget::currentItem instead of querying the actual selected list.

You must query the actual selection list via QListWidget::selectedItems
because QListWidget::currentItem does not work properly for
multi-selection list widgets.
jp9000 9 年之前
父节点
当前提交
9b5ac1fbd2
共有 2 个文件被更改,包括 14 次插入3 次删除
  1. 12 3
      obs/window-basic-main.cpp
  2. 2 0
      obs/window-basic-main.hpp

+ 12 - 3
obs/window-basic-main.cpp

@@ -1285,7 +1285,7 @@ OBSSceneItem OBSBasic::GetSceneItem(QListWidgetItem *item)
 
 
 OBSSceneItem OBSBasic::GetCurrentSceneItem()
 OBSSceneItem OBSBasic::GetCurrentSceneItem()
 {
 {
-	return GetSceneItem(ui->sources->currentItem());
+	return GetSceneItem(GetTopSelectedSourceItem());
 }
 }
 
 
 void OBSBasic::UpdateSources(OBSScene scene)
 void OBSBasic::UpdateSources(OBSScene scene)
@@ -2605,7 +2605,7 @@ void OBSBasic::on_sources_itemSelectionChanged()
 
 
 void OBSBasic::EditSceneItemName()
 void OBSBasic::EditSceneItemName()
 {
 {
-	QListWidgetItem *item = ui->sources->currentItem();
+	QListWidgetItem *item = GetTopSelectedSourceItem();
 	Qt::ItemFlags flags   = item->flags();
 	Qt::ItemFlags flags   = item->flags();
 	OBSSceneItem sceneItem= GetOBSRef<OBSSceneItem>(item);
 	OBSSceneItem sceneItem= GetOBSRef<OBSSceneItem>(item);
 	obs_source_t *source  = obs_sceneitem_get_source(sceneItem);
 	obs_source_t *source  = obs_sceneitem_get_source(sceneItem);
@@ -3339,9 +3339,18 @@ void OBSBasic::on_actionShowProfileFolder_triggered()
 	QDesktopServices::openUrl(QUrl::fromLocalFile(path));
 	QDesktopServices::openUrl(QUrl::fromLocalFile(path));
 }
 }
 
 
+QListWidgetItem *OBSBasic::GetTopSelectedSourceItem()
+{
+	QList<QListWidgetItem*> selectedItems = ui->sources->selectedItems();
+	QListWidgetItem *topItem = nullptr;
+	if (selectedItems.size() != 0)
+		topItem = selectedItems[0];
+	return topItem;
+}
+
 void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
 void OBSBasic::on_preview_customContextMenuRequested(const QPoint &pos)
 {
 {
-	CreateSourcePopupMenu(ui->sources->currentItem(), true);
+	CreateSourcePopupMenu(GetTopSelectedSourceItem(), true);
 
 
 	UNUSED_PARAMETER(pos);
 	UNUSED_PARAMETER(pos);
 }
 }

+ 2 - 0
obs/window-basic-main.hpp

@@ -189,6 +189,8 @@ private:
 
 
 	void SaveProjectNow();
 	void SaveProjectNow();
 
 
+	QListWidgetItem *GetTopSelectedSourceItem();
+
 	obs_hotkey_pair_id streamingHotkeys, recordingHotkeys;
 	obs_hotkey_pair_id streamingHotkeys, recordingHotkeys;
 	obs_hotkey_id forceStreamingStopHotkey;
 	obs_hotkey_id forceStreamingStopHotkey;