nautilus r14489 - in trunk: . libnautilus-private



Author: cneumair
Date: Mon Aug 18 20:47:18 2008
New Revision: 14489
URL: http://svn.gnome.org/viewvc/nautilus?rev=14489&view=rev

Log:
2008-08-18  Christian Neumair  <cneumair gnome org>

	* libnautilus-private/apps_nautilus_preferences.schemas.in:
	* libnautilus-private/nautilus-global-preferences.c:
	* libnautilus-private/nautilus-global-preferences.h:
	Add "icon_view/text_ellipsis_limit" and "desktop/text_ellipsis_limit".
	They specify the maximum number of lines to display before the file
	names should be ellipsized.

	* libnautilus-private/nautilus-icon-canvas-item.c
	(draw_or_measure_label_text):
	* libnautilus-private/nautilus-icon-container.c
	(text_ellipsis_limit_changed_container_callback),
	(nautilus_icon_container_constructor),
	(nautilus_icon_container_class_init),
	(get_text_ellipsis_limit_for_zoom),
	(text_ellipsis_limit_changed_callback),
	(desktop_text_ellipsis_limit_changed_callback),
	(nautilus_icon_container_instance_init),
	(nautilus_icon_container_get_layout_height):
	* libnautilus-private/nautilus-icon-container.h:
	* libnautilus-private/nautilus-icon-info.h:
	Connect icon container to text ellipsis limit preferences.


Modified:
   trunk/ChangeLog
   trunk/libnautilus-private/apps_nautilus_preferences.schemas.in
   trunk/libnautilus-private/nautilus-global-preferences.c
   trunk/libnautilus-private/nautilus-global-preferences.h
   trunk/libnautilus-private/nautilus-icon-canvas-item.c
   trunk/libnautilus-private/nautilus-icon-container.c
   trunk/libnautilus-private/nautilus-icon-container.h
   trunk/libnautilus-private/nautilus-icon-info.h

Modified: trunk/libnautilus-private/apps_nautilus_preferences.schemas.in
==============================================================================
--- trunk/libnautilus-private/apps_nautilus_preferences.schemas.in	(original)
+++ trunk/libnautilus-private/apps_nautilus_preferences.schemas.in	Mon Aug 18 20:47:18 2008
@@ -701,6 +701,38 @@
       </locale>
     </schema>    
 
+    <schema>
+      <key>/schemas/apps/nautilus/icon_view/text_ellipsis_limit</key>
+      <applyto>/apps/nautilus/icon_view/text_ellipsis_limit</applyto>
+      <type>list</type>
+      <list_type>string</list_type>
+      <default>[3]</default>
+      <locale name="C">
+         <short>Text Ellipsis Limit</short>
+         <long>
+	     A string specifying how parts of overlong file names
+	     should be replaced by ellipses, depending on the zoom
+	     level.
+	     Each of the list entries is of the form "Zoom Level:Integer".
+	     For each specified zoom level, if the given integer is
+	     larger than 0, the file name will not exceed the given number of lines.
+	     If the integer is 0 or smaller, no limit is imposed on the specified zoom level.
+	     A default entry of the form "Integer" without any specified zoom level
+	     is also allowed. It defines the maximum number of lines for all other zoom levels.
+	     Examples:
+	     0 - always display overlong file names;
+	     3 - shorten file names if they exceed three lines;
+	     smallest:5,smaller:4,0 - shorten file names if they exceed five lines
+	     for zoom level "smallest". Shorten file names if they exceed four lines
+	     for zoom level "smaller". Do not shorten file names for other zoom levels.
+
+	     Available zoom levels:
+	     smallest (33%), smaller (50%), small (66%), standard (100%), large (150%),
+	     larger (200%), largest (400%)
+         </long>
+      </locale>
+    </schema>
+
    <!-- Icon View -->
     <schema>
       <key>/schemas/apps/nautilus/compact_view/default_zoom_level</key>
