浏览代码

make sure another source by the same name doesn't already exist when choosing a name for that scene

jp9000 11 年之前
父节点
当前提交
6fe59f77ec
共有 4 个文件被更改,包括 19 次插入2 次删除
  1. 3 0
      build/data/obs-studio/locale/en.txt
  2. 1 0
      libobs/obs.c
  3. 14 1
      obs/window-basic-main.cpp
  4. 1 1
      obs/wx-wrappers.cpp

+ 3 - 0
build/data/obs-studio/locale/en.txt

@@ -12,6 +12,9 @@ MainMenu.FIle.Save="Save"
 MainWindow.AddSceneDlg.Title="Add Scene"
 MainWindow.AddSceneDlg.Text="Please enter the name of the scene"
 
+MainWindow.NameExists.Title="Name already exists"
+MainWindow.NameExists.Text="The name is already in use by another source."
+
 MainWindow.Exit="Exit"
 MainWindow.Lock="Lock Preview"
 MainWindow.Preview="Enable Preview"

+ 1 - 0
libobs/obs.c

@@ -498,6 +498,7 @@ obs_source_t obs_get_source_by_name(const char *name)
 		struct obs_source *cur_source = data->sources.array[i];
 		if (strcmp(cur_source->name, name) == 0) {
 			source = cur_source;
+			obs_source_addref(source);
 			break;
 		}
 	}

+ 14 - 1
obs/window-basic-main.cpp

@@ -17,6 +17,8 @@
 
 #include <obs.hpp>
 
+#include <wx/msgdlg.h>
+
 #include "obs-app.hpp"
 #include "wx-wrappers.hpp"
 #include "window-basic-settings.hpp"
@@ -62,8 +64,8 @@ void OBSBasic::SourceAdded(void *data, calldata_t params)
 void OBSBasic::SourceDestroyed(void *data, calldata_t params)
 {
 	OBSBasic *window = (OBSBasic*)data;
-	obs_source_t source;
 
+	obs_source_t source;
 	calldata_getptr(params, "source", (void**)&source);
 
 	obs_source_type type;
@@ -191,6 +193,17 @@ void OBSBasic::sceneAddClicked(wxCommandEvent &event)
 			name);
 
 	if (ret == wxID_OK) {
+		obs_source_t source = obs_get_source_by_name(name.c_str());
+		if (source) {
+			wxMessageBox(WXStr("MainWindow.NameExists.Text"),
+			             WXStr("MainWindow.NameExists.Title"),
+			             wxOK|wxCENTRE, this);
+
+			obs_source_release(source);
+			sceneAddClicked(event);
+			return;
+		}
+
 		obs_scene_t scene = obs_scene_create(name.c_str());
 		obs_add_source(obs_scene_getsource(scene));
 		obs_scene_release(scene);

+ 1 - 1
obs/wx-wrappers.cpp

@@ -42,6 +42,6 @@ void OBSErrorBox(wxWindow *parent, const char *message, ...)
 	vsnprintf(output, 4095, message, args);
 	va_end(args);
 
-	wxMessageBox(message, "Error");
+	wxMessageBox(message, "Error", wxOK|wxCENTRE, parent);
 	blog(LOG_ERROR, "%s", output);
 }