Commit 1d7f9146 authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

gedit-utils.[ch]

2004-10-28  Paolo Borelli  <pborelli@katamail.com>

	* gedit-utils.[ch]
	* gedit-document.c:
	* gedit-file.c:

	More eel removal: move uri_get_basename to utils.
parent e4b272ba
2004-10-28 Paolo Borelli <pborelli@katamail.com>
* gedit-utils.[ch]
* gedit-document.c:
* gedit-file.c:
More eel removal: move uri_get_basename to utils.
2004-10-27 Paolo Borelli <pborelli@katamail.com>
* gedit-document.[ch]: remove unused function.
......
......@@ -665,8 +665,8 @@ gedit_document_get_short_name (const GeditDocument* doc)
{
gchar *basename;
gchar *utf8_basename;
basename = eel_uri_get_basename (doc->priv->uri);
basename = gedit_utils_uri_get_basename (doc->priv->uri);
if (basename != NULL)
{
......
......@@ -37,7 +37,6 @@
#include <libgnomeui/libgnomeui.h>
#include <libgnomevfs/gnome-vfs.h>
#include <eel/eel-vfs-extensions.h>
#include <eel/eel-alert-dialog.h>
#include "gedit2.h"
......@@ -63,7 +62,6 @@
PROFILE (static GTimer *timer = NULL);
static gchar *get_dirname_from_uri (const char *uri);
static void open_files (void);
static void show_progress_bar (gchar *uri,
gboolean show,
......@@ -89,28 +87,6 @@ static gint times_called = 0;
static GtkWidget *loading_window = NULL;
static GtkWidget *progress_bar = NULL;
static gchar *
get_dirname_from_uri (const char *uri)
{
GnomeVFSURI *vfs_uri;
gchar *name;
gchar *res;
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL) {
return NULL;
}
/* Extract name part. */
name = gnome_vfs_uri_extract_dirname (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
res = g_strdup_printf ("file:///%s", name);
g_free (name);
return res;
}
void
gedit_file_new (void)
......@@ -195,7 +171,7 @@ gedit_file_open (GeditMDIChild *active_child)
if ((raw_uri != NULL) && gedit_utils_uri_has_file_scheme (raw_uri))
{
default_path = get_dirname_from_uri (raw_uri);
default_path = gedit_utils_uri_get_dirname (raw_uri);
}
g_free (raw_uri);
......@@ -365,10 +341,10 @@ gedit_file_save_as (GeditMDIChild *child)
if (gedit_utils_uri_has_file_scheme (raw_uri))
{
fname = eel_uri_get_basename (raw_uri);
fname = gedit_utils_uri_get_basename (raw_uri);
g_return_val_if_fail (fname != NULL, FALSE);
path = get_dirname_from_uri (raw_uri);
path = gedit_utils_uri_get_dirname (raw_uri);
}
else
{
......@@ -430,7 +406,7 @@ gedit_file_save_as (GeditMDIChild *child)
if (gedit_default_path != NULL)
g_free (gedit_default_path);
gedit_default_path = get_dirname_from_uri (file_uri);
gedit_default_path = gedit_utils_uri_get_dirname (file_uri);
gedit_recent_add (uri);
......@@ -1157,7 +1133,7 @@ document_loaded_cb (GeditDocument *document,
{
gchar *default_path;
default_path = get_dirname_from_uri (uri);
default_path = gedit_utils_uri_get_dirname (uri);
if (default_path != NULL)
{
......
......@@ -1334,7 +1334,8 @@ gedit_warning (GtkWindow *parent, gchar *format, ...)
g_free (str);
}
/* taken from eel, except that we use "…" instead of "..."*/
/* the following functions are taken from eel */
gchar *
gedit_utils_str_middle_truncate (const char *string,
guint truncate_length)
......@@ -1344,6 +1345,7 @@ gedit_utils_str_middle_truncate (const char *string,
guint num_left_chars;
guint num_right_chars;
/* we use "…" instead of "..." */
const char delimter[] = "…";
const guint delimter_length = strlen (delimter);
const guint min_truncate_length = delimter_length + 2;
......@@ -1380,7 +1382,6 @@ gedit_utils_str_middle_truncate (const char *string,
return truncated;
}
/* pinched from eel too */
gchar *
gedit_utils_make_valid_utf8 (const char *name)
{
......@@ -1419,3 +1420,44 @@ gedit_utils_make_valid_utf8 (const char *name)
return g_string_free (string, FALSE);
}
gchar *
gedit_utils_uri_get_basename (const char *uri)
{
GnomeVFSURI *vfs_uri;
char *name;
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL) {
return NULL;
}
/* Extract name part. */
name = gnome_vfs_uri_extract_short_name (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
return name;
}
gchar *
gedit_utils_uri_get_dirname (const char *uri)
{
GnomeVFSURI *vfs_uri;
gchar *name;
gchar *res;
/* Make VFS version of URI. */
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL) {
return NULL;
}
/* Extract name part. */
name = gnome_vfs_uri_extract_dirname (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
res = g_strdup_printf ("file:///%s", name);
g_free (name);
return res;
}
......@@ -40,8 +40,8 @@
/* some common error strings, %s must be a file path */
#define MISSING_FILE N_("Could not find \"%s\". Please, reinstall gedit.")
#define MISSING_WIDGETS N_("Could not find the required widgets inside\"%s\". Please, reinstall gedit.")
#define MISSING_FILE N_("Could not find \"%s\". Please, reinstall gedit.\n")
#define MISSING_WIDGETS N_("Could not find the required widgets inside\"%s\". Please, reinstall gedit.\n")
void gedit_utils_flash (const gchar *msg);
......@@ -96,6 +96,11 @@ gchar *gedit_utils_str_middle_truncate (const char *string,
gchar *gedit_utils_make_valid_utf8 (const char *name);
gchar *gedit_utils_uri_get_basename (const char *uri);
gchar *gedit_utils_uri_get_dirname (const char *uri);
#endif /* __GEDIT_UTILS_H__ */
2004-10-28 Paolo Borelli <pborelli@katamail.com>
* shell_output/shell_output.c: eel removal.
2004-10-17 Paolo Borelli <pborelli@katamail.com>
* shell_output/shell_output.c: use proper help section.
......
......@@ -35,7 +35,6 @@
#include <libgnome/gnome-i18n.h>
#include <libgnome/gnome-help.h>
#include <libgnomevfs/gnome-vfs.h>
#include <eel/eel-vfs-extensions.h>
#include <libgnomeui/gnome-entry.h>
#include <libgnomeui/gnome-file-entry.h>
......@@ -550,76 +549,83 @@ unescape_command_string (const gchar *text, GeditDocument *doc)
cur = text;
end = text + length;
prev = NULL;
while (cur != end) {
while (cur != end)
{
const gchar *next;
next = g_utf8_next_char (cur);
if (prev && (*prev == '%')) {
if (prev && (*prev == '%'))
{
switch (*cur) {
case 'f':
case 'F':
if (filename == NULL)
case 'f':
case 'F':
if (filename == NULL)
{
tmp = gedit_document_get_raw_uri (doc);
if (tmp != NULL)
{
tmp = gedit_document_get_raw_uri (doc);
if (tmp != NULL)
{
filename = gnome_vfs_get_local_path_from_uri (tmp);
if (filename == NULL)
filename = tmp;
else
g_free (tmp);
}
filename = gnome_vfs_get_local_path_from_uri (tmp);
if (filename == NULL)
filename = tmp;
else
g_free (tmp);
}
}
if (filename != NULL)
{
gchar *qf;
if (filename != NULL)
{
gchar *qf;
qf = g_shell_quote (filename);
str = g_string_append (str, qf);
g_free (qf);
}
break;
case 'n':
case 'N':
if (basename == NULL)
qf = g_shell_quote (filename);
str = g_string_append (str, qf);
g_free (qf);
}
break;
case 'n':
case 'N':
if (basename == NULL)
{
tmp = gedit_document_get_raw_uri (doc);
if (tmp != NULL)
{
tmp = gedit_document_get_raw_uri (doc);
if (tmp != NULL)
{
basename = eel_uri_get_basename (tmp);
g_free (tmp);
}
basename = gedit_utils_uri_get_basename (tmp);
g_free (tmp);
}
}
if (basename != NULL)
{
gchar *qf;
if (basename != NULL)
{
gchar *qf;
qf = g_shell_quote (basename);
str = g_string_append (str, qf);
g_free (qf);
}
break;
case '%':
str = g_string_append (str, "%");
drop_prev = TRUE;
break;
default:
str = g_string_append (str, "%");
str = g_string_append (str, cur);
break;
qf = g_shell_quote (basename);
str = g_string_append (str, qf);
g_free (qf);
}
break;
case '%':
str = g_string_append (str, "%");
drop_prev = TRUE;
break;
default:
str = g_string_append (str, "%");
str = g_string_append (str, cur);
break;
}
} else if (*cur != '%') {
}
else if (*cur != '%')
{
str = g_string_append_len (str, cur, next - cur);
}
if (!drop_prev)
{
prev = cur;
else {
}
else
{
prev = NULL;
drop_prev = FALSE;
}
......
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