From f78955658a9f4d635dd4dee16811dda1dc50601a Mon Sep 17 00:00:00 2001 From: Perry Werneck Date: Fri, 20 Aug 2021 13:44:40 -0300 Subject: [PATCH] Implementing method to get active session. --- src/include/pw3270/application.h | 4 ++++ src/main/tools.c | 32 +++++++++++--------------------- src/objects/window/tools.c | 26 +++++++------------------- 3 files changed, 22 insertions(+), 40 deletions(-) diff --git a/src/include/pw3270/application.h b/src/include/pw3270/application.h index e886014..36d102a 100644 --- a/src/include/pw3270/application.h +++ b/src/include/pw3270/application.h @@ -37,6 +37,7 @@ #define PW3270_APPLICATION_H_INCLUDED #include +#include G_BEGIN_DECLS @@ -98,6 +99,9 @@ void pw3270_application_save_copy_activated(GAction *action, GVariant *parameter // Settings GtkWidget * pw3270_header_settings_new(); +// Tools +H3270 * pw3270_get_active_session(); + G_END_DECLS diff --git a/src/main/tools.c b/src/main/tools.c index 35cb8ea..1027cd0 100644 --- a/src/main/tools.c +++ b/src/main/tools.c @@ -64,27 +64,6 @@ void gtk_container_remove_all(GtkContainer *container) { } -/* -GtkWidget * pw3270_frame_new(GtkWidget * child, const gchar *title) { - -GtkFrame * frame = GTK_FRAME(gtk_frame_new("")); -g_autofree gchar * markup = g_strdup_printf("%s",title); -GtkWidget * label = gtk_label_new(NULL); - -gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_NONE); -gtk_label_set_markup(GTK_LABEL(label),markup); -gtk_frame_set_label_widget(GTK_FRAME(frame),label); - gtk_container_set_border_width(GTK_CONTAINER(child),12); - -gtk_container_add(GTK_CONTAINER(frame),GTK_WIDGET(child)); - -g_object_set(G_OBJECT(frame),"margin-top",6,NULL); - -return GTK_WIDGET(frame); - -} -*/ - void gtk_file_chooser_set_pw3270_filters(GtkFileChooser *chooser) { static const struct Filter { @@ -112,4 +91,15 @@ void gtk_file_chooser_set_pw3270_filters(GtkFileChooser *chooser) { } +H3270 * pw3270_get_active_session() { + + GApplication *app = g_application_get_default(); + + g_return_val_if_fail(GTK_IS_APPLICATION(app),NULL); + + GtkWindow * window = gtk_application_get_active_window(GTK_APPLICATION(app)); + + return pw3270_window_get_session_handle(GTK_WIDGET(window)); + +} diff --git a/src/objects/window/tools.c b/src/objects/window/tools.c index f551546..2756dcd 100644 --- a/src/objects/window/tools.c +++ b/src/objects/window/tools.c @@ -28,28 +28,16 @@ */ #include "private.h" -#include +#include -/* -GtkWidget * pw3270_setup_image_button(GtkWidget *button, const gchar *image_name) { +H3270 * pw3270_window_get_session_handle(GtkWidget *window) { -gtk_button_set_image(GTK_BUTTON(button),gtk_image_new_from_icon_name(image_name,GTK_ICON_SIZE_MENU)); + g_return_val_if_fail(PW3270_IS_APPLICATION_WINDOW(window),NULL); -gtk_widget_set_can_focus(button,FALSE); -gtk_widget_set_can_default(button,FALSE); -gtk_widget_set_focus_on_click(button,FALSE); + GtkWidget * terminal = PW3270_APPLICATION_WINDOW(window)->terminal; + if(!terminal) + return NULL; -return button; + return v3270_get_session(terminal); } -*/ - -/* - gboolean pw3270_settings_set_int(const gchar *key, gint value) { - - GSettings * settings = pw3270_application_get_settings(g_application_get_default()); - if(settings) - return g_settings_set_int(settings,key,value); - return FALSE; - } -*/ -- libgit2 0.21.2