Commit 6ca8c69cfe8a4d7ad6345bbb531b0f09eef5aba6
1 parent
ed47edc8
Exists in
master
and in
2 other branches
Refactoring 'save session properties' action.
Showing
5 changed files
with
116 additions
and
43 deletions
Show diff stats
src/objects/actions/save.c
... | ... | @@ -37,19 +37,44 @@ |
37 | 37 | #include <v3270/keyfile.h> |
38 | 38 | #include <pw3270.h> |
39 | 39 | #include <pw3270/application.h> |
40 | - | |
40 | + #include <pw3270/tools.h> | |
41 | + #include <v3270/settings.h> | |
41 | 42 | |
42 | 43 | static GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal); |
43 | 44 | static void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal); |
44 | 45 | |
45 | - GAction * pw3270_action_save_session_as_new(void) { | |
46 | + static const struct Entry { | |
47 | + | |
48 | + const gchar *label; | |
49 | + const gchar *tooltip; | |
50 | + const gint width; | |
51 | + | |
52 | + } entries[] = { | |
53 | + | |
54 | + // 0 = Session name | |
55 | + { | |
56 | + .label = N_("Session name"), | |
57 | + .tooltip = N_("The session name used in the window/tab title (empty for default)"), | |
58 | + .width = 15, | |
59 | + }, | |
60 | + | |
61 | + // 1 = Session file | |
62 | + { | |
63 | + .label = N_("Session file"), | |
64 | + .tooltip = N_("The file to save the current session preferences"), | |
65 | + .width = 40, | |
66 | + } | |
67 | + | |
68 | + }; | |
69 | + | |
70 | + GAction * pw3270_action_save_session_preferences_new(void) { | |
46 | 71 | |
47 | 72 | V3270SimpleAction * action = v3270_dialog_action_new(factory); |
48 | 73 | |
49 | - action->name = "save.session.as"; | |
50 | - action->label = _("Save As"); | |
74 | + action->name = "save.session.preferences"; | |
75 | + action->label = _("Save session preferences"); | |
51 | 76 | action->icon_name = "document-save-as"; |
52 | - action->tooltip = _("Save session preferences"); | |
77 | + action->tooltip = _("Save current session preferences to file"); | |
53 | 78 | |
54 | 79 | return G_ACTION(action); |
55 | 80 | |
... | ... | @@ -57,64 +82,113 @@ |
57 | 82 | |
58 | 83 | GtkWidget * factory(V3270SimpleAction *action, GtkWidget *terminal) { |
59 | 84 | |
85 | + // Create dialog | |
86 | + gboolean use_header; | |
87 | + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); | |
88 | + | |
60 | 89 | GtkWidget * dialog = |
61 | - gtk_file_chooser_dialog_new( | |
62 | - action->tooltip, | |
63 | - GTK_WINDOW(gtk_widget_get_toplevel(terminal)), | |
64 | - GTK_FILE_CHOOSER_ACTION_SAVE, | |
65 | - _("Save"), GTK_RESPONSE_OK, | |
66 | - _("Cancel"),GTK_RESPONSE_CANCEL, | |
67 | - NULL | |
68 | - ); | |
90 | + GTK_WIDGET(g_object_new( | |
91 | + GTK_TYPE_DIALOG, | |
92 | + "use-header-bar", (use_header ? 1 : 0), | |
93 | + NULL | |
94 | + )); | |
95 | + | |
69 | 96 | |
70 | 97 | gtk_window_set_modal(GTK_WINDOW(dialog),TRUE); |
71 | - gtk_file_chooser_set_pw3270_filters(GTK_FILE_CHOOSER(dialog)); | |
98 | + gtk_window_set_title(GTK_WINDOW(dialog),action->label); | |
99 | + | |
100 | + gtk_dialog_add_buttons( | |
101 | + GTK_DIALOG(dialog), | |
102 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | |
103 | + _("_Save"), GTK_RESPONSE_APPLY, | |
104 | + NULL | |
105 | + ); | |
106 | + | |
107 | + | |
108 | + // Create entry fields | |
109 | + GtkWidget ** inputs = g_new0(GtkWidget *,G_N_ELEMENTS(entries)); | |
110 | + g_object_set_data_full(G_OBJECT(dialog),"inputs",inputs,g_free); | |
111 | + debug("Dialog=%p inputs=%p",dialog,inputs); | |
112 | + | |
113 | + GtkGrid * grid = GTK_GRID(gtk_grid_new()); | |
114 | + | |
115 | + gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),GTK_WIDGET(grid),TRUE,TRUE,0); | |
116 | + | |
117 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | |
118 | + gtk_container_set_border_width(GTK_CONTAINER(grid),18); | |
119 | + gtk_grid_set_row_spacing(GTK_GRID(grid),6); | |
120 | + gtk_grid_set_column_spacing(GTK_GRID(grid),12); | |
121 | + | |
122 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | |
123 | + // gtk_box_set_spacing(GTK_BOX(content_area),18); | |
124 | + | |
125 | + size_t ix; | |
126 | + for(ix = 0; ix < G_N_ELEMENTS(entries); ix++) { | |
127 | + | |
128 | + GtkWidget * label = gtk_label_new(gettext(entries[ix].label)); | |
129 | + gtk_label_set_xalign(GTK_LABEL(label),1); | |
130 | + gtk_grid_attach(grid,label,0,ix,1,1); | |
131 | + | |
132 | + inputs[ix] = gtk_entry_new(); | |
133 | + | |
134 | + if(entries[ix].tooltip) { | |
135 | + gtk_widget_set_tooltip_markup(GTK_WIDGET(inputs[ix]),gettext(entries[ix].tooltip)); | |
136 | + } | |
137 | + | |
138 | + gtk_entry_set_width_chars(GTK_ENTRY(inputs[ix]),entries[ix].width); | |
139 | + gtk_widget_set_hexpand(inputs[ix],FALSE); | |
140 | + gtk_widget_set_vexpand(inputs[ix],FALSE); | |
141 | + | |
142 | + gtk_grid_attach(grid,inputs[ix],1,ix,entries[ix].width,1); | |
72 | 143 | |
73 | - if(terminal) { | |
74 | - g_autofree gchar * filename = v3270_key_file_build_filename(terminal); | |
75 | - gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog),filename); | |
76 | 144 | } |
77 | 145 | |
146 | + gtk_entry_bind_to_filechooser( | |
147 | + inputs[1], | |
148 | + GTK_FILE_CHOOSER_ACTION_SAVE, | |
149 | + _("Save session preferences"), | |
150 | + NULL, | |
151 | + "*.3270", | |
152 | + _("3270 session files") | |
153 | + ); | |
154 | + | |
78 | 155 | g_signal_connect(dialog,"response",G_CALLBACK(response),terminal); |
79 | 156 | |
80 | - gtk_widget_show_all(dialog); | |
157 | + gtk_widget_show_all(GTK_WIDGET(grid)); | |
81 | 158 | return dialog; |
159 | + | |
82 | 160 | } |
83 | 161 | |
84 | 162 | void response(GtkWidget *dialog, gint response_id, GtkWidget *terminal) { |
85 | 163 | |
86 | - debug("%s(%d)",__FUNCTION__,response_id); | |
87 | - | |
88 | - g_autofree gchar * filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
164 | + if(response_id == GTK_RESPONSE_APPLY) { | |
89 | 165 | |
90 | - gtk_widget_destroy(dialog); | |
166 | + GtkWidget ** inputs = g_object_get_data(G_OBJECT(dialog),"inputs"); | |
167 | + gtk_widget_hide(dialog); | |
91 | 168 | |
92 | - if(response_id == GTK_RESPONSE_OK) { | |
93 | 169 | GError * error = NULL; |
94 | - v3270_key_file_open(terminal,filename,&error); | |
170 | + v3270_key_file_save_to_file( | |
171 | + terminal, | |
172 | + gtk_entry_get_text(GTK_ENTRY(inputs[1])), | |
173 | + &error | |
174 | + ); | |
95 | 175 | |
96 | 176 | if(error) { |
97 | 177 | |
98 | - GtkWidget * dialog = gtk_message_dialog_new_with_markup( | |
99 | - GTK_WINDOW(gtk_widget_get_toplevel(terminal)), | |
100 | - GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT, | |
101 | - GTK_MESSAGE_ERROR, | |
102 | - GTK_BUTTONS_CANCEL, | |
103 | - _("Can't open \"%s\""),filename | |
104 | - ); | |
105 | - | |
106 | - gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog),"%s",error->message); | |
107 | - | |
108 | - gtk_window_set_title(GTK_WINDOW(dialog),_("Can't load session file")); | |
178 | + g_message("%s",error->message); | |
179 | + g_error_free(error); | |
109 | 180 | |
110 | - gtk_widget_show_all(dialog); | |
181 | + } else { | |
111 | 182 | |
112 | - g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | |
113 | - g_signal_connect(dialog,"response",G_CALLBACK(gtk_widget_destroy),NULL); | |
183 | + // Set session name (after save to avoid changes on the old session file). | |
184 | + v3270_set_session_name(terminal,gtk_entry_get_text(GTK_ENTRY(inputs[0]))); | |
185 | + v3270_emit_save_settings(terminal,NULL); | |
114 | 186 | |
115 | - g_error_free(error); | |
116 | 187 | } |
117 | 188 | |
118 | 189 | } |
119 | 190 | |
191 | + | |
192 | + gtk_widget_destroy(dialog); | |
193 | + | |
120 | 194 | } | ... | ... |
src/objects/os/linux/savedesktopicon.c
src/objects/window/private.h
... | ... | @@ -90,7 +90,7 @@ |
90 | 90 | G_GNUC_INTERNAL GAction * pw3270_file_transfer_action_new(void); |
91 | 91 | G_GNUC_INTERNAL GAction * pw3270_action_window_close_new(void); |
92 | 92 | G_GNUC_INTERNAL GAction * pw3270_action_connect_new(void); |
93 | - G_GNUC_INTERNAL GAction * pw3270_action_save_session_as_new(void); | |
93 | + G_GNUC_INTERNAL GAction * pw3270_action_save_session_preferences_new(void); | |
94 | 94 | G_GNUC_INTERNAL GAction * pw3270_action_save_desktop_icon_new(void); |
95 | 95 | |
96 | 96 | GAction * pw3270_action_session_properties_new(void); | ... | ... |
src/objects/window/window.c
ui/window.xml
... | ... | @@ -96,7 +96,7 @@ |
96 | 96 | |
97 | 97 | <item> |
98 | 98 | <attribute name="label" translatable="yes">Session preferences</attribute> |
99 | - <attribute name="action">win.save.session.as</attribute> | |
99 | + <attribute name="action">win.save.session.preferences</attribute> | |
100 | 100 | </item> |
101 | 101 | |
102 | 102 | </section> | ... | ... |