[gedit/wip/loader-saver: 16/16] Don't use the deprecated GeditDocument API
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit/wip/loader-saver: 16/16] Don't use the deprecated GeditDocument API
- Date: Fri, 27 Jun 2014 19:56:03 +0000 (UTC)
commit 7cc07d4a34bdb02a8933379e08764f43af7b679c
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jun 27 19:23:28 2014 +0200
Don't use the deprecated GeditDocument API
gedit/gedit-app-osx.c | 5 ++-
gedit/gedit-commands-file.c | 69 +++++++++++++++++++----------------------
gedit/gedit-documents-panel.c | 6 ++--
gedit/gedit-recent.c | 8 +++--
gedit/gedit-tab.c | 66 ++++++++++++++++++---------------------
gedit/gedit-window.c | 43 ++++++++++++-------------
6 files changed, 93 insertions(+), 104 deletions(-)
---
diff --git a/gedit/gedit-app-osx.c b/gedit/gedit-app-osx.c
index e0c72f7..5076b72 100644
--- a/gedit/gedit-app-osx.c
+++ b/gedit/gedit-app-osx.c
@@ -110,14 +110,15 @@ gedit_app_osx_set_window_title_impl (GeditApp *app,
}
else
{
+ GtkSourceFile *file;
GFile *location;
gchar *uri;
- location = gedit_document_get_location (document);
+ file = gedit_document_get_file (document);
+ location = gtk_source_file_get_location (file);
#if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
uri = g_file_get_uri (location);
- g_object_unref (location);
NSURL *nsurl = [NSURL URLWithString:[NSString stringWithUTF8String:uri]];
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 521a797..62c8aaa 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -73,21 +73,17 @@ get_tab_from_file (GList *docs,
while (docs != NULL)
{
GeditDocument *d;
+ GtkSourceFile *source_file;
GFile *l;
d = GEDIT_DOCUMENT (docs->data);
+ source_file = gedit_document_get_file (d);
- l = gedit_document_get_location (d);
- if (l != NULL)
+ l = gtk_source_file_get_location (source_file);
+ if (l != NULL && g_file_equal (l, file))
{
- if (g_file_equal (l, file))
- {
- tab = gedit_tab_get_from_document (d);
- g_object_unref (l);
- break;
- }
-
- g_object_unref (l);
+ tab = gedit_tab_get_from_document (d);
+ break;
}
docs = g_list_next (docs);
@@ -453,14 +449,12 @@ _gedit_cmd_file_open (GSimpleAction *action,
doc = gedit_window_get_active_document (window);
if (doc != NULL)
{
- GFile *file;
+ GtkSourceFile *file = gedit_document_get_file (doc);
+ GFile *location = gtk_source_file_get_location (file);
- file = gedit_document_get_location (doc);
-
- if (file != NULL)
+ if (location != NULL)
{
- default_path = g_file_get_parent (file);
- g_object_unref (file);
+ default_path = g_file_get_parent (location);
}
}
@@ -694,8 +688,9 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
if (tab != NULL)
{
- GFile *file;
+ GFile *location;
GeditDocument *doc;
+ GtkSourceFile *file;
gchar *parse_name;
GtkSourceNewlineType newline_type;
GtkSourceCompressionType compression_type;
@@ -703,22 +698,23 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
const GtkSourceEncoding *encoding;
doc = gedit_tab_get_document (tab);
+ file = gedit_document_get_file (doc);
- file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
- g_return_if_fail (file != NULL);
+ location = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
+ g_return_if_fail (location != NULL);
- compression_type = get_compression_type_from_file (file);
- current_compression_type = gedit_document_get_compression_type (doc);
+ compression_type = get_compression_type_from_file (location);
+ current_compression_type = gtk_source_file_get_compression_type (file);
if ((compression_type == GTK_SOURCE_COMPRESSION_TYPE_NONE) !=
(current_compression_type == GTK_SOURCE_COMPRESSION_TYPE_NONE))
{
if (!change_compression (GTK_WINDOW (dialog),
- file,
+ location,
compression_type != GTK_SOURCE_COMPRESSION_TYPE_NONE))
{
gtk_widget_destroy (GTK_WIDGET (dialog));
- g_object_unref (file);
+ g_object_unref (location);
goto save_next_tab;
}
@@ -732,7 +728,7 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
doc = gedit_tab_get_document (tab);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
- parse_name = g_file_get_parse_name (file);
+ parse_name = g_file_get_parse_name (location);
gedit_statusbar_flash_message (GEDIT_STATUSBAR (window->priv->statusbar),
window->priv->generic_message_cid,
@@ -743,11 +739,11 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
/* let's remember the dir we navigated too,
* even if the saving fails... */
- _gedit_window_set_default_location (window, file);
+ _gedit_window_set_default_location (window, location);
- _gedit_tab_save_as (tab, file, encoding, newline_type, compression_type);
+ _gedit_tab_save_as (tab, location, encoding, newline_type, compression_type);
- g_object_unref (file);
+ g_object_unref (location);
}
save_next_tab:
@@ -831,7 +827,8 @@ _gedit_cmd_file_save_as_tab (GeditTab *tab,
GtkWidget *save_dialog;
GtkWindowGroup *wg;
GeditDocument *doc;
- GFile *file;
+ GtkSourceFile *file;
+ GFile *location;
const GtkSourceEncoding *encoding;
GtkSourceNewlineType newline_type;
@@ -857,23 +854,21 @@ _gedit_cmd_file_save_as_tab (GeditTab *tab,
wg = gedit_window_get_group (window);
- gtk_window_group_add_window (wg,
- GTK_WINDOW (save_dialog));
+ gtk_window_group_add_window (wg, GTK_WINDOW (save_dialog));
/* Save As dialog is modal to its main window */
gtk_window_set_modal (GTK_WINDOW (save_dialog), TRUE);
/* Set the suggested file name */
doc = gedit_tab_get_document (tab);
- file = gedit_document_get_location (doc);
+ file = gedit_document_get_file (doc);
+ location = gtk_source_file_get_location (file);
- if (file != NULL)
+ if (location != NULL)
{
gtk_file_chooser_set_file (GTK_FILE_CHOOSER (save_dialog),
- file,
+ location,
NULL);
-
- g_object_unref (file);
}
else
{
@@ -902,10 +897,10 @@ _gedit_cmd_file_save_as_tab (GeditTab *tab,
}
/* Set suggested encoding */
- encoding = gedit_document_get_encoding (doc);
+ encoding = gtk_source_file_get_encoding (file);
g_return_if_fail (encoding != NULL);
- newline_type = gedit_document_get_newline_type (doc);
+ newline_type = gtk_source_file_get_newline_type (file);
gedit_file_chooser_dialog_set_encoding (GEDIT_FILE_CHOOSER_DIALOG (save_dialog),
encoding);
diff --git a/gedit/gedit-documents-panel.c b/gedit/gedit-documents-panel.c
index 7e19e36..1f05d71 100644
--- a/gedit/gedit-documents-panel.c
+++ b/gedit/gedit-documents-panel.c
@@ -1183,9 +1183,9 @@ panel_on_drag_data_get (GtkWidget *widget,
if (!gedit_document_is_untitled (doc))
{
- GFile *file = gedit_document_get_location (doc);
- full_name = g_file_get_parse_name (file);
- g_object_unref (file);
+ GtkSourceFile *file = gedit_document_get_file (doc);
+ GFile *location = gtk_source_file_get_location (file);
+ full_name = g_file_get_parse_name (location);
gtk_selection_data_set (data,
target,
diff --git a/gedit/gedit-recent.c b/gedit/gedit-recent.c
index 60b4377..f84c30c 100644
--- a/gedit/gedit-recent.c
+++ b/gedit/gedit-recent.c
@@ -27,6 +27,7 @@ gedit_recent_add_document (GeditDocument *document)
{
GtkRecentManager *recent_manager;
GtkRecentData *recent_data;
+ GtkSourceFile *file;
GFile *location;
gchar *uri;
@@ -37,8 +38,10 @@ gedit_recent_add_document (GeditDocument *document)
NULL
};
- location = gedit_document_get_location (document);
- if (location != NULL)
+ file = gedit_document_get_file (document);
+ location = gtk_source_file_get_location (file);
+
+ if (location != NULL)
{
recent_manager = gtk_recent_manager_get_default ();
@@ -61,7 +64,6 @@ gedit_recent_add_document (GeditDocument *document)
g_free (recent_data->app_exec);
g_free (recent_data->mime_type);
g_slice_free (GtkRecentData, recent_data);
- g_object_unref (location);
}
}
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 0a0a405..6f9804f 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -723,15 +723,12 @@ show_loading_info_bar (GeditTab *tab)
}
else
{
- GFile *location;
+ GtkSourceFile *file = gedit_document_get_file (doc);
+ GFile *location = gtk_source_file_get_location (file);
- location = gedit_document_get_location (doc);
if (location != NULL)
{
- gchar *str;
-
- str = gedit_utils_location_get_dirname_for_display (location);
- g_object_unref (location);
+ gchar *str = gedit_utils_location_get_dirname_for_display (location);
/* use the remaining space for the dir, but use a min of 20 chars
* so that we do not end up with a dirname like "(a...b)".
@@ -1095,18 +1092,19 @@ display_externally_modified_notification (GeditTab *tab)
{
GtkWidget *info_bar;
GeditDocument *doc;
+ GtkSourceFile *file;
GFile *location;
gboolean document_modified;
doc = gedit_tab_get_document (tab);
+ file = gedit_document_get_file (doc);
/* we're here because the file we're editing changed on disk */
- location = gedit_document_get_location (doc);
+ location = gtk_source_file_get_location (file);
g_return_if_fail (location != NULL);
document_modified = gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc));
info_bar = gedit_externally_modified_info_bar_new (location, document_modified);
- g_object_unref (location);
set_info_bar (tab, info_bar, GTK_RESPONSE_OK);
@@ -1179,31 +1177,32 @@ _gedit_tab_set_network_available (GeditTab *tab,
gboolean enable)
{
GeditDocument *doc;
- GFile *location;
g_return_if_fail (GEDIT_IS_TAB (tab));
doc = gedit_tab_get_document (tab);
- location = gedit_document_get_location (doc);
+ if (gedit_document_is_local (doc))
+ {
+ return;
+ }
- if (!gedit_document_is_local (doc))
+ if (enable)
{
- if (enable)
- {
- set_info_bar (tab, NULL, GTK_RESPONSE_NONE);
- }
- else
- {
- GtkWidget *bar = gedit_network_unavailable_info_bar_new (location);
+ set_info_bar (tab, NULL, GTK_RESPONSE_NONE);
+ }
+ else
+ {
+ GtkSourceFile *file = gedit_document_get_file (doc);
+ GFile *location = gtk_source_file_get_location (file);
+ GtkWidget *bar = gedit_network_unavailable_info_bar_new (location);
- g_signal_connect (bar,
- "response",
- G_CALLBACK (network_available_warning_info_bar_response),
- tab);
+ g_signal_connect (bar,
+ "response",
+ G_CALLBACK (network_available_warning_info_bar_response),
+ tab);
- set_info_bar (tab, bar, GTK_RESPONSE_CLOSE);
- }
+ set_info_bar (tab, bar, GTK_RESPONSE_CLOSE);
}
}
@@ -1449,6 +1448,7 @@ _gedit_tab_get_tooltip (GeditTab *tab)
gchar *content_description;
gchar *content_full_description;
gchar *encoding;
+ GtkSourceFile *file;
const GtkSourceEncoding *enc;
case GEDIT_TAB_STATE_LOADING_ERROR:
@@ -1480,7 +1480,8 @@ _gedit_tab_get_tooltip (GeditTab *tab)
g_free (mime_type);
g_free (content_description);
- enc = gedit_document_get_encoding (doc);
+ file = gedit_document_get_file (doc);
+ enc = gtk_source_file_get_encoding (file);
if (enc == NULL)
encoding = g_strdup (_("Unicode (UTF-8)"));
@@ -1496,7 +1497,6 @@ _gedit_tab_get_tooltip (GeditTab *tab)
g_free (encoding);
g_free (content_full_description);
-
break;
}
@@ -1829,9 +1829,8 @@ load_cb (GtkSourceFileLoader *loader,
if (cur_doc != doc)
{
- GFile *cur_location;
-
- cur_location = gedit_document_get_location (cur_doc);
+ GtkSourceFile *cur_file = gedit_document_get_file (cur_doc);
+ GFile *cur_location = gtk_source_file_get_location (cur_file);
if (cur_location != NULL && location != NULL &&
g_file_equal (location, cur_location))
@@ -1849,14 +1848,8 @@ load_cb (GtkSourceFileLoader *loader,
set_info_bar (tab, info_bar, GTK_RESPONSE_CANCEL);
- g_object_unref (cur_location);
break;
}
-
- if (cur_location != NULL)
- {
- g_object_unref (cur_location);
- }
}
}
@@ -2357,7 +2350,8 @@ _gedit_tab_save_as (GeditTab *tab,
prev_location = gtk_source_file_get_location (file);
- if (!g_file_equal (prev_location, location))
+ if (prev_location == NULL ||
+ !g_file_equal (prev_location, location))
{
/* Ignore modification time for a save to another location. */
/* TODO do that in GtkSourceFileSaver. */
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 5620121..66b9740 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -995,15 +995,12 @@ set_title (GeditWindow *window)
}
else
{
- GFile *file;
+ GtkSourceFile *file = gedit_document_get_file (doc);
+ GFile *location = gtk_source_file_get_location (file);
- file = gedit_document_get_location (doc);
- if (file != NULL)
+ if (location != NULL)
{
- gchar *str;
-
- str = gedit_utils_location_get_dirname_for_display (file);
- g_object_unref (file);
+ gchar *str = gedit_utils_location_get_dirname_for_display (location);
/* use the remaining space for the dir, but use a min of 20 chars
* so that we do not end up with a dirname like "(a...b)".
@@ -2146,12 +2143,13 @@ push_last_closed_doc (GeditWindow *window,
GeditDocument *doc)
{
GeditWindowPrivate *priv = window->priv;
- GFile *f;
+ GtkSourceFile *file = gedit_document_get_file (doc);
+ GFile *location = gtk_source_file_get_location (file);
- f = gedit_document_get_location (doc);
- if (f != NULL)
+ if (location != NULL)
{
- priv->closed_docs_stack = g_slist_prepend (priv->closed_docs_stack, f);
+ priv->closed_docs_stack = g_slist_prepend (priv->closed_docs_stack, location);
+ g_object_ref (location);
}
}
@@ -3683,24 +3681,23 @@ gedit_window_get_tab_from_location (GeditWindow *window,
for (l = tabs; l != NULL; l = g_list_next (l))
{
- GeditDocument *d;
- GeditTab *t;
- GFile *f;
-
- t = GEDIT_TAB (l->data);
- d = gedit_tab_get_document (t);
+ GeditDocument *doc;
+ GtkSourceFile *file;
+ GeditTab *tab;
+ GFile *cur_location;
- f = gedit_document_get_location (d);
+ tab = GEDIT_TAB (l->data);
+ doc = gedit_tab_get_document (tab);
+ file = gedit_document_get_file (doc);
+ cur_location = gtk_source_file_get_location (file);
- if ((f != NULL))
+ if (cur_location != NULL)
{
- gboolean found = g_file_equal (location, f);
-
- g_object_unref (f);
+ gboolean found = g_file_equal (location, cur_location);
if (found)
{
- ret = t;
+ ret = tab;
break;
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]