Commit 8d7453fa50603773b34d3b06b6c6cad03cbdf38f

Authored by Perry Werneck
1 parent e60dfeef

Implementing dialog to save session properties to file.

pw3270.cbp
... ... @@ -134,9 +134,6 @@
134 134 <Unit filename="src/objects/window/actions/hostproperties.c">
135 135 <Option compilerVar="CC" />
136 136 </Unit>
137   - <Unit filename="src/objects/window/actions/print.c">
138   - <Option compilerVar="CC" />
139   - </Unit>
140 137 <Unit filename="src/objects/window/actions/sessionproperties.c">
141 138 <Option compilerVar="CC" />
142 139 </Unit>
... ...
src/include/pw3270.h
... ... @@ -65,6 +65,13 @@
65 65 void (*apply)(Pw3270SettingsPage *, GtkApplication *, GSettings *);
66 66 };
67 67  
  68 + void gtk_file_chooser_set_pw3270_filters(GtkFileChooser *chooser);
  69 +
  70 + const gchar * v3270_get_session_filename(GtkWidget *widget);
  71 + void v3270_set_session_filename(GtkWidget *widget, const gchar *filename);
  72 +
  73 +
  74 +
68 75 G_END_DECLS
69 76  
70 77 #endif // PW3270_H_INCLUDED
... ...
src/main/tools.c
... ... @@ -34,6 +34,7 @@
34 34 */
35 35  
36 36 #include "private.h"
  37 + #include <pw3270.h>
37 38 #include <pw3270/application.h>
38 39 #include <pw3270/settings.h>
39 40  
... ... @@ -82,3 +83,31 @@
82 83  
83 84 }
84 85  
  86 + void gtk_file_chooser_set_pw3270_filters(GtkFileChooser *chooser) {
  87 +
  88 + static const struct Filter {
  89 + const gchar * name;
  90 + const gchar * pattern;
  91 + } filters[] = {
  92 + {
  93 + .name = N_("TN3270 Session Files"),
  94 + .pattern = "*.3270"
  95 + },
  96 + {
  97 + .name = N_("All files"),
  98 + .pattern = "*.*"
  99 + }
  100 + };
  101 +
  102 + size_t ix;
  103 +
  104 + for(ix = 0; ix < G_N_ELEMENTS(filters); ix++) {
  105 + GtkFileFilter *filter = gtk_file_filter_new();
  106 + gtk_file_filter_add_pattern (filter, filters[ix].pattern);
  107 + gtk_file_filter_set_name(filter, filters[ix].name);
  108 + gtk_file_chooser_add_filter(chooser,filter);
  109 + }
  110 +
  111 + }
  112 +
  113 +
... ...
src/objects/actions/save.c
... ... @@ -34,5 +34,65 @@
34 34  
35 35 #include "private.h"
36 36 #include <v3270.h>
  37 + #include <pw3270.h>
37 38 #include <pw3270/application.h>
38 39  
  40 + static gchar * get_session_file_name(GtkWidget *terminal, const gchar *title) {
  41 +
  42 + gchar * filename = NULL;
  43 +
  44 + GtkWidget * dialog =
  45 + gtk_file_chooser_dialog_new(
  46 + title,
  47 + GTK_WINDOW(gtk_widget_get_toplevel(terminal)),
  48 + GTK_FILE_CHOOSER_ACTION_SAVE,
  49 + _("Save"), GTK_RESPONSE_OK,
  50 + _("Cancel"),GTK_RESPONSE_CANCEL,
  51 + NULL
  52 + );
  53 +
  54 + gtk_window_set_modal(GTK_WINDOW(dialog),TRUE);
  55 + gtk_file_chooser_set_pw3270_filters(GTK_FILE_CHOOSER(dialog));
  56 +
  57 + if(terminal) {
  58 + const gchar * current_file = v3270_get_session_filename(terminal);
  59 + if(current_file)
  60 + gtk_file_chooser_set_filename(GTK_FILE_CHOOSER(dialog),current_file);
  61 + }
  62 +
  63 + gtk_widget_show_all(dialog);
  64 + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
  65 + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
  66 + }
  67 +
  68 + gtk_widget_destroy(dialog);
  69 +
  70 + return filename;
  71 + }
  72 +
  73 + static void activate(GAction G_GNUC_UNUSED(*action), GVariant G_GNUC_UNUSED(*parameter), GtkWidget *terminal) {
  74 +
  75 + debug("%s",__FUNCTION__);
  76 +
  77 + g_autofree gchar * filename = get_session_file_name(terminal, _("Save session properties"));
  78 +
  79 + if(!filename)
  80 + return;
  81 +
  82 +
  83 +
  84 + }
  85 +
  86 + GAction * pw3270_action_save_session_as_new(void) {
  87 +
  88 + pw3270SimpleAction * action = pw3270_simple_action_new();
  89 +
  90 + action->parent.name = "save.session.as";
  91 + action->parent.activate = activate;
  92 + action->label = N_("Save As");
  93 + action->icon_name = "document-save-as";
  94 + action->tooltip = N_("Save session properties to file");
  95 +
  96 + return G_ACTION(action);
  97 +
  98 + }
