Commit de85ecad authored by Darin Adler's avatar Darin Adler

Added open pixbuf support.

	* components/tree/nautilus-tree-model.h:
	* components/tree/nautilus-tree-model.c: (tree_node_destroy),
	(tree_node_get_pixbuf_from_factory), (tree_node_update_pixbuf),
	(tree_node_update_closed_pixbuf), (tree_node_update_open_pixbuf),
	(tree_node_get_closed_pixbuf), (tree_node_get_open_pixbuf),
	(update_node_without_reporting),
	(nautilus_tree_model_get_column_type),
	(nautilus_tree_model_get_value):
	Added open pixbuf support.

	* components/tree/nautilus-tree-view.c: (save_expansion_state):
	Fix storage leak.
	(row_activated_callback): Fix NautilusFile ref. count leak.
	(create_tree): Pass in open pixbuf for "pixbuf_expander_open".
	(get_filtering_as_integer), (update_filtering_from_preferences),
	(filtering_changed_callback), (nautilus_tree_view_instance_init),
	(nautilus_tree_view_finalize): Starting on code needed to
	respect the filtering preferences.
parent d6be4c4a
2002-02-08 Darin Adler <darin@bentspoon.com>
* components/tree/nautilus-tree-model.h:
* components/tree/nautilus-tree-model.c: (tree_node_destroy),
(tree_node_get_pixbuf_from_factory), (tree_node_update_pixbuf),
(tree_node_update_closed_pixbuf), (tree_node_update_open_pixbuf),
(tree_node_get_closed_pixbuf), (tree_node_get_open_pixbuf),
(update_node_without_reporting),
(nautilus_tree_model_get_column_type),
(nautilus_tree_model_get_value):
Added open pixbuf support.
* components/tree/nautilus-tree-view.c: (save_expansion_state):
Fix storage leak.
(row_activated_callback): Fix NautilusFile ref. count leak.
(create_tree): Pass in open pixbuf for "pixbuf_expander_open".
(get_filtering_as_integer), (update_filtering_from_preferences),
(filtering_changed_callback), (nautilus_tree_view_instance_init),
(nautilus_tree_view_finalize): Starting on code needed to
respect the filtering preferences.
2002-02-07 Darin Adler <darin@bentspoon.com>
* components/tree/nautilus-tree-model.h:
......
......@@ -50,6 +50,7 @@ struct TreeNode {
NautilusFile *file;
char *display_name;
GdkPixbuf *closed_pixbuf;
GdkPixbuf *open_pixbuf;
TreeNode *parent;
TreeNode *next;
......@@ -148,6 +149,7 @@ tree_node_destroy (TreeNode *node)
g_object_unref (node->file);
g_free (node->display_name);
object_unref_if_not_NULL (node->closed_pixbuf);
object_unref_if_not_NULL (node->open_pixbuf);
g_assert (node->done_loading_id == 0);
g_assert (node->files_added_id == 0);
......@@ -181,30 +183,45 @@ tree_node_parent (TreeNode *node, TreeNode *parent)
}
static GdkPixbuf *
tree_node_get_closed_pixbuf_from_factory (TreeNode *node)
tree_node_get_pixbuf_from_factory (TreeNode *node,
const char *modifier)
{
return nautilus_icon_factory_get_pixbuf_for_file
(node->file, NULL, NAUTILUS_ICON_SIZE_FOR_MENUS);
(node->file, modifier, NAUTILUS_ICON_SIZE_FOR_MENUS);
}
static gboolean
tree_node_update_closed_pixbuf (TreeNode *node)
tree_node_update_pixbuf (TreeNode *node,
GdkPixbuf **pixbuf_storage,
const char *modifier)
{
GdkPixbuf *closed_pixbuf;
GdkPixbuf *pixbuf;
if (node->closed_pixbuf == NULL) {
if (*pixbuf_storage == NULL) {
return FALSE;
}
closed_pixbuf = tree_node_get_closed_pixbuf_from_factory (node);
if (closed_pixbuf == node->closed_pixbuf) {
g_object_unref (closed_pixbuf);
pixbuf = tree_node_get_pixbuf_from_factory (node, modifier);
if (pixbuf == *pixbuf_storage) {
g_object_unref (pixbuf);
return FALSE;
}
g_object_unref (node->closed_pixbuf);
node->closed_pixbuf = closed_pixbuf;
g_object_unref (*pixbuf_storage);
*pixbuf_storage = pixbuf;
return TRUE;
}
static gboolean
tree_node_update_closed_pixbuf (TreeNode *node)
{
return tree_node_update_pixbuf (node, &node->closed_pixbuf, NULL);
}
static gboolean
tree_node_update_open_pixbuf (TreeNode *node)
{
return tree_node_update_pixbuf (node, &node->open_pixbuf, "accept");
}
static gboolean
tree_node_update_display_name (TreeNode *node)
{
......@@ -227,11 +244,20 @@ static GdkPixbuf *
tree_node_get_closed_pixbuf (TreeNode *node)
{
if (node->closed_pixbuf == NULL) {
node->closed_pixbuf = tree_node_get_closed_pixbuf_from_factory (node);
node->closed_pixbuf = tree_node_get_pixbuf_from_factory (node, NULL);
}
return node->closed_pixbuf;
}
static GdkPixbuf *
tree_node_get_open_pixbuf (TreeNode *node)
{
if (node->open_pixbuf == NULL) {
node->open_pixbuf = tree_node_get_pixbuf_from_factory (node, "accept");
}
return node->open_pixbuf;
}
static const char *
tree_node_get_display_name (TreeNode *node)
{
......@@ -513,8 +539,9 @@ update_node_without_reporting (NautilusTreeModel *model, TreeNode *node)
node->done_loading = FALSE;
}
changed |= tree_node_update_closed_pixbuf (node);
changed |= tree_node_update_display_name (node);
changed |= tree_node_update_closed_pixbuf (node);
changed |= tree_node_update_open_pixbuf (node);
return changed;
}
......@@ -742,6 +769,8 @@ nautilus_tree_model_get_column_type (GtkTreeModel *model, int index)
return G_TYPE_STRING;
case NAUTILUS_TREE_MODEL_CLOSED_PIXBUF_COLUMN:
return GDK_TYPE_PIXBUF;
case NAUTILUS_TREE_MODEL_OPEN_PIXBUF_COLUMN:
return GDK_TYPE_PIXBUF;
default:
g_assert_not_reached ();
}
......@@ -874,6 +903,10 @@ nautilus_tree_model_get_value (GtkTreeModel *model, GtkTreeIter *iter, int colum
g_value_init (value, GDK_TYPE_PIXBUF);
g_value_set_object (value, node == NULL ? NULL : tree_node_get_closed_pixbuf (node));
break;
case NAUTILUS_TREE_MODEL_OPEN_PIXBUF_COLUMN:
g_value_init (value, GDK_TYPE_PIXBUF);
g_value_set_object (value, node == NULL ? NULL : tree_node_get_open_pixbuf (node));
break;
default:
g_assert_not_reached ();
}
......
......@@ -40,6 +40,7 @@
enum {
NAUTILUS_TREE_MODEL_DISPLAY_NAME_COLUMN,
NAUTILUS_TREE_MODEL_CLOSED_PIXBUF_COLUMN,
NAUTILUS_TREE_MODEL_OPEN_PIXBUF_COLUMN,
NAUTILUS_TREE_MODEL_NUM_COLUMNS
};
......@@ -54,9 +55,16 @@ typedef struct {
GObjectClass parent_class;
} NautilusTreeModelClass;
GType nautilus_tree_model_get_type (void);
NautilusTreeModel *nautilus_tree_model_new (const char *root_uri);
NautilusFile * nautilus_tree_model_iter_get_file (NautilusTreeModel *model,
GtkTreeIter *iter);
GType nautilus_tree_model_get_type (void);
NautilusTreeModel *nautilus_tree_model_new (const char *root_uri);
gboolean nautilus_tree_model_would_include_uri (const char *uri);
void nautilus_tree_model_set_show_hidden_files (NautilusTreeModel *model,
gboolean show_hidden_files);
void nautilus_tree_model_set_show_backup_files (NautilusTreeModel *model,
gboolean show_hidden_files);
void nautilus_tree_model_set_show_only_directories (NautilusTreeModel *model,
gboolean show_only_directories);
NautilusFile * nautilus_tree_model_iter_get_file (NautilusTreeModel *model,
GtkTreeIter *iter);
#endif /* NAUTILUS_TREE_MODEL_H */
......@@ -33,6 +33,7 @@
#include "nautilus-tree-view.h"
#include "nautilus-tree-model.h"
#include <eel/eel-glib-extensions.h>
#include <eel/eel-preferences.h>
#include <eel/eel-string.h>
#include <gtk/gtkcellrendererpixbuf.h>
......@@ -41,6 +42,7 @@
#include <gtk/gtktreemodelsort.h>
#include <gtk/gtktreeview.h>
#include <libnautilus-private/nautilus-file-attributes.h>
#include <libnautilus-private/nautilus-global-preferences.h>
#define NAUTILUS_PREFERENCES_TREE_VIEW_EXPANSION_STATE "tree-sidebar-panel/expansion_state"
......@@ -54,6 +56,10 @@ struct NautilusTreeViewDetails {
#endif
NautilusTreeModel *child_model;
gboolean show_hidden_files;
gboolean show_backup_files;
gboolean show_only_directories;
NautilusFile *activation_file;
guint save_expansion_state_idle_id;
};
......@@ -120,7 +126,7 @@ save_expansion_state (NautilusTreeView *view)
gtk_tree_view_map_expanded_rows (view->details->tree_widget, prepend_one_uri, &p);
p.uris = g_list_sort (p.uris, eel_strcmp_compare_func);
uris = eel_string_list_new_from_g_list (p.uris, TRUE);
g_list_free (p.uris);
eel_g_list_free_deep (p.uris);
eel_preferences_set_string_list (NAUTILUS_PREFERENCES_TREE_VIEW_EXPANSION_STATE, uris);
eel_string_list_free (uris);
}
......@@ -194,7 +200,7 @@ row_activated_callback (GtkTreeView *tree_widget,
cancel_activation (view);
view->details->activation_file = nautilus_file_ref (path_to_file (view, path));
view->details->activation_file = path_to_file (view, path);
attrs = g_list_prepend (NULL, NAUTILUS_FILE_ATTRIBUTE_ACTIVATION_URI);
nautilus_file_call_when_ready (view->details->activation_file, attrs,
......@@ -231,6 +237,8 @@ create_tree (NautilusTreeView *view)
gtk_tree_view_column_pack_start (column, cell, FALSE);
gtk_tree_view_column_set_attributes (column, cell,
"pixbuf", NAUTILUS_TREE_MODEL_CLOSED_PIXBUF_COLUMN,
"pixbuf_expander_closed", NAUTILUS_TREE_MODEL_CLOSED_PIXBUF_COLUMN,
"pixbuf_expander_open", NAUTILUS_TREE_MODEL_OPEN_PIXBUF_COLUMN,
NULL);
cell = gtk_cell_renderer_text_new ();
......@@ -267,6 +275,42 @@ tree_activate_callback (BonoboControl *control, gboolean activating, gpointer us
}
}
static int
get_filtering_as_integer (NautilusTreeView *view)
{
return (((view->details->show_hidden_files << 1)
| view->details->show_backup_files) << 1)
| view->details->show_only_directories;
}
static void
update_filtering_from_preferences (NautilusTreeView *view)
{
view->details->show_hidden_files =
eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES);
view->details->show_backup_files =
eel_preferences_get_boolean (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES);
view->details->show_only_directories =
eel_preferences_get_boolean (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES);
}
static void
filtering_changed_callback (gpointer callback_data)
{
NautilusTreeView *view;
int filtering_before;
view = NAUTILUS_TREE_VIEW (callback_data);
filtering_before = get_filtering_as_integer (view);
update_filtering_from_preferences (view);
if (filtering_before == get_filtering_as_integer (view)) {
return;
}
/* FIXME: reload the whole tree */
}
static void
nautilus_tree_view_instance_init (NautilusTreeView *view)
{
......@@ -287,6 +331,15 @@ nautilus_tree_view_instance_init (NautilusTreeView *view)
G_CALLBACK (tree_activate_callback), view, 0);
nautilus_view_construct_from_bonobo_control (NAUTILUS_VIEW (view), control);
eel_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
filtering_changed_callback, view);
eel_preferences_add_callback (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
filtering_changed_callback, view);
eel_preferences_add_callback (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
filtering_changed_callback, view);
update_filtering_from_preferences (view);
}
static void
......@@ -296,6 +349,13 @@ nautilus_tree_view_finalize (GObject *object)
view = NAUTILUS_TREE_VIEW (object);
eel_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_HIDDEN_FILES,
filtering_changed_callback, view);
eel_preferences_remove_callback (NAUTILUS_PREFERENCES_SHOW_BACKUP_FILES,
filtering_changed_callback, view);
eel_preferences_remove_callback (NAUTILUS_PREFERENCES_TREE_SHOW_ONLY_DIRECTORIES,
filtering_changed_callback, view);
cancel_activation (view);
if (view->details->save_expansion_state_idle_id != 0) {
g_source_remove (view->details->save_expansion_state_idle_id);
......
Markdown is supported
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