Commit a31b15c18d8fa9dea5a37fcacd3240338153ff6d
1 parent
49c725e0
Exists in
master
and in
4 other branches
Implementing session name change dialog.
Showing
9 changed files
with
107 additions
and
106 deletions
Show diff stats
pw3270.cbp
@@ -147,6 +147,9 @@ | @@ -147,6 +147,9 @@ | ||
147 | <Option compilerVar="CC" /> | 147 | <Option compilerVar="CC" /> |
148 | </Unit> | 148 | </Unit> |
149 | <Unit filename="src/objects/window/private.h" /> | 149 | <Unit filename="src/objects/window/private.h" /> |
150 | + <Unit filename="src/objects/window/rename.c"> | ||
151 | + <Option compilerVar="CC" /> | ||
152 | + </Unit> | ||
150 | <Unit filename="src/objects/window/terminal.c"> | 153 | <Unit filename="src/objects/window/terminal.c"> |
151 | <Option compilerVar="CC" /> | 154 | <Option compilerVar="CC" /> |
152 | </Unit> | 155 | </Unit> |
src/include/pw3270.h
@@ -70,7 +70,7 @@ | @@ -70,7 +70,7 @@ | ||
70 | const gchar * v3270_get_session_filename(GtkWidget *widget); | 70 | const gchar * v3270_get_session_filename(GtkWidget *widget); |
71 | void v3270_set_session_filename(GtkWidget *widget, const gchar *filename); | 71 | void v3270_set_session_filename(GtkWidget *widget, const gchar *filename); |
72 | 72 | ||
73 | - | 73 | + GtkWidget * pw3270_settings_dialog_new(const gchar *title, GtkWindow *parent); |
74 | 74 | ||
75 | G_END_DECLS | 75 | G_END_DECLS |
76 | 76 |
src/include/pw3270/window.h
@@ -59,6 +59,8 @@ | @@ -59,6 +59,8 @@ | ||
59 | GType pw3270ApplicationWindow_get_type(); | 59 | GType pw3270ApplicationWindow_get_type(); |
60 | GtkWidget * pw3270_application_window_new(GtkApplication * app, const gchar *session_file); | 60 | GtkWidget * pw3270_application_window_new(GtkApplication * app, const gchar *session_file); |
61 | 61 | ||
62 | + gint pw3270_application_window_append_page(GtkWidget *window, GtkWidget *terminal); | ||
63 | + | ||
62 | /// @brief Set the active terminal widget. | 64 | /// @brief Set the active terminal widget. |
63 | void pw3270_application_window_set_active_terminal(GtkWidget *window, GtkWidget *terminal); | 65 | void pw3270_application_window_set_active_terminal(GtkWidget *window, GtkWidget *terminal); |
64 | 66 |
src/main/tools.c
@@ -110,4 +110,34 @@ | @@ -110,4 +110,34 @@ | ||
110 | 110 | ||
111 | } | 111 | } |
112 | 112 | ||
113 | + GtkWidget * pw3270_settings_dialog_new(const gchar *title, GtkWindow *parent) { | ||
114 | + | ||
115 | + gboolean use_header; | ||
116 | + g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); | ||
117 | + | ||
118 | + GtkWidget * dialog = | ||
119 | + GTK_WIDGET(g_object_new( | ||
120 | + GTK_TYPE_DIALOG, | ||
121 | + "use-header-bar", (use_header ? 1 : 0), | ||
122 | + NULL | ||
123 | + )); | ||
124 | + | ||
125 | + gtk_window_set_title(GTK_WINDOW(dialog),title); | ||
126 | + gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | ||
127 | + gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | ||
128 | + gtk_window_set_transient_for(GTK_WINDOW(dialog),parent); | ||
129 | + | ||
130 | + g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | ||
131 | + | ||
132 | + gtk_dialog_add_buttons( | ||
133 | + GTK_DIALOG(dialog), | ||
134 | + _("_Cancel"), GTK_RESPONSE_CANCEL, | ||
135 | + _("_Apply"), GTK_RESPONSE_APPLY, | ||
136 | + NULL | ||
137 | + ); | ||
138 | + | ||
139 | + return dialog; | ||
140 | + | ||
141 | + } | ||
142 | + | ||
113 | 143 |
src/objects/application/actions/preferences.c
@@ -128,29 +128,10 @@ | @@ -128,29 +128,10 @@ | ||
128 | debug("%s",__FUNCTION__); | 128 | debug("%s",__FUNCTION__); |
129 | 129 | ||
130 | // Create dialog. | 130 | // Create dialog. |
131 | - gboolean use_header; | ||
132 | - g_object_get(gtk_settings_get_default(), "gtk-dialogs-use-header", &use_header, NULL); | ||
133 | - | ||
134 | - GtkWidget * dialog = | ||
135 | - GTK_WIDGET(g_object_new( | ||
136 | - GTK_TYPE_DIALOG, | ||
137 | - "use-header-bar", (use_header ? 1 : 0), | ||
138 | - NULL | ||
139 | - )); | ||
140 | - | ||
141 | - gtk_window_set_title(GTK_WINDOW(dialog),_("Application preferences")); | ||
142 | - gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | ||
143 | - gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog), TRUE); | ||
144 | - | ||
145 | - gtk_window_set_transient_for(GTK_WINDOW(dialog),gtk_application_get_active_window(GTK_APPLICATION(application))); | ||
146 | - gtk_window_set_destroy_with_parent(GTK_WINDOW(dialog),TRUE); | ||
147 | - | ||
148 | - gtk_dialog_add_buttons( | ||
149 | - GTK_DIALOG(dialog), | ||
150 | - _("_Cancel"), GTK_RESPONSE_CANCEL, | ||
151 | - _("_Apply"), GTK_RESPONSE_APPLY, | ||
152 | - NULL | ||
153 | - ); | 131 | + GtkWidget * dialog = pw3270_settings_dialog_new( |
132 | + _("Application preferences"), | ||
133 | + gtk_application_get_active_window(GTK_APPLICATION(application)) | ||
134 | + ); | ||
154 | 135 | ||
155 | // Create setttings data. | 136 | // Create setttings data. |
156 | Pw3270SettingsDialog * settings = g_new0(Pw3270SettingsDialog,1); | 137 | Pw3270SettingsDialog * settings = g_new0(Pw3270SettingsDialog,1); |
@@ -159,7 +140,6 @@ | @@ -159,7 +140,6 @@ | ||
159 | settings->application = G_APPLICATION(application); | 140 | settings->application = G_APPLICATION(application); |
160 | 141 | ||
161 | g_simple_action_set_enabled(action,FALSE); | 142 | g_simple_action_set_enabled(action,FALSE); |
162 | - gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | ||
163 | 143 | ||
164 | // Create settings notebook. | 144 | // Create settings notebook. |
165 | 145 | ||
@@ -177,7 +157,6 @@ | @@ -177,7 +157,6 @@ | ||
177 | // Connection signals. | 157 | // Connection signals. |
178 | g_signal_connect(dialog,"destroy",G_CALLBACK(on_destroy),settings); | 158 | g_signal_connect(dialog,"destroy",G_CALLBACK(on_destroy),settings); |
179 | g_signal_connect(dialog,"response",G_CALLBACK(on_response),settings); | 159 | g_signal_connect(dialog,"response",G_CALLBACK(on_response),settings); |
180 | - g_signal_connect(dialog,"close",G_CALLBACK(gtk_widget_destroy),NULL); | ||
181 | 160 | ||
182 | // Load pages. | 161 | // Load pages. |
183 | Pw3270SettingsPage * pages[] = { | 162 | Pw3270SettingsPage * pages[] = { |
@@ -199,7 +178,6 @@ | @@ -199,7 +178,6 @@ | ||
199 | 178 | ||
200 | // Show dialog. | 179 | // Show dialog. |
201 | gtk_widget_show_all(dialog); | 180 | gtk_widget_show_all(dialog); |
202 | - gtk_window_set_deletable(GTK_WINDOW(dialog),FALSE); | ||
203 | 181 | ||
204 | } | 182 | } |
205 | 183 |
src/objects/application/private.h
@@ -47,7 +47,6 @@ | @@ -47,7 +47,6 @@ | ||
47 | #include <lib3270/log.h> | 47 | #include <lib3270/log.h> |
48 | 48 | ||
49 | G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint); | 49 | G_GNUC_INTERNAL void pw3270_application_open(GApplication * application, GFile **files, gint n_files, const gchar *hint); |
50 | - G_GNUC_INTERNAL gint pw3270_application_window_append_page(GtkWidget *window, GtkWidget *terminal); | ||
51 | G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file); | 50 | G_GNUC_INTERNAL GtkWidget * pw3270_terminal_new(const gchar *session_file); |
52 | 51 | ||
53 | // Actions | 52 | // Actions |
src/objects/window/page.c
@@ -33,6 +33,7 @@ | @@ -33,6 +33,7 @@ | ||
33 | #include <v3270/settings.h> | 33 | #include <v3270/settings.h> |
34 | #include <v3270/actions.h> | 34 | #include <v3270/actions.h> |
35 | #include <v3270/print.h> | 35 | #include <v3270/print.h> |
36 | + #include <pw3270.h> | ||
36 | 37 | ||
37 | //---[ Gtk Label with customized popup-menu ]--------------------------------------------------------------------------------------- | 38 | //---[ Gtk Label with customized popup-menu ]--------------------------------------------------------------------------------------- |
38 | 39 | ||
@@ -110,7 +111,7 @@ | @@ -110,7 +111,7 @@ | ||
110 | static gboolean on_popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEvent *event, pw3270ApplicationWindow * window); | 111 | static gboolean on_popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEvent *event, pw3270ApplicationWindow * window); |
111 | static void label_populate_popup(GtkLabel *label, GtkMenu *menu, GtkWidget *terminal); | 112 | static void label_populate_popup(GtkLabel *label, GtkMenu *menu, GtkWidget *terminal); |
112 | 113 | ||
113 | - gint pw3270_application_window_append_page(pw3270ApplicationWindow * window, GtkWidget * terminal) { | 114 | + gint pw3270_application_window_append_page(GtkWidget * window, GtkWidget * terminal) { |
114 | 115 | ||
115 | GtkWidget * label = | 116 | GtkWidget * label = |
116 | GTK_WIDGET( | 117 | GTK_WIDGET( |
@@ -123,13 +124,12 @@ | @@ -123,13 +124,12 @@ | ||
123 | 124 | ||
124 | // gtk_label_new(v3270_get_session_name(terminal)); | 125 | // gtk_label_new(v3270_get_session_name(terminal)); |
125 | 126 | ||
126 | - GtkWidget * tab = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2); | ||
127 | - GtkWidget * button = gtk_button_new_from_icon_name("window-close-symbolic",GTK_ICON_SIZE_MENU); | 127 | + GtkWidget * tab = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,2); |
128 | + GtkWidget * button = gtk_button_new_from_icon_name("window-close-symbolic",GTK_ICON_SIZE_MENU); | ||
129 | + GtkNotebook * notebook = PW3270_APPLICATION_WINDOW(window)->notebook; | ||
128 | 130 | ||
129 | gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE); | 131 | gtk_button_set_relief(GTK_BUTTON(button),GTK_RELIEF_NONE); |
130 | 132 | ||
131 | - debug("notebook: %p", window->notebook); | ||
132 | - | ||
133 | g_signal_connect(G_OBJECT(label), "populate-popup", G_CALLBACK(label_populate_popup), terminal); | 133 | g_signal_connect(G_OBJECT(label), "populate-popup", G_CALLBACK(label_populate_popup), terminal); |
134 | 134 | ||
135 | g_signal_connect(G_OBJECT(terminal), "focus-in-event", G_CALLBACK(on_terminal_focus), window); | 135 | g_signal_connect(G_OBJECT(terminal), "focus-in-event", G_CALLBACK(on_terminal_focus), window); |
@@ -147,14 +147,10 @@ | @@ -147,14 +147,10 @@ | ||
147 | gtk_widget_show_all(terminal); | 147 | gtk_widget_show_all(terminal); |
148 | gtk_widget_show_all(tab); | 148 | gtk_widget_show_all(tab); |
149 | 149 | ||
150 | - gint page = gtk_notebook_append_page(window->notebook,terminal,tab); | ||
151 | - | ||
152 | - gtk_notebook_set_tab_detachable(window->notebook,terminal,TRUE); | ||
153 | - gtk_notebook_set_tab_reorderable(window->notebook,terminal,TRUE); | ||
154 | - | ||
155 | - // Setup session. | 150 | + gint page = gtk_notebook_append_page(notebook,terminal,tab); |
156 | 151 | ||
157 | -// H3270 * hSession = v3270_get_session(terminal); | 152 | + gtk_notebook_set_tab_detachable(notebook,terminal,TRUE); |
153 | + gtk_notebook_set_tab_reorderable(notebook,terminal,TRUE); | ||
158 | 154 | ||
159 | return page; | 155 | return page; |
160 | 156 | ||
@@ -164,47 +160,6 @@ | @@ -164,47 +160,6 @@ | ||
164 | 160 | ||
165 | gtk_widget_grab_default(terminal); | 161 | gtk_widget_grab_default(terminal); |
166 | pw3270_application_window_set_active_terminal(window,terminal); | 162 | pw3270_application_window_set_active_terminal(window,terminal); |
167 | - | ||
168 | - /* | ||
169 | - if(gtk_window_get_default_widget(window) == terminal) { | ||
170 | - return FALSE; | ||
171 | - } | ||
172 | - | ||
173 | - // Store the active terminal widget. | ||
174 | - gtk_widget_grab_default(terminal); | ||
175 | - debug("Terminal %p is now default",terminal); | ||
176 | - | ||
177 | - // Change window title | ||
178 | - g_autofree gchar * title = v3270_get_session_title(terminal); | ||
179 | - gtk_window_set_title(window, title); | ||
180 | - | ||
181 | - pw3270_window_set_subtitle(GTK_WIDGET(window), v3270_is_connected(terminal) ? _("Connected to host") : _("Disconnected from host")); | ||
182 | - | ||
183 | - // Update actions | ||
184 | - size_t ix; | ||
185 | - gchar ** actions = g_action_group_list_actions(G_ACTION_GROUP(window)); | ||
186 | - | ||
187 | - for(ix = 0; actions[ix]; ix++) { | ||
188 | - | ||
189 | -// debug("%s",actions[ix]); | ||
190 | - | ||
191 | - GAction * action = g_action_map_lookup_action(G_ACTION_MAP(window), actions[ix]); | ||
192 | - | ||
193 | - if(action) { | ||
194 | - | ||
195 | - if(V3270_IS_ACTION(action)) { | ||
196 | - v3270_action_set_terminal_widget(action,terminal); | ||
197 | - } else if(PW3270_IS_ACTION(action)) { | ||
198 | - pw3270_action_set_terminal_widget(action,terminal); | ||
199 | - } | ||
200 | - | ||
201 | - } | ||
202 | - | ||
203 | - } | ||
204 | - | ||
205 | - g_strfreev(actions); | ||
206 | - */ | ||
207 | - | ||
208 | return FALSE; | 163 | return FALSE; |
209 | } | 164 | } |
210 | 165 | ||
@@ -273,7 +228,61 @@ | @@ -273,7 +228,61 @@ | ||
273 | } | 228 | } |
274 | 229 | ||
275 | static void rename_session(GtkWidget G_GNUC_UNUSED(*widget), GtkWidget *terminal) { | 230 | static void rename_session(GtkWidget G_GNUC_UNUSED(*widget), GtkWidget *terminal) { |
231 | + | ||
276 | debug("%s",__FUNCTION__); | 232 | debug("%s",__FUNCTION__); |
233 | + | ||
234 | + GtkWidget * dialog = pw3270_settings_dialog_new( | ||
235 | + _("Rename session"), | ||
236 | + GTK_WINDOW(gtk_widget_get_toplevel(terminal)) | ||
237 | + ); | ||
238 | + | ||
239 | + // https://developer.gnome.org/hig/stable/visual-layout.html.en | ||
240 | + GtkWidget * content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | ||
241 | + gtk_container_set_border_width(GTK_CONTAINER(content),18); | ||
242 | + | ||
243 | + GtkWidget * box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,12); | ||
244 | + gtk_box_pack_start(GTK_BOX(content),box,TRUE,TRUE,0); | ||
245 | + | ||
246 | + | ||
247 | + // Create label. | ||
248 | + GtkWidget *label = gtk_label_new(_("Session name")); | ||
249 | + gtk_label_set_xalign(GTK_LABEL(label),1); | ||
250 | + gtk_box_pack_start(GTK_BOX(box),label,FALSE,TRUE,0); | ||
251 | + | ||
252 | + // Create entry | ||
253 | + GtkWidget * entry = gtk_entry_new(); | ||
254 | + gtk_entry_set_max_length(GTK_ENTRY(entry),10); | ||
255 | + gtk_entry_set_activates_default(GTK_ENTRY(entry),TRUE); | ||
256 | + gtk_entry_set_width_chars(GTK_ENTRY(entry),12); | ||
257 | + gtk_entry_set_placeholder_text(GTK_ENTRY(entry),G_STRINGIFY(PRODUCT_NAME)); | ||
258 | + gtk_entry_set_input_purpose(GTK_ENTRY(entry),GTK_INPUT_PURPOSE_ALPHA); | ||
259 | + | ||
260 | + { | ||
261 | + g_autofree gchar * session_name = g_strdup(v3270_get_session_name(terminal)); | ||
262 | + | ||
263 | + gchar *ptr = strrchr(session_name,':'); | ||
264 | + if(ptr) | ||
265 | + *ptr = 0; | ||
266 | + | ||
267 | + gtk_entry_set_text(GTK_ENTRY(entry),session_name); | ||
268 | + | ||
269 | + } | ||
270 | + | ||
271 | + gtk_box_pack_start(GTK_BOX(box),entry,FALSE,TRUE,0); | ||
272 | + | ||
273 | + gtk_widget_show_all(dialog); | ||
274 | + | ||
275 | + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_APPLY) { | ||
276 | + | ||
277 | + v3270_set_session_name(terminal, gtk_entry_get_text(GTK_ENTRY(entry))); | ||
278 | + | ||
279 | + | ||
280 | + g_signal_emit_by_name(terminal,"save-settings"); | ||
281 | + } | ||
282 | + | ||
283 | + gtk_widget_destroy(dialog); | ||
284 | + | ||
285 | + | ||
277 | } | 286 | } |
278 | 287 | ||
279 | static gboolean on_popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEvent *event, pw3270ApplicationWindow * window) { | 288 | static gboolean on_popup_menu(GtkWidget *widget, gboolean selected, gboolean online, GdkEvent *event, pw3270ApplicationWindow * window) { |
@@ -298,7 +307,7 @@ | @@ -298,7 +307,7 @@ | ||
298 | 307 | ||
299 | } | 308 | } |
300 | 309 | ||
301 | - static void label_populate_popup(GtkLabel *label, GtkMenu *menu, GtkWidget *terminal) { | 310 | + static void label_populate_popup(GtkLabel G_GNUC_UNUSED(*label), GtkMenu *menu, GtkWidget *terminal) { |
302 | 311 | ||
303 | static const struct Item { | 312 | static const struct Item { |
304 | const gchar * label; | 313 | const gchar * label; |
src/objects/window/terminal.c
@@ -69,6 +69,8 @@ | @@ -69,6 +69,8 @@ | ||
69 | 69 | ||
70 | session->changed = FALSE; | 70 | session->changed = FALSE; |
71 | 71 | ||
72 | + debug("%s(%p,%p)",__FUNCTION__,terminal,session); | ||
73 | + | ||
72 | v3270_to_key_file(terminal,session->key_file,"terminal"); | 74 | v3270_to_key_file(terminal,session->key_file,"terminal"); |
73 | v3270_accelerator_map_to_key_file(terminal, session->key_file, "accelerators"); | 75 | v3270_accelerator_map_to_key_file(terminal, session->key_file, "accelerators"); |
74 | 76 |
src/objects/window/window.c
@@ -52,28 +52,6 @@ | @@ -52,28 +52,6 @@ | ||
52 | 52 | ||
53 | pw3270_application_window_set_active_terminal(widget,NULL); | 53 | pw3270_application_window_set_active_terminal(widget,NULL); |
54 | 54 | ||
55 | - /* | ||
56 | - // Update actions | ||
57 | - gchar ** actions = g_action_group_list_actions(G_ACTION_GROUP(widget)); | ||
58 | - | ||
59 | - for(ix = 0; actions[ix]; ix++) { | ||
60 | - | ||
61 | - GAction * action = g_action_map_lookup_action(G_ACTION_MAP(widget), actions[ix]); | ||
62 | - | ||
63 | - if(!action) | ||
64 | - continue; | ||
65 | - | ||
66 | - if(PW3270_IS_ACTION(action)) { | ||
67 | - pw3270_action_set_terminal_widget(action,NULL); | ||
68 | - } else if(V3270_IS_ACTION(action)) { | ||
69 | - v3270_action_set_terminal_widget(action,NULL); | ||
70 | - } | ||
71 | - | ||
72 | - } | ||
73 | - g_strfreev(actions); | ||
74 | - */ | ||
75 | - | ||
76 | - | ||
77 | // Destroy popups | 55 | // Destroy popups |
78 | for(ix = 0; ix < G_N_ELEMENTS(window->popups); ix++) { | 56 | for(ix = 0; ix < G_N_ELEMENTS(window->popups); ix++) { |
79 | if(window->popups[ix]) { | 57 | if(window->popups[ix]) { |
@@ -410,12 +388,12 @@ | @@ -410,12 +388,12 @@ | ||
410 | g_autofree gchar * title = v3270_get_session_title(terminal); | 388 | g_autofree gchar * title = v3270_get_session_title(terminal); |
411 | gtk_window_set_title(GTK_WINDOW(window), title); | 389 | gtk_window_set_title(GTK_WINDOW(window), title); |
412 | 390 | ||
413 | - pw3270_window_set_subtitle(window, v3270_is_connected(terminal) ? _("Connected to host") : _("Disconnected from host")); | 391 | + pw3270_window_set_subtitle(GTK_WIDGET(window), v3270_is_connected(terminal) ? _("Connected to host") : _("Disconnected from host")); |
414 | 392 | ||
415 | } else { | 393 | } else { |
416 | 394 | ||
417 | terminal = NULL; | 395 | terminal = NULL; |
418 | - pw3270_window_set_subtitle(window, _("Disconnected from host")); | 396 | + pw3270_window_set_subtitle(GTK_WIDGET(window), _("Disconnected from host")); |
419 | 397 | ||
420 | } | 398 | } |
421 | 399 |