... ...
src/objects/application/actions/open.c
... ... @@ -34,35 +34,9 @@
34 34  
35 35 #include "../private.h"
36 36 #include <v3270.h>
  37 + #include <pw3270.h>
37 38 #include <pw3270/application.h>
38 39  
39   - static void set_file_filters(GtkFileChooser *chooser) {
40   -
41   - static const struct Filter {
42   - const gchar * name;
43   - const gchar * pattern;
44   - } filters[] = {
45   - {
46   - .name = N_("TN3270 Session Files"),
47   - .pattern = "*.3270"
48   - },
49   - {
50   - .name = N_("All files"),
51   - .pattern = "*.*"
52   - }
53   - };
54   -
55   - size_t ix;
56   -
57   - for(ix = 0; ix < G_N_ELEMENTS(filters); ix++) {
58   - GtkFileFilter *filter = gtk_file_filter_new();
59   - gtk_file_filter_add_pattern (filter, filters[ix].pattern);
60   - gtk_file_filter_set_name(filter, filters[ix].name);
61   - gtk_file_chooser_add_filter(chooser,filter);
62   - }
63   -
64   - }
65   -
66 40 static gchar * get_session_file_name(GtkApplication *application, const gchar *title) {
67 41  
68 42 gchar * filename = NULL;
... ... @@ -77,7 +51,7 @@
77 51 NULL
78 52 );
79 53  
80   - set_file_filters(GTK_FILE_CHOOSER(dialog));
  54 + gtk_file_chooser_set_pw3270_filters(GTK_FILE_CHOOSER(dialog));
81 55  
82 56 gtk_widget_show_all(dialog);
83 57 if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
... ...
src/objects/window/private.h
... ... @@ -79,6 +79,7 @@
79 79 G_GNUC_INTERNAL GAction * pw3270_file_transfer_action_new(void);
80 80 G_GNUC_INTERNAL GAction * pw3270_action_window_close_new(void);
81 81 G_GNUC_INTERNAL GAction * pw3270_action_connect_new(void);
  82 + G_GNUC_INTERNAL GAction * pw3270_action_save_session_as_new(void);
82 83  
83 84 GAction * pw3270_action_session_properties_new(void);
84 85  
... ...
src/objects/window/terminal.c
... ... @@ -311,6 +311,18 @@
311 311 g_free(session);
312 312 }
313 313  
  314 + const gchar * v3270_get_session_filename(GtkWidget *widget) {
  315 +
  316 + g_return_val_if_fail(GTK_IS_V3270(widget),NULL);
  317 +
  318 + const struct SessionDescriptor * descriptor = (const struct SessionDescriptor *) g_object_get_data(G_OBJECT(widget),"session-descriptor");
  319 +
  320 + if(descriptor)
  321 + return descriptor->filename;
  322 +
  323 + return NULL;
  324 + }
  325 +