@@ -1056,6 +1088,23 @@
          </long>
       </locale>
     </schema>
+
+    <schema>
+      <key>/schemas/apps/nautilus/desktop/text_ellipsis_limit</key>
+      <applyto>/apps/nautilus/desktop/text_ellipsis_limit</applyto>
+      <type>integer</type>
+      <default>3</default>
+      <locale name="C">
+         <short>Text Ellipsis Limit</short>
+         <long>
+	     An integer specifying how parts of overlong file names
+	     should be replaced by ellipses on the desktop.
+	     If the number is larger than 0, the file name will not exceed
+	     the given number of lines. If the number is 0 or smaller, no
+	     limit is imposed on the number of displayed lines.
+         </long>
+      </locale>
+    </schema>
         
   </schemalist>  
 </gconfschemafile>

Modified: trunk/libnautilus-private/nautilus-global-preferences.c
==============================================================================
--- trunk/libnautilus-private/nautilus-global-preferences.c	(original)
+++ trunk/libnautilus-private/nautilus-global-preferences.c	Mon Aug 18 20:47:18 2008
@@ -432,7 +432,12 @@
 	  PREFERENCE_INTEGER,
 	  GINT_TO_POINTER (96)
 	},
-
+	{ NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
+	  PREFERENCE_STRING_ARRAY,
+	  "3",
+	  NULL,NULL,
+	  NULL,
+	},
 	/* Compact Icon View Default Preferences */
 	{ NAUTILUS_PREFERENCES_COMPACT_VIEW_DEFAULT_ZOOM_LEVEL,
 	  PREFERENCE_STRING,
@@ -533,6 +538,10 @@
 	  PREFERENCE_STRING_ARRAY,
 	  "", NULL, NULL, NULL
 	},	
+	{ NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT,
+	  PREFERENCE_INTEGER,
+	  GINT_TO_POINTER (3)
+	},
 	{ NULL }
 };
 

Modified: trunk/libnautilus-private/nautilus-global-preferences.h
==============================================================================
--- trunk/libnautilus-private/nautilus-global-preferences.h	(original)
+++ trunk/libnautilus-private/nautilus-global-preferences.h	Mon Aug 18 20:47:18 2008
@@ -153,6 +153,10 @@
 /* The default size for thumbnail icons */
 #define NAUTILUS_PREFERENCES_ICON_VIEW_THUMBNAIL_SIZE			"icon_view/thumbnail_size"
 
+/* ellipsization preferences */
+#define NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT		"icon_view/text_ellipsis_limit"
+#define NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT		"desktop/text_ellipsis_limit"
+
 /* Compact View */
 #define NAUTILUS_PREFERENCES_COMPACT_VIEW_DEFAULT_ZOOM_LEVEL		"compact_view/default_zoom_level"
 #define NAUTILUS_PREFERENCES_COMPACT_VIEW_ALL_COLUMNS_SAME_WIDTH	"compact_view/all_columns_have_same_width"

Modified: trunk/libnautilus-private/nautilus-icon-canvas-item.c
==============================================================================
--- trunk/libnautilus-private/nautilus-icon-canvas-item.c	(original)
+++ trunk/libnautilus-private/nautilus-icon-canvas-item.c	Mon Aug 18 20:47:18 2008
@@ -1106,7 +1106,8 @@
 			/* VOODOO-TODO, cf. compute_text_rectangle() */
 			pango_layout_set_height (editable_layout, G_MININT);
 		} else {
-			pango_layout_set_height (editable_layout, -3);
+			pango_layout_set_height (editable_layout,
+						 nautilus_icon_container_get_layout_height (container));
 		}
 		layout_get_full_size (editable_layout, &editable_width, &editable_height, &editable_for_layout_height, &editable_dx);
 	}

