Commit 50e7b3d3 authored by Paolo Maggi's avatar Paolo Maggi Committed by Paolo Maggi

new function

2004-11-09  Paolo Maggi  <paolo@gnome.org>

	* gedit-utils.[ch] (gedit_utils_replace_home_dir_with_tilde): new function

	* gedit-mdi-child.c (gedit_mdi_child_real_state_changed):
	uses "*doc" instead of "doc*" for changed documents. Does not use
	"RO" for read only documents.
	(menu_show) (create_popup_menu): fixes a problem with the sensitivity
	of the "Save" menu item.
	(set_tooltip): call gedit_utils_replace_home_dir_with_tilde on the displayed URI.

	* gedit-mdi.c (get_dirname) (gedit_mdi_set_active_window_title): Uses
	"filename (dirname) - gedit" as window title. Fixes bug #152803 and bug #149553.
parent 9ed604c8
2004-11-09 Paolo Maggi <paolo@gnome.org>
* gedit-utils.[ch] (gedit_utils_replace_home_dir_with_tilde): new function
* gedit-mdi-child.c (gedit_mdi_child_real_state_changed):
uses "*doc" instead of "doc*" for changed documents. Does not use
"RO" for read only documents.
(menu_show) (create_popup_menu): fixes a problem with the sensitivity
of the "Save" menu item.
(set_tooltip): call gedit_utils_replace_home_dir_with_tilde on the displayed URI.
* gedit-mdi.c (get_dirname) (gedit_mdi_set_active_window_title): Uses
"filename (dirname) - gedit" as window title. Fixes bug #152803 and bug #149553.
2004-11-09 Paolo Maggi <paolo@gnome.org>
* gedit/dialogs/gedit-page-setup-dialog.c (restore_button_clicked)
......
......@@ -238,19 +238,23 @@ gedit_mdi_child_real_state_changed (GeditMDIChild* child)
if (gedit_document_get_modified (child->document))
{
tab_name = g_strdup_printf ("%s*", docname);
tab_name = g_strdup_printf ("*%s", docname);
}
else
{
#if 0
if (gedit_document_is_readonly (child->document))
{
tab_name = g_strdup_printf ("%s - %s", docname,
tab_name = g_strdup_printf ("%s [%s]", docname,
/*Read only*/ _("RO"));
}
else
{
tab_name = g_strdup_printf ("%s", docname);
}
#endif
tab_name = g_strdup_printf ("%s", docname);
}
g_free (docname);
......@@ -550,8 +554,6 @@ menu_show (GtkWidget *widget, GtkWidget *view)
if (bonobo_mdi_get_active_view (BONOBO_MDI (gedit_mdi)) != view)
bonobo_mdi_set_active_view (BONOBO_MDI (gedit_mdi), view);
/* FIXME: I should set sensitivity of the children, not of the entire memu -
* Paolo (Jan 13, 2004) */
if (gedit_mdi_get_state (gedit_mdi) != GEDIT_STATE_NORMAL)
{
gtk_container_foreach (GTK_CONTAINER (widget),
......@@ -560,6 +562,8 @@ menu_show (GtkWidget *widget, GtkWidget *view)
}
else
{
GtkWidget *menu_item;
gtk_container_foreach (GTK_CONTAINER (widget),
(GtkCallback)gtk_widget_set_sensitive,
GINT_TO_POINTER (TRUE));
......@@ -567,21 +571,19 @@ menu_show (GtkWidget *widget, GtkWidget *view)
if (bonobo_mdi_n_views_for_window (
bonobo_mdi_get_window_from_view (view)) <= 1)
{
GtkWidget *menu_item;
menu_item = g_object_get_data (G_OBJECT (widget), "move-to-menu-item");
gtk_widget_set_sensitive (menu_item, FALSE);
}
}
}
static void
read_only_changed_cb (GeditDocument *doc, gboolean readonly, gpointer *data)
{
g_return_if_fail (GTK_IS_WIDGET (data));
menu_item = g_object_get_data (G_OBJECT (widget), "save-menu-item");
gtk_widget_set_sensitive (GTK_WIDGET (data), !readonly);
gtk_widget_set_sensitive (menu_item,
!gedit_document_is_readonly (
gedit_view_get_document (GEDIT_VIEW (view))));
}
}
static GtkWidget *
......@@ -632,13 +634,12 @@ create_popup_menu (BonoboMDIChild *child, GtkWidget *view)
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
gtk_widget_set_sensitive (menu_item, !gedit_document_is_readonly (doc));
g_signal_connect (G_OBJECT (doc), "readonly_changed",
G_CALLBACK (read_only_changed_cb), menu_item);
g_signal_connect (G_OBJECT (menu_item), "activate",
G_CALLBACK (gedit_mdi_child_tab_save_clicked), view);
gtk_menu_shell_prepend (GTK_MENU_SHELL (menu), menu_item);
g_object_set_data (G_OBJECT (menu), "save-menu-item", menu_item);
/* Add the separator */
menu_item = gtk_separator_menu_item_new ();
......@@ -740,6 +741,7 @@ set_tooltip (GeditTooltips *tooltips, GtkWidget *widget, BonoboMDIChild *child)
{
gchar *tip;
gchar *uri;
gchar *ruri;
gchar *raw_uri;
gchar *mime_type = NULL;
const gchar *mime_description = NULL;
......@@ -779,18 +781,21 @@ set_tooltip (GeditTooltips *tooltips, GtkWidget *widget, BonoboMDIChild *child)
encoding = g_strdup (_("Unicode (UTF-8)"));
else
encoding = gedit_encoding_to_string (enc);
ruri = gedit_utils_replace_home_dir_with_tilde (uri);
g_free (uri);
tip = g_strdup_printf ("<b>%s</b> %s\n\n"
"<b>%s</b> %s\n"
"<b>%s</b> %s",
_("Name:"), uri,
_("Name:"), ruri,
_("MIME Type:"), mime_full_description,
_("Encoding:"), encoding);
gedit_tooltips_set_tip (tooltips, widget, tip, NULL);
g_free (tip);
g_free (uri);
g_free (ruri);
g_free (raw_uri);
g_free (mime_type);
g_free (encoding);
......
......@@ -1362,14 +1362,40 @@ gedit_mdi_remove_all (GeditMDI *mdi)
#define MAX_URI_IN_TITLE_LENGTH 75
static gchar *
get_dirname (const gchar *uri)
{
gchar *res;
gchar *str;
str = g_path_get_dirname (uri);
g_return_val_if_fail (str != NULL, ".");
if ((strlen (str) == 1) && (*str == '.'))
{
g_free (str);
return NULL;
}
res = gedit_utils_replace_home_dir_with_tilde (str);
g_free (str);
return res;
}
void
gedit_mdi_set_active_window_title (BonoboMDI *mdi)
{
BonoboMDIChild *active_child = NULL;
GeditDocument *doc = NULL;
gchar *docname = NULL;
gchar *str;
gchar *dirname = NULL;
gchar *title = NULL;
gchar *uri;
gchar *name;
GtkWidget *active_window;
gedit_debug (DEBUG_MDI, "");
......@@ -1385,42 +1411,53 @@ gedit_mdi_set_active_window_title (BonoboMDI *mdi)
uri = gedit_document_get_uri (doc);
g_return_if_fail (uri != NULL);
/* Truncate the URI so it doesn't get insanely wide. */
docname = gedit_utils_str_middle_truncate (uri, MAX_URI_IN_TITLE_LENGTH);
str = get_dirname (uri);
g_free (uri);
if (str != NULL)
{
/* Truncate the URI so it doesn't get insanely wide. */
dirname = gedit_utils_str_middle_truncate (str, MAX_URI_IN_TITLE_LENGTH);
g_free (str);
}
else
{
dirname = NULL;
}
name = gedit_document_get_short_name (doc);
if (gedit_document_get_modified (doc))
{
title = g_strdup_printf ("%s %s - gedit", docname, _("(modified)"));
if (dirname != NULL)
title = g_strdup_printf ("*%s (%s) - gedit", name, dirname);
else
title = g_strdup_printf ("*%s - gedit", name);
}
else
{
if (gedit_document_is_readonly (doc))
{
title = g_strdup_printf ("%s %s - gedit", docname, _("(readonly)"));
if (dirname != NULL)
title = g_strdup_printf ("%s [%s] (%s) - gedit", name, _("Read Only"), dirname);
else
title = g_strdup_printf ("%s [%s] - gedit", name, _("Read Only"));
}
else
{
title = g_strdup_printf ("%s - gedit", docname);
if (dirname != NULL)
title = g_strdup_printf ("%s (%s) - gedit", name, dirname);
else
title = g_strdup_printf ("%s - gedit", name);
}
}
active_window = GTK_WIDGET (gedit_get_active_window ());
if (GTK_WIDGET_REALIZED (active_window))
{
gchar *short_name;
short_name = gedit_document_get_short_name (doc);
gdk_window_set_icon_name (active_window->window, short_name);
g_free (short_name);
}
gtk_window_set_title (GTK_WINDOW (active_window), title);
g_free (docname);
g_free (dirname);
g_free (name);
g_free (title);
}
......
......@@ -1461,3 +1461,48 @@ gedit_utils_uri_get_dirname (const char *uri)
return res;
}
gchar *
gedit_utils_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);
}
......@@ -100,6 +100,7 @@ gchar *gedit_utils_uri_get_basename (const char *uri);
gchar *gedit_utils_uri_get_dirname (const char *uri);
gchar *gedit_utils_replace_home_dir_with_tilde (const gchar *uri);
#endif /* __GEDIT_UTILS_H__ */
......
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