如果发出“负载失败”信号,我想将Gearmenu的一个元素设置为不敏感。
struct GActionEntry {
const gchar *name;
void (* activate) (GSimpleAction *action,
GVariant *parameter,
gpointer user_data);
const gchar *parameter_type;
const gchar *state;
void (* change_state) (GSimpleAction *action,
GVariant *value,
gpointer user_data);
};
这是我发现的(https://developer.gnome.org/gio/stable/GActionMap.html#GActionEntry),我也这样使用它:
const GActionEntry app_actions[] = {
{ "setAsHome", set_clicked , NULL, NULL, NULL, {0, 0, 0} },
{ "about", about_clicked, NULL, NULL, NULL, {0, 0, 0} }
};
我现在想将set_clicked设置为不活动,但是我不知道该怎么做。 我的意思是我知道如何对“加载失败”信号进行回调功能,但不知道如何将其设置为不活动状态。
int main (int argc, char **argv)
{
int status;
struct widget *w = g_malloc (sizeof (struct widget));
w->app = gtk_application_new ("org.gtk.dialog", G_APPLICATION_HANDLES_COMMAND_LINE);
g_signal_connect (w->app, "command-line", G_CALLBACK (activate), (gpointer) w);
g_action_map_add_action_entries (G_ACTION_MAP (w->app), app_actions,
G_N_ELEMENTS (app_actions), (gpointer) w);
status = g_application_run (G_APPLICATION (w->app), argc, argv);
g_object_unref (w->app);
// free the memory for the widgets struct
g_free (w);
w = NULL;
return status;
}
struct widget
{
GtkApplication *app;
GtkWidget *window;
GtkWidget *box;
GMenu *appmenu;
GMenu *editmenu;
GtkWidget *find;
GtkWidget *back;
GtkWidget *forward;
GtkWidget *home;
GtkWidget *entry;
GtkWidget *header;
GMenu *gearmenu;
GtkWidget *gearmenubutton;
GtkWidget *gearicon;
GtkWidget *status;
WebKitWebView *wv;
guint id;
const gchar *url;
const gchar *homedir;
gboolean success;
};
// create the gear menu button
w->gearmenubutton = gtk_menu_button_new();
w->gearicon = gtk_image_new_from_icon_name ("emblem-system-symbolic", GTK_ICON_SIZE_SMALL_TOOLBAR);
gtk_button_set_image (GTK_BUTTON (w->gearmenubutton), w->gearicon);
// create a menu for the gear button
w->gearmenu = g_menu_new();
g_menu_append (w->gearmenu, "_Set as Homepage", "app.setAsHome");
w->editmenu = g_menu_new();
g_menu_append (w->editmenu, "_About", "app.about");
g_menu_append_section (w->gearmenu, NULL, G_MENU_MODEL (w->editmenu));
gtk_menu_button_set_menu_model (GTK_MENU_BUTTON (w->gearmenubutton),
G_MENU_MODEL (w->gearmenu));
g_object_unref (w->editmenu);
g_object_unref (w->gearmenu);
答案 0 :(得分:0)
在加载失败的回调中,您需要删除“ setAsHome”:
g_action_map_remove_action(G_ACTION_MAP (w->app), "setAsHome"
当发生故障时,也会加载失败信号,您将被重定向到错误消息页面。请记住,您的负载变化信号将发出两次,因为无法加载该网址,而不是加载错误页面。
要再次使它“敏感”,您需要再次将其添加到菜单中。