Replace GdMainView with AgIconView in the main window
This commit is contained in:
parent
a18e11f023
commit
a8170b90fd
151
src/ag-window.c
151
src/ag-window.c
@ -22,8 +22,6 @@
|
||||
#include <libxml/parser.h>
|
||||
#include <libxml/tree.h>
|
||||
#include <webkit2/webkit2.h>
|
||||
#include <libgd/gd-main-view.h>
|
||||
#include <libgd/gd-main-view-generic.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <swe-glib.h>
|
||||
@ -35,6 +33,7 @@
|
||||
#include "ag-settings.h"
|
||||
#include "ag-db.h"
|
||||
#include "ag-display-theme.h"
|
||||
#include "ag-icon-view.h"
|
||||
|
||||
struct _AgWindowPrivate {
|
||||
GtkWidget *header_bar;
|
||||
@ -72,12 +71,12 @@ struct _AgWindowPrivate {
|
||||
GtkWidget *points_eq;
|
||||
GtkAdjustment *year_adjust;
|
||||
|
||||
GtkWidget *chart_list;
|
||||
AgSettings *settings;
|
||||
AgChart *chart;
|
||||
gboolean aspect_table_populated;
|
||||
GtkTextBuffer *note_buffer;
|
||||
GtkListStore *house_system_model;
|
||||
GtkListStore *db_chart_data;
|
||||
AgDbChartSave *saved_data;
|
||||
GtkEntryCompletion *country_comp;
|
||||
GtkEntryCompletion *city_comp;
|
||||
@ -1685,7 +1684,10 @@ ag_window_selection_mode_action(GSimpleAction *action,
|
||||
FALSE
|
||||
);
|
||||
gtk_style_context_add_class(style, "selection-mode");
|
||||
gd_main_view_set_selection_mode(GD_MAIN_VIEW(priv->tab_list), TRUE);
|
||||
ag_icon_view_set_mode(
|
||||
AG_ICON_VIEW(priv->chart_list),
|
||||
AG_ICON_VIEW_MODE_SELECTION
|
||||
);
|
||||
gtk_widget_hide(priv->new_back_stack);
|
||||
gtk_stack_set_visible_child_name(
|
||||
GTK_STACK(priv->menubutton_stack),
|
||||
@ -1697,7 +1699,10 @@ ag_window_selection_mode_action(GSimpleAction *action,
|
||||
TRUE
|
||||
);
|
||||
gtk_style_context_remove_class(style, "selection-mode");
|
||||
gd_main_view_set_selection_mode(GD_MAIN_VIEW(priv->tab_list), FALSE);
|
||||
ag_icon_view_set_mode(
|
||||
AG_ICON_VIEW(priv->chart_list),
|
||||
AG_ICON_VIEW_MODE_NORMAL
|
||||
);
|
||||
gtk_widget_show_all(priv->new_back_stack);
|
||||
gtk_stack_set_visible_child_name(
|
||||
GTK_STACK(priv->menubutton_stack),
|
||||
@ -1713,31 +1718,20 @@ ag_window_delete_action(GSimpleAction *action,
|
||||
{
|
||||
GList *selection,
|
||||
*item;
|
||||
GtkTreeModel *model;
|
||||
AgWindow *window = AG_WINDOW(user_data);
|
||||
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||
AgDb *db = ag_db_get();
|
||||
|
||||
selection = gd_main_view_get_selection(GD_MAIN_VIEW(priv->tab_list));
|
||||
model = gd_main_view_get_model(GD_MAIN_VIEW(priv->tab_list));
|
||||
selection = ag_icon_view_get_selected_items(AG_ICON_VIEW(priv->chart_list));
|
||||
|
||||
for (item = selection; item; item = g_list_next(item)) {
|
||||
GtkTreePath *path = item->data;
|
||||
GtkTreeIter iter;
|
||||
gchar *id_str;
|
||||
gint id;
|
||||
GError *err = NULL;
|
||||
GtkTreePath *path = item->data;
|
||||
GError *err = NULL;
|
||||
AgDbChartSave *save_data;
|
||||
|
||||
gtk_tree_model_get_iter(model, &iter, path);
|
||||
gtk_tree_model_get(
|
||||
model, &iter,
|
||||
GD_MAIN_COLUMN_ID, &id_str,
|
||||
-1
|
||||
);
|
||||
id = atoi(id_str);
|
||||
g_free(id_str);
|
||||
save_data = ag_icon_view_get_chart_save_at_path(AG_ICON_VIEW(priv->chart_list), path);
|
||||
|
||||
if (!ag_db_chart_delete(db, id, &err)) {
|
||||
if (!ag_db_chart_delete(db, save_data->db_id, &err)) {
|
||||
ag_app_message_dialog(
|
||||
GTK_WINDOW(window),
|
||||
GTK_MESSAGE_ERROR,
|
||||
@ -1749,6 +1743,8 @@ ag_window_delete_action(GSimpleAction *action,
|
||||
}
|
||||
}
|
||||
|
||||
ag_icon_view_remove_selected(AG_ICON_VIEW(priv->chart_list));
|
||||
|
||||
g_action_group_activate_action(G_ACTION_GROUP(window), "selection", NULL);
|
||||
g_action_group_activate_action(G_ACTION_GROUP(window), "refresh", NULL);
|
||||
}
|
||||
@ -1878,15 +1874,14 @@ ag_window_add_display_theme(AgDisplayTheme *display_theme,
|
||||
}
|
||||
|
||||
static void
|
||||
ag_window_list_item_activated_cb(GdMainView *view,
|
||||
const gchar *id,
|
||||
ag_window_list_item_activated_cb(AgIconView *icon_view,
|
||||
const GtkTreePath *path,
|
||||
AgWindow *window)
|
||||
{
|
||||
guint row_id = atoi(id);
|
||||
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||
AgDb *db = ag_db_get();
|
||||
GError *err = NULL;
|
||||
AgDbChartSave *save_data;
|
||||
|
||||
if (priv->saved_data != NULL) {
|
||||
ag_app_message_dialog(
|
||||
@ -1902,11 +1897,17 @@ ag_window_list_item_activated_cb(GdMainView *view,
|
||||
return;
|
||||
}
|
||||
|
||||
g_debug("Loading chart with ID %d", row_id);
|
||||
save_data = ag_icon_view_get_chart_save_at_path(icon_view, path);
|
||||
|
||||
if (save_data == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
g_debug("Loading chart with ID %d", save_data->db_id);
|
||||
|
||||
if ((priv->saved_data = ag_db_chart_get_data_by_id(
|
||||
db,
|
||||
row_id,
|
||||
save_data->db_id,
|
||||
&err)) == NULL) {
|
||||
ag_app_message_dialog(
|
||||
GTK_WINDOW(window),
|
||||
@ -1943,13 +1944,13 @@ ag_window_list_item_activated_cb(GdMainView *view,
|
||||
}
|
||||
|
||||
static void
|
||||
ag_window_list_selection_changed_cb(GdMainView *view, AgWindow *window)
|
||||
ag_window_list_selection_changed_cb(AgIconView *view, AgWindow *window)
|
||||
{
|
||||
GList *selection;
|
||||
guint count;
|
||||
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||
|
||||
selection = gd_main_view_get_selection(view);
|
||||
selection = ag_icon_view_get_selected_items(view);
|
||||
|
||||
if ((count = g_list_length(selection)) > 0) {
|
||||
gtk_revealer_set_reveal_child(
|
||||
@ -2130,32 +2131,6 @@ ag_window_init(AgWindow *window)
|
||||
NULL
|
||||
);
|
||||
|
||||
priv->tab_list = GTK_WIDGET(gd_main_view_new(GD_MAIN_VIEW_ICON));
|
||||
gtk_stack_add_titled(
|
||||
GTK_STACK(priv->stack),
|
||||
priv->tab_list,
|
||||
"list",
|
||||
"Chart list"
|
||||
);
|
||||
|
||||
gd_main_view_set_selection_mode(GD_MAIN_VIEW(priv->tab_list), FALSE);
|
||||
gd_main_view_set_model(
|
||||
GD_MAIN_VIEW(priv->tab_list),
|
||||
GTK_TREE_MODEL(priv->db_chart_data)
|
||||
);
|
||||
g_signal_connect(
|
||||
priv->tab_list,
|
||||
"item-activated",
|
||||
G_CALLBACK(ag_window_list_item_activated_cb),
|
||||
window
|
||||
);
|
||||
g_signal_connect(
|
||||
priv->tab_list,
|
||||
"view-selection-changed",
|
||||
G_CALLBACK(ag_window_list_selection_changed_cb),
|
||||
window
|
||||
);
|
||||
|
||||
gtk_stack_set_visible_child_name(GTK_STACK(priv->stack), "list");
|
||||
priv->current_tab = priv->tab_list;
|
||||
|
||||
@ -2402,12 +2377,29 @@ ag_window_display_theme_changed_cb(GtkComboBox *combo_box,
|
||||
ag_window_set_theme(window, theme);
|
||||
}
|
||||
|
||||
static void
|
||||
ag_window_destroy(GtkWidget *widget)
|
||||
{
|
||||
AgWindowPrivate *priv = ag_window_get_instance_private(AG_WINDOW(widget));
|
||||
|
||||
// Destroy the signal handlers on priv->stack, as “tab” switching
|
||||
// can cause trouble during destroy. However, this function might
|
||||
// get called multiple times for the same object, in which case
|
||||
// priv->stack is NULL.
|
||||
if (priv->stack) {
|
||||
g_signal_handlers_destroy(priv->stack);
|
||||
}
|
||||
|
||||
GTK_WIDGET_CLASS(ag_window_parent_class)->destroy(widget);
|
||||
}
|
||||
|
||||
static void
|
||||
ag_window_class_init(AgWindowClass *klass)
|
||||
{
|
||||
GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS(klass);
|
||||
|
||||
widget_class->destroy = ag_window_destroy;
|
||||
gobject_class->dispose = ag_window_dispose;
|
||||
|
||||
gtk_widget_class_set_template_from_resource(
|
||||
@ -2429,11 +2421,6 @@ ag_window_class_init(AgWindowClass *klass)
|
||||
AgWindow,
|
||||
menubutton_stack
|
||||
);
|
||||
gtk_widget_class_bind_template_child_private(
|
||||
widget_class,
|
||||
AgWindow,
|
||||
db_chart_data
|
||||
);
|
||||
gtk_widget_class_bind_template_child_private(
|
||||
widget_class,
|
||||
AgWindow,
|
||||
@ -2561,6 +2548,16 @@ ag_window_class_init(AgWindowClass *klass)
|
||||
AgWindow,
|
||||
toolbar_aspect
|
||||
);
|
||||
gtk_widget_class_bind_template_child_private(
|
||||
widget_class,
|
||||
AgWindow,
|
||||
tab_list
|
||||
);
|
||||
gtk_widget_class_bind_template_child_private(
|
||||
widget_class,
|
||||
AgWindow,
|
||||
chart_list
|
||||
);
|
||||
|
||||
gtk_widget_class_bind_template_callback(
|
||||
widget_class,
|
||||
@ -2586,6 +2583,14 @@ ag_window_class_init(AgWindowClass *klass)
|
||||
widget_class,
|
||||
ag_window_display_theme_changed_cb
|
||||
);
|
||||
gtk_widget_class_bind_template_callback(
|
||||
widget_class,
|
||||
ag_window_list_item_activated_cb
|
||||
);
|
||||
gtk_widget_class_bind_template_callback(
|
||||
widget_class,
|
||||
ag_window_list_selection_changed_cb
|
||||
);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@ -2744,33 +2749,10 @@ ag_window_change_tab(AgWindow *window, const gchar *tab_name)
|
||||
|
||||
static void
|
||||
ag_window_add_chart_to_list(AgDbChartSave *save_data, AgWindow *window)
|
||||
{
|
||||
GtkTreeIter iter;
|
||||
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||
gchar *id = g_strdup_printf("%d", save_data->db_id);
|
||||
|
||||
gtk_list_store_append(priv->db_chart_data, &iter);
|
||||
gtk_list_store_set(
|
||||
priv->db_chart_data, &iter,
|
||||
0, id, /* ID */
|
||||
1, NULL, /* URI */
|
||||
2, save_data->name, /* Primary text */
|
||||
3, NULL, /* Secondary text */
|
||||
4, NULL, /* Icon */
|
||||
5, 0, /* mtime */
|
||||
6, FALSE, /* Selected */
|
||||
7, 0, /* Pulse */
|
||||
-1
|
||||
);
|
||||
g_free(id);
|
||||
}
|
||||
|
||||
static void
|
||||
ag_window_clear_chart_list(AgWindow *window)
|
||||
{
|
||||
AgWindowPrivate *priv = ag_window_get_instance_private(window);
|
||||
|
||||
gtk_list_store_clear(priv->db_chart_data);
|
||||
ag_icon_view_add_chart(AG_ICON_VIEW(priv->chart_list), save_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
@ -2780,7 +2762,6 @@ ag_window_load_chart_list(AgWindow *window)
|
||||
GError *err = NULL;
|
||||
GList *chart_list = ag_db_chart_get_list(db, &err);
|
||||
|
||||
ag_window_clear_chart_list(window);
|
||||
/* With only a few charts, this should be fine. Maybe implementing lazy
|
||||
* loading would be a better idea. See:
|
||||
* http://blogs.gnome.org/ebassi/documentation/lazy-loading/
|
||||
|
@ -124,26 +124,6 @@
|
||||
</object>
|
||||
<object class="GtkTextBuffer" id="note_buffer">
|
||||
</object>
|
||||
<object class="GtkListStore" id="db_chart_data">
|
||||
<columns>
|
||||
<!-- column-name id -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name uri -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name name -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name secondary-text -->
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name icon -->
|
||||
<column type="GdkPixbuf"/>
|
||||
<!-- column-name mtime -->
|
||||
<column type="gint64"/>
|
||||
<!-- column-name selected -->
|
||||
<column type="gboolean"/>
|
||||
<!-- column-name pulse -->
|
||||
<column type="guint"/>
|
||||
</columns>
|
||||
</object>
|
||||
<object class="GtkEntryCompletion" id="country_comp">
|
||||
<property name="inline_completion">True</property>
|
||||
</object>
|
||||
@ -363,6 +343,20 @@
|
||||
<property name="vexpand">True</property>
|
||||
<property name="hexpand">True</property>
|
||||
<signal name="notify::visible-child" handler="ag_window_tab_changed_cb" object="AgWindow" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkScrolledWindow" id="tab_list">
|
||||
<child>
|
||||
<object class="AgIconView" id="chart_list">
|
||||
<signal name="item-activated" handler="ag_window_list_item_activated_cb" object="AgWindow" swapped="no"/>
|
||||
<signal name="selection-changed" handler="ag_window_list_selection_changed_cb" object="AgWindow" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="name">list</property>
|
||||
<property name="title" translatable="yes">Chart list</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkGrid" id="tab_edit">
|
||||
<property name="visible">True</property>
|
||||
|
Loading…
Reference in New Issue
Block a user