anjuta r3907 - in trunk: . libanjuta plugins/document-manager
- From: jhs svn gnome org
- To: svn-commits-list gnome org
- Subject: anjuta r3907 - in trunk: . libanjuta plugins/document-manager
- Date: Thu, 1 May 2008 11:16:13 +0100 (BST)
Author: jhs
Date: Thu May 1 10:16:13 2008
New Revision: 3907
URL: http://svn.gnome.org/viewvc/anjuta?rev=3907&view=rev
Log:
2008-05-01 Johannes Schmid <jhs gnome org>
* libanjuta/anjuta-utils.c (anjuta_util_uri_get_dirname),
(anjuta_util_replace_home_dir_with_tilde),
(anjuta_util_str_middle_truncate):
* libanjuta/anjuta-utils.h:
Added some utility methods (derived from gedit)
* plugins/document-manager/plugin.c (get_directory_display_name),
(update_title):
Really fix #530033 now
Modified:
trunk/ChangeLog
trunk/libanjuta/anjuta-utils.c
trunk/libanjuta/anjuta-utils.h
trunk/plugins/document-manager/plugin.c
Modified: trunk/libanjuta/anjuta-utils.c
==============================================================================
--- trunk/libanjuta/anjuta-utils.c (original)
+++ trunk/libanjuta/anjuta-utils.c Thu May 1 10:16:13 2008
@@ -1435,3 +1435,121 @@
return folder;
}
+/* The following functions are taken from gedit */
+
+/* Note that this function replace home dir with ~ */
+gchar *
+anjuta_util_uri_get_dirname (const gchar *uri)
+{
+ gchar *res;
+ gchar *str;
+
+ // CHECK: does it work with uri chaining? - Paolo
+ str = g_path_get_dirname (uri);
+ g_return_val_if_fail (str != NULL, ".");
+
+ if ((strlen (str) == 1) && (*str == '.'))
+ {
+ g_free (str);
+
+ return NULL;
+ }
+
+ res = anjuta_util_replace_home_dir_with_tilde (str);
+
+ g_free (str);
+
+ return res;
+}
+
+gchar*
+anjuta_util_replace_home_dir_with_tilde (const gchar *uri)
+{
+ gchar *tmp;
+ gchar *home;
+
+ g_return_val_if_fail (uri != NULL, NULL);
+
+ /* Note that g_get_home_dir returns a const string */
+ tmp = (gchar *)g_get_home_dir ();
+
+ if (tmp == NULL)
+ return g_strdup (uri);
+
+ home = g_filename_to_utf8 (tmp, -1, NULL, NULL, NULL);
+ if (home == NULL)
+ return g_strdup (uri);
+
+ if (strcmp (uri, home) == 0)
+ {
+ g_free (home);
+
+ return g_strdup ("~");
+ }
+
+ tmp = home;
+ home = g_strdup_printf ("%s/", tmp);
+ g_free (tmp);
+
+ if (g_str_has_prefix (uri, home))
+ {
+ gchar *res;
+
+ res = g_strdup_printf ("~/%s", uri + strlen (home));
+
+ g_free (home);
+
+ return res;
+ }
+
+ g_free (home);
+
+ return g_strdup (uri);
+}
+
+gchar *
+anjuta_util_str_middle_truncate (const gchar *string,
+ guint truncate_length)
+{
+ GString *truncated;
+ guint length;
+ guint n_chars;
+ guint num_left_chars;
+ guint right_offset;
+ guint delimiter_length;
+ const gchar *delimiter = "\342\200\246";
+
+ g_return_val_if_fail (string != NULL, NULL);
+
+ length = strlen (string);
+
+ g_return_val_if_fail (g_utf8_validate (string, length, NULL), NULL);
+
+ /* It doesnt make sense to truncate strings to less than
+ * the size of the delimiter plus 2 characters (one on each
+ * side)
+ */
+ delimiter_length = g_utf8_strlen (delimiter, -1);
+ if (truncate_length < (delimiter_length + 2)) {
+ return g_strdup (string);
+ }
+
+ n_chars = g_utf8_strlen (string, length);
+
+ /* Make sure the string is not already small enough. */
+ if (n_chars <= truncate_length) {
+ return g_strdup (string);
+ }
+
+ /* Find the 'middle' where the truncation will occur. */
+ num_left_chars = (truncate_length - delimiter_length) / 2;
+ right_offset = n_chars - truncate_length + num_left_chars + delimiter_length;
+
+ truncated = g_string_new_len (string,
+ g_utf8_offset_to_pointer (string, num_left_chars) - string);
+ g_string_append (truncated, delimiter);
+ g_string_append (truncated, g_utf8_offset_to_pointer (string, right_offset));
+
+ return g_string_free (truncated, FALSE);
+}
+
Modified: trunk/libanjuta/anjuta-utils.h
==============================================================================
--- trunk/libanjuta/anjuta-utils.h (original)
+++ trunk/libanjuta/anjuta-utils.h Thu May 1 10:16:13 2008
@@ -111,13 +111,19 @@
gboolean anjuta_util_path_has_extension (const gchar *path, const gchar *ext);
gchar* anjuta_util_get_real_path (const gchar *path);
+gchar* anjuta_util_uri_get_dirname (const gchar *uri);
+gchar* anjuta_util_replace_home_dir_with_tilde (const gchar *uri);
+gchar* anjuta_util_str_middle_truncate (const gchar *string,
+ guint truncate_length);
+
gchar* anjuta_util_get_uri_mime_type (const gchar *uri);
void anjuta_util_help_display (GtkWindow *parent,
const gchar *doc_id,
const gchar *file_name);
-gchar *anjuta_util_get_user_config_dir ();
+gchar *anjuta_util_get_user_config_dir (void);
+
/* Temporarily copied here */
Modified: trunk/plugins/document-manager/plugin.c
==============================================================================
--- trunk/plugins/document-manager/plugin.c (original)
+++ trunk/plugins/document-manager/plugin.c Thu May 1 10:16:13 2008
@@ -449,76 +449,70 @@
#define VIEW_EOL "view.eol"
#define VIEW_LINE_WRAP "view.line.wrap"
+#define MAX_TITLE_LENGTH 80
+
+static gchar*
+get_directory_display_name (DocmanPlugin* plugin,
+ const gchar* uri)
+{
+ gchar* dir;
+ gchar* display_uri = display_uri = gnome_vfs_format_uri_for_display (uri);
+ gchar* display_dir;
+ dir = anjuta_util_uri_get_dirname (display_uri);
+
+ display_dir = anjuta_util_str_middle_truncate (dir,
+ MAX (20, MAX_TITLE_LENGTH));
+ g_free (display_uri);
+ g_free (dir);
+ return display_dir;
+}
+
static void
update_title (DocmanPlugin* doc_plugin)
{
IAnjutaDocument *doc;
AnjutaStatus *status;
- gchar *filename;
gchar *title;
doc = anjuta_docman_get_current_document (ANJUTA_DOCMAN (doc_plugin->docman));
if (doc)
{
+ gchar* real_filename;
+ gchar *dir;
gchar *uri;
+ const gchar *filename;
+ filename = ianjuta_document_get_filename (doc, NULL);
uri = ianjuta_file_get_uri (IANJUTA_FILE (doc), NULL);
- if (uri)
+ dir = get_directory_display_name (doc_plugin, uri);
+ g_free (uri);
+ if (ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE (doc), NULL))
{
- filename = gnome_vfs_get_local_path_from_uri (uri);
- g_free (uri);
+ gchar* dirty_name = g_strconcat ("*", filename, NULL);
+ real_filename = dirty_name;
}
else
- filename = NULL;
- }
- else
- filename = NULL;
-
- if (filename && doc_plugin->project_name)
- {
- gchar *display_filename = NULL;
- const gchar *home = g_get_home_dir();
- if (doc_plugin->project_path)
+ real_filename = g_strdup (filename);
+
+ if (doc_plugin->project_name)
{
- if (g_str_has_prefix (filename, doc_plugin->project_path))
- {
- /* the +1 is the '/' */
- display_filename = filename + strlen (doc_plugin->project_path) + 1;
- }
+ title = g_strdup_printf ("%s (%s) - %s", real_filename, dir,
+ doc_plugin->project_name);
}
- if (!display_filename &&
- g_str_has_prefix (filename, home))
+ else
{
- filename[strlen (home) - 1] = '~';
- display_filename = filename + strlen (home) - 1;
+ title = g_strdup_printf ("%s (%s)", real_filename, dir);
}
- if (!display_filename)
- display_filename = filename;
- title = g_strconcat (display_filename, " - ", doc_plugin->project_name, NULL);
- }
- else if (filename)
- {
- title = g_strdup (filename);
- }
- else if (doc_plugin->project_name)
- {
- title = g_strdup (doc_plugin->project_name);
+ g_free (real_filename);
+ g_free (dir);
}
else
- title = NULL;
-
- if (title && doc &&
- ianjuta_file_savable_is_dirty(IANJUTA_FILE_SAVABLE (doc), NULL))
{
- gchar* dirty_title = g_strconcat ("*", title, NULL);
- g_free(title);
- title = dirty_title;
+ title = g_strdup (doc_plugin->project_name);
}
-
status = anjuta_shell_get_status (ANJUTA_PLUGIN (doc_plugin)->shell, NULL);
/* NULL title is ok */
anjuta_status_set_title (status, title);
- g_free (filename);
g_free (title);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]