[Fwd: [PATCH] Zooming for the list view and other small cleanups]



The old eazel address tricked me...
--- Begin Message ---
I didn't change the method of icon zooming because it seems unreasonable
to allocated 7 icons when only 1 is needed...  To do this in a nicer way
I think we will need to change gtk so until 3.0 I guess were stuck with
this...
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/nautilus/ChangeLog,v
retrieving revision 1.5256
diff -p -u -r1.5256 ChangeLog
--- ChangeLog	29 Apr 2002 01:50:25 -0000	1.5256
+++ ChangeLog	1 May 2002 13:02:21 -0000
@@ -1,3 +1,30 @@
+2002-05-01  David Emory Watson  <dwatson cs ucr edu>
+
+	Implements zooming for the list view and other small cleanups.
+
+	* src/file-manager/fm-list-view.c:
+	(create_and_set_up_tree_view): Keep track of cell renderers and don't
+	make the file name column resizable since it interferes with zooming.
+	(fm_list_view_begin_loading): Set initial zoom level.
+	(set_zoom_level_from_metadata_and_preferences),
+	(fm_list_view_set_zoom_level),
+	(fm_list_view_bump_zoom_level),
+	(fm_list_view_zoom_to_level),
+	(fm_list_view_restore_default_zoom_level),
+	(fm_list_view_can_zoom_in),
+	(fm_list_view_can_zoom_out),
+	(default_zoom_level_changed): Impl.
+	(fm_list_view_finalize): Removal of callback no longer needed.
+	(fm_list_view_class_init): Hook up zoom auto value.
+	(fm_list_view_instance_init): Use while_alive to monitor changes to
+	default zoom level and click policy.
+
+	* src/file-manager/fm-list-model.c,
+	src/file-manager/fm-list-model.h:
+	(fm_list_model_get_zoom_level),
+	(fm_list_model_get_zoom_level): Impl.
+	(fm_list_model_get_value): Make pixbuf depend on zoom level.
+
 === nautilus 1.1.14 ===
  
 2002-04-28  Alexander Larsson  <alla lysator liu se>
