Commit 79a41c3578e8503227894b3d4d59cfb6b7a4f38e

Authored by Perry Werneck
1 parent 72fde623

Adding action to open session file in the active terminal.

schemas/linux/application.gschema.xml.in
@@ -45,6 +45,12 @@ @@ -45,6 +45,12 @@
45 <description>Allow changing of host session properties</description> 45 <description>Allow changing of host session properties</description>
46 </key> 46 </key>
47 47
  48 + <key name="allow-open-session-actions" type="b">
  49 + <default>true</default>
  50 + <summary>Enable open session actions actions</summary>
  51 + <description>Enable open session actions</description>
  52 + </key>
  53 +
48 <key name="allow-new-tab-actions" type="b"> 54 <key name="allow-new-tab-actions" type="b">
49 <default>true</default> 55 <default>true</default>
50 <summary>Enable new tab actions</summary> 56 <summary>Enable new tab actions</summary>
schemas/windows/application.gschema.xml.in
@@ -57,6 +57,12 @@ @@ -57,6 +57,12 @@
57 <description>Allow changing of host session properties</description> 57 <description>Allow changing of host session properties</description>
58 </key> 58 </key>
59 59
  60 + <key name="allow-open-session-actions" type="b">
  61 + <default>true</default>
  62 + <summary>Enable open session actions actions</summary>
  63 + <description>Enable open session actions</description>
  64 + </key>
  65 +
60 <key name="allow-new-tab-actions" type="b"> 66 <key name="allow-new-tab-actions" type="b">
61 <default>true</default> 67 <default>true</default>
62 <summary>Enable new tab actions</summary> 68 <summary>Enable new tab actions</summary>
src/objects/application/actions/open.c
@@ -37,6 +37,7 @@ @@ -37,6 +37,7 @@
37 #include <pw3270.h> 37 #include <pw3270.h>
38 #include <pw3270/application.h> 38 #include <pw3270/application.h>
39 #include <pw3270/actions.h> 39 #include <pw3270/actions.h>
  40 + #include <v3270/keyfile.h>
40 41
41 static GtkWidget * session_dialog_new(PW3270Action *action, GtkApplication *application) { 42 static GtkWidget * session_dialog_new(PW3270Action *action, GtkApplication *application) {
42 43
@@ -74,6 +75,57 @@ @@ -74,6 +75,57 @@
74 75
75 } 76 }
76 77
  78 + static void open_session(GtkWidget *dialog, gint response_id, GtkApplication *application) {
  79 +
  80 + if(response_id == GTK_RESPONSE_OK) {
  81 +
  82 + g_autofree gchar * file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
  83 +
  84 + if(file_name) {
  85 + GError * error = NULL;
  86 + GtkWidget * window = GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application)));
  87 + GtkWidget * terminal = pw3270_application_window_get_active_terminal(window);
  88 +
  89 + v3270_disconnect(terminal);
  90 + v3270_key_file_open(terminal,file_name,&error);
  91 +
  92 + if(error) {
  93 +
  94 + GtkWidget * dialog = gtk_message_dialog_new_with_markup(
  95 + GTK_WINDOW(gtk_widget_get_toplevel(terminal)),
  96 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
  97 + GTK_MESSAGE_ERROR,
  98 + GTK_BUTTONS_OK,
  99 + _("Can't use \"%s\""), file_name
  100 + );
  101 +
  102 + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message);
  103 +
  104 + gtk_window_set_title(GTK_WINDOW(dialog),_("Can't load session file"));
  105 +
  106 + gtk_widget_show_all(dialog);
  107 +
  108 + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL);
  109 + g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL);
  110 +
  111 + g_error_free(error);
  112 +
  113 + } else {
  114 +
  115 + gtk_window_present(GTK_WINDOW(window));
  116 +
  117 + }
  118 +
  119 +
  120 + }
  121 +
  122 + }
  123 +
  124 + gtk_widget_destroy(dialog);
  125 +
  126 + }
  127 +
  128 +
