Commit 869adb76 authored by Sébastien Wilmet's avatar Sébastien Wilmet

Don't use GeditDocument:read-only (deprecated)

FIXME: regression: open several times the same file. The second time the
view must be forced read-only.
parent 77de7209
......@@ -330,10 +330,12 @@ add_buttons (GeditCloseConfirmationDialog *dlg)
if (GET_MODE (dlg) == SINGLE_DOC_MODE)
{
GeditDocument *doc;
GtkSourceFile *file;
doc = GEDIT_DOCUMENT (dlg->unsaved_documents->data);
file = gedit_document_get_file (doc);
if (gedit_document_get_readonly (doc) ||
if (gtk_source_file_is_readonly (file) ||
gedit_document_is_untitled (doc))
{
save_as = TRUE;
......
......@@ -1003,6 +1003,7 @@ gedit_commands_save_document_async (GeditDocument *document,
{
GTask *task;
GeditTab *tab;
GtkSourceFile *file;
gchar *uri_for_display;
gedit_debug (DEBUG_COMMANDS);
......@@ -1014,9 +1015,10 @@ gedit_commands_save_document_async (GeditDocument *document,
task = g_task_new (document, cancellable, callback, user_data);
tab = gedit_tab_get_from_document (document);
file = gedit_document_get_file (document);
if (gedit_document_is_untitled (document) ||
gedit_document_get_readonly (document))
gtk_source_file_is_readonly (file))
{
gedit_debug_message (DEBUG_COMMANDS, "Untitled or Readonly");
......@@ -1308,10 +1310,12 @@ save_documents_list (GeditWindow *window,
{
if (_gedit_document_needs_saving (doc))
{
GtkSourceFile *file = gedit_document_get_file (doc);
/* FIXME: manage the case of local readonly files owned by the
user is running gedit - Paolo (Dec. 8, 2005) */
if (gedit_document_is_untitled (doc) ||
gedit_document_get_readonly (doc))
gtk_source_file_is_readonly (file))
{
if (data == NULL)
{
......@@ -1748,13 +1752,15 @@ save_and_close_documents (GList *docs,
state != GEDIT_TAB_STATE_LOADING_ERROR &&
state != GEDIT_TAB_STATE_REVERTING) /* FIXME: is this the right behavior with REVERTING ?*/
{
GtkSourceFile *file = gedit_document_get_file (doc);
/* The document must be saved before closing */
g_return_if_fail (_gedit_document_needs_saving (doc));
/* FIXME: manage the case of local readonly files owned by the
* user is running gedit - Paolo (Dec. 8, 2005) */
if (gedit_document_is_untitled (doc) ||
gedit_document_get_readonly (doc))
gtk_source_file_is_readonly (file))
{
if (data == NULL)
{
......
......@@ -495,6 +495,7 @@ document_row_sync_tab_name_and_icon (GeditTab *tab,
{
GeditDocumentsDocumentRow *document_row = GEDIT_DOCUMENTS_DOCUMENT_ROW (row);
GeditDocument *doc;
GtkSourceFile *file;
gchar *name;
GdkPixbuf *pixbuf;
......@@ -517,8 +518,10 @@ document_row_sync_tab_name_and_icon (GeditTab *tab,
g_free (name);
file = gedit_document_get_file (doc);
/* The status has as separate label to prevent ellipsizing */
if (!gedit_document_get_readonly (doc))
if (!gtk_source_file_is_readonly (file))
{
gtk_widget_hide (GTK_WIDGET (document_row->status_label));
}
......
......@@ -190,15 +190,17 @@ static void
update_auto_save_timeout (GeditTab *tab)
{
GeditDocument *doc;
GtkSourceFile *file;
gedit_debug (DEBUG_TAB);
doc = gedit_tab_get_document (tab);
file = gedit_document_get_file (doc);
if (tab->state == GEDIT_TAB_STATE_NORMAL &&
tab->auto_save &&
!gedit_document_is_untitled (doc) &&
!gedit_document_get_readonly (doc))
!gtk_source_file_is_readonly (file))
{
install_auto_save_timeout (tab);
}
......@@ -1520,17 +1522,6 @@ _gedit_tab_get_name (GeditTab *tab)
}
else
{
#if 0
if (gedit_document_get_readonly (doc))
{
tab_name = g_strdup_printf ("%s [%s]", docname,
/*Read only*/ _("RO"));
}
else
{
tab_name = g_strdup_printf ("%s", docname);
}
#endif
tab_name = g_strdup (docname);
}
......@@ -1765,6 +1756,7 @@ load_cb (GtkSourceFileLoader *loader,
GeditTab *tab)
{
GeditDocument *doc = gedit_tab_get_document (tab);
GtkSourceFile *file = gedit_document_get_file (doc);
GFile *location = gtk_source_file_loader_get_location (loader);
gboolean create_named_new_doc;
GError *error = NULL;
......@@ -1933,7 +1925,7 @@ load_cb (GtkSourceFileLoader *loader,
/* If the document is readonly we don't care how many times the document
* is opened.
*/
if (!gedit_document_get_readonly (doc))
if (!gtk_source_file_is_readonly (file))
{
GList *all_documents;
GList *l;
......@@ -2517,8 +2509,10 @@ gedit_tab_auto_save (GeditTab *tab)
gedit_debug (DEBUG_TAB);
doc = gedit_tab_get_document (tab);
file = gedit_document_get_file (doc);
g_return_val_if_fail (!gedit_document_is_untitled (doc), G_SOURCE_REMOVE);
g_return_val_if_fail (!gedit_document_get_readonly (doc), G_SOURCE_REMOVE);
g_return_val_if_fail (!gtk_source_file_is_readonly (file), G_SOURCE_REMOVE);
if (!gtk_text_buffer_get_modified (GTK_TEXT_BUFFER (doc)))
{
......@@ -2558,8 +2552,6 @@ gedit_tab_auto_save (GeditTab *tab)
data,
(GDestroyNotify) saver_data_free);
file = gedit_document_get_file (doc);
data->saver = gtk_source_file_saver_new (GTK_SOURCE_BUFFER (doc), file);
save_flags = get_initial_save_flags (tab, TRUE);
......
......@@ -70,14 +70,14 @@ enum
static guint view_signals [LAST_SIGNAL] = { 0 };
static void
document_read_only_notify_handler (GeditDocument *document,
GParamSpec *pspec,
GeditView *view)
file_read_only_notify_handler (GtkSourceFile *file,
GParamSpec *pspec,
GeditView *view)
{
gedit_debug (DEBUG_VIEW);
gtk_text_view_set_editable (GTK_TEXT_VIEW (view),
!gedit_document_get_readonly (document));
!gtk_source_file_is_readonly (file));
}
static void
......@@ -85,8 +85,12 @@ current_buffer_removed (GeditView *view)
{
if (view->priv->current_buffer != NULL)
{
g_signal_handlers_disconnect_by_func (view->priv->current_buffer,
document_read_only_notify_handler,
GtkSourceFile *file;
file = gedit_document_get_file (GEDIT_DOCUMENT (view->priv->current_buffer));
g_signal_handlers_disconnect_by_func (file,
file_read_only_notify_handler,
view);
g_object_unref (view->priv->current_buffer);
......@@ -100,6 +104,7 @@ on_notify_buffer_cb (GeditView *view,
gpointer userdata)
{
GtkTextBuffer *buffer;
GtkSourceFile *file;
current_buffer_removed (view);
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
......@@ -107,14 +112,17 @@ on_notify_buffer_cb (GeditView *view,
if (buffer == NULL || !GEDIT_IS_DOCUMENT (buffer))
return;
file = gedit_document_get_file (GEDIT_DOCUMENT (buffer));
view->priv->current_buffer = g_object_ref (buffer);
g_signal_connect (buffer,
"notify::read-only",
G_CALLBACK (document_read_only_notify_handler),
view);
g_signal_connect_object (file,
"notify::read-only",
G_CALLBACK (file_read_only_notify_handler),
view,
0);
gtk_text_view_set_editable (GTK_TEXT_VIEW (view),
!gedit_document_get_readonly (GEDIT_DOCUMENT (buffer)));
!gtk_source_file_is_readonly (file));
}
static void
......@@ -854,11 +862,9 @@ gedit_view_cut_clipboard (GeditView *view)
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
GDK_SELECTION_CLIPBOARD);
/* FIXME: what is default editability of a buffer? */
gtk_text_buffer_cut_clipboard (buffer,
clipboard,
!gedit_document_get_readonly (
GEDIT_DOCUMENT (buffer)));
gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
gtk_text_buffer_get_insert (buffer),
......@@ -905,12 +911,10 @@ gedit_view_paste_clipboard (GeditView *view)
clipboard = gtk_widget_get_clipboard (GTK_WIDGET (view),
GDK_SELECTION_CLIPBOARD);
/* FIXME: what is default editability of a buffer? */
gtk_text_buffer_paste_clipboard (buffer,
clipboard,
NULL,
!gedit_document_get_readonly (
GEDIT_DOCUMENT (buffer)));
gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
gtk_text_buffer_get_insert (buffer),
......@@ -939,11 +943,9 @@ gedit_view_delete_selection (GeditView *view)
buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
g_return_if_fail (buffer != NULL);
/* FIXME: what is default editability of a buffer? */
gtk_text_buffer_delete_selection (buffer,
TRUE,
!gedit_document_get_readonly (
GEDIT_DOCUMENT (buffer)));
gtk_text_view_get_editable (GTK_TEXT_VIEW (view)));
gtk_text_view_scroll_to_mark (GTK_TEXT_VIEW (view),
gtk_text_buffer_get_insert (buffer),
......
......@@ -577,6 +577,7 @@ update_actions_sensitivity (GeditWindow *window)
gint num_tabs;
GeditTabState state = GEDIT_TAB_STATE_NORMAL;
GeditDocument *doc = NULL;
GtkSourceFile *file = NULL;
GeditView *view = NULL;
gint tab_number = -1;
GAction *action;
......@@ -598,6 +599,7 @@ update_actions_sensitivity (GeditWindow *window)
state = gedit_tab_get_state (tab);
view = gedit_tab_get_view (tab);
doc = GEDIT_DOCUMENT (gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)));
file = gedit_document_get_file (doc);
tab_number = gtk_notebook_page_num (GTK_NOTEBOOK (notebook), GTK_WIDGET (tab));
editable = gtk_text_view_get_editable (GTK_TEXT_VIEW (view));
empty_search = _gedit_document_get_empty_search (doc);
......@@ -611,7 +613,7 @@ update_actions_sensitivity (GeditWindow *window)
g_simple_action_set_enabled (G_SIMPLE_ACTION (action),
((state == GEDIT_TAB_STATE_NORMAL) ||
(state == GEDIT_TAB_STATE_EXTERNALLY_MODIFIED_NOTIFICATION)) &&
(doc != NULL) && !gedit_document_get_readonly (doc) &&
(file != NULL) && !gtk_source_file_is_readonly (file) &&
!(lockdown & GEDIT_LOCKDOWN_SAVE_TO_DISK));
action = g_action_map_lookup_action (G_ACTION_MAP (window), "save-as");
......@@ -1064,6 +1066,7 @@ set_title (GeditWindow *window)
{
GeditTab *tab;
GeditDocument *doc = NULL;
GtkSourceFile *file;
gchar *name;
gchar *dirname = NULL;
gchar *main_title = NULL;
......@@ -1092,6 +1095,8 @@ set_title (GeditWindow *window)
doc = gedit_tab_get_document (tab);
g_return_if_fail (doc != NULL);
file = gedit_document_get_file (doc);
name = gedit_document_get_short_name_for_display (doc);
len = g_utf8_strlen (name, -1);
......@@ -1110,7 +1115,6 @@ set_title (GeditWindow *window)
}
else
{
GtkSourceFile *file = gedit_document_get_file (doc);
GFile *location = gtk_source_file_get_location (file);
if (location != NULL)
......@@ -1139,7 +1143,7 @@ set_title (GeditWindow *window)
name = tmp_name;
}
if (gedit_document_get_readonly (doc))
if (gtk_source_file_is_readonly (file))
{
title = g_strdup_printf ("%s [%s]",
name, _("Read-Only"));
......@@ -1901,7 +1905,7 @@ selection_changed (GeditDocument *doc,
}
static void
readonly_changed (GeditDocument *doc,
readonly_changed (GtkSourceFile *file,
GParamSpec *pspec,
GeditWindow *window)
{
......@@ -1932,6 +1936,7 @@ on_tab_added (GeditMultiNotebook *multi,
{
GeditView *view;
GeditDocument *doc;
GtkSourceFile *file;
gedit_debug (DEBUG_WINDOW);
......@@ -1939,6 +1944,7 @@ on_tab_added (GeditMultiNotebook *multi,
view = gedit_tab_get_view (tab);
doc = gedit_tab_get_document (tab);
file = gedit_document_get_file (doc);
/* IMPORTANT: remember to disconnect the signal in notebook_tab_removed
* if a new signal is connected here */
......@@ -1983,10 +1989,6 @@ on_tab_added (GeditMultiNotebook *multi,
"notify::has-selection",
G_CALLBACK (selection_changed),
window);
g_signal_connect (doc,
"notify::read-only",
G_CALLBACK (readonly_changed),
window);
g_signal_connect (view,
"notify::overwrite",
G_CALLBACK (overwrite_mode_changed),
......@@ -1995,6 +1997,10 @@ on_tab_added (GeditMultiNotebook *multi,
"notify::editable",
G_CALLBACK (editable_changed),
window);
g_signal_connect (file,
"notify::read-only",
G_CALLBACK (readonly_changed),
window);
update_window_state (window);
update_can_close (window);
......
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