[PATCH] Partial implementation of zooming for the list view
- From: David Emory Watson <dwatson cs ucr edu>
- To: nautilus-list gnome org
- Subject: [PATCH] Partial implementation of zooming for the list view
- Date: 29 Apr 2002 12:35:44 -0400
Known issues:
1) GtkCellRenderer does not automagically update itself when properties
are set. Thus a refresh is required to see the results of changing the
zoom level. Unless someone here knows why, I will contact the gtk list.
2) The patch does not currently zoom in on the icon. Limitations of
GtkCellPixmapRenderer will make this a pain to do perfectly.
3) The font sizes and row heights are not tuned yet. I basically just
made up some numbers for this...
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 29 Apr 2002 16:30:04 -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>
@@ -45,8 +46,13 @@ struct FMListViewDetails {
GtkTreeView *tree_view;
FMListModel *model;
+ NautilusZoomLevel zoom_level;
+
GtkTreeViewColumn *file_name_column;
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)
@@ -277,7 +286,7 @@ 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 ();
@@ -292,6 +301,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);
@@ -302,13 +312,13 @@ create_and_set_up_tree_view (FMListView
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 +332,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 +343,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 +392,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 +417,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 +524,129 @@ 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)
+{
+ /* These tables work differently from the tables in nautilus-icon-container.c and
+ fm-icon-view.c. If we go ahead with the pango scaling method of controling font
+ size then we will need to tweak these tables to our taste... */
+
+ 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 };
+
+ static int row_height[7] = { 24, 32, 40, 48, 64, 96, 128 };
+
+ 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 (view->details->zoom_level == new_level) {
+ if (always_set_level) {
+ fm_directory_view_set_zoom_level (FM_DIRECTORY_VIEW(view), new_level);
+ }
+ return;
+ }
+
+ view->details->zoom_level = 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[view->details->zoom_level],
+ NULL);
+ g_object_set (G_OBJECT (view->details->size_cell),
+ "scale", pango_scale[view->details->zoom_level],
+ NULL);
+ g_object_set (G_OBJECT (view->details->type_cell),
+ "scale", pango_scale[view->details->zoom_level],
+ NULL);
+ g_object_set (G_OBJECT (view->details->date_modified_cell),
+ "scale", pango_scale[view->details->zoom_level],
+ NULL);
+
+ gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (view->details->file_name_cell),
+ -1, row_height[view->details->zoom_level]);
+ gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (view->details->size_cell),
+ -1, row_height[view->details->zoom_level]);
+ gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (view->details->type_cell),
+ -1, row_height[view->details->zoom_level]);
+ gtk_cell_renderer_set_fixed_size (GTK_CELL_RENDERER (view->details->date_modified_cell),
+ -1, row_height[view->details->zoom_level]);
+
+ 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 = list_view->details->zoom_level + 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_VIEW (view)->details->zoom_level < 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_VIEW (view)->details->zoom_level > NAUTILUS_ZOOM_LEVEL_SMALLEST;
+}
+
+static void
fm_list_view_start_renaming_file (FMDirectoryView *view, NautilusFile *file)
{
FMListView *list_view;
@@ -521,6 +668,27 @@ fm_list_view_start_renaming_file (FMDire
}
static void
+default_zoom_level_changed_callback (gpointer callback_data)
+{
+ FMListView *list_view;
+ NautilusFile *file;
+ int level;
+
+ g_return_if_fail (FM_IS_LIST_VIEW (callback_data));
+
+ list_view = FM_LIST_VIEW (callback_data);
+
+ 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_sort_directories_first_changed (FMDirectoryView *view)
{
FMListView *list_view;
@@ -569,20 +737,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 +759,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 +769,10 @@ 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));
fm_list_view_sort_directories_first_changed (FM_DIRECTORY_VIEW (list_view));
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]