gpt4 book ai didi

c - 如何设置 Gearmenu 的一个元素不敏感?

转载 作者:太空狗 更新时间:2023-10-29 12:38:59 27 4
gpt4 key购买 nike

如果发出“加载失败”信号,我想将齿轮菜单的一个元素设置为不敏感。

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);

最佳答案

在加载失败的回调中,您需要删除“setAsHome”:

g_action_map_remove_action(G_ACTION_MAP (w->app), "setAsHome"

加载失败信号也会在出现故障时发出,您将被重定向到错误消息页面。请记住,您的加载更改信号将发出 2 次,因为 url 无法加载,而不是加载错误页面。

为了让它再次“敏感”,您需要再次将它添加到您的菜单中。

关于c - 如何设置 Gearmenu 的一个元素不敏感?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56599573/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com