Commit c7740f9c authored by Elliot's avatar Elliot
Browse files

Revert "Automatically open save-as dialog upon saving read-only files"

This reverts commit f0739dc8
parent f0739dc8
Pipeline #8821 passed with stages
in 2 minutes and 7 seconds
......@@ -42,6 +42,9 @@ static void mousepad_file_monitor_changed (GFileMonitor *monitor,
GFile *other_location,
GFileMonitorEvent event_type,
MousepadFile *file);
static void mousepad_file_set_read_only (MousepadFile *file,
gboolean readonly);
struct _MousepadFileClass
......@@ -178,21 +181,7 @@ mousepad_file_new (GtkTextBuffer *buffer)
return file;
}
void
mousepad_file_set_read_only (MousepadFile *file,
gboolean readonly)
{
g_return_if_fail (MOUSEPAD_IS_FILE (file));
if (G_LIKELY (file->readonly != readonly))
{
/* store new value */
file->readonly = readonly;
/* emit signal */
g_signal_emit (file, file_signals[READONLY_CHANGED], 0, readonly);
}
}
static void
mousepad_file_monitor_changed (GFileMonitor *monitor,
......@@ -342,6 +331,26 @@ mousepad_file_get_uri (MousepadFile *file)
return g_file_get_uri (file->location);
}
static void
mousepad_file_set_read_only (MousepadFile *file,
gboolean readonly)
{
g_return_if_fail (MOUSEPAD_IS_FILE (file));
if (G_LIKELY (file->readonly != readonly))
{
/* store new value */
file->readonly = readonly;
/* emit signal */
g_signal_emit (file, file_signals[READONLY_CHANGED], 0, readonly);
}
}
gboolean
mousepad_file_get_read_only (MousepadFile *file)
{
......@@ -358,7 +367,7 @@ mousepad_file_is_savable (MousepadFile *file)
g_return_val_if_fail (MOUSEPAD_IS_FILE (file), FALSE);
return file->location == NULL
|| gtk_text_buffer_get_modified (file->buffer);
|| (! file->readonly && gtk_text_buffer_get_modified (file->buffer));
}
......
......@@ -70,8 +70,6 @@ gchar *mousepad_file_get_uri (MousepadFile
gboolean mousepad_file_get_read_only (MousepadFile *file);
void mousepad_file_set_read_only (MousepadFile *file, gboolean readonly);
gboolean mousepad_file_is_savable (MousepadFile *file);
void mousepad_file_set_encoding (MousepadFile *file,
......
......@@ -2968,7 +2968,7 @@ mousepad_window_readonly_changed (MousepadFile *file,
gboolean readonly,
MousepadWindow *window)
{
//GAction *action;
GAction *action;
g_return_if_fail (MOUSEPAD_IS_WINDOW (window));
......@@ -2978,8 +2978,8 @@ mousepad_window_readonly_changed (MousepadFile *file,
mousepad_window_set_title (window);
/* set the save action sensitivity */
//action = g_action_map_lookup_action (G_ACTION_MAP (window), "file.save");
//g_simple_action_set_enabled (G_SIMPLE_ACTION (action), mousepad_file_is_savable (file));
action = g_action_map_lookup_action (G_ACTION_MAP (window), "file.save");
g_simple_action_set_enabled (G_SIMPLE_ACTION (action), mousepad_file_is_savable (file));
}
}
......@@ -4657,9 +4657,9 @@ mousepad_window_action_save (GSimpleAction *action,
g_return_if_fail (MOUSEPAD_IS_WINDOW (window));
g_return_if_fail (MOUSEPAD_IS_DOCUMENT (document));
if (! mousepad_file_location_is_set (document->file) || mousepad_file_get_read_only (document->file) )
if (! mousepad_file_location_is_set (document->file))
{
/* file has no filename yet or is read-only, open the save as dialog */
/* file has no filename yet, open the save as dialog */
g_action_group_activate_action (G_ACTION_GROUP (window), "file.save-as", NULL);
v_succeed = g_action_group_get_action_state (G_ACTION_GROUP (window), "file.save-as");
succeed = g_variant_get_int32 (v_succeed);
......@@ -4723,8 +4723,7 @@ mousepad_window_action_save_as (GSimpleAction *action,
MousepadEncoding encoding, current_encoding = MOUSEPAD_ENCODING_NONE;
GAction *action_save;
GVariant *v_succeed;
GFile *file, *current_file = NULL, *directory;
GFileInfo *directory_info;
GFile *file, *current_file = NULL;
gboolean succeed = FALSE;
g_return_if_fail (MOUSEPAD_IS_WINDOW (window));
......@@ -4742,18 +4741,10 @@ mousepad_window_action_save_as (GSimpleAction *action,
current_encoding = mousepad_file_get_encoding (document->file);
}
directory = g_file_get_parent (file);
directory_info = g_file_query_info (directory, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE,
G_FILE_QUERY_INFO_NONE, NULL, NULL);
/* virtually set the new file location */
mousepad_file_set_location (document->file, file, FALSE);
mousepad_file_set_encoding (document->file, encoding);
/* update read-only status */
mousepad_file_set_read_only (document->file,
! g_file_info_get_attribute_boolean (directory_info, G_FILE_ATTRIBUTE_ACCESS_CAN_WRITE));
/* save the file by an internal call (the save action may be disabled, depending
* on the file status) */
action_save = g_action_map_lookup_action (G_ACTION_MAP (window), "file.save");
......@@ -4784,9 +4775,6 @@ mousepad_window_action_save_as (GSimpleAction *action,
/* cleanup */
g_object_unref (file);
g_object_unref (directory);
g_object_unref (directory_info);
if (current_file != NULL)
g_object_unref (current_file);
}
......
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