Commit ca5cdb7ec33a1a118b2332fed625c34fd0617c36
1 parent
3f279bba
Exists in
master
and in
4 other branches
Refactoring "open" actions.
Showing
3 changed files
with
103 additions
and
56 deletions
Show diff stats
src/objects/application/actions/open.c
@@ -36,7 +36,103 @@ | @@ -36,7 +36,103 @@ | ||
36 | #include <v3270.h> | 36 | #include <v3270.h> |
37 | #include <pw3270.h> | 37 | #include <pw3270.h> |
38 | #include <pw3270/application.h> | 38 | #include <pw3270/application.h> |
39 | + #include <pw3270/actions.h> | ||
39 | 40 | ||
41 | + static GtkWidget * session_dialog_new(PW3270Action *action, GtkApplication *application) { | ||
42 | + | ||
43 | + GtkWidget * dialog = | ||
44 | + gtk_file_chooser_dialog_new( | ||
45 | + action->label, | ||
46 | + gtk_application_get_active_window(application), | ||
47 | + GTK_FILE_CHOOSER_ACTION_OPEN, | ||
48 | + _("Open Session"), GTK_RESPONSE_OK, | ||
49 | + _("Cancel"),GTK_RESPONSE_CANCEL, | ||
50 | + NULL | ||
51 | + ); | ||
52 | + | ||
53 | + gtk_file_chooser_set_pw3270_filters(GTK_FILE_CHOOSER(dialog)); | ||
54 | + gtk_widget_show_all(dialog); | ||
55 | + | ||
56 | + return dialog; | ||
57 | + } | ||
58 | + | ||
59 | + static void open_window(GtkWidget *dialog, gint response_id, GtkApplication *application) { | ||
60 | + | ||
61 | + if(response_id == GTK_RESPONSE_OK) { | ||
62 | + | ||
63 | + g_autofree gchar * file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | ||
64 | + | ||
65 | + if(file_name) { | ||
66 | + GtkWidget *window = pw3270_application_window_new(application, file_name); | ||
67 | + pw3270_window_set_current_page(window,0); | ||
68 | + gtk_window_present(GTK_WINDOW(window)); | ||
69 | + } | ||
70 | + | ||
71 | + } | ||
72 | + | ||
73 | + gtk_widget_destroy(dialog); | ||
74 | + | ||
75 | + } | ||
76 | + | ||
77 | + static void open_tab(GtkWidget *dialog, gint response_id, GtkApplication *application) { | ||
78 | + | ||
79 | + if(response_id == GTK_RESPONSE_OK) { | ||
80 | + | ||
81 | + g_autofree gchar * file_name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | ||
82 | + | ||
83 | + if(file_name) { | ||
84 | + | ||
85 | + pw3270_application_window_new_tab(GTK_WIDGET(gtk_application_get_active_window(GTK_APPLICATION(application))), file_name); | ||
86 | + | ||
87 | + } | ||
88 | + | ||
89 | + } | ||
90 | + | ||
91 | + gtk_widget_destroy(dialog); | ||
92 | + | ||
93 | + } | ||
94 | + | ||
95 | + static GtkWidget * open_window_factory(PW3270Action *action, GtkApplication *application) { | ||
96 | + | ||
97 | + GtkWidget * dialog = session_dialog_new(action,application); | ||
98 | + g_signal_connect(dialog,"response",G_CALLBACK(open_window),application); | ||
99 | + return dialog; | ||
100 | + | ||
101 | + } | ||
102 | + | ||
103 | + static GtkWidget * open_tab_factory(PW3270Action *action, GtkApplication *application) { | ||
104 | + | ||
105 | + GtkWidget * dialog = session_dialog_new(action,application); | ||
106 | + g_signal_connect(dialog,"response",G_CALLBACK(open_tab),application); | ||
107 | + return dialog; | ||
108 | + | ||
109 | + } | ||
110 | + | ||
111 | + GAction * pw3270_open_window_action_new() { | ||
112 | + | ||
113 | + PW3270Action * action = pw3270_dialog_action_new(open_window_factory); | ||
114 | + | ||
115 | + action->name = "open.session.window"; | ||
116 | + action->label = _( "Open in window" ); | ||
117 | + action->tooltip = _( "Open session in New window" ); | ||
118 | + action->icon_name = "window-new"; | ||
119 | + | ||
120 | + return G_ACTION(action); | ||
121 | + } | ||
122 | + | ||
123 | + GAction * pw3270_open_tab_action_new() { | ||
124 | + | ||
125 | + PW3270Action * action = pw3270_dialog_action_new(open_tab_factory); | ||
126 | + | ||
127 | + action->name = "open.session.tab"; | ||
128 | + action->label = _( "Open in tab" ); | ||
129 | + action->tooltip = _( "Open session in New Tab" ); | ||
130 | + action->icon_name = "tab-new"; | ||
131 | + | ||
132 | + return G_ACTION(action); | ||
133 | + } | ||
134 | + | ||
135 | + /* | ||
40 | static gchar * get_session_file_name(GtkApplication *application, const gchar *title) { | 136 | static gchar * get_session_file_name(GtkApplication *application, const gchar *title) { |
41 | 137 | ||
42 | gchar * filename = NULL; | 138 | gchar * filename = NULL; |
@@ -98,4 +194,5 @@ | @@ -98,4 +194,5 @@ | ||
98 | 194 | ||
99 | g_simple_action_set_enabled(action,TRUE); | 195 | g_simple_action_set_enabled(action,TRUE); |
100 | } | 196 | } |
197 | + */ | ||
101 | 198 |
src/objects/application/application.c
@@ -325,63 +325,14 @@ | @@ -325,63 +325,14 @@ | ||
325 | 325 | ||
326 | G_APPLICATION_CLASS(pw3270Application_parent_class)->startup(application); | 326 | G_APPLICATION_CLASS(pw3270Application_parent_class)->startup(application); |
327 | 327 | ||
328 | - /* | ||
329 | - // | ||
330 | - // Setup application default actions. | ||
331 | - // | ||
332 | - static GActionEntry actions[] = { | ||
333 | - | ||
334 | - { | ||
335 | - .name = "preferences", | ||
336 | - .activate = pw3270_application_preferences_activated, | ||
337 | - }, | ||
338 | - | ||
339 | - { | ||
340 | - .name = "quit", | ||
341 | - .activate = pw3270_application_quit_activated, | ||
342 | - }, | ||
343 | - | ||
344 | - { | ||
345 | - .name = "new.tab", | ||
346 | - .activate = pw3270_application_new_tab_activated, | ||
347 | - }, | ||
348 | - | ||
349 | - { | ||
350 | - .name = "new.window", | ||
351 | - .activate = pw3270_application_new_window_activated, | ||
352 | - }, | ||
353 | - | ||
354 | - { | ||
355 | - .name = "open.session", | ||
356 | - .activate = pw3270_application_open_activated, | ||
357 | - }, | ||
358 | - | ||
359 | - { | ||
360 | - .name = "open.session.tab", | ||
361 | - .activate = pw3270_application_open_tab_activated, | ||
362 | - }, | ||
363 | - | ||
364 | - { | ||
365 | - .name = "open.session.window", | ||
366 | - .activate = pw3270_application_open_window_activated, | ||
367 | - }, | ||
368 | - | ||
369 | - }; | ||
370 | - | ||
371 | - g_action_map_add_action_entries( | ||
372 | - G_ACTION_MAP(application), | ||
373 | - actions, | ||
374 | - G_N_ELEMENTS(actions), | ||
375 | - application | ||
376 | - ); | ||
377 | - */ | ||
378 | - | ||
379 | GAction * actions[] = { | 328 | GAction * actions[] = { |
380 | pw3270_about_action_new(), | 329 | pw3270_about_action_new(), |
381 | pw3270_preferences_action_new(), | 330 | pw3270_preferences_action_new(), |
382 | pw3270_new_tab_action_new(), | 331 | pw3270_new_tab_action_new(), |
383 | pw3270_new_window_action_new(), | 332 | pw3270_new_window_action_new(), |
384 | - pw3270_quit_action_new() | 333 | + pw3270_quit_action_new(), |
334 | + pw3270_open_window_action_new(), | ||
335 | + pw3270_open_tab_action_new() | ||
385 | }; | 336 | }; |
386 | 337 | ||
387 | for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { | 338 | for(ix = 0; ix < G_N_ELEMENTS(actions); ix++) { |
src/objects/application/private.h
@@ -56,10 +56,9 @@ | @@ -56,10 +56,9 @@ | ||
56 | G_GNUC_INTERNAL GAction * pw3270_new_window_action_new(); | 56 | G_GNUC_INTERNAL GAction * pw3270_new_window_action_new(); |
57 | G_GNUC_INTERNAL GAction * pw3270_quit_action_new(); | 57 | G_GNUC_INTERNAL GAction * pw3270_quit_action_new(); |
58 | 58 | ||
59 | - G_GNUC_INTERNAL void pw3270_application_generic_activated(GSimpleAction * action, GVariant *parameter, gpointer application); | 59 | + G_GNUC_INTERNAL GAction * pw3270_open_window_action_new(); |
60 | + G_GNUC_INTERNAL GAction * pw3270_open_tab_action_new(); | ||
60 | 61 | ||
61 | - G_GNUC_INTERNAL void pw3270_application_open_activated(GSimpleAction * action, GVariant *parameter, gpointer application); | ||
62 | - G_GNUC_INTERNAL void pw3270_application_open_tab_activated(GSimpleAction * action, GVariant *parameter, gpointer application); | ||
63 | - G_GNUC_INTERNAL void pw3270_application_open_window_activated(GSimpleAction * action, GVariant *parameter, gpointer application); | 62 | + G_GNUC_INTERNAL void pw3270_application_generic_activated(GSimpleAction * action, GVariant *parameter, gpointer application); |
64 | 63 | ||
65 | #endif // PRIVATE_H_INCLUDED | 64 | #endif // PRIVATE_H_INCLUDED |