Commit ec4ae8f7 authored by Mohammed Sadiq's avatar Mohammed Sadiq
Browse files

window: Use GtkStack to stack sidebar widgets

Fixes #244
parent a107ab41
......@@ -38,6 +38,9 @@ struct _ChattyWindow
ChattySettings *settings;
GtkWidget *sidebar_stack;
GtkWidget *empty_view;
GtkWidget *chat_list_view;
GtkWidget *chats_listbox;
GtkWidget *content_box;
......@@ -49,6 +52,7 @@ struct _ChattyWindow
GtkWidget *new_chat_dialog;
GtkWidget *search_button;
GtkWidget *chats_search_bar;
GtkWidget *chats_search_entry;
......@@ -65,7 +69,6 @@ struct _ChattyWindow
GtkWidget *convs_notebook;
GtkWidget *overlay;
GtkWidget *overlay_icon;
GtkWidget *overlay_label_1;
GtkWidget *overlay_label_2;
......@@ -137,6 +140,30 @@ window_chat_list_row_new (ChattyItem *item,
return row;
}
static void
chatty_window_update_sidebar_view (ChattyWindow *self)
{
GtkWidget *current_view;
GListModel *model;
gboolean has_child;
g_assert (CHATTY_IS_WINDOW (self));
model = chatty_manager_get_chat_list (self->manager);
has_child = g_list_model_get_n_items (model) > 0;
if (has_child)
current_view = self->chat_list_view;
else
current_view = self->empty_view;
gtk_widget_set_sensitive (self->search_button, has_child);
gtk_stack_set_visible_child (GTK_STACK (self->sidebar_stack), current_view);
if (!has_child)
hdy_search_bar_set_search_mode (HDY_SEARCH_BAR (self->chats_search_bar), FALSE);
}
static void
window_chat_changed_cb (ChattyWindow *self)
{
......@@ -151,7 +178,6 @@ window_chat_changed_cb (ChattyWindow *self)
model = chatty_manager_get_chat_list (self->manager);
has_child = g_list_model_get_n_items (model) > 0;
gtk_widget_set_visible (self->overlay, !has_child);
gtk_widget_set_sensitive (self->header_sub_menu_button, has_child);
if (!CHATTY_IS_CHAT (self->selected_item)) {
......@@ -179,6 +205,8 @@ window_chat_changed_cb (ChattyWindow *self)
}
}
chatty_window_update_sidebar_view (self);
if (has_child)
return;
......@@ -1081,14 +1109,21 @@ chatty_window_class_init (ChattyWindowClass *klass)
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, header_chat_info_button);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, header_add_chat_button);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, header_sub_menu_button);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, search_button);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, chats_search_bar);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, chats_search_entry);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, content_box);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, header_box);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, header_group);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, sidebar_stack);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, empty_view);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, chat_list_view);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, chats_listbox);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, convs_notebook);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, overlay);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, overlay_icon);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, overlay_label_1);
gtk_widget_class_bind_template_child (widget_class, ChattyWindow, overlay_label_2);
......
......@@ -257,7 +257,7 @@
</packing>
</child>
<child>
<object class="GtkToggleButton">
<object class="GtkToggleButton" id="search_button">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="receives_default">False</property>
......@@ -405,17 +405,20 @@
<property name="visible">True</property>
<property name="hexpand">False</property>
<property name="kinetic-scrolling">True</property>
<child>
<object class="GtkOverlay">
<object class="GtkStack" id="sidebar_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<child type="overlay">
<object class="GtkBox" id="overlay">
<property name="visible">False</property>
<property name="can_focus">False</property>
<!-- Empty chat list view -->
<child>
<object class="GtkBox" id="empty_view">
<property name="visible">True</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="expand">True</property>
<property name="margin_start">36</property>
<property name="margin_end">36</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkImage" id="overlay_icon">
......@@ -430,88 +433,57 @@
<class name="dim-label"/>
</style>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkBox">
<object class="GtkLabel" id="overlay_label_1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="margin_start">36</property>
<property name="margin_end">36</property>
<property name="expand">True</property>
<child>
<object class="GtkLabel" id="overlay_label_1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="halign">center</property>
<property name="margin_bottom">12</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="overlay_label_2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="margin_top">24</property>
<property name="xalign">0</property>
<property name="justify">left</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="overlay_label_3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="margin_top">24</property>
<property name="margin_bottom">64</property>
<property name="xalign">0</property>
<property name="justify">left</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<property name="opacity">0.5</property>
<property name="halign">center</property>
<property name="margin_bottom">12</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel" id="overlay_label_2">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="margin_top">24</property>
<property name="xalign">0</property>
<property name="justify">left</property>
<property name="wrap">True</property>
</object>
</child>
<child>
<object class="GtkLabel" id="overlay_label_3">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="opacity">0.5</property>
<property name="margin_top">24</property>
<property name="margin_bottom">64</property>
<property name="xalign">0</property>
<property name="justify">left</property>
<property name="wrap">True</property>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
</child>
<!-- Chat list view -->
<child>
<object class="GtkBox">
<object class="GtkBox" id="chat_list_view">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="expand">True</property>
<!-- Search bar -->
<child>
<object class="HdySearchBar" id="chats_search_bar">
<property name="visible">True</property>
......@@ -537,6 +509,8 @@
</child>
</object>
</child>
<!-- Chat list -->
<child>
<object class="GtkListBox" id="chats_listbox">
<property name="visible">True</property>
......@@ -546,8 +520,10 @@
<signal name="row-activated" handler="window_chat_row_activated_cb" swapped="no"/>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment