From 473abfa1e322b4516b69f972e6907ec8ef91da96 Mon Sep 17 00:00:00 2001 From: Kolan Sh Date: Fri, 27 Apr 2018 10:18:20 +0300 Subject: [PATCH] Plugin.{Data,Object}.preferences(): show preferences window. --- src/AppDirs.vala | 34 ++++++ src/DataDialog.vala | 47 +++++++++ src/main.vala | 8 +- ui/glade/laview-plugin-data-example.glade | 123 ++++++++++++++++++++++ 4 files changed, 211 insertions(+), 1 deletion(-) create mode 100644 src/AppDirs.vala create mode 100644 src/DataDialog.vala diff --git a/src/AppDirs.vala b/src/AppDirs.vala new file mode 100644 index 0000000..b4bc513 --- /dev/null +++ b/src/AppDirs.vala @@ -0,0 +1,34 @@ +namespace Get { + extern void library_path (string so_path, void *addr); +} + +namespace LAview.Core.Plugins { + + class AppDirs : Object { + + public static File so_path; + public static File exec_dir; + public static File common_dir; + public static string ui_dir; + public static string settings_dir; + + public static void init () { + char _so_path[256]; + Get.library_path ((string)_so_path, (void*)init); + so_path = File.new_for_path ((string)_so_path); + exec_dir = so_path.get_parent (); + common_dir = exec_dir.get_parent (); + common_dir = common_dir.get_parent().get_parent().get_parent(); + ui_dir = Path.build_path (Path.DIR_SEPARATOR_S, common_dir.get_path(), + "share/laview-plugin-data-example-"+Config.VERSION_MAJOR.to_string()+"/ui"); + stdout.printf ("Vala:so_path=%s\n", so_path.get_path()); + settings_dir = Path.build_path (Path.DIR_SEPARATOR_S, common_dir.get_path(), "share/glib-2.0/schemas"); + stdout.printf ("ui_dir = %s\n", ui_dir); + stdout.printf ("settings_dir = %s\n", settings_dir); + + } + + public static void terminate () { + } + } +} diff --git a/src/DataDialog.vala b/src/DataDialog.vala new file mode 100644 index 0000000..f11982e --- /dev/null +++ b/src/DataDialog.vala @@ -0,0 +1,47 @@ +namespace LAview.Core.Plugins { + using Gtk, LAview; + + class DataExampleDialog : Object { + Dialog dialog; + + public bool composed { get; private set; default = false; } + + public DataExampleDialog (Object parent) throws Error { + var builder = new Builder (); + builder.add_from_file (AppDirs.ui_dir + "/laview-plugin-data-example.glade"); + builder.connect_signals (this); + + dialog = builder.get_object ("data_example_dialog") as Dialog; + if (parent is Window) { + dialog.destroy_with_parent = true; + dialog.transient_for = parent as Window; + dialog.modal = true; + dialog.delete_event.connect ((source) => { + dialog.hide_on_delete(); + return true; + }); + } + } + + public void show_all () { + composed = false; + dialog.run (); + } + + [CCode (instance_pos = -1)] + public void button_apply_clicked (Button button) { + composed = true; + } + + [CCode (instance_pos = -1)] + public void button_ok_clicked (Button button) { + composed = true; + dialog.hide (); + } + + [CCode (instance_pos = -1)] + public void button_cancel_clicked (Button button) { + dialog.hide (); + } + } +} diff --git a/src/main.vala b/src/main.vala index 823c3e7..30e5fb9 100644 --- a/src/main.vala +++ b/src/main.vala @@ -8,6 +8,8 @@ namespace LAview.Core.Plugins { */ public class PluginDataExample : PluginData { + DataExampleDialog data_dialog = null; + /** * Constructs a new ``PluginDataExample``. */ @@ -41,9 +43,13 @@ namespace LAview.Core.Plugins { /** * Open Preferences. */ - public override void preferences () { + public override void preferences (Object parent) throws Error { // TODO: Open Preferences window. stdout.puts("Data Example preferences () called.\n"); + + if (data_dialog == null) data_dialog = new DataExampleDialog (parent); + + data_dialog.show_all (); } /** diff --git a/ui/glade/laview-plugin-data-example.glade b/ui/glade/laview-plugin-data-example.glade index e69de29..ebde9f6 100644 --- a/ui/glade/laview-plugin-data-example.glade +++ b/ui/glade/laview-plugin-data-example.glade @@ -0,0 +1,123 @@ + + + + + + False + dialog + + + False + vertical + 2 + + + False + end + + + gtk-apply + True + True + True + True + True + + + + True + True + 0 + + + + + gtk-ok + True + True + True + True + True + + + + True + True + 1 + + + + + gtk-undo + True + True + True + True + True + + + + True + True + 2 + + + + + False + False + 0 + + + + + True + False + vertical + + + True + False + label + + + True + True + 0 + + + + + True + False + label + + + True + True + 1 + + + + + True + False + label + + + True + True + 2 + + + + + True + True + 1 + + + + + +