2014-05-15 23:34:38 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-05-15 23:34:38 +00:00
|
|
|
#include "resource-list.h"
|
|
|
|
|
2018-02-09 00:06:59 +00:00
|
|
|
#include "gtkbutton.h"
|
2014-07-12 03:45:18 +00:00
|
|
|
#include "gtklabel.h"
|
2018-02-09 00:06:59 +00:00
|
|
|
#include "gtksearchbar.h"
|
|
|
|
#include "gtksearchentry.h"
|
2014-07-12 03:45:18 +00:00
|
|
|
#include "gtkstack.h"
|
2014-07-12 03:14:04 +00:00
|
|
|
#include "gtktextbuffer.h"
|
|
|
|
#include "gtktreeselection.h"
|
2018-02-09 00:06:59 +00:00
|
|
|
#include "gtktreestore.h"
|
2018-02-04 08:29:44 +00:00
|
|
|
#include "gtkeventcontrollerkey.h"
|
2020-04-26 15:25:23 +00:00
|
|
|
#include "gtkpicture.h"
|
|
|
|
#include "gtkmediafile.h"
|
2020-07-16 01:22:21 +00:00
|
|
|
#include "gtkbinlayout.h"
|
2019-12-08 03:26:35 +00:00
|
|
|
#include "resource-holder.h"
|
2018-02-09 00:06:59 +00:00
|
|
|
|
|
|
|
#include <glib/gi18n-lib.h>
|
2014-07-12 03:14:04 +00:00
|
|
|
|
2014-10-11 04:58:47 +00:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
PROP_0,
|
2014-10-25 01:14:16 +00:00
|
|
|
PROP_BUTTONS
|
2014-10-11 04:58:47 +00:00
|
|
|
};
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
struct _GtkInspectorResourceList
|
2014-05-15 23:34:38 +00:00
|
|
|
{
|
2020-07-16 01:22:21 +00:00
|
|
|
GtkWidget parent_instance;
|
2020-07-16 00:28:05 +00:00
|
|
|
|
2014-05-15 23:34:38 +00:00
|
|
|
GtkTextBuffer *buffer;
|
2020-04-26 15:25:23 +00:00
|
|
|
GtkWidget *video;
|
2014-05-15 23:34:38 +00:00
|
|
|
GtkWidget *image;
|
|
|
|
GtkWidget *content;
|
2014-10-11 00:20:02 +00:00
|
|
|
GtkWidget *name_label;
|
2014-07-19 05:20:28 +00:00
|
|
|
GtkWidget *type;
|
2014-05-19 11:10:33 +00:00
|
|
|
GtkWidget *type_label;
|
|
|
|
GtkWidget *size_label;
|
|
|
|
GtkWidget *info_grid;
|
2014-10-11 00:20:02 +00:00
|
|
|
GtkWidget *stack;
|
2014-10-25 01:14:16 +00:00
|
|
|
GtkWidget *buttons;
|
|
|
|
GtkWidget *open_details_button;
|
2014-10-11 04:58:47 +00:00
|
|
|
GtkWidget *close_details_button;
|
2014-11-08 01:38:42 +00:00
|
|
|
GtkWidget *search_bar;
|
|
|
|
GtkWidget *search_entry;
|
2019-12-08 03:26:35 +00:00
|
|
|
|
|
|
|
GtkWidget *list;
|
|
|
|
GtkColumnViewColumn *path;
|
|
|
|
GtkColumnViewColumn *count;
|
|
|
|
GtkColumnViewColumn *size;
|
|
|
|
|
|
|
|
GtkTreeListModel *tree_model;
|
|
|
|
GtkSingleSelection *selection;
|
2014-05-15 23:34:38 +00:00
|
|
|
};
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
typedef struct _GtkInspectorResourceListClass
|
|
|
|
{
|
2020-07-16 01:22:21 +00:00
|
|
|
GtkWidgetClass parent;
|
2020-07-16 00:28:05 +00:00
|
|
|
} GtkInspectorResourceListClass;
|
|
|
|
|
2014-10-11 04:58:47 +00:00
|
|
|
|
2020-07-16 01:22:21 +00:00
|
|
|
G_DEFINE_TYPE (GtkInspectorResourceList, gtk_inspector_resource_list, GTK_TYPE_WIDGET)
|
2014-05-15 23:34:38 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
static GListModel *
|
|
|
|
load_resources_recurse (const char *path,
|
|
|
|
int *count_out,
|
|
|
|
gsize *size_out)
|
2014-05-15 23:34:38 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char **names;
|
2020-07-24 13:54:49 +00:00
|
|
|
int i;
|
2019-12-08 03:26:35 +00:00
|
|
|
GListStore *result;
|
|
|
|
|
|
|
|
result = g_list_store_new (RESOURCE_TYPE_HOLDER);
|
2014-05-15 23:34:38 +00:00
|
|
|
|
|
|
|
names = g_resources_enumerate_children (path, 0, NULL);
|
|
|
|
for (i = 0; names[i]; i++)
|
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int len;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *p;
|
2014-05-15 23:34:38 +00:00
|
|
|
gboolean has_slash;
|
2020-07-24 13:54:49 +00:00
|
|
|
int count;
|
2014-07-19 05:20:28 +00:00
|
|
|
gsize size;
|
2019-12-08 03:26:35 +00:00
|
|
|
GListModel *children;
|
|
|
|
ResourceHolder *holder;
|
2014-05-15 23:34:38 +00:00
|
|
|
|
|
|
|
p = g_strconcat (path, names[i], NULL);
|
|
|
|
|
|
|
|
len = strlen (names[i]);
|
|
|
|
has_slash = names[i][len - 1] == '/';
|
|
|
|
|
|
|
|
if (has_slash)
|
|
|
|
names[i][len - 1] = '\0';
|
|
|
|
|
2014-07-19 05:20:28 +00:00
|
|
|
count = 0;
|
|
|
|
size = 0;
|
|
|
|
|
2014-05-15 23:34:38 +00:00
|
|
|
if (has_slash)
|
2014-07-19 05:20:28 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
children = load_resources_recurse (p, &count, &size);
|
|
|
|
|
2014-10-10 23:15:02 +00:00
|
|
|
*count_out += count;
|
|
|
|
*size_out += size;
|
2014-07-19 05:20:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-10-10 23:15:02 +00:00
|
|
|
count = 0;
|
2015-07-17 19:56:34 +00:00
|
|
|
if (g_resources_get_info (p, 0, &size, NULL, NULL))
|
|
|
|
{
|
|
|
|
*count_out += 1;
|
|
|
|
*size_out += size;
|
|
|
|
}
|
2019-12-08 03:26:35 +00:00
|
|
|
children = NULL;
|
2014-07-19 05:20:28 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
holder = resource_holder_new (names[i], p, count, size, children);
|
|
|
|
g_clear_object (&children);
|
|
|
|
g_list_store_append (result, holder);
|
|
|
|
g_object_unref (holder);
|
2014-05-15 23:34:38 +00:00
|
|
|
|
|
|
|
g_free (p);
|
|
|
|
}
|
2019-12-08 03:26:35 +00:00
|
|
|
|
2014-05-15 23:34:38 +00:00
|
|
|
g_strfreev (names);
|
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
return G_LIST_MODEL (result);
|
2014-05-15 23:34:38 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 00:20:02 +00:00
|
|
|
static gboolean
|
|
|
|
populate_details (GtkInspectorResourceList *rl,
|
2019-12-08 03:26:35 +00:00
|
|
|
ResourceHolder *holder)
|
2014-05-15 23:34:38 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
const char *path;
|
|
|
|
const char *name;
|
2014-10-11 00:20:02 +00:00
|
|
|
GBytes *bytes;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *type;
|
2014-10-11 00:20:02 +00:00
|
|
|
gconstpointer data;
|
|
|
|
gsize size;
|
|
|
|
GError *error = NULL;
|
2020-07-24 18:40:36 +00:00
|
|
|
char *markup;
|
2014-10-11 00:20:02 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
path = resource_holder_get_path (holder);
|
|
|
|
name = resource_holder_get_name (holder);
|
|
|
|
size = resource_holder_get_size (holder);
|
2014-10-11 00:20:02 +00:00
|
|
|
|
|
|
|
if (g_str_has_suffix (path, "/"))
|
2019-12-08 03:26:35 +00:00
|
|
|
return FALSE;
|
2014-10-11 00:20:02 +00:00
|
|
|
|
|
|
|
markup = g_strconcat ("<span face='Monospace' size='small'>", path, "</span>", NULL);
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_label_set_markup (GTK_LABEL (rl->name_label), markup);
|
2014-10-11 00:20:02 +00:00
|
|
|
g_free (markup);
|
|
|
|
|
|
|
|
bytes = g_resources_lookup_data (path, 0, &error);
|
|
|
|
if (bytes == NULL)
|
2014-05-15 23:34:38 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_text_buffer_set_text (rl->buffer, error->message, -1);
|
2014-10-11 00:20:02 +00:00
|
|
|
g_error_free (error);
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->content), "text");
|
2014-10-11 00:20:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *text;
|
|
|
|
char *content_image;
|
|
|
|
char *content_text;
|
|
|
|
char *content_video;
|
2017-03-09 03:52:58 +00:00
|
|
|
|
|
|
|
content_image = g_content_type_from_mime_type ("image/*");
|
|
|
|
content_text = g_content_type_from_mime_type ("text/*");
|
2020-04-26 15:25:23 +00:00
|
|
|
content_video = g_content_type_from_mime_type ("video/*");
|
2014-05-19 11:10:33 +00:00
|
|
|
|
2014-10-11 00:20:02 +00:00
|
|
|
data = g_bytes_get_data (bytes, &size);
|
|
|
|
type = g_content_type_guess (name, data, size, NULL);
|
2014-07-19 05:20:28 +00:00
|
|
|
|
2014-10-11 00:20:02 +00:00
|
|
|
text = g_content_type_get_description (type);
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (rl->type_label), text);
|
2014-10-11 00:20:02 +00:00
|
|
|
g_free (text);
|
2014-07-19 05:20:28 +00:00
|
|
|
|
2014-10-11 00:20:02 +00:00
|
|
|
text = g_format_size (size);
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_label_set_text (GTK_LABEL (rl->size_label), text);
|
2014-10-11 00:20:02 +00:00
|
|
|
g_free (text);
|
2015-01-09 19:44:26 +00:00
|
|
|
|
2017-03-09 03:52:58 +00:00
|
|
|
if (g_content_type_is_a (type, content_text))
|
2014-10-11 00:20:02 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_text_buffer_set_text (rl->buffer, data, -1);
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->content), "text");
|
2014-05-15 23:34:38 +00:00
|
|
|
}
|
2017-03-09 03:52:58 +00:00
|
|
|
else if (g_content_type_is_a (type, content_image))
|
2014-05-15 23:34:38 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_picture_set_resource (GTK_PICTURE (rl->image), path);
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->content), "image");
|
2014-05-15 23:34:38 +00:00
|
|
|
}
|
2020-04-26 15:25:23 +00:00
|
|
|
else if (g_content_type_is_a (type, content_video))
|
|
|
|
{
|
|
|
|
GtkMediaStream *stream;
|
|
|
|
|
|
|
|
stream = gtk_media_file_new_for_resource (path);
|
|
|
|
gtk_media_stream_set_loop (GTK_MEDIA_STREAM (stream), TRUE);
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_picture_set_paintable (GTK_PICTURE (rl->image), GDK_PAINTABLE (stream));
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->content), "image");
|
2020-04-26 15:25:23 +00:00
|
|
|
gtk_media_stream_play (GTK_MEDIA_STREAM (stream));
|
|
|
|
g_object_unref (stream);
|
|
|
|
}
|
2014-05-15 23:34:38 +00:00
|
|
|
else
|
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_text_buffer_set_text (rl->buffer, "", 0);
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->content), "text");
|
2014-10-11 00:20:02 +00:00
|
|
|
}
|
2014-05-19 11:10:33 +00:00
|
|
|
|
2014-10-11 00:20:02 +00:00
|
|
|
g_free (type);
|
|
|
|
g_bytes_unref (bytes);
|
2017-03-09 03:52:58 +00:00
|
|
|
|
|
|
|
g_free (content_image);
|
|
|
|
g_free (content_text);
|
2014-10-11 00:20:02 +00:00
|
|
|
}
|
2014-05-19 11:10:33 +00:00
|
|
|
|
2014-10-11 00:20:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-08 03:26:35 +00:00
|
|
|
on_row_activated (GtkColumnView *view,
|
|
|
|
guint position,
|
|
|
|
GtkInspectorResourceList *rl)
|
2014-10-11 00:20:02 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
gpointer item;
|
|
|
|
ResourceHolder *holder;
|
2014-10-25 01:14:16 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
item = g_list_model_get_item (G_LIST_MODEL (rl->selection), position);
|
2019-12-08 03:26:35 +00:00
|
|
|
holder = gtk_tree_list_row_get_item (item);
|
|
|
|
g_object_unref (item);
|
|
|
|
if (populate_details (rl, holder))
|
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->stack), "details");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->buttons), "details");
|
2019-12-08 03:26:35 +00:00
|
|
|
}
|
|
|
|
g_object_unref (holder);
|
2014-10-25 01:14:16 +00:00
|
|
|
}
|
|
|
|
|
2014-10-25 01:52:23 +00:00
|
|
|
static gboolean
|
|
|
|
can_show_details (GtkInspectorResourceList *rl)
|
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
gpointer item;
|
|
|
|
ResourceHolder *holder;
|
|
|
|
const char *path;
|
2014-10-25 01:52:23 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
item = gtk_single_selection_get_selected_item (rl->selection);
|
2019-12-08 03:26:35 +00:00
|
|
|
holder = gtk_tree_list_row_get_item (item);
|
|
|
|
if (holder == NULL)
|
2014-10-25 01:52:23 +00:00
|
|
|
return FALSE;
|
2019-12-08 03:26:35 +00:00
|
|
|
path = resource_holder_get_path (holder);
|
|
|
|
g_object_unref (holder);
|
|
|
|
return !g_str_has_suffix (path, "/");
|
2014-10-25 01:52:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-08 03:26:35 +00:00
|
|
|
on_selection_changed (GtkSelectionModel *selection,
|
|
|
|
guint position,
|
|
|
|
guint n_items,
|
2014-10-25 01:52:23 +00:00
|
|
|
GtkInspectorResourceList *rl)
|
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_widget_set_sensitive (rl->open_details_button, can_show_details (rl));
|
2014-10-25 01:52:23 +00:00
|
|
|
}
|
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
static void
|
|
|
|
open_details (GtkWidget *button,
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl)
|
2014-10-25 01:14:16 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
gpointer item;
|
|
|
|
ResourceHolder *holder;
|
2014-10-25 01:14:16 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
item = gtk_single_selection_get_selected_item (rl->selection);
|
2019-12-08 03:26:35 +00:00
|
|
|
holder = gtk_tree_list_row_get_item (item);
|
|
|
|
if (holder == NULL)
|
2014-10-25 01:14:16 +00:00
|
|
|
return;
|
2019-12-08 03:26:35 +00:00
|
|
|
if (populate_details (rl, holder))
|
2014-10-25 01:14:16 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->stack), "details");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->buttons), "details");
|
2014-10-25 01:14:16 +00:00
|
|
|
}
|
2019-12-08 03:26:35 +00:00
|
|
|
g_object_unref (holder);
|
2014-10-11 00:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
close_details (GtkWidget *button,
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl)
|
2014-10-11 00:20:02 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->stack), "list");
|
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->buttons), "list");
|
2014-05-15 23:34:38 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
static GListModel *
|
|
|
|
load_resources (void)
|
2014-05-15 23:34:38 +00:00
|
|
|
{
|
2020-07-24 13:54:49 +00:00
|
|
|
int count = 0;
|
2014-07-19 05:20:28 +00:00
|
|
|
gsize size = 0;
|
2014-05-15 23:34:38 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
return load_resources_recurse ("/", &count, &size);
|
2014-10-10 23:15:02 +00:00
|
|
|
}
|
|
|
|
|
2014-10-11 00:20:02 +00:00
|
|
|
static void
|
|
|
|
on_map (GtkWidget *widget)
|
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (widget);
|
2014-10-11 00:20:02 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_stack_set_visible_child_name (GTK_STACK (rl->stack), "list");
|
|
|
|
gtk_widget_set_sensitive (rl->open_details_button, can_show_details (rl));
|
2014-10-11 04:58:47 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
static gboolean search (GtkInspectorResourceList *rl,
|
|
|
|
gboolean forward,
|
|
|
|
gboolean force_progress);
|
2014-11-08 01:38:42 +00:00
|
|
|
|
|
|
|
static gboolean
|
2018-02-04 08:29:44 +00:00
|
|
|
key_pressed (GtkEventController *controller,
|
|
|
|
guint keyval,
|
|
|
|
guint keycode,
|
|
|
|
GdkModifierType state,
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
if (gtk_widget_get_mapped (GTK_WIDGET (rl)))
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
|
|
|
GdkModifierType default_accel;
|
|
|
|
gboolean search_started;
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
search_started = gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (rl->search_bar));
|
2020-04-05 23:52:25 +00:00
|
|
|
default_accel = GDK_CONTROL_MASK;
|
2014-11-08 01:38:42 +00:00
|
|
|
|
|
|
|
if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
(keyval == GDK_KEY_Return ||
|
|
|
|
keyval == GDK_KEY_ISO_Enter ||
|
|
|
|
keyval == GDK_KEY_KP_Enter))
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_widget_activate (GTK_WIDGET (rl->list));
|
2019-12-08 03:26:35 +00:00
|
|
|
return GDK_EVENT_PROPAGATE;
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
else if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
(keyval == GDK_KEY_Escape))
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (rl->search_bar), FALSE);
|
2014-11-08 01:38:42 +00:00
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
else if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
((state & (default_accel | GDK_SHIFT_MASK)) == (default_accel | GDK_SHIFT_MASK)) &&
|
|
|
|
(keyval == GDK_KEY_g || keyval == GDK_KEY_G))
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
if (!search (rl, FALSE, TRUE))
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (rl));
|
2014-11-08 01:38:42 +00:00
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
else if (search_started &&
|
2017-08-25 14:57:26 +00:00
|
|
|
((state & (default_accel | GDK_SHIFT_MASK)) == default_accel) &&
|
|
|
|
(keyval == GDK_KEY_g || keyval == GDK_KEY_G))
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
if (!search (rl, TRUE, TRUE))
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (rl));
|
2014-11-08 01:38:42 +00:00
|
|
|
return GDK_EVENT_STOP;
|
|
|
|
}
|
|
|
|
}
|
2018-03-11 12:54:54 +00:00
|
|
|
|
|
|
|
return GDK_EVENT_PROPAGATE;
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 17:03:17 +00:00
|
|
|
static void
|
|
|
|
destroy_controller (GtkEventController *controller)
|
|
|
|
{
|
|
|
|
gtk_widget_remove_controller (gtk_event_controller_get_widget (controller), controller);
|
|
|
|
}
|
|
|
|
|
2014-11-08 01:38:42 +00:00
|
|
|
static void
|
2019-02-23 05:29:52 +00:00
|
|
|
root (GtkWidget *widget)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (widget);
|
2018-02-04 08:29:44 +00:00
|
|
|
GtkEventController *controller;
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
2019-02-23 05:29:52 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_resource_list_parent_class)->root (widget);
|
2018-02-04 08:29:44 +00:00
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
2018-05-05 07:06:22 +00:00
|
|
|
|
2018-04-20 17:58:06 +00:00
|
|
|
controller = gtk_event_controller_key_new ();
|
2018-05-14 17:03:17 +00:00
|
|
|
g_object_set_data_full (G_OBJECT (toplevel), "resource-controller", controller, (GDestroyNotify)destroy_controller);
|
2018-02-04 08:29:44 +00:00
|
|
|
g_signal_connect (controller, "key-pressed", G_CALLBACK (key_pressed), widget);
|
2018-04-20 17:58:06 +00:00
|
|
|
gtk_widget_add_controller (toplevel, controller);
|
2018-03-11 12:54:54 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_search_bar_set_key_capture_widget (GTK_SEARCH_BAR (rl->search_bar), toplevel);
|
2019-02-23 05:29:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
unroot (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkWidget *toplevel;
|
|
|
|
|
2019-05-20 04:47:50 +00:00
|
|
|
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
2019-02-23 05:29:52 +00:00
|
|
|
g_object_set_data (G_OBJECT (toplevel), "resource-controller", NULL);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_inspector_resource_list_parent_class)->unroot (widget);
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2020-07-24 18:40:36 +00:00
|
|
|
match_string (const char *string,
|
|
|
|
const char *text)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2020-07-24 18:40:36 +00:00
|
|
|
char *lower;
|
2014-11-08 01:38:42 +00:00
|
|
|
gboolean match = FALSE;
|
|
|
|
|
|
|
|
if (string)
|
|
|
|
{
|
|
|
|
lower = g_ascii_strdown (string, -1);
|
|
|
|
match = g_str_has_prefix (lower, text);
|
|
|
|
g_free (lower);
|
|
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
2019-12-08 03:26:35 +00:00
|
|
|
match_object (GObject *object,
|
|
|
|
const char *text)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
const char *name = resource_holder_get_name (RESOURCE_HOLDER (object));
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
if (match_string (name, text))
|
|
|
|
return TRUE;
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
static GObject *
|
|
|
|
search_children (GObject *object,
|
|
|
|
const char *text,
|
|
|
|
gboolean forward)
|
|
|
|
{
|
|
|
|
GListModel *children;
|
|
|
|
GObject *child, *result;
|
|
|
|
guint i, n;
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
children = resource_holder_get_children (RESOURCE_HOLDER (object));
|
|
|
|
if (children == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
n = g_list_model_get_n_items (children);
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
{
|
|
|
|
child = g_list_model_get_item (children, forward ? i : n - i - 1);
|
|
|
|
if (match_object (child, text))
|
|
|
|
return child;
|
|
|
|
|
|
|
|
result = search_children (child, text, forward);
|
|
|
|
g_object_unref (child);
|
|
|
|
if (result)
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static guint
|
|
|
|
model_get_item_index (GListModel *model,
|
|
|
|
gpointer item)
|
|
|
|
{
|
|
|
|
gpointer cmp;
|
|
|
|
guint i;
|
|
|
|
|
|
|
|
for (i = 0; (cmp = g_list_model_get_item (model, i)); i++)
|
|
|
|
{
|
|
|
|
if (cmp == item)
|
|
|
|
{
|
|
|
|
g_object_unref (cmp);
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
g_object_unref (cmp);
|
|
|
|
}
|
|
|
|
|
|
|
|
return G_MAXUINT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static GtkTreeListRow *
|
|
|
|
find_and_expand_object (GtkTreeListModel *model,
|
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkTreeListRow *result;
|
|
|
|
GObject *parent;
|
|
|
|
guint pos;
|
|
|
|
|
|
|
|
parent = G_OBJECT (resource_holder_get_parent (RESOURCE_HOLDER (object)));
|
|
|
|
if (parent)
|
|
|
|
{
|
|
|
|
GtkTreeListRow *parent_row = find_and_expand_object (model, parent);
|
|
|
|
if (parent_row == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
gtk_tree_list_row_set_expanded (parent_row, TRUE);
|
|
|
|
pos = model_get_item_index (gtk_tree_list_row_get_children (parent_row), object);
|
|
|
|
result = gtk_tree_list_row_get_child_row (parent_row, pos);
|
|
|
|
g_object_unref (parent_row);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pos = model_get_item_index (gtk_tree_list_model_get_model (model), object);
|
|
|
|
result = gtk_tree_list_model_get_child_row (model, pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-12-08 03:26:35 +00:00
|
|
|
select_object (GtkInspectorResourceList *rl,
|
|
|
|
GObject *object)
|
|
|
|
{
|
|
|
|
GtkTreeListRow *row_item;
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
row_item = find_and_expand_object (rl->tree_model, object);
|
2019-12-08 03:26:35 +00:00
|
|
|
if (row_item == NULL)
|
|
|
|
return;
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_single_selection_set_selected (rl->selection,
|
2019-12-08 03:26:35 +00:00
|
|
|
gtk_tree_list_row_get_position (row_item));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
search (GtkInspectorResourceList *rl,
|
|
|
|
gboolean forward,
|
|
|
|
gboolean force_progress)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
GListModel *model = G_LIST_MODEL (rl->tree_model);
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkTreeListRow *row_item;
|
|
|
|
GObject *child, *result;
|
|
|
|
guint i, selected, n, row;
|
|
|
|
const char *text;
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
text = gtk_editable_get_text (GTK_EDITABLE (rl->search_entry));
|
|
|
|
selected = gtk_single_selection_get_selected (rl->selection);
|
2019-12-08 03:26:35 +00:00
|
|
|
n = g_list_model_get_n_items (model);
|
|
|
|
if (selected >= n)
|
|
|
|
selected = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
row = (selected + (forward ? i : n - i - 1)) % n;
|
|
|
|
row_item = g_list_model_get_item (model, row);
|
|
|
|
child = gtk_tree_list_row_get_item (row_item);
|
|
|
|
if (i > 0 || !force_progress)
|
|
|
|
{
|
|
|
|
if (match_object (child, text))
|
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_single_selection_set_selected (rl->selection, row);
|
2019-12-08 03:26:35 +00:00
|
|
|
g_object_unref (child);
|
|
|
|
g_object_unref (row_item);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!gtk_tree_list_row_get_expanded (row_item))
|
|
|
|
{
|
|
|
|
result = search_children (child, text, forward);
|
|
|
|
if (result)
|
|
|
|
{
|
|
|
|
select_object (rl, result);
|
|
|
|
g_object_unref (result);
|
|
|
|
g_object_unref (child);
|
|
|
|
g_object_unref (row_item);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
g_object_unref (child);
|
|
|
|
g_object_unref (row_item);
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
2019-12-08 03:26:35 +00:00
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
on_search_changed (GtkSearchEntry *entry,
|
|
|
|
GtkInspectorResourceList *rl)
|
|
|
|
{
|
|
|
|
if (!search (rl, TRUE, FALSE))
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (rl));
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
next_match (GtkButton *button,
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (rl->search_bar)))
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
if (!search (rl, TRUE, TRUE))
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (rl));
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
previous_match (GtkButton *button,
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
if (gtk_search_bar_get_search_mode (GTK_SEARCH_BAR (rl->search_bar)))
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
if (!search (rl, FALSE, TRUE))
|
|
|
|
gtk_widget_error_bell (GTK_WIDGET (rl));
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-05-15 23:34:38 +00:00
|
|
|
static void
|
2019-12-08 03:26:35 +00:00
|
|
|
stop_search (GtkWidget *entry,
|
|
|
|
GtkInspectorResourceList *rl)
|
2014-05-15 23:34:38 +00:00
|
|
|
{
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_editable_set_text (GTK_EDITABLE (rl->search_entry), "");
|
|
|
|
gtk_search_bar_set_search_mode (GTK_SEARCH_BAR (rl->search_bar), FALSE);
|
2019-12-08 03:26:35 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 21:02:14 +00:00
|
|
|
static char *
|
|
|
|
holder_name (gpointer item)
|
|
|
|
{
|
|
|
|
return g_strdup (resource_holder_get_name (RESOURCE_HOLDER (item)));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
holder_count (gpointer item)
|
|
|
|
{
|
|
|
|
return resource_holder_get_count (RESOURCE_HOLDER (item));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gsize
|
|
|
|
holder_size (gpointer item)
|
|
|
|
{
|
|
|
|
return resource_holder_get_size (RESOURCE_HOLDER (item));
|
|
|
|
}
|
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_resource_list_init (GtkInspectorResourceList *rl)
|
|
|
|
{
|
2019-12-08 21:02:14 +00:00
|
|
|
GtkSorter *sorter;
|
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
gtk_widget_init_template (GTK_WIDGET (rl));
|
2014-10-11 04:58:47 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
g_signal_connect (rl, "map", G_CALLBACK (on_map), NULL);
|
2014-10-11 04:58:47 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_search_bar_connect_entry (GTK_SEARCH_BAR (rl->search_bar),
|
|
|
|
GTK_EDITABLE (rl->search_entry));
|
2019-12-08 21:02:14 +00:00
|
|
|
|
|
|
|
sorter = gtk_string_sorter_new (gtk_cclosure_expression_new (G_TYPE_STRING, NULL,
|
|
|
|
0, NULL,
|
|
|
|
(GCallback)holder_name,
|
|
|
|
NULL, NULL));
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_column_view_column_set_sorter (rl->path, sorter);
|
2019-12-08 21:02:14 +00:00
|
|
|
g_object_unref (sorter);
|
|
|
|
|
|
|
|
sorter = gtk_numeric_sorter_new (gtk_cclosure_expression_new (G_TYPE_INT, NULL,
|
|
|
|
0, NULL,
|
|
|
|
(GCallback)holder_count,
|
|
|
|
NULL, NULL));
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_column_view_column_set_sorter (rl->count, sorter);
|
2019-12-08 21:02:14 +00:00
|
|
|
g_object_unref (sorter);
|
|
|
|
|
|
|
|
sorter = gtk_numeric_sorter_new (gtk_cclosure_expression_new (G_TYPE_UINT64, NULL,
|
|
|
|
0, NULL,
|
|
|
|
(GCallback)holder_size,
|
|
|
|
NULL, NULL));
|
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_column_view_column_set_sorter (rl->size, sorter);
|
2019-12-08 21:02:14 +00:00
|
|
|
g_object_unref (sorter);
|
2019-12-08 03:26:35 +00:00
|
|
|
}
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
static GListModel *
|
|
|
|
create_model_for_object (gpointer item, gpointer data)
|
|
|
|
{
|
|
|
|
GListModel *model = resource_holder_get_children (RESOURCE_HOLDER (item));
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
if (model)
|
|
|
|
return g_object_ref (model);
|
|
|
|
|
|
|
|
return NULL;
|
2014-10-11 04:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
constructed (GObject *object)
|
|
|
|
{
|
|
|
|
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
|
2019-12-08 03:26:35 +00:00
|
|
|
GListModel *root_model;
|
2019-12-08 21:02:14 +00:00
|
|
|
GListModel *sort_model;
|
2020-07-16 02:14:36 +00:00
|
|
|
GtkSorter *column_sorter;
|
2019-12-08 21:02:14 +00:00
|
|
|
GtkSorter *sorter;
|
2019-12-08 03:26:35 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
g_signal_connect (rl->open_details_button, "clicked",
|
2014-10-25 01:14:16 +00:00
|
|
|
G_CALLBACK (open_details), rl);
|
2020-07-16 00:28:05 +00:00
|
|
|
g_signal_connect (rl->close_details_button, "clicked",
|
2014-10-11 04:58:47 +00:00
|
|
|
G_CALLBACK (close_details), rl);
|
2019-12-08 03:26:35 +00:00
|
|
|
|
|
|
|
root_model = load_resources ();
|
2020-07-16 00:28:05 +00:00
|
|
|
rl->tree_model = gtk_tree_list_model_new (FALSE,
|
|
|
|
root_model,
|
|
|
|
FALSE,
|
|
|
|
create_model_for_object,
|
|
|
|
NULL,
|
|
|
|
NULL);
|
|
|
|
|
2020-07-16 02:14:36 +00:00
|
|
|
column_sorter = gtk_column_view_get_sorter (GTK_COLUMN_VIEW (rl->list));
|
|
|
|
sorter = gtk_tree_list_row_sorter_new (g_object_ref (column_sorter));
|
2020-07-16 00:28:05 +00:00
|
|
|
sort_model = G_LIST_MODEL (gtk_sort_list_model_new (G_LIST_MODEL (rl->tree_model), sorter));
|
|
|
|
rl->selection = gtk_single_selection_new (sort_model);
|
2019-12-08 03:26:35 +00:00
|
|
|
g_object_unref (root_model);
|
2019-12-08 21:02:14 +00:00
|
|
|
g_object_unref (sort_model);
|
|
|
|
g_object_unref (sorter);
|
2019-12-08 03:26:35 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_column_view_set_model (GTK_COLUMN_VIEW (rl->list), G_LIST_MODEL (rl->selection));
|
2019-12-08 03:26:35 +00:00
|
|
|
|
2020-07-16 00:28:05 +00:00
|
|
|
g_signal_connect (rl->selection, "selection-changed", G_CALLBACK (on_selection_changed), rl);
|
2014-10-11 04:58:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
get_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
|
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2014-10-25 01:14:16 +00:00
|
|
|
case PROP_BUTTONS:
|
2020-07-16 00:28:05 +00:00
|
|
|
g_value_take_object (value, rl->buttons);
|
2014-10-11 04:58:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
set_property (GObject *object,
|
|
|
|
guint param_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
|
|
|
{
|
|
|
|
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
|
|
|
|
|
|
|
|
switch (param_id)
|
|
|
|
{
|
2014-10-25 01:14:16 +00:00
|
|
|
case PROP_BUTTONS:
|
2020-07-16 00:28:05 +00:00
|
|
|
rl->buttons = g_value_get_object (value);
|
|
|
|
rl->open_details_button = gtk_stack_get_child_by_name (GTK_STACK (rl->buttons), "list");
|
|
|
|
rl->close_details_button = gtk_stack_get_child_by_name (GTK_STACK (rl->buttons), "details");
|
2014-10-11 04:58:47 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, param_id, pspec);
|
|
|
|
break;
|
|
|
|
}
|
2014-05-15 23:34:38 +00:00
|
|
|
}
|
|
|
|
|
2014-11-08 01:38:42 +00:00
|
|
|
static void
|
2020-07-16 02:14:36 +00:00
|
|
|
dispose (GObject *object)
|
2014-11-08 01:38:42 +00:00
|
|
|
{
|
2019-12-08 03:26:35 +00:00
|
|
|
GtkInspectorResourceList *rl = GTK_INSPECTOR_RESOURCE_LIST (object);
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2020-07-16 02:14:36 +00:00
|
|
|
g_clear_pointer (&rl->stack, gtk_widget_unparent);
|
|
|
|
g_clear_object (&rl->selection);
|
|
|
|
g_clear_object (&rl->tree_model);
|
2014-11-08 01:38:42 +00:00
|
|
|
|
2020-07-16 02:14:36 +00:00
|
|
|
G_OBJECT_CLASS (gtk_inspector_resource_list_parent_class)->dispose (object);
|
2014-11-08 01:38:42 +00:00
|
|
|
}
|
|
|
|
|
2019-12-08 03:26:35 +00:00
|
|
|
static void
|
|
|
|
setup_name_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *expander;
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
expander = gtk_tree_expander_new ();
|
|
|
|
gtk_list_item_set_child (list_item, expander);
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_widget_set_margin_start (label, 5);
|
|
|
|
gtk_widget_set_margin_end (label, 5);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 0.0);
|
|
|
|
gtk_tree_expander_set_child (GTK_TREE_EXPANDER (expander), label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_name_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkTreeListRow *list_row;
|
|
|
|
GtkWidget *expander;
|
|
|
|
GtkWidget *label;
|
|
|
|
gpointer item;
|
|
|
|
|
|
|
|
list_row = gtk_list_item_get_item (list_item);
|
|
|
|
expander = gtk_list_item_get_child (list_item);
|
|
|
|
gtk_tree_expander_set_list_row (GTK_TREE_EXPANDER (expander), list_row);
|
|
|
|
item = gtk_tree_list_row_get_item (list_row);
|
|
|
|
label = gtk_tree_expander_get_child (GTK_TREE_EXPANDER (expander));
|
|
|
|
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), resource_holder_get_name (RESOURCE_HOLDER (item)));
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_size_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_widget_set_margin_start (label, 5);
|
|
|
|
gtk_widget_set_margin_end (label, 5);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_size_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GObject *item;
|
|
|
|
GtkWidget *label;
|
|
|
|
gsize size;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
item = gtk_tree_list_row_get_item (gtk_list_item_get_item (list_item));
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
|
|
|
|
size = resource_holder_get_size (RESOURCE_HOLDER (item));
|
|
|
|
text = g_format_size (size);
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), text);
|
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
setup_count_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GtkWidget *label;
|
|
|
|
|
|
|
|
label = gtk_label_new (NULL);
|
|
|
|
gtk_widget_set_margin_start (label, 5);
|
|
|
|
gtk_widget_set_margin_end (label, 5);
|
|
|
|
gtk_label_set_xalign (GTK_LABEL (label), 1.0);
|
|
|
|
gtk_list_item_set_child (list_item, label);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
bind_count_cb (GtkSignalListItemFactory *factory,
|
|
|
|
GtkListItem *list_item)
|
|
|
|
{
|
|
|
|
GObject *item;
|
|
|
|
GtkWidget *label;
|
|
|
|
int count;
|
|
|
|
char *text;
|
|
|
|
|
|
|
|
item = gtk_tree_list_row_get_item (gtk_list_item_get_item (list_item));
|
|
|
|
label = gtk_list_item_get_child (list_item);
|
|
|
|
|
|
|
|
count = resource_holder_get_count (RESOURCE_HOLDER (item));
|
|
|
|
if (count > 0)
|
|
|
|
{
|
|
|
|
text = g_strdup_printf ("%d", count);
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), text);
|
|
|
|
g_free (text);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
gtk_label_set_label (GTK_LABEL (label), "");
|
|
|
|
g_object_unref (item);
|
|
|
|
}
|
|
|
|
|
2014-05-15 23:34:38 +00:00
|
|
|
static void
|
|
|
|
gtk_inspector_resource_list_class_init (GtkInspectorResourceListClass *klass)
|
|
|
|
{
|
2014-10-11 04:58:47 +00:00
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
2014-05-15 23:34:38 +00:00
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
|
|
|
|
2014-10-11 04:58:47 +00:00
|
|
|
object_class->get_property = get_property;
|
|
|
|
object_class->set_property = set_property;
|
|
|
|
object_class->constructed = constructed;
|
2020-07-16 02:14:36 +00:00
|
|
|
object_class->dispose = dispose;
|
2014-10-11 04:58:47 +00:00
|
|
|
|
2019-02-23 05:29:52 +00:00
|
|
|
widget_class->root = root;
|
|
|
|
widget_class->unroot = unroot;
|
|
|
|
|
2014-10-25 01:14:16 +00:00
|
|
|
g_object_class_install_property (object_class, PROP_BUTTONS,
|
|
|
|
g_param_spec_object ("buttons", NULL, NULL,
|
2014-10-11 04:58:47 +00:00
|
|
|
GTK_TYPE_WIDGET, G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
|
|
|
|
2014-11-30 20:59:53 +00:00
|
|
|
gtk_widget_class_set_template_from_resource (widget_class, "/org/gtk/libgtk/inspector/resource-list.ui");
|
2020-07-16 00:28:05 +00:00
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, buffer);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, content);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, image);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, name_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, type_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, type);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, size_label);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, info_grid);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, stack);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, search_bar);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, search_entry);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, list);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, path);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, count);
|
|
|
|
gtk_widget_class_bind_template_child (widget_class, GtkInspectorResourceList, size);
|
2014-05-15 23:34:38 +00:00
|
|
|
|
2014-11-08 01:38:42 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_search_changed);
|
2019-12-08 03:26:35 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, on_row_activated);
|
2014-11-08 01:38:42 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, next_match);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, previous_match);
|
2019-12-08 03:26:35 +00:00
|
|
|
gtk_widget_class_bind_template_callback (widget_class, stop_search);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_name_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_name_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_count_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_count_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, setup_size_cb);
|
|
|
|
gtk_widget_class_bind_template_callback (widget_class, bind_size_cb);
|
2020-07-16 01:22:21 +00:00
|
|
|
|
|
|
|
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
2014-05-15 23:34:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// vim: set et sw=2 ts=2:
|