Commit e60dfeef9d02ac4ee3f2908d298b2112b93660bc

Authored by Perry Werneck
1 parent 9ed9e421

Implementing session dialogs.

src/objects/application/actions/open.c
... ... @@ -36,20 +36,84 @@
36 36 #include <v3270.h>
37 37 #include <pw3270/application.h>
38 38  
  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 + static gchar * get_session_file_name(GtkApplication *application, const gchar *title) {
  67 +
  68 + gchar * filename = NULL;
  69 +
  70 + GtkWidget * dialog =
  71 + gtk_file_chooser_dialog_new(
  72 + title,
  73 + gtk_application_get_active_window(application),
  74 + GTK_FILE_CHOOSER_ACTION_OPEN,
  75 + _("Open Session"), GTK_RESPONSE_OK,
  76 + _("Cancel"),GTK_RESPONSE_CANCEL,
  77 + NULL
  78 + );
  79 +
  80 + set_file_filters(GTK_FILE_CHOOSER(dialog));
  81 +
  82 + gtk_widget_show_all(dialog);
  83 + if(gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
  84 + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
  85 + }
  86 +
  87 + gtk_widget_destroy(dialog);
  88 +
  89 + return filename;
  90 + }
  91 +
39 92 void pw3270_application_open_activated(GSimpleAction * action, GVariant *parameter, gpointer application) {
40 93  
41 94 debug("%s",__FUNCTION__);
  95 + g_simple_action_set_enabled(action,FALSE);
42 96  
  97 + g_simple_action_set_enabled(action,TRUE);
43 98 }
44 99  
45 100 void pw3270_application_open_tab_activated(GSimpleAction * action, GVariant *parameter, gpointer application) {
46 101  
47 102 debug("%s",__FUNCTION__);
  103 + g_simple_action_set_enabled(action,FALSE);
  104 + g_autofree gchar * session_file_name = get_session_file_name(GTK_APPLICATION(application),_("Open session in new tab"));
  105 +
48 106  
  107 + g_simple_action_set_enabled(action,TRUE);
49 108 }
50 109  
51 110 void pw3270_application_open_window_activated(GSimpleAction * action, GVariant *parameter, gpointer application) {
52 111  
53 112 debug("%s",__FUNCTION__);
  113 + g_simple_action_set_enabled(action,FALSE);
  114 + g_autofree gchar * session_file_name = get_session_file_name(GTK_APPLICATION(application),_("Open session in new window"));
54 115  
  116 +
  117 + g_simple_action_set_enabled(action,TRUE);
55 118 }
  119 +
... ...
ui/application.xml
... ... @@ -38,15 +38,15 @@
38 38  
39 39 <submenu>
40 40  
41   - <attribute name='label' translatable='yes'>Open</attribute>
  41 + <attribute name='label' translatable='yes'>Session</attribute>
42 42  
43 43 <item>
44   - <attribute name="label" translatable="yes">New Window</attribute>
  44 + <attribute name="label" translatable="yes">Open in New Window</attribute>
45 45 <attribute name="action">app.open.session.window</attribute>
46 46 </item>
47 47  
48 48 <item>
49   - <attribute name="label" translatable="yes">New Tab</attribute>
  49 + <attribute name="label" translatable="yes">Open in New Tab</attribute>
50 50 <attribute name="action">app.open.session.tab</attribute>
51 51 </item>
52 52  
... ... @@ -54,27 +54,28 @@
54 54  
55 55 <submenu>
56 56  
57   - <attribute name='label' translatable='yes'>Options</attribute>
  57 + <attribute name='label' translatable='yes'>View</attribute>
58 58  
59 59 <item>
60   - <attribute name="label" translatable="yes">Show toolbar</attribute>
  60 + <attribute name="label" translatable="yes">Main Toolbar</attribute>
61 61 <attribute name="action">win.toolbar</attribute>
62 62 </item>
63 63  
64 64 <item>
65   - <attribute name="label" translatable="yes">Show menu</attribute>
  65 + <attribute name="label" translatable="yes">Main Menu</attribute>
66 66 <attribute name="action">win.menubar</attribute>
67 67 </item>
68 68  
69 69 <item>
70   - <attribute name="label" translatable="yes">Show trace</attribute>
  70 + <attribute name="label" translatable="yes">Session Trace</attribute>
71 71 <attribute name="action">win.trace</attribute>
72 72 </item>
73 73  
74 74 </submenu>
75 75  
  76 +
76 77 <item>
77   - <attribute name="label" translatable="yes">Preferences</attribute>
  78 + <attribute name="label" translatable="yes">Application preferences</attribute>
78 79 <attribute name="action">app.preferences</attribute>
79 80 </item>
80 81  
... ...