[gnome-calendar/search-improvements] search-view: make it a GtkPopover descendant
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-calendar/search-improvements] search-view: make it a GtkPopover descendant
- Date: Wed, 7 Jan 2015 16:12:34 +0000 (UTC)
commit 321c24ec1a90d1e315400b96ece6d4a0da65b2a1
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Jan 7 14:11:22 2015 -0200
search-view: make it a GtkPopover descendant
This huge patch makes GcalSearchView a GtkPopover
descendant. Also, it poorly adapts GcalWindow to
make it work with it.
data/ui/search-view.ui | 117 ++++++++++++++++++++++-------------------------
data/ui/window.ui | 28 +++++++++--
src/gcal-search-view.c | 9 ++--
src/gcal-search-view.h | 4 +-
src/gcal-window.c | 73 +++++++++---------------------
5 files changed, 106 insertions(+), 125 deletions(-)
---
diff --git a/data/ui/search-view.ui b/data/ui/search-view.ui
index b0fd4e5..483d792 100644
--- a/data/ui/search-view.ui
+++ b/data/ui/search-view.ui
@@ -2,95 +2,88 @@
<!-- Generated with glade 3.18.1 -->
<interface>
<requires lib="gtk+" version="3.10"/>
- <template class="GcalSearchView" parent="GtkScrolledWindow">
+ <template class="GcalSearchView" parent="GtkPopover">
<property name="visible">True</property>
<property name="can_focus">True</property>
+ <property name="width_request">600</property>
+ <property name="height_request">300</property>
+ <property name="border_width">12</property>
+ <property name="modal">False</property>
<child>
- <object class="GtkViewport" id="viewport">
+ <object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="shadow_type">none</property>
<child>
- <object class="GtkGrid" id="grid">
- <property name="visible">True</property>
+ <object class="GtkGrid" id="no_results_grid">
<property name="can_focus">False</property>
- <property name="margin_start">96</property>
- <property name="margin_end">96</property>
- <property name="margin_top">24</property>
- <property name="margin_bottom">24</property>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="row_spacing">24</property>
<child>
- <object class="GtkFrame" id="frame">
+ <object class="GtkImage" id="image">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="hexpand">True</property>
- <property name="vexpand">False</property>
- <property name="valign">GTK_ALIGN_START</property>
- <property name="label_xalign">0</property>
- <style>
- <class name="search-list" />
- </style>
- <child>
- <object class="GtkListBox" id="listbox">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="selection_mode">none</property>
- <signal name="row-activated" handler="open_event" object="GcalSearchView" swapped="no"/>
- <style>
- <class name="search-list"/>
- </style>
- </object>
- </child>
- <child type="label_item">
- <placeholder/>
- </child>
+ <property name="halign">center</property>
+ <property name="valign">center</property>
+ <property name="pixel_size">48</property>
+ <property name="icon_name">face-sad-symbolic</property>
</object>
<packing>
<property name="left_attach">0</property>
- <property name="top_attach">1</property>
+ <property name="top_attach">0</property>
</packing>
</child>
<child>
- <object class="GtkGrid" id="no_results_grid">
+ <object class="GtkLabel" id="label">
+ <property name="visible">True</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
- <property name="hexpand">True</property>
- <property name="vexpand">True</property>
- <property name="row_spacing">24</property>
- <child>
- <object class="GtkImage" id="image">
- <property name="visible">True</property>
- <property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="pixel_size">48</property>
- <property name="icon_name">face-sad-symbolic</property>
- </object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
- </child>
+ <property name="label" translatable="yes">No results found</property>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
+ </child>
+ </object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkScrolledWindow" id="scrolled_window">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="hexpand">True</property>
+ <property name="vexpand">True</property>
+ <property name="shadow_type">in</property>
+ <child>
+ <object class="GtkViewport" id="viewport">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="shadow_type">none</property>
<child>
- <object class="GtkLabel" id="label">
+ <object class="GtkListBox" id="listbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
- <property name="halign">center</property>
- <property name="valign">center</property>
- <property name="label" translatable="yes">No results found</property>
+ <property name="selection_mode">none</property>
+ <signal name="row-activated" handler="open_event" object="GcalSearchView" swapped="no"/>
+ <style>
+ <class name="search-list"/>
+ </style>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">1</property>
- </packing>
</child>
</object>
- <packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
- </packing>
</child>
</object>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="top_attach">1</property>
+ </packing>
</child>
</object>
</child>
diff --git a/data/ui/window.ui b/data/ui/window.ui
index b5ed2f3..a405c16 100644
--- a/data/ui/window.ui
+++ b/data/ui/window.ui
@@ -27,12 +27,15 @@
<property name="no_show_all">True</property>
<property name="hexpand">True</property>
<property name="show_close_button">True</property>
- <property name="search-mode-enabled" bind-source="search_button" bind-property="active"
bind-flags="bidirectional"/>
+ <property name="search-mode-enabled" bind-source="search_button" bind-property="active"
bind-flags="bidirectional"/>
<signal name="notify::search-mode-enabled" handler="search_toggled" object="GcalWindow"
swapped="no"/>
<child>
- <object class="GtkGrid" id="search_entry_grid">
+ <object class="GtkBox" id="search_entry_box">
<property name="visible">True</property>
<property name="can_focus">False</property>
+ <style>
+ <class name="linked" />
+ </style>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="width_request">500</property>
@@ -46,8 +49,24 @@
<signal name="search-changed" handler="search_changed" object="GcalWindow"
swapped="no"/>
</object>
<packing>
- <property name="left_attach">0</property>
- <property name="top_attach">0</property>
+ <property name="position">0</property>
+ </packing>
+ </child>
+ <child>
+ <object class="GtkToggleButton" id="search_list_button">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="active" bind-source="search_entry" bind-property="has-focus"
bind-flags="bidirectional"/>
+ <child>
+ <object class="GtkImage" id="search_list_image">
+ <property name="visible">True</property>
+ <property name="can_focus">False</property>
+ <property name="icon_name">open-menu-symbolic</property>
+ </object>
+ </child>
+ </object>
+ <packing>
+ <property name="position">1</property>
</packing>
</child>
</object>
@@ -66,7 +85,6 @@
<property name="vexpand">True</property>
<property name="transition_duration">250</property>
<property name="transition_type">slide-left-right</property>
- <signal name="notify::transition-running" handler="stack_transition_running"
object="GcalWindow" swapped="no"/>
<signal name="notify::visible-child" handler="view_changed" object="GcalWindow"
swapped="no"/>
<style>
<class name="views"/>
diff --git a/src/gcal-search-view.c b/src/gcal-search-view.c
index 9e197b0..9fee107 100644
--- a/src/gcal-search-view.c
+++ b/src/gcal-search-view.c
@@ -34,7 +34,7 @@ typedef struct
typedef struct
{
GtkWidget *listbox;
- GtkWidget *frame;
+ GtkWidget *scrolled_window;
GtkWidget *no_results_grid;
/* internal hashes */
@@ -120,7 +120,7 @@ static void gcal_search_view_thaw (ECalDataModelSu
G_DEFINE_TYPE_WITH_CODE (GcalSearchView,
gcal_search_view,
- GTK_TYPE_SCROLLED_WINDOW,
+ GTK_TYPE_POPOVER,
G_ADD_PRIVATE (GcalSearchView)
G_IMPLEMENT_INTERFACE (E_TYPE_CAL_DATA_MODEL_SUBSCRIBER,
gcal_data_model_subscriber_interface_init));
@@ -221,6 +221,7 @@ make_row_for_event_data (GcalSearchView *view,
name_label = gtk_label_new (summary.value);
gtk_widget_set_hexpand (name_label, TRUE);
gtk_widget_set_halign (name_label, GTK_ALIGN_START);
+ gtk_label_set_ellipsize (GTK_LABEL (name_label), PANGO_ELLIPSIZE_END);
/* attach things up */
gtk_grid_attach (GTK_GRID (box), time_label, 0, 0, 1, 1);
@@ -395,7 +396,7 @@ show_no_results_page (GcalSearchView *view)
priv = gcal_search_view_get_instance_private (view);
priv->no_results_timeout_id = 0;
- gtk_widget_set_visible (priv->frame, priv->num_results != 0);
+ gtk_widget_set_visible (priv->scrolled_window, priv->num_results != 0);
gtk_widget_set_visible (priv->no_results_grid, priv->num_results == 0);
return G_SOURCE_REMOVE;
@@ -457,7 +458,7 @@ gcal_search_view_class_init (GcalSearchViewClass *klass)
gtk_widget_class_set_template_from_resource (GTK_WIDGET_CLASS (klass),
"/org/gnome/calendar/search-view.ui");
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GcalSearchView, no_results_grid);
- gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GcalSearchView, frame);
+ gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GcalSearchView, scrolled_window);
gtk_widget_class_bind_template_child_private (GTK_WIDGET_CLASS (klass), GcalSearchView, listbox);
gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (klass), open_event);
diff --git a/src/gcal-search-view.h b/src/gcal-search-view.h
index 798dc09..52f806f 100644
--- a/src/gcal-search-view.h
+++ b/src/gcal-search-view.h
@@ -39,12 +39,12 @@ typedef struct _GcalSearchViewClass GcalSearchViewClass;
struct _GcalSearchView
{
- GtkScrolledWindow parent;
+ GtkPopover parent;
};
struct _GcalSearchViewClass
{
- GtkScrolledWindowClass parent_class;
+ GtkPopoverClass parent_class;
/* signals */
void (*event_activated) (GcalSearchView *view, icaltimetype *date);
diff --git a/src/gcal-window.c b/src/gcal-window.c
index 8c2d998..293f3e4 100644
--- a/src/gcal-window.c
+++ b/src/gcal-window.c
@@ -73,6 +73,7 @@ typedef struct
GtkWidget *today_button;
GtkWidget *forward_button;
GtkWidget *views_switcher;
+ GtkWidget *search_list_button;
/* new event popover widgets */
GtkWidget *popover;
@@ -141,8 +142,7 @@ static void view_changed (GObject *o
GParamSpec *pspec,
gpointer user_data);
-static void stack_transition_running (GObject *object,
- GParamSpec *pspec,
+static void search_view_closed (GtkPopover *popover,
gpointer user_data);
static void set_new_event_mode (GcalWindow *window,
@@ -316,6 +316,10 @@ search_event_selected (GcalSearchView *search_view,
icaltimetype *date,
gpointer user_data)
{
+ GcalWindowPrivate *priv;
+
+ priv = gcal_window_get_instance_private (GCAL_WINDOW (user_data));
+
g_object_set (user_data, "active-date", date, NULL);
update_view (GCAL_WINDOW (user_data));
gcal_window_set_search_mode (GCAL_WINDOW (user_data), FALSE);
@@ -507,17 +511,16 @@ view_changed (GObject *object,
}
/**
- * stack_transition_running:
+ * search_view_closed:
* @object:
* @pspec:
* @user_data:
*
- * Listen on the transition of the stack to leave search-mode properly
+ *
**/
static void
-stack_transition_running (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
+search_view_closed (GtkPopover *popover,
+ gpointer user_data)
{
GcalWindowPrivate *priv;
@@ -527,17 +530,8 @@ stack_transition_running (GObject *object,
if (!gtk_widget_get_visible (priv->views_stack))
return;
- if (!priv->leaving_search_mode)
- return;
-
- priv->leaving_search_mode = FALSE;
- gtk_container_remove (GTK_CONTAINER (priv->views_stack),
- priv->views[GCAL_WINDOW_VIEW_SEARCH]);
- gtk_widget_hide (priv->views[GCAL_WINDOW_VIEW_SEARCH]);
gtk_widget_hide (priv->search_bar);
-
- gtk_header_bar_set_custom_title (GTK_HEADER_BAR (priv->header_bar),
- priv->views_switcher);
+ gtk_header_bar_set_custom_title (GTK_HEADER_BAR (priv->header_bar), priv->views_switcher);
}
static void
@@ -1048,33 +1042,13 @@ search_toggled (GObject *object,
gtk_widget_show (priv->search_bar);
/* update header_bar widget */
- gtk_header_bar_set_custom_title (GTK_HEADER_BAR (priv->header_bar),
- NULL);
- gtk_widget_hide (priv->today_button);
- gtk_widget_hide (priv->nav_bar);
-
- gtk_widget_show (priv->views[GCAL_WINDOW_VIEW_SEARCH]);
- gtk_stack_add_named (GTK_STACK (priv->views_stack),
- priv->views[GCAL_WINDOW_VIEW_SEARCH],
- "search");
-
- if (gtk_stack_get_visible_child (GTK_STACK (priv->views_stack)) !=
- priv->views[GCAL_WINDOW_VIEW_SEARCH])
- {
- gtk_stack_set_visible_child (GTK_STACK (priv->views_stack),
- priv->views[GCAL_WINDOW_VIEW_SEARCH]);
- }
+ gtk_header_bar_set_custom_title (GTK_HEADER_BAR (priv->header_bar), NULL);
}
else
{
g_debug ("Leaving search mode");
/* update header_bar */
- gtk_widget_show (priv->nav_bar);
- gtk_widget_show (priv->today_button);
gtk_header_bar_set_title (GTK_HEADER_BAR (priv->header_bar), _("Calendar"));
-
- gtk_stack_set_visible_child (GTK_STACK (priv->views_stack),
- priv->views[priv->active_view]);
priv->leaving_search_mode = TRUE;
}
}
@@ -1223,6 +1197,7 @@ gcal_window_class_init(GcalWindowClass *klass)
gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, search_button);
gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, calendars_button);
gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, search_entry);
+ gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, search_list_button);
gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, back_button);
gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, today_button);
gtk_widget_class_bind_template_child_private (widget_class, GcalWindow, forward_button);
@@ -1245,7 +1220,6 @@ gcal_window_class_init(GcalWindowClass *klass)
gtk_widget_class_bind_template_callback (widget_class, search_toggled);
gtk_widget_class_bind_template_callback (widget_class, search_changed);
gtk_widget_class_bind_template_callback (widget_class, view_changed);
- gtk_widget_class_bind_template_callback (widget_class, stack_transition_running);
gtk_widget_class_bind_template_callback (widget_class, date_updated);
/* Event removal related */
@@ -1343,23 +1317,17 @@ gcal_window_constructed (GObject *object)
priv->views[GCAL_WINDOW_VIEW_YEAR],
"year", _("Year"));
- priv->views[GCAL_WINDOW_VIEW_SEARCH] =
- gcal_search_view_new (priv->manager);
+ /* search view */
+ priv->views[GCAL_WINDOW_VIEW_SEARCH] = gcal_search_view_new (priv->manager);
g_object_ref_sink (priv->views[GCAL_WINDOW_VIEW_SEARCH]);
+
gcal_search_view_set_time_format (GCAL_SEARCH_VIEW (priv->views[GCAL_WINDOW_VIEW_SEARCH]), use_24h_format);
+ gtk_popover_set_relative_to (GTK_POPOVER (priv->views[GCAL_WINDOW_VIEW_SEARCH]), priv->search_entry);
- g_object_bind_property (GCAL_WINDOW (object), "active-date",
- priv->views[GCAL_WINDOW_VIEW_SEARCH],
- "active-date",
+ g_object_bind_property (GCAL_WINDOW (object), "active-date", priv->views[GCAL_WINDOW_VIEW_SEARCH],
"active-date",
G_BINDING_DEFAULT | G_BINDING_SYNC_CREATE);
-
- /* search related bindings */
- g_object_bind_property (priv->search_bar, "search-mode-enabled", priv->back_button, "visible",
- G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN);
- g_object_bind_property (priv->search_bar, "search-mode-enabled", priv->today_button, "visible",
- G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN);
- g_object_bind_property (priv->search_bar, "search-mode-enabled", priv->forward_button, "visible",
- G_BINDING_DEFAULT | G_BINDING_INVERT_BOOLEAN);
+ g_object_bind_property (GTK_TOGGLE_BUTTON (priv->search_list_button), "active",
priv->views[GCAL_WINDOW_VIEW_SEARCH],
+ "visible", G_BINDING_DEFAULT);
/* signals connection/handling */
/* HACK to ensure proper destroy of search-view widget */
@@ -1383,6 +1351,7 @@ gcal_window_constructed (GObject *object)
g_signal_connect (priv->views[GCAL_WINDOW_VIEW_SEARCH], "event-activated", G_CALLBACK
(search_event_selected),
object);
+ g_signal_connect (priv->views[GCAL_WINDOW_VIEW_SEARCH], "closed", G_CALLBACK (search_view_closed), object);
/* refresh timeout, first is fast */
priv->refresh_timeout_id = g_timeout_add (FAST_REFRESH_TIMEOUT, (GSourceFunc) refresh_sources, object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]