From fef59d6d4f161fbbc1157c6507cd292f7326b781 Mon Sep 17 00:00:00 2001 From: ZenitsuDev Date: Wed, 9 Feb 2022 17:37:51 +0800 Subject: [PATCH 1/8] Replace FileChooserButton for GTK4 --- src/Widgets/SaveDialog.vala | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index f5313d76..f935c029 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -131,8 +131,11 @@ public class Screenshot.SaveDialog : Granite.Dialog { var location_label = new Gtk.Label (_("Folder:")); location_label.halign = Gtk.Align.END; - var location = new Gtk.FileChooserButton (_("Select Screenshots Folder…"), Gtk.FileChooserAction.SELECT_FOLDER); - location.set_current_folder (folder_dir); + var location_dialog = new Gtk.FileChooserDialog (_("Select Screenshots Folder…"), this, + Gtk.FileChooserAction.SELECT_FOLDER); + location_dialog.set_current_folder (folder_dir); + + var location_button = new Gtk.Button (); var grid = new Gtk.Grid (); grid.margin = 12; @@ -146,7 +149,7 @@ public class Screenshot.SaveDialog : Granite.Dialog { grid.attach (format_label, 0, 3, 1, 1); grid.attach (format_cmb, 1, 3, 1, 1); grid.attach (location_label, 0, 4, 1, 1); - grid.attach (location, 1, 4, 1, 1); + grid.attach (location_button, 1, 4, 1, 1); var content = this.get_content_area () as Gtk.Box; content.add (grid); @@ -175,8 +178,12 @@ public class Screenshot.SaveDialog : Granite.Dialog { settings.set_string ("format", format_cmb.get_active_text ()); }); - location.selection_changed.connect (() => { - SList uris = location.get_uris (); + location_button.clicked.connect (() => { + location_dialog.run (); + }); + + location_dialog.selection_changed.connect (() => { + SList uris = location_dialog.get_uris (); foreach (unowned string uri in uris) { settings.set_string ("folder-dir", Uri.unescape_string (uri.substring (7, -1))); folder_dir = settings.get_string ("folder-dir"); From 9adf0183fc47df1e4e4e600ea488e8c3065cfd06 Mon Sep 17 00:00:00 2001 From: ZenitsuDev Date: Thu, 19 May 2022 12:27:27 +0800 Subject: [PATCH 2/8] Use response signal --- src/Widgets/SaveDialog.vala | 61 ++++++++++++++++++++++++++++++++----- 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index f935c029..506b5c45 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -45,10 +45,29 @@ public class Screenshot.SaveDialog : Granite.Dialog { var folder_from_settings = settings.get_string ("folder-dir"); + var folder_name = new Gtk.Label ("") { + halign = Gtk.Align.START + }; + + var folder_icon = new Gtk.Image () { + pixel_size = 16 + }; + if (folder_from_settings != folder_dir && folder_from_settings != "") { folder_dir = folder_from_settings; } + if (folder_dir == Environment.get_home_dir ()) { + folder_name.label = "Home"; + folder_icon.gicon = new ThemedIcon ("user-home"); + } else if (folder_dir == "/") { + folder_name.label = "File System"; + folder_icon.gicon = new ThemedIcon ("drive-harddisk"); + } else { + folder_name.label = folder_dir.reverse ().split ("/")[0].reverse (); + folder_icon.gicon = new ThemedIcon ("folder"); + } + Application.create_dir_if_missing (folder_dir); int width = pixbuf.get_width () / 4; @@ -131,11 +150,17 @@ public class Screenshot.SaveDialog : Granite.Dialog { var location_label = new Gtk.Label (_("Folder:")); location_label.halign = Gtk.Align.END; - var location_dialog = new Gtk.FileChooserDialog (_("Select Screenshots Folder…"), this, - Gtk.FileChooserAction.SELECT_FOLDER); + var location_dialog = new Gtk.FileChooserNative (_("Select Screenshots Folder…"), this, + Gtk.FileChooserAction.SELECT_FOLDER, "Open", "Cancel"); location_dialog.set_current_folder (folder_dir); + var location_button_indicator = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); + location_button_indicator.pack_start (folder_icon, false, false); + location_button_indicator.pack_start (folder_name, true, true); + location_button_indicator.pack_start (new Gtk.Image.from_icon_name ("document-open-symbolic", Gtk.IconSize.BUTTON), false, false); + var location_button = new Gtk.Button (); + location_button.add (location_button_indicator); var grid = new Gtk.Grid (); grid.margin = 12; @@ -180,13 +205,35 @@ public class Screenshot.SaveDialog : Granite.Dialog { location_button.clicked.connect (() => { location_dialog.run (); + var f = new Gtk.FileChooserButton ("HIIIII", Gtk.FileChooserAction.SELECT_FOLDER); + var cont = ((Gtk.Container) f.get_children ().nth_data (0)); + var box = (Gtk.Box) cont.get_children ().nth_data (0); + box.foreach ((item) => { + if (item is Gtk.Image) { + print ("yoohoo\n"); + print ("%s\n", ((Gtk.Image) item).icon_name); + } + }); }); - location_dialog.selection_changed.connect (() => { - SList uris = location_dialog.get_uris (); - foreach (unowned string uri in uris) { - settings.set_string ("folder-dir", Uri.unescape_string (uri.substring (7, -1))); - folder_dir = settings.get_string ("folder-dir"); + location_dialog.response.connect ((response) => { + if (response == Gtk.ResponseType.ACCEPT) { + SList uris = location_dialog.get_uris (); + foreach (unowned string uri in uris) { + settings.set_string ("folder-dir", Uri.unescape_string (uri.substring (7, -1))); + folder_dir = settings.get_string ("folder-dir"); + } + + if (folder_dir == Environment.get_home_dir ()) { + folder_name.label = "Home"; + folder_icon.gicon = new ThemedIcon ("user-home"); + } else if (folder_dir == "/") { + folder_name.label = "File System"; + folder_icon.gicon = new ThemedIcon ("drive-harddisk"); + } else { + folder_name.label = folder_dir.reverse ().split ("/")[0].reverse (); + folder_icon.gicon = new ThemedIcon ("folder"); + } } }); From 35d7b0b89109b6d48843700d4fffd98c68667ba7 Mon Sep 17 00:00:00 2001 From: ZenitsuDev Date: Thu, 19 May 2022 12:41:20 +0800 Subject: [PATCH 3/8] Fix sizes --- src/Widgets/SaveDialog.vala | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index 506b5c45..7da2a7c0 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -154,14 +154,23 @@ public class Screenshot.SaveDialog : Granite.Dialog { Gtk.FileChooserAction.SELECT_FOLDER, "Open", "Cancel"); location_dialog.set_current_folder (folder_dir); + var arrow = new Gtk.Image () { + gicon = new ThemedIcon ("pan-down-symbolic"), + halign = Gtk.Align.END + }; + var location_button_indicator = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); location_button_indicator.pack_start (folder_icon, false, false); location_button_indicator.pack_start (folder_name, true, true); - location_button_indicator.pack_start (new Gtk.Image.from_icon_name ("document-open-symbolic", Gtk.IconSize.BUTTON), false, false); + location_button_indicator.pack_start (arrow, false, false); var location_button = new Gtk.Button (); location_button.add (location_button_indicator); + var size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.VERTICAL); + size_group.add_widget (format_cmb); + size_group.add_widget (location_button); + var grid = new Gtk.Grid (); grid.margin = 12; grid.margin_top = 0; @@ -205,15 +214,6 @@ public class Screenshot.SaveDialog : Granite.Dialog { location_button.clicked.connect (() => { location_dialog.run (); - var f = new Gtk.FileChooserButton ("HIIIII", Gtk.FileChooserAction.SELECT_FOLDER); - var cont = ((Gtk.Container) f.get_children ().nth_data (0)); - var box = (Gtk.Box) cont.get_children ().nth_data (0); - box.foreach ((item) => { - if (item is Gtk.Image) { - print ("yoohoo\n"); - print ("%s\n", ((Gtk.Image) item).icon_name); - } - }); }); location_dialog.response.connect ((response) => { From bce2a3b0e8df3e160dc5f512966821e6581d8651 Mon Sep 17 00:00:00 2001 From: ZenitsuDev Date: Thu, 19 May 2022 12:44:44 +0800 Subject: [PATCH 4/8] Clean the additions --- src/Widgets/SaveDialog.vala | 44 ++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index 7da2a7c0..fc192f13 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -45,29 +45,10 @@ public class Screenshot.SaveDialog : Granite.Dialog { var folder_from_settings = settings.get_string ("folder-dir"); - var folder_name = new Gtk.Label ("") { - halign = Gtk.Align.START - }; - - var folder_icon = new Gtk.Image () { - pixel_size = 16 - }; - if (folder_from_settings != folder_dir && folder_from_settings != "") { folder_dir = folder_from_settings; } - if (folder_dir == Environment.get_home_dir ()) { - folder_name.label = "Home"; - folder_icon.gicon = new ThemedIcon ("user-home"); - } else if (folder_dir == "/") { - folder_name.label = "File System"; - folder_icon.gicon = new ThemedIcon ("drive-harddisk"); - } else { - folder_name.label = folder_dir.reverse ().split ("/")[0].reverse (); - folder_icon.gicon = new ThemedIcon ("folder"); - } - Application.create_dir_if_missing (folder_dir); int width = pixbuf.get_width () / 4; @@ -150,9 +131,24 @@ public class Screenshot.SaveDialog : Granite.Dialog { var location_label = new Gtk.Label (_("Folder:")); location_label.halign = Gtk.Align.END; - var location_dialog = new Gtk.FileChooserNative (_("Select Screenshots Folder…"), this, - Gtk.FileChooserAction.SELECT_FOLDER, "Open", "Cancel"); - location_dialog.set_current_folder (folder_dir); + var folder_name = new Gtk.Label ("") { + halign = Gtk.Align.START + }; + + var folder_icon = new Gtk.Image () { + pixel_size = 16 + }; + + if (folder_dir == Environment.get_home_dir ()) { + folder_name.label = "Home"; + folder_icon.gicon = new ThemedIcon ("user-home"); + } else if (folder_dir == "/") { + folder_name.label = "File System"; + folder_icon.gicon = new ThemedIcon ("drive-harddisk"); + } else { + folder_name.label = folder_dir.reverse ().split ("/")[0].reverse (); + folder_icon.gicon = new ThemedIcon ("folder"); + } var arrow = new Gtk.Image () { gicon = new ThemedIcon ("pan-down-symbolic"), @@ -167,6 +163,10 @@ public class Screenshot.SaveDialog : Granite.Dialog { var location_button = new Gtk.Button (); location_button.add (location_button_indicator); + var location_dialog = new Gtk.FileChooserNative (_("Select Screenshots Folder…"), this, + Gtk.FileChooserAction.SELECT_FOLDER, "Open", "Cancel"); + location_dialog.set_current_folder (folder_dir); + var size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.VERTICAL); size_group.add_widget (format_cmb); size_group.add_widget (location_button); From 74961a76982bbe662c958a08c29e80589f1b12db Mon Sep 17 00:00:00 2001 From: zenitsudev Date: Wed, 1 Jun 2022 10:59:37 +0800 Subject: [PATCH 5/8] Use Path.get_basename --- src/Widgets/SaveDialog.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index fc192f13..40be2cfe 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -146,7 +146,7 @@ public class Screenshot.SaveDialog : Granite.Dialog { folder_name.label = "File System"; folder_icon.gicon = new ThemedIcon ("drive-harddisk"); } else { - folder_name.label = folder_dir.reverse ().split ("/")[0].reverse (); + folder_name.label = Path.get_basename (folder_dir); folder_icon.gicon = new ThemedIcon ("folder"); } From 9a0996f1e495dbaec26f29a3b482911f98ec6358 Mon Sep 17 00:00:00 2001 From: zenitsudev Date: Wed, 1 Jun 2022 11:04:56 +0800 Subject: [PATCH 6/8] Use add for box --- src/Widgets/SaveDialog.vala | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index 40be2cfe..4902607d 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -132,7 +132,8 @@ public class Screenshot.SaveDialog : Granite.Dialog { location_label.halign = Gtk.Align.END; var folder_name = new Gtk.Label ("") { - halign = Gtk.Align.START + halign = Gtk.Align.START, + hexpand = true }; var folder_icon = new Gtk.Image () { @@ -156,9 +157,9 @@ public class Screenshot.SaveDialog : Granite.Dialog { }; var location_button_indicator = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 0); - location_button_indicator.pack_start (folder_icon, false, false); - location_button_indicator.pack_start (folder_name, true, true); - location_button_indicator.pack_start (arrow, false, false); + location_button_indicator.add (folder_icon); + location_button_indicator.add (folder_name); + location_button_indicator.add (arrow); var location_button = new Gtk.Button (); location_button.add (location_button_indicator); From 3319e8d6ae21106209e905840ef093c640c836aa Mon Sep 17 00:00:00 2001 From: zenitsudev Date: Wed, 1 Jun 2022 11:11:31 +0800 Subject: [PATCH 7/8] Use basename --- src/Widgets/SaveDialog.vala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index 4902607d..0e571aa1 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -232,7 +232,7 @@ public class Screenshot.SaveDialog : Granite.Dialog { folder_name.label = "File System"; folder_icon.gicon = new ThemedIcon ("drive-harddisk"); } else { - folder_name.label = folder_dir.reverse ().split ("/")[0].reverse (); + folder_name.label = Path.get_basename (folder_dir); folder_icon.gicon = new ThemedIcon ("folder"); } } From e9748a60ac001cb7d936fe9b7ee3de14a1624ef1 Mon Sep 17 00:00:00 2001 From: zenitsudev Date: Wed, 1 Jun 2022 04:14:00 +0000 Subject: [PATCH 8/8] Use row_homogeneous in grid --- src/Widgets/SaveDialog.vala | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/src/Widgets/SaveDialog.vala b/src/Widgets/SaveDialog.vala index 0e571aa1..ac56f808 100644 --- a/src/Widgets/SaveDialog.vala +++ b/src/Widgets/SaveDialog.vala @@ -168,25 +168,21 @@ public class Screenshot.SaveDialog : Granite.Dialog { Gtk.FileChooserAction.SELECT_FOLDER, "Open", "Cancel"); location_dialog.set_current_folder (folder_dir); - var size_group = new Gtk.SizeGroup (Gtk.SizeGroupMode.VERTICAL); - size_group.add_widget (format_cmb); - size_group.add_widget (location_button); - var grid = new Gtk.Grid (); grid.margin = 12; - grid.margin_top = 0; grid.row_spacing = 12; grid.column_spacing = 12; - grid.attach (preview_box, 0, 0, 2, 1); - grid.attach (dialog_label, 0, 1, 2, 1); - grid.attach (name_label, 0, 2, 1, 1); - grid.attach (name_entry, 1, 2, 1, 1); - grid.attach (format_label, 0, 3, 1, 1); - grid.attach (format_cmb, 1, 3, 1, 1); - grid.attach (location_label, 0, 4, 1, 1); - grid.attach (location_button, 1, 4, 1, 1); + grid.row_homogeneous = true; + grid.attach (dialog_label, 0, 0, 2, 1); + grid.attach (name_label, 0, 1, 1, 1); + grid.attach (name_entry, 1, 1, 1, 1); + grid.attach (format_label, 0, 2, 1, 1); + grid.attach (format_cmb, 1, 2, 1, 1); + grid.attach (location_label, 0, 3, 1, 1); + grid.attach (location_button, 1, 3, 1, 1); var content = this.get_content_area () as Gtk.Box; + content.add (preview_box); content.add (grid); var clipboard_btn = (Gtk.Button) add_button (_("Copy to Clipboard"), 0);