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

tools: generalize import action

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

+ 3 - 2
tools/level_editor/level_editor.vala

@@ -125,7 +125,7 @@ public class LevelEditorApplication : Gtk.Application
 		{ "open-project", on_open_project, null, null },
 		{ "save",         on_save,         null, null },
 		{ "save-as",      on_save_as,      null, null },
-		{ "import",       on_import,       null, null },
+		{ "import",       on_import,       "s",  null },
 		{ "preferences",  on_preferences,  null, null },
 		{ "deploy",       on_deploy,       null, null },
 		{ "close",        on_close,        null, null },
@@ -1640,7 +1640,8 @@ public class LevelEditorApplication : Gtk.Application
 
 	private void on_import(GLib.SimpleAction action, GLib.Variant? param)
 	{
-		_project.import(null, this.active_window);
+		string destination_dir = param.get_string();
+		_project.import(destination_dir != "" ? destination_dir : null, this.active_window);
 	}
 
 	private void on_preferences(GLib.SimpleAction action, GLib.Variant? param)

+ 1 - 1
tools/level_editor/project.vala

@@ -598,7 +598,7 @@ public class Project
 		}
 		else
 		{
-			out_dir = destination_dir;
+			out_dir = GLib.File.new_for_path(GLib.Path.build_filename(source_dir(), destination_dir)).get_path();
 		}
 
 		Gtk.FileFilter? current_filter = src.get_filter();

+ 2 - 2
tools/level_editor/project_browser.vala

@@ -242,8 +242,8 @@ public class ProjectBrowser : Gtk.Box
 
 					mi = new Gtk.MenuItem.with_label("Import...");
 					mi.activate.connect(() => {
-						GLib.File file = GLib.File.new_for_path(GLib.Path.build_filename(_project.source_dir(), (string)name));
-						_project.import(file.get_path(), (Gtk.Window)this.get_toplevel());
+						Gtk.Application app = ((Gtk.Window)this.get_toplevel()).application;
+						app.activate_action("import", new GLib.Variant.string((string)name));
 					});
 					menu.add(mi);
 

+ 1 - 0
tools/level_editor/resources/gtk/menus.ui

@@ -39,6 +39,7 @@
         <item>
           <attribute name="label" translatable="yes">Import...</attribute>
           <attribute name="action">app.import</attribute>
+          <attribute name="target"></attribute>
           <attribute name="accel">&lt;Primary&gt;I</attribute>
         </item>
       </section>