Commit 86e31d0d authored by Paolo Borelli's avatar Paolo Borelli Committed by Paolo Borelli

make the file load api return null in all the involved functions to

2006-02-19  Paolo Borelli  <pborelli@katamail.com>

	* gedit/gedit-document.[ch]:
	* gedit/gedit-document-loader.[ch]:
	* gedit/gedit-tab.[ch]:
	* gedit/gedit-command-file.c:

	make the file load api return null in all the involved functions to
	reflect that it is async. Handle correctly valid uris that however
	return a null vfs-uri.
parent 9914e080
2006-02-19 Paolo Borelli <pborelli@katamail.com>
* gedit/gedit-document.[ch]:
* gedit/gedit-document-loader.[ch]:
* gedit/gedit-tab.[ch]:
* gedit/gedit-command-file.c:
make the file load api return null in all the involved functions to
reflect that it is async. Handle correctly valid uris that however
return a null vfs-uri.
2006-02-19 Jesse van den Kieboom <jesse@icecrew.nl>
* plugins/snippets/snippets/SnippetsLibrary.py: inspect files as lazy as
......
......@@ -205,7 +205,7 @@
(define-method load
(of-object "GeditDocument")
(c-name "gedit_document_load")
(return-type "gboolean")
(return-type "none")
(parameters
'("const-gchar*" "uri")
'("const-GeditEncoding*" "encoding")
......
......@@ -107,36 +107,34 @@ load_file_list (GeditWindow *window,
gboolean ret;
uri = (const gchar *)uris->data;
ret = _gedit_tab_load (tab,
uri,
encoding,
line_pos,
create);
_gedit_tab_load (tab,
uri,
encoding,
line_pos,
create);
uris = g_slist_next (uris);
jump_to = FALSE;
if (ret)
if (uris == NULL)
{
if (uris == NULL)
{
/* There is only a single file to load */
gchar *uri_for_display;
uri_for_display = gnome_vfs_format_uri_for_display (uri);
/* There is only a single file to load */
gchar *uri_for_display;
gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
_("Loading file '%s'\342\200\246"),
uri_for_display);
uri_for_display = gnome_vfs_format_uri_for_display (uri);
g_free (uri_for_display);
gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
_("Loading file '%s'\342\200\246"),
uri_for_display);
flash = FALSE;
}
g_free (uri_for_display);
++loaded_files;
flash = FALSE;
}
++loaded_files;
}
}
......
......@@ -877,23 +877,47 @@ load_remote_file (GeditDocumentLoader *loader)
/* ---------- public api ---------- */
static gboolean
vfs_uri_new_failed (GeditDocumentLoader *loader)
{
load_completed_or_failed (loader);
/* stop the timeout */
return FALSE;
}
/* If enconding == NULL, the encoding will be autodetected */
gboolean
void
gedit_document_loader_load (GeditDocumentLoader *loader,
const gchar *uri,
const GeditEncoding *encoding)
{
gchar *local_path;
g_return_val_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
g_return_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader));
g_return_if_fail (uri != NULL);
/* the loader can be used just once, then it must be thrown away */
g_return_val_if_fail (loader->priv->used == FALSE, FALSE);
g_return_if_fail (loader->priv->used == FALSE);
loader->priv->used = TRUE;
/* vfs_uri may be NULL for some valid but unsupported uris */
loader->priv->vfs_uri = gnome_vfs_uri_new (uri);
if (loader->priv->vfs_uri == NULL)
return FALSE;
{
g_set_error (&loader->priv->error,
GEDIT_DOCUMENT_ERROR,
GNOME_VFS_ERROR_NOT_SUPPORTED,
gnome_vfs_result_to_string (GNOME_VFS_ERROR_NOT_SUPPORTED));
g_timeout_add_full (G_PRIORITY_HIGH,
0,
(GSourceFunc) vfs_uri_new_failed,
loader,
NULL);
return;
}
loader->priv->encoding = encoding;
......@@ -909,8 +933,6 @@ gedit_document_loader_load (GeditDocumentLoader *loader,
{
load_remote_file (loader);
}
return TRUE;
}
/* Returns STDIN_URI if loading from stdin */
......
......@@ -85,7 +85,7 @@ GType gedit_document_loader_get_type (void) G_GNUC_CONST;
GeditDocumentLoader *gedit_document_loader_new (GeditDocument *doc);
/* If enconding == NULL, the encoding will be autodetected */
gboolean gedit_document_loader_load (GeditDocumentLoader *loader,
void gedit_document_loader_load (GeditDocumentLoader *loader,
const gchar *uri,
const GeditEncoding *encoding);
#if 0
......
......@@ -675,8 +675,9 @@ set_uri (GeditDocument *doc,
if (doc->priv->vfs_uri != NULL)
gnome_vfs_uri_unref (doc->priv->vfs_uri);
/* Note: vfs_uri may be NULL for some valid but
* unsupported uris */
doc->priv->vfs_uri = gnome_vfs_uri_new (uri);
g_return_if_fail (doc->priv->vfs_uri != NULL);
if (doc->priv->untitled_number > 0)
{
......@@ -685,8 +686,6 @@ set_uri (GeditDocument *doc,
}
}
g_return_if_fail (doc->priv->vfs_uri != NULL);
g_free (doc->priv->mime_type);
if (mime_type != NULL)
{
......@@ -694,10 +693,11 @@ set_uri (GeditDocument *doc,
}
else
{
gchar *base_name;
gchar *base_name = NULL;
/* Guess the mime type from file extension or fallback to "text/plain" */
base_name = gnome_vfs_uri_extract_short_path_name (doc->priv->vfs_uri);
if (doc->priv->vfs_uri != NULL)
base_name = gnome_vfs_uri_extract_short_path_name (doc->priv->vfs_uri);
if (base_name != NULL)
{
const gchar *detected_mime;
......@@ -708,13 +708,13 @@ set_uri (GeditDocument *doc,
detected_mime = "text/plain";
doc->priv->mime_type = g_strdup (detected_mime);
g_free (base_name);
}
else
{
doc->priv->mime_type = g_strdup ("text/plain");
}
g_free (base_name);
}
if (!doc->priv->language_set_by_user)
......@@ -785,6 +785,7 @@ get_uri_shortname_for_display (GnomeVFSURI *uri)
gboolean validated;
validated = FALSE;
name = gnome_vfs_uri_extract_short_name (uri);
if (name == NULL)
......@@ -853,6 +854,8 @@ gedit_document_get_short_name_for_display (GeditDocument *doc)
if (doc->priv->uri == NULL)
return g_strdup_printf (_("Unsaved Document %d"),
doc->priv->untitled_number);
else if (doc->priv->vfs_uri == NULL)
return g_strdup (doc->priv->uri);
else
return get_uri_shortname_for_display (doc->priv->vfs_uri);
}
......@@ -1024,18 +1027,18 @@ document_loader_loading (GeditDocumentLoader *loader,
}
}
gboolean
void
gedit_document_load (GeditDocument *doc,
const gchar *uri,
const GeditEncoding *encoding,
gint line_pos,
gboolean create)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
g_return_val_if_fail (uri != NULL, FALSE);
g_return_val_if_fail (gedit_utils_is_valid_uri (uri), FALSE);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
g_return_if_fail (uri != NULL);
g_return_if_fail (gedit_utils_is_valid_uri (uri));
g_return_val_if_fail (doc->priv->loader == NULL, FALSE);
g_return_if_fail (doc->priv->loader == NULL);
/* create a loader. It will be destroyed when loading is completed */
doc->priv->loader = gedit_document_loader_new (doc);
......@@ -1051,9 +1054,9 @@ gedit_document_load (GeditDocument *doc,
set_uri (doc, uri, NULL);
return gedit_document_loader_load (doc->priv->loader,
uri,
encoding);
gedit_document_loader_load (doc->priv->loader,
uri,
encoding);
}
gboolean
......@@ -1224,7 +1227,7 @@ gedit_document_get_deleted (GeditDocument *doc)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), FALSE);
if (doc->priv->uri == NULL)
if (doc->priv->uri == NULL || doc->priv->vfs_uri == NULL)
return FALSE;
return !gnome_vfs_uri_exists (doc->priv->vfs_uri);
......
......@@ -154,12 +154,12 @@ gchar *gedit_document_get_mime_type (GeditDocument *doc);
gboolean gedit_document_get_readonly (GeditDocument *doc);
gboolean gedit_document_load (GeditDocument *doc,
const gchar *uri,
void gedit_document_load (GeditDocument *doc,
const gchar *uri,
const GeditEncoding *encoding,
gint line_pos,
gboolean create);
gboolean gedit_document_insert_file (GeditDocument *doc,
GtkTextIter *iter,
const gchar *uri,
......
......@@ -1450,17 +1450,11 @@ _gedit_tab_new_from_uri (const gchar *uri,
tab = GEDIT_TAB (_gedit_tab_new ());
ret = _gedit_tab_load (tab,
uri,
encoding,
line_pos,
create);
if (!ret)
{
g_object_unref (tab);
return NULL;
}
_gedit_tab_load (tab,
uri,
encoding,
line_pos,
create);
return GTK_WIDGET (tab);
}
......@@ -1768,7 +1762,7 @@ gedit_tab_get_from_document (GeditDocument *doc)
return (res != NULL) ? GEDIT_TAB (res) : NULL;
}
gboolean
void
_gedit_tab_load (GeditTab *tab,
const gchar *uri,
const GeditEncoding *encoding,
......@@ -1791,11 +1785,11 @@ _gedit_tab_load (GeditTab *tab,
if (tab->priv->auto_save_timeout > 0)
remove_auto_save_timeout (tab);
return gedit_document_load (doc,
uri,
encoding,
line_pos,
create);
gedit_document_load (doc,
uri,
encoding,
line_pos,
create);
}
void
......
......@@ -136,7 +136,7 @@ GtkWidget *_gedit_tab_new_from_uri (const gchar *uri,
gchar *_gedit_tab_get_name (GeditTab *tab);
gchar *_gedit_tab_get_tooltips (GeditTab *tab);
GdkPixbuf *_gedit_tab_get_icon (GeditTab *tab);
gboolean _gedit_tab_load (GeditTab *tab,
void _gedit_tab_load (GeditTab *tab,
const gchar *uri,
const GeditEncoding *encoding,
gint line_pos,
......
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