314 326 GtkWidget * pw3270_terminal_new(GtkWidget *widget, const gchar *session_file) {
315 327  
316 328 struct SessionDescriptor * descriptor;
... ...
src/objects/window/window.c
... ... @@ -162,6 +162,8 @@
162 162 pw3270_action_session_properties_new(),
163 163 pw3270_set_color_action_new(),
164 164  
  165 + pw3270_action_save_session_as_new(),
  166 +
165 167 pw3270_file_transfer_action_new(),
166 168  
167 169 pw3270_action_window_close_new(),
... ...
ui/application.xml
... ... @@ -31,10 +31,16 @@
31 31 <requires lib="gtk+" version="3.0"/>
32 32 <menu id="app-menu">
33 33  
34   - <item>
35   - <attribute name="label" translatable="yes">About PW3270</attribute>
36   - <attribute name="action">app.about</attribute>
37   - </item>
  34 + <submenu id="help-menu-placeholder">
  35 +
  36 + <attribute name='label' translatable='yes'>Help</attribute>
  37 +
  38 + <item>
  39 + <attribute name="label" translatable="yes">About PW3270</attribute>
  40 + <attribute name="action">app.about</attribute>
  41 + </item>
  42 +
  43 + </submenu>
38 44  
39 45 <submenu>
40 46  
... ... @@ -92,43 +98,84 @@
92 98  
93 99 <attribute name='label' translatable='yes'>_File</attribute>
94 100  
95   - <section>
  101 + <submenu>
  102 +
  103 + <attribute name='label' translatable='yes'>_New</attribute>
  104 +
  105 + <item>
  106 + <attribute name="label" translatable="yes">Window with default session</attribute>
  107 + <attribute name="action">app.new.window</attribute>
  108 + </item>
  109 +
  110 + <item>
  111 + <attribute name="label" translatable="yes">Tab with default session</attribute>
  112 + <attribute name="action">app.new.tab</attribute>
  113 + </item>
  114 +
  115 + </submenu>
  116 +
  117 + <submenu>
  118 +
  119 + <attribute name='label' translatable='yes'>_Open</attribute>
  120 +
  121 + <item>
  122 + <attribute name="label" translatable="yes">Session in new window</attribute>
  123 + <attribute name="action">app.open.session.window</attribute>
  124 + </item>
96 125  
97 126 <item>
98   - <attribute name="label" translatable="yes">Save screen</attribute>
  127 + <attribute name="label" translatable="yes">Session in New Tab</attribute>
  128 + <attribute name="action">app.open.session.tab</attribute>
  129 + </item>
  130 +
  131 + </submenu>
  132 +
  133 + <submenu>
  134 +
  135 + <attribute name='label' translatable='yes'>Save</attribute>
  136 +
  137 + <item>
  138 + <attribute name="label" translatable="yes">Session properties</attribute>
  139 + <attribute name="action">win.save.session.as</attribute>
  140 + </item>
  141 +
  142 + <item>
  143 + <attribute name="label" translatable="yes">Current screen</attribute>
99 144 <attribute name="action">win.save-all</attribute>
100 145 </item>
101 146  
102 147 <item>
103   - <attribute name="label" translatable="yes">Save selected</attribute>
  148 + <attribute name="label" translatable="yes">Selected area</attribute>
104 149 <attribute name="action">win.save-selected</attribute>
105 150 </item>
106 151  
107 152 <item>
108   - <attribute name="label" translatable="yes">Save copy</attribute>
  153 + <attribute name="label" translatable="yes">Clipboard contents</attribute>
109 154 <attribute name="action">win.save-copy</attribute>
110 155 </item>
111 156  
112   - </section>
  157 + </submenu>
113 158  
114   - <section>
  159 + <submenu>
  160 +
  161 + <attribute name='label' translatable='yes'>Print</attribute>
115 162  
116 163 <item>
117   - <attribute name="label" translatable="yes">Print Screen</attribute>
  164 + <attribute name="label" translatable="yes">Current Screen</attribute>
118 165 <attribute name="action">win.print-all</attribute>
119 166 </item>
120 167  
121 168 <item>
122   - <attribute name="label" translatable="yes">Print selected</attribute>
  169 + <attribute name="label" translatable="yes">Selected area</attribute>
123 170 <attribute name="action">win.print-selected</attribute>
124 171 </item>
125 172  
126 173 <item>
127   - <attribute name="label" translatable="yes">Print copy</attribute>
  174 + <attribute name="label" translatable="yes">Clipboard contents</attribute>
128 175 <attribute name="action">win.print-copy</attribute>
129 176 </item>
130 177  
131   - </section>
  178 + </submenu>
132 179  
133 180 <section>
134 181  
... ... @@ -137,10 +184,31 @@
137 184 <attribute name="action">win.file.transfer</attribute>
138 185 </item>
139 186  
  187 + <submenu>
  188 +
  189 + <attribute name='label' translatable='yes'>Preferences</attribute>
  190 +
  191 + <item>
  192 + <attribute name="label" translatable="yes">Application</attribute>
  193 + <attribute name="action">app.preferences</attribute>
  194 + </item>
  195 +
  196 + <item>
  197 + <attribute name="label" translatable="yes">Current session</attribute>
  198 + <attribute name="action">win.session.properties</attribute>
  199 + </item>
  200 +
  201 + </submenu>
  202 +
140 203 <item>
  204 + <attribute name="label" translatable="yes">Close window</attribute>
  205 + <attribute name="action">win.close</attribute>
  206 + </item>
  207 +
  208 + <!-- item>
141 209 <attribute name="label" translatable="yes">Quit application</attribute>
142 210 <attribute name="action">app.quit</attribute>
143   - </item>
  211 + </item -->
144 212  
145 213 </section>
146 214  
... ... @@ -447,7 +515,7 @@
447 515  
448 516 </submenu>
449 517  
450   - <submenu>
  518 + <submenu id="help-menu-placeholder">
451 519  
452 520 <attribute name='label' translatable='yes'>Help</attribute>
453 521  
... ...