window: Simplify navigation code
Using <accelerator> in GtkBuilder can simplify lots of C code.
This commit is contained in:
+9
-3
@@ -188,7 +188,9 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="action_name">win.today</property>
|
<accelerator key="t" modifiers="GDK_CONTROL_MASK" signal="clicked"/>
|
||||||
|
<accelerator key="Home" signal="clicked"/>
|
||||||
|
<signal name="clicked" handler="date_updated" object="GcalWindow" swapped="yes"/>
|
||||||
</object>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
@@ -202,7 +204,9 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="action_name">win.previous</property>
|
<accelerator key="Left" modifiers="GDK_MOD1_MASK" signal="clicked"/>
|
||||||
|
<accelerator key="Page_Up" signal="clicked"/>
|
||||||
|
<signal name="clicked" handler="date_updated" object="GcalWindow" swapped="yes"/>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="go_back_image">
|
<object class="GtkImage" id="go_back_image">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
@@ -216,7 +220,9 @@
|
|||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="receives_default">True</property>
|
<property name="receives_default">True</property>
|
||||||
<property name="action_name">win.next</property>
|
<accelerator key="Right" modifiers="GDK_MOD1_MASK" signal="clicked"/>
|
||||||
|
<accelerator key="Page_Down" signal="clicked"/>
|
||||||
|
<signal name="clicked" handler="date_updated" object="GcalWindow" swapped="yes"/>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkImage" id="go_next_image">
|
<object class="GtkImage" id="go_next_image">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
|
|||||||
+3
-37
@@ -197,10 +197,6 @@ static void on_show_calendars_action_activated (GSimpleAction *a
|
|||||||
GVariant *param,
|
GVariant *param,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
|
|
||||||
static void on_date_action_activated (GSimpleAction *action,
|
|
||||||
GVariant *param,
|
|
||||||
gpointer user_data);
|
|
||||||
|
|
||||||
static void on_view_action_activated (GSimpleAction *action,
|
static void on_view_action_activated (GSimpleAction *action,
|
||||||
GVariant *param,
|
GVariant *param,
|
||||||
gpointer user_data);
|
gpointer user_data);
|
||||||
@@ -212,9 +208,6 @@ static void on_toggle_search_bar_activated (GSimpleAction *a
|
|||||||
G_DEFINE_TYPE (GcalWindow, gcal_window, GTK_TYPE_APPLICATION_WINDOW)
|
G_DEFINE_TYPE (GcalWindow, gcal_window, GTK_TYPE_APPLICATION_WINDOW)
|
||||||
|
|
||||||
static const GActionEntry actions[] = {
|
static const GActionEntry actions[] = {
|
||||||
{"next", on_date_action_activated },
|
|
||||||
{"previous", on_date_action_activated },
|
|
||||||
{"today", on_date_action_activated },
|
|
||||||
{"change-view", on_view_action_activated, "i" },
|
{"change-view", on_view_action_activated, "i" },
|
||||||
{"show-calendars", on_show_calendars_action_activated },
|
{"show-calendars", on_show_calendars_action_activated },
|
||||||
{"toggle-search-bar", on_toggle_search_bar_activated }
|
{"toggle-search-bar", on_toggle_search_bar_activated }
|
||||||
@@ -375,11 +368,9 @@ update_active_date (GcalWindow *window,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
date_updated (GtkButton *button,
|
date_updated (GcalWindow *window,
|
||||||
gpointer user_data)
|
GtkButton *button)
|
||||||
{
|
{
|
||||||
GcalWindow *window = GCAL_WINDOW (user_data);
|
|
||||||
|
|
||||||
icaltimetype *new_date;
|
icaltimetype *new_date;
|
||||||
gboolean move_back, move_today;
|
gboolean move_back, move_today;
|
||||||
gint factor;
|
gint factor;
|
||||||
@@ -426,7 +417,7 @@ date_updated (GtkButton *button,
|
|||||||
*new_date = icaltime_normalize (*new_date);
|
*new_date = icaltime_normalize (*new_date);
|
||||||
}
|
}
|
||||||
|
|
||||||
update_active_date (user_data, new_date);
|
update_active_date (window, new_date);
|
||||||
|
|
||||||
GCAL_EXIT;
|
GCAL_EXIT;
|
||||||
}
|
}
|
||||||
@@ -446,27 +437,6 @@ on_show_calendars_action_activated (GSimpleAction *action,
|
|||||||
gtk_widget_show (window->source_dialog);
|
gtk_widget_show (window->source_dialog);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
|
||||||
on_date_action_activated (GSimpleAction *action,
|
|
||||||
GVariant *param,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
|
||||||
GcalWindow *window;
|
|
||||||
const gchar *action_name;
|
|
||||||
|
|
||||||
g_return_if_fail (GCAL_IS_WINDOW (user_data));
|
|
||||||
|
|
||||||
window = GCAL_WINDOW (user_data);
|
|
||||||
action_name = g_action_get_name (G_ACTION (action));
|
|
||||||
|
|
||||||
if (g_strcmp0 (action_name, "next") == 0)
|
|
||||||
date_updated (GTK_BUTTON (window->forward_button), user_data);
|
|
||||||
else if (g_strcmp0 (action_name, "previous") == 0)
|
|
||||||
date_updated (GTK_BUTTON (window->back_button), user_data);
|
|
||||||
else if (g_strcmp0 (action_name, "today") == 0)
|
|
||||||
date_updated (GTK_BUTTON (window->today_button), user_data);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
on_view_action_activated (GSimpleAction *action,
|
on_view_action_activated (GSimpleAction *action,
|
||||||
GVariant *param,
|
GVariant *param,
|
||||||
@@ -1588,10 +1558,6 @@ gcal_window_init (GcalWindow *self)
|
|||||||
/* setup accels */
|
/* setup accels */
|
||||||
app = g_application_get_default ();
|
app = g_application_get_default ();
|
||||||
|
|
||||||
gcal_window_add_accelerator (app, "win.next", "<Alt>Right", "Page_Down");
|
|
||||||
gcal_window_add_accelerator (app, "win.previous", "<Alt>Left", "Page_Up");
|
|
||||||
gcal_window_add_accelerator (app, "win.today", "<Alt>Down", "<Ctrl>t", "Home");
|
|
||||||
|
|
||||||
gcal_window_add_accelerator (app, "win.change-view(-1)", "<Ctrl>Page_Down");
|
gcal_window_add_accelerator (app, "win.change-view(-1)", "<Ctrl>Page_Down");
|
||||||
gcal_window_add_accelerator (app, "win.change-view(-2)", "<Ctrl>Page_Up");
|
gcal_window_add_accelerator (app, "win.change-view(-2)", "<Ctrl>Page_Up");
|
||||||
gcal_window_add_accelerator (app, "win.change-view(1)", "<Ctrl>1")
|
gcal_window_add_accelerator (app, "win.change-view(1)", "<Ctrl>1")
|
||||||
|
|||||||
Reference in New Issue
Block a user