summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSébastien Wilmet <swilmet@informatique-libre.be>2023-03-21 16:00:00 +0100
committerSébastien Wilmet <swilmet@informatique-libre.be>2023-03-21 16:00:00 +0100
commitfcceaa7ce6d87f954575b3a4d77155dc254f5fa9 (patch)
tree06f4ab3fc14d3aa67a66ccbdf1ae70d4a7c0c0df
parent80f02a7a90a4424b898939328bad8dc85795ae3d (diff)
downloadgedit-fcceaa7ce6d87f954575b3a4d77155dc254f5fa9.tar.gz
Tab: rename load() to load_file() and make it public
Now there is load_file() and load_stream().
-rw-r--r--docs/reference/gedit-sections.txt1
-rw-r--r--gedit/gedit-commands-file.c12
-rw-r--r--gedit/gedit-tab-private.h7
-rw-r--r--gedit/gedit-tab.c38
-rw-r--r--gedit/gedit-tab.h7
-rw-r--r--gedit/gedit-window.c17
6 files changed, 53 insertions, 29 deletions
diff --git a/docs/reference/gedit-sections.txt b/docs/reference/gedit-sections.txt
index e1f948b1e..7d3d91828 100644
--- a/docs/reference/gedit-sections.txt
+++ b/docs/reference/gedit-sections.txt
@@ -168,6 +168,7 @@ GEDIT_STATUSBAR_GET_CLASS
<TITLE>GeditTab</TITLE>
GeditTab
GeditTabState
+gedit_tab_load_file
gedit_tab_load_stream
gedit_tab_get_view
gedit_tab_get_document
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index c430e48d8..ce9012329 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -197,12 +197,12 @@ load_file_list (GeditWindow *window,
if (tepl_buffer_is_untouched (TEPL_BUFFER (doc)) &&
gedit_tab_get_state (tab) == GEDIT_TAB_STATE_NORMAL)
{
- _gedit_tab_load (tab,
- l->data,
- encoding,
- line_pos,
- column_pos,
- create);
+ gedit_tab_load_file (tab,
+ l->data,
+ encoding,
+ line_pos,
+ column_pos,
+ create);
/* make sure the view has focus */
gtk_widget_grab_focus (GTK_WIDGET (gedit_tab_get_view (tab)));
diff --git a/gedit/gedit-tab-private.h b/gedit/gedit-tab-private.h
index ccdf2249b..bbd7f9ae9 100644
--- a/gedit/gedit-tab-private.h
+++ b/gedit/gedit-tab-private.h
@@ -34,13 +34,6 @@ gchar *_gedit_tab_get_tooltip (GeditTab *tab);
GdkPixbuf *_gedit_tab_get_icon (GeditTab *tab);
-void _gedit_tab_load (GeditTab *tab,
- GFile *location,
- const GtkSourceEncoding *encoding,
- gint line_pos,
- gint column_pos,
- gboolean create);
-
void _gedit_tab_revert (GeditTab *tab);
void _gedit_tab_save_async (GeditTab *tab,
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 366b50361..592114598 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -2071,14 +2071,40 @@ load_finish (GeditTab *tab,
return g_task_propagate_boolean (G_TASK (result), NULL);
}
+/**
+ * gedit_tab_load_file:
+ * @tab: a #GeditTab.
+ * @location: the #GFile to load.
+ * @encoding: (nullable): a #GtkSourceEncoding, or %NULL.
+ * @line_pos: the line position to visualize.
+ * @column_pos: the column position to visualize.
+ * @create: %TRUE to show no errors if @location doesn't exist.
+ *
+ * This function tries to load @location into @tab. It is usually called only on
+ * a newly-created tab.
+ *
+ * If @location doesn't exist, the behavior depends on @create:
+ * - If @create is %FALSE, an error is shown.
+ * - If @create is %TRUE, an empty #GeditDocument is created without error (but
+ * the file is not yet created on disk).
+ *
+ * The @tab needs to be in %GEDIT_TAB_STATE_NORMAL. The previous
+ * #GtkTextBuffer's content is lost.
+ *
+ * Since: 45
+ */
void
-_gedit_tab_load (GeditTab *tab,
- GFile *location,
- const GtkSourceEncoding *encoding,
- gint line_pos,
- gint column_pos,
- gboolean create)
+gedit_tab_load_file (GeditTab *tab,
+ GFile *location,
+ const GtkSourceEncoding *encoding,
+ gint line_pos,
+ gint column_pos,
+ gboolean create)
{
+ g_return_if_fail (GEDIT_IS_TAB (tab));
+ g_return_if_fail (G_IS_FILE (location));
+ g_return_if_fail (tab->state == GEDIT_TAB_STATE_NORMAL);
+
if (tab->cancellable != NULL)
{
g_cancellable_cancel (tab->cancellable);
diff --git a/gedit/gedit-tab.h b/gedit/gedit-tab.h
index 47837874f..d188f245a 100644
--- a/gedit/gedit-tab.h
+++ b/gedit/gedit-tab.h
@@ -48,6 +48,13 @@ typedef enum
G_DECLARE_FINAL_TYPE (GeditTab, gedit_tab, GEDIT, TAB, GtkBox)
+void gedit_tab_load_file (GeditTab *tab,
+ GFile *location,
+ const GtkSourceEncoding *encoding,
+ gint line_pos,
+ gint column_pos,
+ gboolean create);
+
void gedit_tab_load_stream (GeditTab *tab,
GInputStream *stream,
const GtkSourceEncoding *encoding,
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index 515cede47..76a632f52 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -2959,10 +2959,7 @@ gedit_window_create_tab (GeditWindow *window,
*
* This function always creates a new #GeditTab. It tries to load @location.
*
- * If @location doesn't exist, the behavior depends on @create:
- * - If @create is %FALSE, an error is shown.
- * - If @create is %TRUE, an empty #GeditDocument is created without error (but
- * the file is not yet created on disk).
+ * See gedit_tab_load_file().
*
* Returns: (transfer none): the new #GeditTab.
*/
@@ -2984,12 +2981,12 @@ gedit_window_create_tab_from_location (GeditWindow *window,
tab = gedit_window_create_tab (window, jump_to);
- _gedit_tab_load (tab,
- location,
- encoding,
- line_pos,
- column_pos,
- create);
+ gedit_tab_load_file (tab,
+ location,
+ encoding,
+ line_pos,
+ column_pos,
+ create);
return tab;
}