Просмотр исходного кода

tools: replace DialogOpenProject class with a function

Daniele Bartolini 5 лет назад
Родитель
Сommit
3af32ded4f

+ 0 - 30
tools/level_editor/dialog_open_project.vala

@@ -1,30 +0,0 @@
-/*
- * Copyright (c) 2012-2020 Daniele Bartolini and individual contributors.
- * License: https://github.com/dbartolini/crown/blob/master/LICENSE
- */
-
-using Gtk;
-
-namespace Crown
-{
-public class DialogOpenProject : Gtk.FileChooserDialog
-{
-	public DialogOpenProject(Gtk.Window? parent)
-	{
-		Object(title: "Open Project..."
-			, modal: true
-			, action: FileChooserAction.SELECT_FOLDER
-			);
-
-		add_buttons("Cancel"
-			, ResponseType.CANCEL
-			, "Open"
-			, ResponseType.ACCEPT
-			);
-
-		if (parent != null)
-			this.set_transient_for(parent);
-	}
-}
-
-}

+ 17 - 8
tools/level_editor/level_editor.vala

@@ -1400,16 +1400,10 @@ public class LevelEditorApplication : Gtk.Application
 
 		if (!_database.changed() || rt == ResponseType.YES && save() || rt == ResponseType.NO)
 		{
-			DialogOpenProject op = new DialogOpenProject(this.active_window);
-			rt = op.run();
+			string source_dir;
+			rt = run_open_project_dialog(out source_dir, this.active_window);
 			if (rt != ResponseType.ACCEPT)
-			{
-				op.destroy();
 				return;
-			}
-
-			string source_dir = op.get_filename();
-			op.destroy();
 
 			if (_project.source_dir() == source_dir)
 				return;
@@ -1475,6 +1469,21 @@ public class LevelEditorApplication : Gtk.Application
 		return rt;
 	}
 
+	public int run_open_project_dialog(out string source_dir, Gtk.Window? parent)
+	{
+		Gtk.FileChooserDialog fcd = new Gtk.FileChooserDialog("Open Project..."
+			, parent
+			, FileChooserAction.SELECT_FOLDER
+			, "Cancel"
+			, ResponseType.CANCEL
+			, "Open"
+			, ResponseType.ACCEPT
+			);
+		int rt = fcd.run();
+		fcd.destroy();
+		return rt;
+	}
+
 	private void on_close(GLib.SimpleAction action, GLib.Variant? param)
 	{
 		int rt = ResponseType.YES;

+ 3 - 8
tools/level_editor/panel_projects_list.vala

@@ -42,15 +42,10 @@ public class PanelProjectsList : Gtk.ScrolledWindow
 		});
 
 		_button_import_project.clicked.connect(() => {
-			DialogOpenProject op = new DialogOpenProject((Gtk.Window)this.get_toplevel());
-			if (op.run() != ResponseType.ACCEPT)
-			{
-				op.destroy();
+			string source_dir;
+			int rt = _application.run_open_project_dialog(out source_dir, (Gtk.Window)this.get_toplevel());
+			if (rt != ResponseType.ACCEPT)
 				return;
-			}
-
-			string source_dir = op.get_filename();
-			op.destroy();
 
 			_user.add_recent_project(source_dir, source_dir);
 		});