Modified: trunk/libnautilus-private/nautilus-icon-container.c
==============================================================================
--- trunk/libnautilus-private/nautilus-icon-container.c	(original)
+++ trunk/libnautilus-private/nautilus-icon-container.c	Mon Aug 18 20:47:18 2008
@@ -45,6 +45,8 @@
 #include <eel/eel-editable-label.h>
 #include <eel/eel-marshal.h>
 #include <eel/eel-string.h>
+#include <eel/eel-preferences.h>
+#include <eel/eel-enumeration.h>
 #include <eel/eel-canvas-rect-ellipse.h>
 #include <libgnomeui/gnome-icon-item.h>
 #include <gdk/gdkkeysyms.h>
@@ -5099,6 +5101,41 @@
 	}
 }
 
+static void
+text_ellipsis_limit_changed_container_callback (gpointer callback_data)
+{
+	NautilusIconContainer *container;
+
+	container = NAUTILUS_ICON_CONTAINER (callback_data);
+	invalidate_label_sizes (container);
+	schedule_redo_layout (container);
+}
+
+static GObject*
+nautilus_icon_container_constructor (GType                  type,
+				     guint                  n_construct_params,
+				     GObjectConstructParam *construct_params)
+{
+	NautilusIconContainer *container;
+	GObject *object;
+
+	object = G_OBJECT_CLASS (parent_class)->constructor (type,
+							     n_construct_params,
+							     construct_params);
+
+	container = NAUTILUS_ICON_CONTAINER (object);
+	if (nautilus_icon_container_get_is_desktop (container)) {
+		eel_preferences_add_callback (NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT,
+					      text_ellipsis_limit_changed_container_callback,
+					      container);
+	} else {
+		eel_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
+					      text_ellipsis_limit_changed_container_callback,
+					      container);
+	}
+
+	return object;
+}
 
 /* Initialization.  */
 
@@ -5109,6 +5146,7 @@
 	EelCanvasClass *canvas_class;
 	GtkBindingSet *binding_set;
 
+	G_OBJECT_CLASS (class)->constructor = nautilus_icon_container_constructor;
 	G_OBJECT_CLASS (class)->finalize = finalize;
 	GTK_OBJECT_CLASS (class)->destroy = destroy;
 
@@ -5611,11 +5649,88 @@
 	return FALSE;
 }
 