Index: src/file-manager/fm-list-model.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-model.c,v
retrieving revision 1.13
diff -p -u -r1.13 fm-list-model.c
--- src/file-manager/fm-list-model.c	24 Apr 2002 14:40:56 -0000	1.13
+++ src/file-manager/fm-list-model.c	1 May 2002 13:02:27 -0000
@@ -46,6 +46,11 @@ struct FMListModelDetails {
 	GtkSortType order;
 
 	gboolean sort_directories_first;
+
+	/* FUBAR: FMListModel contains pixbufs so the zoom can't be done
+	   entirely from FMListView.  Obviously this blurs the distinction
+	   between the M and V in MVC... */
+	NautilusZoomLevel zoom_level;
 };
 
 typedef struct {
@@ -57,7 +62,7 @@ typedef struct {
  * Do not change the order of the type and size attributes, they 
  * have to be in this order so that the column_id to attribute mapping
  * works. This is needed to store the sorting preferences. This duplicate
- * entry is here to allow the ordering by icon (i think...)
+ * entry is here because it does not make sense to sort by icon.
  */
 
 static const AttributeEntry attributes[] = {
@@ -158,6 +163,33 @@ fm_list_model_get_path (GtkTreeModel *tr
 	return path;
 }
 
+NautilusZoomLevel
+fm_list_model_get_zoom_level (FMListModel *model)
+{
+	return model->details->zoom_level;
+}
+
+void
+fm_list_model_set_zoom_level (FMListModel *model,
+			      NautilusZoomLevel new_level)
+{
+	GtkTreeModel *tree_model;
+	GtkTreePath *path;
+	GtkTreeIter iter;
+
+	tree_model = GTK_TREE_MODEL (model);
+
+	model->details->zoom_level = new_level;
+
+	if (!gtk_tree_model_get_iter_first (tree_model, &iter)) {
+		return;
+	}
+
+	do {
+		path = gtk_tree_model_get_path (tree_model, &iter);
+		gtk_tree_model_row_changed (tree_model, path, &iter);
+	} while (gtk_tree_model_iter_next (tree_model, &iter));
+}
 
 static void
 fm_list_model_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value)
@@ -166,7 +198,8 @@ fm_list_model_get_value (GtkTreeModel *t
 	NautilusFile *file;
 	char *str;
 	GdkPixbuf *icon;
-	
+	int icon_size;
+
 	model = (FMListModel *)tree_model;
 
 	g_return_if_fail (model->details->stamp == iter->stamp);
@@ -188,7 +221,8 @@ fm_list_model_get_value (GtkTreeModel *t
 	case FM_LIST_MODEL_ICON_COLUMN:
 		g_value_init (value, GDK_TYPE_PIXBUF);
 
-		icon = nautilus_icon_factory_get_pixbuf_for_file (file, NULL, NAUTILUS_ICON_SIZE_SMALLER);
+		icon_size = nautilus_get_icon_size_for_zoom_level (model->details->zoom_level);
+		icon = nautilus_icon_factory_get_pixbuf_for_file (file, NULL, icon_size);
 		g_value_set_object (value, icon);
 		g_object_unref (icon);
 		break;
Index: src/file-manager/fm-list-model.h
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-model.h,v
retrieving revision 1.4
diff -p -u -r1.4 fm-list-model.h
--- src/file-manager/fm-list-model.h	24 Apr 2002 00:16:50 -0000	1.4
+++ src/file-manager/fm-list-model.h	1 May 2002 13:02:27 -0000
@@ -24,6 +24,7 @@
 
 #include <gtk/gtktreemodel.h>
 #include <libnautilus-private/nautilus-file.h>
+#include <libnautilus-private/nautilus-icon-factory.h>
 
 #ifndef FM_LIST_MODEL_H
 #define FM_LIST_MODEL_H
@@ -73,5 +74,9 @@ void     fm_list_model_set_should_sort_d
 int      fm_list_model_get_sort_column_id_from_attribute (const char           *attribute);
 int      fm_list_model_get_sort_column_id_from_sort_type (NautilusFileSortType  sort_type);
 char    *fm_list_model_get_attribute_from_sort_column_id (int                   sort_column_id);
+
+NautilusZoomLevel fm_list_model_get_zoom_level           (FMListModel          *model);
+void     fm_list_model_set_zoom_level                    (FMListModel          *model,
+							  NautilusZoomLevel     new_level);
 
 #endif /* FM_LIST_MODEL_H */
Index: src/file-manager/fm-list-view.c
===================================================================
RCS file: /cvs/gnome/nautilus/src/file-manager/fm-list-view.c,v
retrieving revision 1.168
diff -p -u -r1.168 fm-list-view.c
--- src/file-manager/fm-list-view.c	24 Apr 2002 00:16:50 -0000	1.168
+++ src/file-manager/fm-list-view.c	1 May 2002 13:02:28 -0000
@@ -22,6 +22,7 @@
 
    Authors: John Sullivan <sullivan eazel com>
             Anders Carlsson <andersca gnu org>
+	    David Emory Watson <dwatson cs ucr edu>
 */
 
 #include <config.h>
@@ -46,7 +47,12 @@ struct FMListViewDetails {
 	FMListModel *model;
 
 	GtkTreeViewColumn   *file_name_column;
-	GtkCellRendererText *file_name_cell;
+
+	GtkCellRendererPixbuf *pixbuf_cell;
+	GtkCellRendererText   *file_name_cell;
+	GtkCellRendererText   *size_cell;
+	GtkCellRendererText   *type_cell;
+	GtkCellRendererText   *date_modified_cell;
 };
 
 static GtkTargetEntry drag_types [] = {
@@ -64,9 +70,12 @@ static GtkTargetEntry drag_types [] = {
 
 static NautilusFileSortType	default_sort_order_auto_value;
 static gboolean			default_sort_reversed_auto_value;
+static NautilusZoomLevel        default_zoom_level_auto_value;
 
-static GList *     fm_list_view_get_selection         (FMDirectoryView *view);
-
+static GList *              fm_list_view_get_selection         (FMDirectoryView *view);
+static void                 fm_list_view_set_zoom_level        (FMListView *view,
+								NautilusZoomLevel new_level,
+								gboolean always_set_level);
 
 GNOME_CLASS_BOILERPLATE (FMListView, fm_list_view,
 			 FMDirectoryView, FM_TYPE_DIRECTORY_VIEW)
@@ -227,7 +236,7 @@ cell_renderer_edited (GtkCellRendererTex
 }
 
 static void
-click_policy_changed (gpointer callback_data)
+click_policy_changed_callback (gpointer callback_data)
 {
 	FMListView *view;
 
@@ -277,14 +286,18 @@ create_and_set_up_tree_view (FMListView 
 
 	gtk_tree_view_enable_model_drag_source (view->details->tree_view, 0, drag_types, G_N_ELEMENTS (drag_types),
 						GDK_ACTION_MOVE | GDK_ACTION_COPY | GDK_ACTION_LINK);
-	
+
 	/* Create the file name column */
 	cell = gtk_cell_renderer_pixbuf_new ();
+	view->details->pixbuf_cell = (GtkCellRendererPixbuf *)cell;
 	
 	view->details->file_name_column = gtk_tree_view_column_new ();
 	gtk_tree_view_column_set_sort_column_id (view->details->file_name_column, FM_LIST_MODEL_NAME_COLUMN);
 	gtk_tree_view_column_set_title (view->details->file_name_column, _("File name"));
-	gtk_tree_view_column_set_resizable (view->details->file_name_column, TRUE);
+
+	/* This makes resizing the filename column impossible, but is needed to make columns
+	   render nicely when moving from a higher zoom level to a lower zoom level. */
+	gtk_tree_view_column_set_sizing (view->details->file_name_column, GTK_TREE_VIEW_COLUMN_AUTOSIZE);
 
 	gtk_tree_view_column_pack_start (view->details->file_name_column, cell, FALSE);
 	gtk_tree_view_column_set_attributes (view->details->file_name_column, cell,
@@ -292,6 +305,7 @@ create_and_set_up_tree_view (FMListView 
 					     NULL);
 
 	cell = gtk_cell_renderer_text_new ();
+	view->details->file_name_cell = (GtkCellRendererText *)cell;
 	g_signal_connect (cell, "edited", G_CALLBACK (cell_renderer_edited), view);
 
 	gtk_tree_view_column_pack_start (view->details->file_name_column, cell, TRUE);
@@ -301,14 +315,9 @@ create_and_set_up_tree_view (FMListView 
 					     NULL);
 	gtk_tree_view_append_column (view->details->tree_view, view->details->file_name_column);
 
-	/* Set up underline of file name. */
-	view->details->file_name_cell = (GtkCellRendererText *)cell;
-	eel_preferences_add_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
-				      click_policy_changed, view);
-	click_policy_changed (view);
-
 	/* Create the size column */
 	cell = gtk_cell_renderer_text_new ();
+	view->details->size_cell = (GtkCellRendererText *)cell;
 	g_object_set (G_OBJECT (cell),
 		      "xalign", 1.0,
 		      NULL);
@@ -322,6 +331,7 @@ create_and_set_up_tree_view (FMListView 
 
 	/* Create the type column */
 	cell = gtk_cell_renderer_text_new ();
+	view->details->type_cell = (GtkCellRendererText *)cell;
 	column = gtk_tree_view_column_new_with_attributes (_("Type"),
 							   cell,
 							   "text", FM_LIST_MODEL_TYPE_COLUMN,
@@ -332,6 +342,7 @@ create_and_set_up_tree_view (FMListView 
 
 	/* Create the date modified column */
 	cell = gtk_cell_renderer_text_new ();
+	view->details->date_modified_cell = (GtkCellRendererText *)cell;
 	column = gtk_tree_view_column_new_with_attributes (_("Date Modified"),
 							   cell,
 							   "text", FM_LIST_MODEL_DATE_MODIFIED_COLUMN,
@@ -380,6 +391,21 @@ set_sort_order_from_metadata_and_prefere
 }
 
 static void
+set_zoom_level_from_metadata_and_preferences (FMListView *list_view)
+{
+	NautilusFile *file;
+	int level;
+
+	if (fm_directory_view_supports_zooming (FM_DIRECTORY_VIEW (list_view))) {
+		file = fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (list_view));
+		level = nautilus_file_get_integer_metadata (file,
+							    NAUTILUS_METADATA_KEY_LIST_VIEW_ZOOM_LEVEL, 
+							    default_zoom_level_auto_value);
+		fm_list_view_set_zoom_level (list_view, level, TRUE);
+	}
+}
+
+static void
 fm_list_view_begin_loading (FMDirectoryView *view)
 {
 	FMListView *list_view;
@@ -390,6 +416,7 @@ fm_list_view_begin_loading (FMDirectoryV
 						      fm_directory_view_get_directory_as_file (view));
 
 	set_sort_order_from_metadata_and_preferences (list_view);
+	set_zoom_level_from_metadata_and_preferences (list_view);
 }
 
 static void
@@ -496,10 +523,122 @@ fm_list_view_reset_to_defaults (FMDirect
 		(GTK_TREE_SORTABLE (FM_LIST_VIEW (view)->details->model),
 		 fm_list_model_get_sort_column_id_from_sort_type (default_sort_order_auto_value),
 		 default_sort_reversed_auto_value ? GTK_SORT_DESCENDING : GTK_SORT_ASCENDING);
+
         fm_directory_view_restore_default_zoom_level (view);
 }
 
 static void
+fm_list_view_set_zoom_level (FMListView *view,
+			     NautilusZoomLevel new_level,
+			     gboolean always_set_level)
+{
+	static double pango_scale[7] = { PANGO_SCALE_XX_SMALL, PANGO_SCALE_X_SMALL, PANGO_SCALE_SMALL,
+					 PANGO_SCALE_MEDIUM,
+					 PANGO_SCALE_LARGE, PANGO_SCALE_X_LARGE, PANGO_SCALE_XX_LARGE };
+	int icon_size;
+
+	g_return_if_fail (FM_IS_LIST_VIEW (view));
+	g_return_if_fail (new_level >= NAUTILUS_ZOOM_LEVEL_SMALLEST &&
+			  new_level <= NAUTILUS_ZOOM_LEVEL_LARGEST);
+
+	if (fm_list_model_get_zoom_level (view->details->model) == new_level) {
+		if (always_set_level) {
+			fm_directory_view_set_zoom_level (FM_DIRECTORY_VIEW(view), new_level);
+		}
+		return;
+	}
+
+	fm_list_model_set_zoom_level (view->details->model, new_level);
+	fm_directory_view_set_zoom_level (FM_DIRECTORY_VIEW(view), new_level);
+
+	nautilus_file_set_integer_metadata
+		(fm_directory_view_get_directory_as_file (FM_DIRECTORY_VIEW (view)), 
+		 NAUTILUS_METADATA_KEY_LIST_VIEW_ZOOM_LEVEL, 
+		 default_zoom_level_auto_value,
+		 new_level);
+
+	/* Update list view to reflect new zoom level. */
+	g_object_set (G_OBJECT (view->details->file_name_cell),
+		      "scale", pango_scale[new_level],
+		      NULL);
+	g_object_set (G_OBJECT (view->details->size_cell),
+		      "scale", pango_scale[new_level],
+		      NULL);
+	g_object_set (G_OBJECT (view->details->type_cell),
+		      "scale", pango_scale[new_level],
+		      NULL);
+	g_object_set (G_OBJECT (view->details->date_modified_cell),
+		      "scale", pango_scale[new_level],
+		      NULL);
+
+	/* Make all rows the same size. */
+	icon_size = nautilus_get_icon_size_for_zoom_level (new_level);
+	gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (view->details->pixbuf_cell),
+					  -1, icon_size);
+
+	fm_directory_view_update_menus (FM_DIRECTORY_VIEW (view));
+}
+
+static void
+fm_list_view_bump_zoom_level (FMDirectoryView *view, int zoom_increment)
+{
+	FMListView *list_view;
+	NautilusZoomLevel new_level;
+
+	g_return_if_fail (FM_IS_LIST_VIEW (view));
+
+	list_view = FM_LIST_VIEW (view);
+	new_level = fm_list_model_get_zoom_level (list_view->details->model) + zoom_increment;
+
+	if (new_level >= NAUTILUS_ZOOM_LEVEL_SMALLEST &&
+	    new_level <= NAUTILUS_ZOOM_LEVEL_LARGEST) {
+		fm_list_view_set_zoom_level (list_view, new_level, FALSE);
+	}
+}
+
+static void
+fm_list_view_zoom_to_level (FMDirectoryView *view, int zoom_level)
+{
+	FMListView *list_view;
+
+	g_return_if_fail (FM_IS_LIST_VIEW (view));
+
+	list_view = FM_LIST_VIEW (view);
+
+	fm_list_view_set_zoom_level (list_view, zoom_level, FALSE);
+}
+
+static void
+fm_list_view_restore_default_zoom_level (FMDirectoryView *view)
+{
+	FMListView *list_view;
+
+	g_return_if_fail (FM_IS_LIST_VIEW (view));
+
+	list_view = FM_LIST_VIEW (view);
+
+	fm_list_view_set_zoom_level (list_view, default_zoom_level_auto_value, FALSE);
+}
+
+static gboolean 
+fm_list_view_can_zoom_in (FMDirectoryView *view) 
+{
+	g_return_val_if_fail (FM_IS_LIST_VIEW (view), FALSE);
+
+	return fm_list_model_get_zoom_level (FM_LIST_VIEW (view)->details->model)
+		< NAUTILUS_ZOOM_LEVEL_LARGEST;
+}
+
+static gboolean 
+fm_list_view_can_zoom_out (FMDirectoryView *view) 
+{
+	g_return_val_if_fail (FM_IS_LIST_VIEW (view), FALSE);
+
+	return fm_list_model_get_zoom_level (FM_LIST_VIEW (view)->details->model)
+		> NAUTILUS_ZOOM_LEVEL_SMALLEST;
+}
+
+static void
 fm_list_view_start_renaming_file (FMDirectoryView *view, NautilusFile *file)
 {
 	FMListView *list_view;
@@ -521,6 +660,16 @@ fm_list_view_start_renaming_file (FMDire
 }
 
 static void
+default_zoom_level_changed_callback (gpointer callback_data)
+{
+	FMListView *list_view;
+
+	list_view = FM_LIST_VIEW (callback_data);
+
+	set_zoom_level_from_metadata_and_preferences (list_view);
+}
+
+static void
 fm_list_view_sort_directories_first_changed (FMDirectoryView *view)
 {
 	FMListView *list_view;
@@ -538,9 +687,6 @@ fm_list_view_finalize (GObject *object)
 
 	list_view = FM_LIST_VIEW (object);
 
-	eel_preferences_remove_callback (NAUTILUS_PREFERENCES_CLICK_POLICY,
-					 click_policy_changed, list_view);
-
 	g_free (list_view->details);
 
 	G_OBJECT_CLASS (parent_class)->finalize (object);
@@ -569,20 +715,17 @@ fm_list_view_class_init (FMListViewClass
 
 	fm_directory_view_class->add_file = fm_list_view_add_file;
 	fm_directory_view_class->begin_loading = fm_list_view_begin_loading;
-#if GNOME2_CONVERSION_COMPLETE
-	fm_directory_view_class->bump_zoom_level = xxx;
-	fm_directory_view_class->can_zoom_in = xxx;
-	fm_directory_view_class->can_zoom_out = xxx;
-#endif
+	fm_directory_view_class->bump_zoom_level = fm_list_view_bump_zoom_level;
+	fm_directory_view_class->zoom_to_level = fm_list_view_zoom_to_level;
+	fm_directory_view_class->can_zoom_in = fm_list_view_can_zoom_in;
+	fm_directory_view_class->can_zoom_out = fm_list_view_can_zoom_out;
 	fm_directory_view_class->clear = fm_list_view_clear;
 	fm_directory_view_class->file_changed = fm_list_view_file_changed;
 	fm_directory_view_class->get_background_widget = fm_list_view_get_background_widget;
 	fm_directory_view_class->get_selection = fm_list_view_get_selection;
 	fm_directory_view_class->is_empty = fm_list_view_is_empty;
 	fm_directory_view_class->reset_to_defaults = fm_list_view_reset_to_defaults;
-#if GNOME2_CONVERSION_COMPLETE
-	fm_directory_view_class->restore_default_zoom_level = xxx;
-#endif
+	fm_directory_view_class->restore_default_zoom_level = fm_list_view_restore_default_zoom_level;
 	fm_directory_view_class->remove_file = fm_list_view_remove_file;
 	fm_directory_view_class->select_all = fm_list_view_select_all;
 	fm_directory_view_class->set_selection = fm_list_view_set_selection;
@@ -594,6 +737,8 @@ fm_list_view_class_init (FMListViewClass
 				       (int *) &default_sort_order_auto_value);
 	eel_preferences_add_auto_boolean (NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_SORT_IN_REVERSE_ORDER,
 					  &default_sort_reversed_auto_value);
+	eel_preferences_add_auto_enum (NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL,
+				       (int *) &default_zoom_level_auto_value);
 }
 
 static void
@@ -602,6 +747,15 @@ fm_list_view_instance_init (FMListView *
 	list_view->details = g_new0 (FMListViewDetails, 1);
 
 	create_and_set_up_tree_view (list_view);
+
+	eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_LIST_VIEW_DEFAULT_ZOOM_LEVEL,
+						  default_zoom_level_changed_callback,
+						  list_view, G_OBJECT (list_view));
+	eel_preferences_add_callback_while_alive (NAUTILUS_PREFERENCES_CLICK_POLICY,
+						  click_policy_changed_callback,
+						  list_view, G_OBJECT (list_view));
+
+	click_policy_changed_callback (list_view);
 
 	fm_list_view_sort_directories_first_changed (FM_DIRECTORY_VIEW (list_view));
 }

--- End Message ---


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]