From 05c16456e7a1fcdc29192e25fe2f3492fda66042 Mon Sep 17 00:00:00 2001 From: Adithyan-KV Date: Thu, 25 Nov 2021 11:04:23 +0530 Subject: [PATCH 1/3] Implements opening images using file chooser --- src/HeaderBar.vala | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/HeaderBar.vala b/src/HeaderBar.vala index 3cee47d..0eb68aa 100644 --- a/src/HeaderBar.vala +++ b/src/HeaderBar.vala @@ -45,7 +45,35 @@ namespace Resizer { info_menu.valign = Gtk.Align.CENTER; info_menu.popover = infoPopover; + var insert_button = new Gtk.Button.from_icon_name ("insert-image", + Gtk.IconSize.SMALL_TOOLBAR); + insert_button.tooltip_text = _("Insert image(s)"); + insert_button.valign = Gtk.Align.CENTER; + insert_button.clicked.connect (open_files_using_file_chooser); + pack_end (info_menu); + pack_end (insert_button); + } + } + + private void open_files_using_file_chooser() { + var file_chooser = new Gtk.FileChooserNative (_("Open Image(s)"), + null, + Gtk.FileChooserAction.OPEN, + _("Open"), + _("Cancel")); + + var files = new GenericArray (); + file_chooser.select_multiple = true; + var response = file_chooser.run(); + if (response == Gtk.ResponseType.ACCEPT) { + var uris = file_chooser.get_uris(); + foreach (var uri in uris) { + stdout.printf ("opening: %s\n", uri); + var file = File.new_for_uri (uri); + files.add(file); + Resizer.get_default().files = files.data; + } } } } From 02ec42c214d5a3d2b1e21d7758866ee0796b810a Mon Sep 17 00:00:00 2001 From: Adithyan-KV Date: Fri, 26 Nov 2021 01:29:47 +0530 Subject: [PATCH 2/3] Changes UI. Moves select images button to drop area --- src/DropArea.vala | 48 +++++++++++++++++++++++++++++++++++++++++----- src/HeaderBar.vala | 28 --------------------------- 2 files changed, 43 insertions(+), 33 deletions(-) diff --git a/src/DropArea.vala b/src/DropArea.vala index aa2963e..19010c9 100644 --- a/src/DropArea.vala +++ b/src/DropArea.vala @@ -24,7 +24,7 @@ namespace Resizer { private Gtk.Image image; private Gtk.Image image2; - private Gtk.Label drag_label; + private Gtk.Box overlay_box; construct { image = new Gtk.Image (); @@ -41,7 +41,20 @@ namespace Resizer { image2.margin_top = 6; image2.visible = false; - drag_label = new Gtk.Label (_("Drop Image(s) Here")); + overlay_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); + overlay_box.valign = Gtk.Align.CENTER; + overlay_box.halign = Gtk.Align.CENTER; + + var or_label = new Gtk.Label(_("or")); + var or_label_style_context = or_label.get_style_context(); + or_label_style_context.add_class(Granite.STYLE_CLASS_H2_LABEL); + or_label_style_context.add_class(Gtk.STYLE_CLASS_DIM_LABEL); + + var select_button = new Gtk.Button.with_label(_("Select image")); + select_button.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION); + select_button.clicked.connect(open_files_using_file_chooser); + + var drag_label = new Gtk.Label (_("Drop Image(s) Here")); drag_label.justify = Gtk.Justification.CENTER; var drag_label_style_context = drag_label.get_style_context (); @@ -53,8 +66,12 @@ namespace Resizer { images.halign = Gtk.Align.CENTER; images.put (image2, 0, 0); images.put (image, 0, 0); + + overlay_box.pack_start(drag_label); + overlay_box.pack_start(or_label); + overlay_box.pack_start(select_button); this.add(images); - this.add_overlay (drag_label); + this.add_overlay (overlay_box); } public void show_preview(File[] files) throws Error { @@ -66,8 +83,8 @@ namespace Resizer { true ); - drag_label.no_show_all = true; - drag_label.visible = false; + overlay_box.no_show_all = true; + overlay_box.visible = false; image.set_from_pixbuf (pixbuf); image.height_request = pixbuf.height; @@ -91,5 +108,26 @@ namespace Resizer { image.margin_top = 6; } } + + private void open_files_using_file_chooser() { + var file_chooser = new Gtk.FileChooserNative (_("Open Image(s)"), + null, + Gtk.FileChooserAction.OPEN, + _("Open"), + _("Cancel")); + + var files = new GenericArray (); + file_chooser.select_multiple = true; + var response = file_chooser.run(); + if (response == Gtk.ResponseType.ACCEPT) { + var uris = file_chooser.get_uris(); + foreach (var uri in uris) { + stdout.printf ("opening: %s\n", uri); + var file = File.new_for_uri (uri); + files.add(file); + Resizer.get_default().files = files.data; + } + } + } } } diff --git a/src/HeaderBar.vala b/src/HeaderBar.vala index 0eb68aa..3cee47d 100644 --- a/src/HeaderBar.vala +++ b/src/HeaderBar.vala @@ -45,35 +45,7 @@ namespace Resizer { info_menu.valign = Gtk.Align.CENTER; info_menu.popover = infoPopover; - var insert_button = new Gtk.Button.from_icon_name ("insert-image", - Gtk.IconSize.SMALL_TOOLBAR); - insert_button.tooltip_text = _("Insert image(s)"); - insert_button.valign = Gtk.Align.CENTER; - insert_button.clicked.connect (open_files_using_file_chooser); - pack_end (info_menu); - pack_end (insert_button); - } - } - - private void open_files_using_file_chooser() { - var file_chooser = new Gtk.FileChooserNative (_("Open Image(s)"), - null, - Gtk.FileChooserAction.OPEN, - _("Open"), - _("Cancel")); - - var files = new GenericArray (); - file_chooser.select_multiple = true; - var response = file_chooser.run(); - if (response == Gtk.ResponseType.ACCEPT) { - var uris = file_chooser.get_uris(); - foreach (var uri in uris) { - stdout.printf ("opening: %s\n", uri); - var file = File.new_for_uri (uri); - files.add(file); - Resizer.get_default().files = files.data; - } } } } From 680addbafaff811fd1741845f50d502769ca0672 Mon Sep 17 00:00:00 2001 From: Adithyan-KV Date: Fri, 26 Nov 2021 01:37:26 +0530 Subject: [PATCH 3/3] Formatting fixes --- src/DropArea.vala | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/src/DropArea.vala b/src/DropArea.vala index 19010c9..4a1a035 100644 --- a/src/DropArea.vala +++ b/src/DropArea.vala @@ -41,18 +41,18 @@ namespace Resizer { image2.margin_top = 6; image2.visible = false; - overlay_box = new Gtk.Box(Gtk.Orientation.VERTICAL, 0); + overlay_box = new Gtk.Box (Gtk.Orientation.VERTICAL, 0); overlay_box.valign = Gtk.Align.CENTER; overlay_box.halign = Gtk.Align.CENTER; - var or_label = new Gtk.Label(_("or")); - var or_label_style_context = or_label.get_style_context(); - or_label_style_context.add_class(Granite.STYLE_CLASS_H2_LABEL); - or_label_style_context.add_class(Gtk.STYLE_CLASS_DIM_LABEL); + var or_label = new Gtk.Label (_("or")); + var or_label_style_context = or_label.get_style_context (); + or_label_style_context.add_class (Granite.STYLE_CLASS_H2_LABEL); + or_label_style_context.add_class (Gtk.STYLE_CLASS_DIM_LABEL); - var select_button = new Gtk.Button.with_label(_("Select image")); - select_button.get_style_context().add_class(Gtk.STYLE_CLASS_SUGGESTED_ACTION); - select_button.clicked.connect(open_files_using_file_chooser); + var select_button = new Gtk.Button.with_label (_("Select image")); + select_button.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION); + select_button.clicked.connect (open_files_using_file_chooser); var drag_label = new Gtk.Label (_("Drop Image(s) Here")); drag_label.justify = Gtk.Justification.CENTER; @@ -67,10 +67,10 @@ namespace Resizer { images.put (image2, 0, 0); images.put (image, 0, 0); - overlay_box.pack_start(drag_label); - overlay_box.pack_start(or_label); - overlay_box.pack_start(select_button); - this.add(images); + overlay_box.pack_start (drag_label); + overlay_box.pack_start (or_label); + overlay_box.pack_start (select_button); + this.add (images); this.add_overlay (overlay_box); } public void show_preview(File[] files) throws Error { @@ -109,7 +109,7 @@ namespace Resizer { } } - private void open_files_using_file_chooser() { + private void open_files_using_file_chooser () { var file_chooser = new Gtk.FileChooserNative (_("Open Image(s)"), null, Gtk.FileChooserAction.OPEN, @@ -118,14 +118,14 @@ namespace Resizer { var files = new GenericArray (); file_chooser.select_multiple = true; - var response = file_chooser.run(); + var response = file_chooser.run (); if (response == Gtk.ResponseType.ACCEPT) { - var uris = file_chooser.get_uris(); + var uris = file_chooser.get_uris (); foreach (var uri in uris) { stdout.printf ("opening: %s\n", uri); var file = File.new_for_uri (uri); - files.add(file); - Resizer.get_default().files = files.data; + files.add (file); + Resizer.get_default ().files = files.data; } } }