77 static void open_tab(GtkWidget *dialog, gint response_id, GtkApplication *application) { 129 static void open_tab(GtkWidget *dialog, gint response_id, GtkApplication *application) {
78 130
79 if(response_id == GTK_RESPONSE_OK) { 131 if(response_id == GTK_RESPONSE_OK) {
@@ -100,6 +152,14 @@ @@ -100,6 +152,14 @@
100 152
101 } 153 }
102 154
  155 + static GtkWidget * open_session_factory(PW3270Action *action, GtkApplication *application) {
  156 +
  157 + GtkWidget * dialog = session_dialog_new(action,application);
  158 + g_signal_connect(dialog,"response",G_CALLBACK(open_session),application);
  159 + return dialog;
  160 +
  161 + }
  162 +
103 static GtkWidget * open_tab_factory(PW3270Action *action, GtkApplication *application) { 163 static GtkWidget * open_tab_factory(PW3270Action *action, GtkApplication *application) {
104 164
105 GtkWidget * dialog = session_dialog_new(action,application); 165 GtkWidget * dialog = session_dialog_new(action,application);
@@ -108,6 +168,19 @@ @@ -108,6 +168,19 @@
108 168
109 } 169 }
110 170
  171 + GAction * pw3270_open_session_action_new() {
  172 +
  173 + PW3270Action * action = pw3270_dialog_action_new(open_session_factory);
  174 +
  175 + action->name = "open.session";
  176 + action->label = _( "Open session" );
  177 + action->tooltip = _( "Open session on the active terminal" );
  178 + action->icon_name = "document-open";
  179 +
  180 + return G_ACTION(action);
  181 +
  182 + }
  183 +
111 GAction * pw3270_open_window_action_new() { 184 GAction * pw3270_open_window_action_new() {
112 185
113 PW3270Action * action = pw3270_dialog_action_new(open_window_factory); 186 PW3270Action * action = pw3270_dialog_action_new(open_window_factory);
src/objects/application/application.c
@@ -375,6 +375,13 @@ @@ -375,6 +375,13 @@
375 } 375 }
376 376
377 // 377 //
  378 + // Open session actions.
  379 + //
  380 + if(g_settings_get_boolean(settings,"allow-open-session-actions")) {
  381 + g_action_map_add_action(G_ACTION_MAP(application),pw3270_open_session_action_new());
  382 + }
  383 +
  384 + //
378 // New tab actions 385 // New tab actions
379 // 386 //
380 if(g_settings_get_boolean(settings,"allow-new-tab-actions")) { 387 if(g_settings_get_boolean(settings,"allow-new-tab-actions")) {
src/objects/application/open.c
@@ -69,10 +69,24 @@ @@ -69,10 +69,24 @@
69 69
70 } 70 }
71 71
  72 + static void save_open_file(GApplication *application, const gchar *path) {
  73 +
  74 + GSettings * settings = pw3270_application_get_settings(application);
  75 +
  76 + if(g_settings_get_boolean(settings,"update-session-file")) {
  77 +
  78 + g_message("Updating default session file to '%s'",path);
  79 + g_settings_set_string(settings,"default-session-file",path);
  80 +
  81 + }
  82 +
  83 + gtk_recent_manager_add_item(gtk_recent_manager_get_default(),path);
  84 +
  85 + }
  86 +
72 void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) { 87 void pw3270_application_open(GApplication *application, GFile **files, gint n_files, const gchar G_GNUC_UNUSED(*hint)) {
73 88
74 GtkWidget * window = GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))); 89 GtkWidget * window = GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application)));
75 - GSettings * settings = pw3270_application_get_settings(application);  
76 90
77 gint file; 91 gint file;
78 92
@@ -116,12 +130,7 @@ @@ -116,12 +130,7 @@
116 pw3270_application_window_new_tab(window,path); 130 pw3270_application_window_new_tab(window,path);
117 } 131 }
118 132
119 - if(g_settings_get_boolean(settings,"update-session-file")) {  
120 -  
121 - g_message("Updating default session file to '%s'",path);  
122 - g_settings_set_string(settings,"default-session-file",path);  
123 -  
124 - } 133 + save_open_file(application,path);
125 134
126 continue; 135 continue;
127 } 136 }
@@ -140,12 +149,7 @@ @@ -140,12 +149,7 @@
140 pw3270_application_window_new_tab(window, filename); 149 pw3270_application_window_new_tab(window, filename);
141 } 150 }
142 151
143 - if(g_settings_get_boolean(settings,"update-session-file")) {  
144 -  
145 - g_message("Updating default session file to '%s'",filename);  
146 - g_settings_set_string(settings,"default-session-file",filename);  
147 -  
148 - } 152 + save_open_file(application,filename);
149 153
150 continue; 154 continue;
151 } 155 }
src/objects/application/private.h
@@ -57,6 +57,7 @@ @@ -57,6 +57,7 @@
57 G_GNUC_INTERNAL GAction * pw3270_new_window_action_new(); 57 G_GNUC_INTERNAL GAction * pw3270_new_window_action_new();
58 G_GNUC_INTERNAL GAction * pw3270_quit_action_new(); 58 G_GNUC_INTERNAL GAction * pw3270_quit_action_new();
59 59
  60 + G_GNUC_INTERNAL GAction * pw3270_open_session_action_new();
60 G_GNUC_INTERNAL GAction * pw3270_open_window_action_new(); 61 G_GNUC_INTERNAL GAction * pw3270_open_window_action_new();
61 G_GNUC_INTERNAL GAction * pw3270_open_tab_action_new(); 62 G_GNUC_INTERNAL GAction * pw3270_open_tab_action_new();
62 63
@@ -53,6 +53,11 @@ @@ -53,6 +53,11 @@
53 <attribute name='label' translatable='yes'>_Open</attribute> 53 <attribute name='label' translatable='yes'>_Open</attribute>
54 54
55 <item> 55 <item>
  56 + <attribute name="label" translatable="yes">Session</attribute>
  57 + <attribute name="action">app.open.session</attribute>
  58 + </item>
  59 +
  60 + <item>
56 <attribute name="label" translatable="yes">Session in new window</attribute> 61 <attribute name="label" translatable="yes">Session in new window</attribute>
57 <attribute name="action">app.open.session.window</attribute> 62 <attribute name="action">app.open.session.window</attribute>
58 </item> 63 </item>