Преглед на файлове

UI: Wipe undo/redo stack when switching scene collections

Ford Smith преди 4 години
родител
ревизия
0b583260a2
променени са 3 файла, в които са добавени 16 реда и са изтрити 24 реда
  1. 14 0
      UI/undo-stack-obs.cpp
  2. 1 0
      UI/undo-stack-obs.hpp
  3. 1 24
      UI/window-basic-main-scene-collections.cpp

+ 14 - 0
UI/undo-stack-obs.cpp

@@ -17,6 +17,20 @@ void undo_stack::release()
 			f.d(false);
 }
 
+void undo_stack::clear()
+{
+	release();
+
+	undo_items.clear();
+	redo_items.clear();
+
+	ui->actionMainUndo->setText(QTStr("Undo.Undo"));
+	ui->actionMainRedo->setText(QTStr("Undo.Redo"));
+
+	ui->actionMainUndo->setDisabled(true);
+	ui->actionMainRedo->setDisabled(true);
+}
+
 void undo_stack::add_action(const QString &name, undo_redo_cb undo,
 			    undo_redo_cb redo, std::string undo_data,
 			    std::string redo_data, func d)

+ 1 - 0
UI/undo-stack-obs.hpp

@@ -38,6 +38,7 @@ public:
 	void disable_undo_redo();
 
 	void release();
+	void clear();
 	void add_action(const QString &name, undo_redo_cb undo,
 			undo_redo_cb redo, std::string undo_data,
 			std::string redo_data, func d);

+ 1 - 24
UI/window-basic-main-scene-collections.cpp

@@ -532,8 +532,6 @@ void OBSBasic::ChangeSceneCollection()
 
 	const char *oldName = config_get_string(App()->GlobalConfig(), "Basic",
 						"SceneCollection");
-	std::string oldFile = std::string(config_get_string(
-		App()->GlobalConfig(), "Basic", "SceneCollectionFile"));
 
 	if (action->text().compare(QT_UTF8(oldName)) == 0) {
 		action->setChecked(true);
@@ -556,28 +554,7 @@ void OBSBasic::ChangeSceneCollection()
 
 	UpdateTitleBar();
 
-	auto undo = [this, fn = std::string(oldFile)](const std::string &) {
-		string fileName = fn;
-		char path[512];
-		int ret = GetConfigPath(path, 512, "obs-studio/basic/scenes/");
-		if (ret <= 0) {
-			blog(LOG_WARNING,
-			     "Failed to get scene collection config path");
-			return;
-		}
-		fileName.insert(0, path);
-		fileName += ".json";
-		Load(fileName.c_str());
-		RefreshSceneCollections();
-	};
-
-	auto redo = [this, fileName](const std::string &) {
-		Load(fileName.c_str());
-		RefreshSceneCollections();
-	};
-
-	undo_s.add_action(QTStr("Undo.SceneCollection.Switch").arg(newName),
-			  undo, redo, "", "", NULL);
+	undo_s.clear();
 
 	if (api)
 		api->on_event(OBS_FRONTEND_EVENT_SCENE_COLLECTION_CHANGED);