Browse Source

UI: Display filename when dragging & dropping

After dragging and dropping a file, the source name will be the
filename.

(Jim: When dragging and dropping raw text, the raw text would then be
used as the source's name, which is bad if there's a lot of text.  It's
now been changed so that it uses the source type's display name, i.e.
"Text (GDI+)" as the source name in that case)

Closes jp9000/obs-studio#888
cg2121 8 years ago
parent
commit
012b5ef6a5
1 changed files with 8 additions and 2 deletions
  1. 8 2
      UI/window-basic-main-dropfiles.cpp

+ 8 - 2
UI/window-basic-main-dropfiles.cpp

@@ -62,6 +62,7 @@ void OBSBasic::AddDropSource(const char *data, DropType image)
 	obs_data_t *settings = obs_data_create();
 	obs_source_t *source = nullptr;
 	const char *type = nullptr;
+	QString name;
 
 	switch (image) {
 	case DropType_RawText:
@@ -71,20 +72,25 @@ void OBSBasic::AddDropSource(const char *data, DropType image)
 	case DropType_Text:
 		obs_data_set_bool(settings, "read_from_file", true);
 		obs_data_set_string(settings, "file", data);
+		name = QUrl::fromLocalFile(QString(data)).fileName();
 		type = "text_gdiplus";
 		break;
 	case DropType_Image:
 		obs_data_set_string(settings, "file", data);
+		name = QUrl::fromLocalFile(QString(data)).fileName();
 		type = "image_source";
 		break;
 	case DropType_Media:
 		obs_data_set_string(settings, "local_file", data);
+		name = QUrl::fromLocalFile(QString(data)).fileName();
 		type = "ffmpeg_source";
 		break;
 	}
 
-	const char *name = obs_source_get_display_name(type);
-	source = obs_source_create(type, GenerateSourceName(name).c_str(),
+	if (name.isEmpty())
+		name = obs_source_get_display_name(type);
+	source = obs_source_create(type,
+			GenerateSourceName(QT_TO_UTF8(name)).c_str(),
 			settings, nullptr);
 	if (source) {
 		OBSScene scene = main->GetCurrentScene();