actions.c
2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* SPDX-License-Identifier: LGPL-3.0-or-later */
/*
* Copyright (C) 2008 Banco do Brasil S.A.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "private.h"
#include <pw3270/actions.h>
GtkWidget * pw3270_toolbar_insert_action(GtkWidget *toolbar, const gchar *name, gint pos) {
g_return_val_if_fail(PW3270_IS_TOOLBAR(toolbar),NULL);
if(!g_ascii_strcasecmp(name,"")) {
GtkToolItem * item = gtk_separator_tool_item_new();
gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(item),FALSE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, pos);
gtk_widget_show_all(GTK_WIDGET(item));
return GTK_WIDGET(item);
} else if(!g_ascii_strcasecmp(name,"separator")) {
GtkToolItem * item = gtk_separator_tool_item_new();
gtk_separator_tool_item_set_draw(GTK_SEPARATOR_TOOL_ITEM(item),TRUE);
gtk_toolbar_insert(GTK_TOOLBAR(toolbar), item, pos);
gtk_widget_show_all(GTK_WIDGET(item));
return GTK_WIDGET(item);
}
GtkWidget * window = gtk_widget_get_toplevel(toolbar);
if(window && G_IS_ACTION_MAP(window)) {
GtkToolItem * item = NULL;
GAction *action = g_action_map_lookup_action(G_ACTION_MAP(window), name);
if(!action) {
const gchar *ptr = strchr(name,'.');
if(ptr) {
action = g_action_map_lookup_action(G_ACTION_MAP(window), ptr+1);
}
}
if(!action) {
action = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()),name);
}
if(!action) {
const gchar *ptr = strchr(name,'.');
if(ptr) {
action = g_action_map_lookup_action(G_ACTION_MAP(g_application_get_default()), ptr+1);
}
}
// debug("%s(%s)=%p",__FUNCTION__,name,action);
if(!action) {
g_warning("Can't find action \"%s\"",name);
return NULL;
}
item = gtk_tool_button_new_from_action(
action,
GTK_ICON_SIZE_LARGE_TOOLBAR,
pw3270_toolbar_get_icon_type(GTK_TOOLBAR(toolbar)) == 1
);
if(item) {
gtk_widget_show_all(GTK_WIDGET(item));
if(action && g_action_get_parameter_type(action) == G_VARIANT_TYPE_STRING) {
g_autofree gchar * detailed = g_strconcat(name,"::",NULL);
gtk_actionable_set_detailed_action_name(GTK_ACTIONABLE(item),detailed);
} else {
gtk_actionable_set_action_name(GTK_ACTIONABLE(item),name);
}
gtk_toolbar_insert(GTK_TOOLBAR(toolbar),item,pos);
return GTK_WIDGET(item);
} else {
g_warning("Can't create toolbar item for action \"%s\"",name);
}
}
return NULL;
}