+
+static int text_ellipsis_limits[NAUTILUS_ZOOM_LEVEL_N_ENTRIES];
+static int desktop_text_ellipsis_limit;
+
+static gboolean
+get_text_ellipsis_limit_for_zoom (char **strs,
+				  const char *zoom_level,
+				  int *limit)
+{
+	char **p;
+	char *str;
+	gboolean success;
+
+	success = FALSE;
+
+	/* default */
+	*limit = 3;
+
+	if (zoom_level != NULL) {
+		str = g_strdup_printf ("%s:%%d", zoom_level);
+	} else {
+		str = g_strdup ("%d");
+	}
+
+	if (strs != NULL) {
+		for (p = strs; *p != NULL; p++) {
+			if (sscanf (*p, str, limit)) {
+				success = TRUE;
+			}
+		}
+	}
+
+	g_free (str);
+
+	return success;
+}
+
+static void
+text_ellipsis_limit_changed_callback (gpointer callback_data)
+{
+	char **pref;
+	unsigned int i;
+	int one_limit;
+	const EelEnumeration *eenum;
+	const EelEnumerationEntry *entry;
+
+	pref = eel_preferences_get_string_array (NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT);
+
+	/* set default */
+	get_text_ellipsis_limit_for_zoom (pref, NULL, &one_limit);
+	for (i = 0; i < NAUTILUS_ZOOM_LEVEL_N_ENTRIES; i++) {
+		text_ellipsis_limits[i] = one_limit;
+	}
+
+	/* override for each zoom level */
+	eenum = eel_enumeration_lookup ("default_zoom_level");
+	g_assert (eenum != NULL);
+	for (i = 0; i < eel_enumeration_get_length (eenum); i++) {
+		entry = eel_enumeration_get_nth_entry (eenum, i);
+		if (get_text_ellipsis_limit_for_zoom (pref, entry->name, &one_limit)) {
+			text_ellipsis_limits[entry->value] = one_limit;
+		}
+	}
+
+	g_strfreev (pref);
+}
+
+static void
+desktop_text_ellipsis_limit_changed_callback (gpointer callback_data)
+{
+	int pref;
+
+	pref = eel_preferences_get_integer (NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT);
+	desktop_text_ellipsis_limit = pref;
+}
+
 static void
 nautilus_icon_container_instance_init (NautilusIconContainer *container)
 {
 	NautilusIconContainerDetails *details;
 	EelBackground *background;
+	static gboolean setup_prefs = FALSE;
 	
 	details = g_new0 (NautilusIconContainerDetails, 1);
 
@@ -5651,6 +5766,20 @@
 	eel_preferences_add_callback (NAUTILUS_PREFERENCES_THEME,
 				      nautilus_icon_container_theme_changed,
 				      container);	
+
+	if (!setup_prefs) {
+		eel_preferences_add_callback (NAUTILUS_PREFERENCES_ICON_VIEW_TEXT_ELLIPSIS_LIMIT,
+					      text_ellipsis_limit_changed_callback,
+					      NULL);
+		text_ellipsis_limit_changed_callback (NULL);
+
+		eel_preferences_add_callback (NAUTILUS_PREFERENCES_DESKTOP_TEXT_ELLIPSIS_LIMIT,
+					      desktop_text_ellipsis_limit_changed_callback,
+					      NULL);
+		desktop_text_ellipsis_limit_changed_callback (NULL);
+
+		setup_prefs = TRUE;
+	}
 }
 
 typedef struct {
@@ -8844,5 +8973,23 @@
 		container->details->layout_mode == NAUTILUS_ICON_LAYOUT_T_B_R_L);
 }
 
+int
+nautilus_icon_container_get_layout_height (NautilusIconContainer  *container)
+{
+	int limit;
+
+	if (nautilus_icon_container_get_is_desktop (container)) {
+		limit = desktop_text_ellipsis_limit;
+	} else {
+		limit = text_ellipsis_limits[container->details->zoom_level];
+	}
+
+	if (limit <= 0) {
+		return G_MININT;
+	}
+
+	return -limit;
+}
+
 
 #endif /* ! NAUTILUS_OMIT_SELF_CHECK */

Modified: trunk/libnautilus-private/nautilus-icon-container.h
==============================================================================
--- trunk/libnautilus-private/nautilus-icon-container.h	(original)
+++ trunk/libnautilus-private/nautilus-icon-container.h	Mon Aug 18 20:47:18 2008
@@ -252,6 +252,8 @@
 void              nautilus_icon_container_sort                          (NautilusIconContainer  *container);
 void              nautilus_icon_container_freeze_icon_positions         (NautilusIconContainer  *container);
 
+int               nautilus_icon_container_get_layout_height             (NautilusIconContainer  *container);
+
 
 /* operations on all icons */
 void              nautilus_icon_container_unselect_all                  (NautilusIconContainer  *view);

Modified: trunk/libnautilus-private/nautilus-icon-info.h
==============================================================================
--- trunk/libnautilus-private/nautilus-icon-info.h	(original)
+++ trunk/libnautilus-private/nautilus-icon-info.h	Mon Aug 18 20:47:18 2008
@@ -20,6 +20,8 @@
 	NAUTILUS_ZOOM_LEVEL_LARGEST
 } NautilusZoomLevel;
 
+#define NAUTILUS_ZOOM_LEVEL_N_ENTRIES (NAUTILUS_ZOOM_LEVEL_LARGEST + 1)
+
 /* Nominal icon sizes for each Nautilus zoom level.
  * This scheme assumes that icons are designed to
  * fit in a square space, though each image needn't



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