Commit 0863222b authored by Jesse van den Kieboom's avatar Jesse van den Kieboom

Implemented full support for compressed files

This adds a CompressionType similar to NewlineType.
parent 80d1da59
...@@ -571,17 +571,106 @@ replace_read_only_file (GtkWindow *parent, GFile *file) ...@@ -571,17 +571,106 @@ replace_read_only_file (GtkWindow *parent, GFile *file)
return (ret == GTK_RESPONSE_YES); return (ret == GTK_RESPONSE_YES);
} }
static gboolean
change_compression (GtkWindow *parent,
GFile *file,
gboolean compressed)
{
GtkWidget *dialog;
gint ret;
gchar *parse_name;
gchar *name_for_display;
const gchar *primary_message;
const gchar *secondary_message;
const gchar *button_label;
gedit_debug (DEBUG_COMMANDS);
parse_name = g_file_get_parse_name (file);
/* Truncate the name so it doesn't get insanely wide. Note that even
* though the dialog uses wrapped text, if the name doesn't contain
* white space then the text-wrapping code is too stupid to wrap it.
*/
name_for_display = gedit_utils_str_middle_truncate (parse_name, 50);
g_free (parse_name);
if (compressed)
{
primary_message = _("Save the file using compression?");
secondary_message = _("The file \"%s\" was previously saved as plain "
"text and will now be saved using compression.");
button_label = _("Save using compression");
}
else
{
primary_message = _("Save the file as plain text?");
secondary_message = _("The file \"%s\" was previously saved "
"using compression and will now be saved as plain text.");
button_label = _("Save as plain text");
}
dialog = gtk_message_dialog_new (parent,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_NONE,
"%s",
primary_message);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
secondary_message,
name_for_display);
g_free (name_for_display);
gtk_dialog_add_button (GTK_DIALOG (dialog),
GTK_STOCK_CANCEL,
GTK_RESPONSE_CANCEL);
gedit_dialog_add_button (GTK_DIALOG (dialog),
button_label,
GTK_STOCK_SAVE_AS,
GTK_RESPONSE_YES);
gtk_dialog_set_default_response (GTK_DIALOG (dialog),
GTK_RESPONSE_CANCEL);
gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
ret = gtk_dialog_run (GTK_DIALOG (dialog));
gtk_widget_destroy (dialog);
return (ret == GTK_RESPONSE_YES);
}
static GeditDocumentCompressionType
get_compression_type_from_file (GFile *file)
{
gchar *name;
gchar *content_type;
GeditDocumentCompressionType type;
name = g_file_get_basename (file);
content_type = g_content_type_guess (name, NULL, 0, NULL);
type = gedit_utils_get_compression_type_from_content_type (content_type);
g_free (name);
g_free (content_type);
return type;
}
static void static void
save_dialog_response_cb (GeditFileChooserDialog *dialog, save_dialog_response_cb (GeditFileChooserDialog *dialog,
gint response_id, gint response_id,
GeditWindow *window) GeditWindow *window)
{ {
GFile *file; GFile *file;
const GeditEncoding *encoding;
GeditTab *tab; GeditTab *tab;
gpointer data; gpointer data;
GSList *tabs_to_save_as; GSList *tabs_to_save_as;
GeditDocumentNewlineType newline_type;
gedit_debug (DEBUG_COMMANDS); gedit_debug (DEBUG_COMMANDS);
...@@ -598,15 +687,36 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog, ...@@ -598,15 +687,36 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog)); file = gtk_file_chooser_get_file (GTK_FILE_CHOOSER (dialog));
g_return_if_fail (file != NULL); g_return_if_fail (file != NULL);
encoding = gedit_file_chooser_dialog_get_encoding (dialog);
newline_type = gedit_file_chooser_dialog_get_newline_type (dialog);
gtk_widget_destroy (GTK_WIDGET (dialog));
if (tab != NULL) if (tab != NULL)
{ {
GeditDocument *doc; GeditDocument *doc;
gchar *parse_name; gchar *parse_name;
GeditDocumentNewlineType newline_type;
GeditDocumentCompressionType compression_type;
GeditDocumentCompressionType current_compression_type;
const GeditEncoding *encoding;
doc = gedit_tab_get_document (tab);
compression_type = get_compression_type_from_file (file);
current_compression_type = gedit_document_get_compression_type (doc);
if ((compression_type == GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE) !=
(current_compression_type == GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE))
{
if (!change_compression (GTK_WINDOW (dialog),
file,
compression_type != GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE))
{
gtk_widget_destroy (GTK_WIDGET (dialog));
goto save_next_tab;
}
}
encoding = gedit_file_chooser_dialog_get_encoding (dialog);
newline_type = gedit_file_chooser_dialog_get_newline_type (dialog);
gtk_widget_destroy (GTK_WIDGET (dialog));
doc = gedit_tab_get_document (tab); doc = gedit_tab_get_document (tab);
g_return_if_fail (GEDIT_IS_DOCUMENT (doc)); g_return_if_fail (GEDIT_IS_DOCUMENT (doc));
...@@ -624,7 +734,7 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog, ...@@ -624,7 +734,7 @@ save_dialog_response_cb (GeditFileChooserDialog *dialog,
* even if the saving fails... */ * even if the saving fails... */
_gedit_window_set_default_location (window, file); _gedit_window_set_default_location (window, file);
_gedit_tab_save_as (tab, file, encoding, newline_type); _gedit_tab_save_as (tab, file, encoding, newline_type, compression_type);
} }
g_object_unref (file); g_object_unref (file);
......
...@@ -79,7 +79,8 @@ enum ...@@ -79,7 +79,8 @@ enum
PROP_LOCATION, PROP_LOCATION,
PROP_ENCODING, PROP_ENCODING,
PROP_NEWLINE_TYPE, PROP_NEWLINE_TYPE,
PROP_STREAM PROP_STREAM,
PROP_COMPRESSION_TYPE
}; };
#define READ_CHUNK_SIZE 8192 #define READ_CHUNK_SIZE 8192
...@@ -110,6 +111,7 @@ struct _GeditDocumentLoaderPrivate ...@@ -110,6 +111,7 @@ struct _GeditDocumentLoaderPrivate
const GeditEncoding *encoding; const GeditEncoding *encoding;
const GeditEncoding *auto_detected_encoding; const GeditEncoding *auto_detected_encoding;
GeditDocumentNewlineType auto_detected_newline_type; GeditDocumentNewlineType auto_detected_newline_type;
GeditDocumentCompressionType auto_detected_compression_type;
goffset bytes_read; goffset bytes_read;
...@@ -154,6 +156,9 @@ gedit_document_loader_set_property (GObject *object, ...@@ -154,6 +156,9 @@ gedit_document_loader_set_property (GObject *object,
case PROP_STREAM: case PROP_STREAM:
loader->priv->stream = g_value_dup_object (value); loader->priv->stream = g_value_dup_object (value);
break; break;
case PROP_COMPRESSION_TYPE:
loader->priv->auto_detected_compression_type = g_value_get_enum (value);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -185,6 +190,9 @@ gedit_document_loader_get_property (GObject *object, ...@@ -185,6 +190,9 @@ gedit_document_loader_get_property (GObject *object,
case PROP_STREAM: case PROP_STREAM:
g_value_set_object (value, loader->priv->stream); g_value_set_object (value, loader->priv->stream);
break; break;
case PROP_COMPRESSION_TYPE:
g_value_set_enum (value, loader->priv->auto_detected_compression_type);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -295,6 +303,18 @@ gedit_document_loader_class_init (GeditDocumentLoaderClass *klass) ...@@ -295,6 +303,18 @@ gedit_document_loader_class_init (GeditDocumentLoaderClass *klass)
GEDIT_TYPE_DOCUMENT_NEWLINE_TYPE, GEDIT_TYPE_DOCUMENT_NEWLINE_TYPE,
GEDIT_DOCUMENT_NEWLINE_TYPE_LF, GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
g_object_class_install_property (object_class, PROP_COMPRESSION_TYPE,
g_param_spec_enum ("compression-type",
"Compression type",
"The compression type",
GEDIT_TYPE_DOCUMENT_COMPRESSION_TYPE,
GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE,
G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NAME | G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB)); G_PARAM_STATIC_BLURB));
...@@ -327,10 +347,6 @@ gedit_document_loader_init (GeditDocumentLoader *loader) ...@@ -327,10 +347,6 @@ gedit_document_loader_init (GeditDocumentLoader *loader)
{ {
loader->priv = GEDIT_DOCUMENT_LOADER_GET_PRIVATE (loader); loader->priv = GEDIT_DOCUMENT_LOADER_GET_PRIVATE (loader);
loader->priv->used = FALSE;
loader->priv->auto_detected_newline_type = GEDIT_DOCUMENT_NEWLINE_TYPE_DEFAULT;
loader->priv->converter = NULL;
loader->priv->error = NULL;
loader->priv->enc_settings = g_settings_new ("org.gnome.gedit.preferences.encodings"); loader->priv->enc_settings = g_settings_new ("org.gnome.gedit.preferences.encodings");
} }
...@@ -593,6 +609,8 @@ async_read_cb (GInputStream *stream, ...@@ -593,6 +609,8 @@ async_read_cb (GInputStream *stream,
g_file_info_set_attribute_string (loader->priv->info, g_file_info_set_attribute_string (loader->priv->info,
G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE,
guessed); guessed);
g_free (guessed);
} }
} }
...@@ -669,12 +687,30 @@ get_candidate_encodings (GeditDocumentLoader *loader) ...@@ -669,12 +687,30 @@ get_candidate_encodings (GeditDocumentLoader *loader)
return encodings; return encodings;
} }
static GInputStream *
compression_gzip_stream (GeditDocumentLoader *loader)
{
GZlibDecompressor *decompressor;
GInputStream *base_stream;
decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP);
base_stream = g_converter_input_stream_new (loader->priv->stream,
G_CONVERTER (decompressor));
g_object_unref (decompressor);
loader->priv->auto_detected_compression_type = GEDIT_DOCUMENT_COMPRESSION_TYPE_GZIP;
return base_stream;
}
static void static void
start_stream_read (AsyncData *async) start_stream_read (AsyncData *async)
{ {
GSList *candidate_encodings; GSList *candidate_encodings;
GeditDocumentLoader *loader; GeditDocumentLoader *loader;
GInputStream *base_stream; GInputStream *base_stream = NULL;
GFileInfo *info; GFileInfo *info;
loader = async->loader; loader = async->loader;
...@@ -693,21 +729,25 @@ start_stream_read (AsyncData *async) ...@@ -693,21 +729,25 @@ start_stream_read (AsyncData *async)
loader->priv->converter = gedit_smart_charset_converter_new (candidate_encodings); loader->priv->converter = gedit_smart_charset_converter_new (candidate_encodings);
g_slist_free (candidate_encodings); g_slist_free (candidate_encodings);
if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE) && if (g_file_info_has_attribute (info, G_FILE_ATTRIBUTE_STANDARD_CONTENT_TYPE))
g_strcmp0 (g_file_info_get_content_type (info), "application/x-gzip") == 0)
{ {
GZlibDecompressor *decompressor; const gchar *content_type = g_file_info_get_content_type (info);
decompressor = g_zlib_decompressor_new (G_ZLIB_COMPRESSOR_FORMAT_GZIP); switch (gedit_utils_get_compression_type_from_content_type (content_type))
{
base_stream = g_converter_input_stream_new (loader->priv->stream, case GEDIT_DOCUMENT_COMPRESSION_TYPE_GZIP:
G_CONVERTER (decompressor)); base_stream = compression_gzip_stream (loader);
break;
g_object_unref (decompressor); case GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE:
/* NOOP */
break;
}
} }
else
if (base_stream == NULL)
{ {
base_stream = g_object_ref (loader->priv->stream); base_stream = g_object_ref (loader->priv->stream);
loader->priv->auto_detected_compression_type = GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE;
} }
g_object_unref (loader->priv->stream); g_object_unref (loader->priv->stream);
...@@ -755,6 +795,7 @@ query_info_cb (GFile *source, ...@@ -755,6 +795,7 @@ query_info_cb (GFile *source,
{ {
GFileInfo *info; GFileInfo *info;
GError *error = NULL; GError *error = NULL;
GeditDocumentLoaderPrivate *priv;
gedit_debug (DEBUG_LOADER); gedit_debug (DEBUG_LOADER);
...@@ -765,8 +806,10 @@ query_info_cb (GFile *source, ...@@ -765,8 +806,10 @@ query_info_cb (GFile *source,
return; return;
} }
priv = async->loader->priv;
/* finish the info query */ /* finish the info query */
info = g_file_query_info_finish (async->loader->priv->location, info = g_file_query_info_finish (priv->location,
res, res,
&error); &error);
...@@ -777,8 +820,8 @@ query_info_cb (GFile *source, ...@@ -777,8 +820,8 @@ query_info_cb (GFile *source,
return; return;
} }
async->loader->priv->info = info; priv->info = info;
finish_query_info (async); finish_query_info (async);
} }
...@@ -1039,6 +1082,15 @@ gedit_document_loader_get_newline_type (GeditDocumentLoader *loader) ...@@ -1039,6 +1082,15 @@ gedit_document_loader_get_newline_type (GeditDocumentLoader *loader)
return loader->priv->auto_detected_newline_type; return loader->priv->auto_detected_newline_type;
} }
GeditDocumentCompressionType
gedit_document_loader_get_compression_type (GeditDocumentLoader *loader)
{
g_return_val_if_fail (GEDIT_IS_DOCUMENT_LOADER (loader),
GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE);
return loader->priv->auto_detected_compression_type;
}
GFileInfo * GFileInfo *
gedit_document_loader_get_info (GeditDocumentLoader *loader) gedit_document_loader_get_info (GeditDocumentLoader *loader)
{ {
...@@ -1046,4 +1098,5 @@ gedit_document_loader_get_info (GeditDocumentLoader *loader) ...@@ -1046,4 +1098,5 @@ gedit_document_loader_get_info (GeditDocumentLoader *loader)
return loader->priv->info; return loader->priv->info;
} }
/* ex:ts=8:noet: */ /* ex:ts=8:noet: */
...@@ -110,6 +110,8 @@ const GeditEncoding *gedit_document_loader_get_encoding (GeditDocumentLoader *lo ...@@ -110,6 +110,8 @@ const GeditEncoding *gedit_document_loader_get_encoding (GeditDocumentLoader *lo
GeditDocumentNewlineType gedit_document_loader_get_newline_type (GeditDocumentLoader *loader); GeditDocumentNewlineType gedit_document_loader_get_newline_type (GeditDocumentLoader *loader);
GeditDocumentCompressionType gedit_document_loader_get_compression_type (GeditDocumentLoader *loader);
goffset gedit_document_loader_get_bytes_read (GeditDocumentLoader *loader); goffset gedit_document_loader_get_bytes_read (GeditDocumentLoader *loader);
/* You can get from the info: content_type, time_modified, standard_size, access_can_write /* You can get from the info: content_type, time_modified, standard_size, access_can_write
......
...@@ -64,6 +64,7 @@ enum { ...@@ -64,6 +64,7 @@ enum {
PROP_LOCATION, PROP_LOCATION,
PROP_ENCODING, PROP_ENCODING,
PROP_NEWLINE_TYPE, PROP_NEWLINE_TYPE,
PROP_COMPRESSION_TYPE,
PROP_FLAGS PROP_FLAGS
}; };
...@@ -98,6 +99,7 @@ struct _GeditDocumentSaverPrivate ...@@ -98,6 +99,7 @@ struct _GeditDocumentSaverPrivate
GFile *location; GFile *location;
const GeditEncoding *encoding; const GeditEncoding *encoding;
GeditDocumentNewlineType newline_type; GeditDocumentNewlineType newline_type;
GeditDocumentCompressionType compression_type;
GeditDocumentSaveFlags flags; GeditDocumentSaveFlags flags;
...@@ -142,6 +144,9 @@ gedit_document_saver_set_property (GObject *object, ...@@ -142,6 +144,9 @@ gedit_document_saver_set_property (GObject *object,
case PROP_NEWLINE_TYPE: case PROP_NEWLINE_TYPE:
saver->priv->newline_type = g_value_get_enum (value); saver->priv->newline_type = g_value_get_enum (value);
break; break;
case PROP_COMPRESSION_TYPE:
saver->priv->compression_type = g_value_get_enum (value);
break;
case PROP_FLAGS: case PROP_FLAGS:
saver->priv->flags = g_value_get_flags (value); saver->priv->flags = g_value_get_flags (value);
break; break;
...@@ -173,6 +178,9 @@ gedit_document_saver_get_property (GObject *object, ...@@ -173,6 +178,9 @@ gedit_document_saver_get_property (GObject *object,
case PROP_NEWLINE_TYPE: case PROP_NEWLINE_TYPE:
g_value_set_enum (value, saver->priv->newline_type); g_value_set_enum (value, saver->priv->newline_type);
break; break;
case PROP_COMPRESSION_TYPE:
g_value_set_enum (value, saver->priv->compression_type);
break;
case PROP_FLAGS: case PROP_FLAGS:
g_value_set_flags (value, saver->priv->flags); g_value_set_flags (value, saver->priv->flags);
break; break;
...@@ -315,6 +323,18 @@ gedit_document_saver_class_init (GeditDocumentSaverClass *klass) ...@@ -315,6 +323,18 @@ gedit_document_saver_class_init (GeditDocumentSaverClass *klass)
G_PARAM_STATIC_BLURB | G_PARAM_STATIC_BLURB |
G_PARAM_CONSTRUCT_ONLY)); G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class,
PROP_COMPRESSION_TYPE,
g_param_spec_enum ("compression-type",
"Compression type",
"The compression type",
GEDIT_TYPE_DOCUMENT_COMPRESSION_TYPE,
GEDIT_DOCUMENT_COMPRESSION_TYPE_NONE,
G_PARAM_READWRITE |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB |
G_PARAM_CONSTRUCT_ONLY));
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_FLAGS, PROP_FLAGS,
g_param_spec_flags ("flags", g_param_spec_flags ("flags",
...@@ -352,11 +372,12 @@ gedit_document_saver_init (GeditDocumentSaver *saver) ...@@ -352,11 +372,12 @@ gedit_document_saver_init (GeditDocumentSaver *saver)
} }
GeditDocumentSaver * GeditDocumentSaver *
gedit_document_saver_new (GeditDocument *doc, gedit_document_saver_new (GeditDocument *doc,
GFile *location, GFile *location,
const GeditEncoding *encoding, const GeditEncoding *encoding,
GeditDocumentNewlineType newline_type, GeditDocumentNewlineType newline_type,
GeditDocumentSaveFlags flags) GeditDocumentCompressionType compression_type,
GeditDocumentSaveFlags flags)
{ {
g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL); g_return_val_if_fail (GEDIT_IS_DOCUMENT (doc), NULL);
...@@ -368,6 +389,7 @@ gedit_document_saver_new (GeditDocument *doc, ...@@ -368,6 +389,7 @@ gedit_document_saver_new (GeditDocument *doc,
"location", location, "location", location,
"encoding", encoding, "encoding", encoding,
"newline_type", newline_type, "newline_type", newline_type,
"compression_type", compression_type,
"flags", flags, "flags", flags,
NULL)); NULL));
} }
...@@ -720,7 +742,7 @@ async_replace_ready_callback (GFile *source, ...@@ -720,7 +742,7 @@ async_replace_ready_callback (GFile *source,
content_type = gedit_document_get_content_type (saver->priv->document); content_type = gedit_document_get_content_type (saver->priv->document);
if (g_strcmp0 (content_type, "application/x-gzip") == 0) if (saver->priv->compression_type == GEDIT_DOCUMENT_COMPRESSION_TYPE_GZIP)
{ {
GZlibCompressor *compressor; GZlibCompressor *compressor;
......
...@@ -82,11 +82,12 @@ struct _GeditDocumentSaverClass ...@@ -82,11 +82,12 @@ struct _GeditDocumentSaverClass
GType gedit_document_saver_get_type (void) G_GNUC_CONST; GType gedit_document_saver_get_type (void) G_GNUC_CONST;
/* If enconding == NULL, the encoding will be autodetected */ /* If enconding == NULL, the encoding will be autodetected */
GeditDocumentSaver *gedit_document_saver_new (GeditDocument *doc, GeditDocumentSaver *gedit_document_saver_new (GeditDocument *doc,
GFile *location, GFile *location,
const GeditEncoding *encoding, const GeditEncoding *encoding,
GeditDocumentNewlineType newline_type, GeditDocumentNewlineType newline_type,
GeditDocumentSaveFlags flags); GeditDocumentCompressionType compression_type,
GeditDocumentSaveFlags flags);
void gedit_document_saver_saving (GeditDocumentSaver *saver, void gedit_document_saver_saving (GeditDocumentSaver *saver,
gboolean completed, gboolean completed,
......
...@@ -78,28 +78,29 @@ PROFILE (static GTimer *timer = NULL) ...@@ -78,28 +78,29 @@ PROFILE (static GTimer *timer = NULL)
#define GEDIT_DOCUMENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_DOCUMENT, GeditDocumentPrivate)) #define GEDIT_DOCUMENT_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), GEDIT_TYPE_DOCUMENT, GeditDocumentPrivate))
static void gedit_document_load_real (GeditDocument *doc, static void gedit_document_load_real (GeditDocument *doc,
GFile *location, GFile *location,
const GeditEncoding *encoding, const GeditEncoding *encoding,
gint line_pos, gint line_pos,
gint column_pos, gint column_pos,
gboolean create); gboolean create);
static void gedit_document_save_real (GeditDocument *doc, static void gedit_document_save_real (GeditDocument *doc,
GFile *location, GFile *location,
const GeditEncoding *encoding, const GeditEncoding *encoding,
GeditDocumentNewlineType newline_type, GeditDocumentNewlineType newline_type,
GeditDocumentSaveFlags flags); GeditDocumentCompressionType compression_type,
static void to_search_region_range (GeditDocument *doc, GeditDocumentSaveFlags flags);
GtkTextIter *start, static void to_search_region_range (GeditDocument *doc,
GtkTextIter *end); GtkTextIter *start,
static void insert_text_cb (GeditDocument *doc, GtkTextIter *end);
GtkTextIter *pos, static void insert_text_cb (GeditDocument *doc,
const gchar *text, GtkTextIter *pos,
gint length); const gchar *text,
gint length);
static void delete_range_cb (GeditDocument *doc, static void delete_range_cb (GeditDocument *doc,
GtkTextIter *start, GtkTextIter *start,
GtkTextIter *end); GtkTextIter *end);
struct _GeditDocumentPrivate struct _GeditDocumentPrivate
{ {
...@@ -124,6 +125,7 @@ struct _GeditDocumentPrivate ...@@ -124,6 +125,7 @@ struct _GeditDocumentPrivate
gint num_of_lines_search_text; gint num_of_lines_search_text;
GeditDocumentNewlineType newline_type; GeditDocumentNewlineType newline_type;
GeditDocumentCompressionType compression_type;
/* Temp data while loading */ /* Temp data while loading */
GeditDocumentLoader *loader; GeditDocumentLoader *loader;
...@@ -162,7 +164,8 @@ enum { ...@@ -162,7 +164,8 @@ enum {
PROP_ENCODING, PROP_ENCODING,
PROP_CAN_SEARCH_AGAIN, PROP_CAN_SEARCH_AGAIN,
PROP_ENABLE_SEARCH_HIGHLIGHTING, PROP_ENABLE_SEARCH_HIGHLIGHTING,
PROP_NEWLINE_TYPE PROP_NEWLINE_TYPE,
PROP_COMPRESSION_TYPE
}; };
enum { enum {
...@@ -239,6 +242,18 @@ set_newline_type (GeditDocument *doc, ...@@ -239,6 +242,18 @@ set_newline_type (GeditDocument *doc,
} }
} }
static void
set_compression_type (GeditDocument *doc,
GeditDocumentCompressionType compression_type)
{
if (doc->priv->compression_type != compression_type)
{
doc->priv->compression_type = compression_type;
g_object_notify (G_OBJECT (doc), "compression-type");
}
}
static void static void
gedit_document_dispose (GObject *object) gedit_document_dispose (GObject *object)
{ {
...@@ -376,6 +391,9 @@ gedit_document_get_property (GObject *object, ...@@ -376,6 +391,9 @@ gedit_document_get_property (GObject *object,
case PROP_NEWLINE_TYPE: case PROP_NEWLINE_TYPE:
g_value_set_enum (value, doc->priv->newline_type); g_value_set_enum (value, doc->priv->newline_type);
break; break;
case PROP_COMPRESSION_TYPE:
g_value_set_enum (value, doc->priv->compression_type);
break;
default: default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break; break;
...@@ -400,6 +418,10 @@ gedit_document_set_property (GObject *object, ...@@ -400,6 +418,10 @@ gedit_document_set_property (GObject *object,
set_newline_type (doc, set_newline_type (doc,
g_value_get_enum (value)); g_value_get_enum (value));
break; break;
case PROP_COMPRESSION_TYPE:
set_compression_type (doc,
g_value_get_enum (value));
break;
case PROP_SHORTNAME: case PROP_SHORTNAME:
gedit_document_set_short_name_for_display (doc, gedit_document_set_short_name_for_display (doc,
g_value_get_string (value)); g_value_get_string (value));
...@@ -545,6 +567,24 @@ gedit_document_class_init (GeditDocumentClass *klass) ...@@ -545,6 +567,24 @@ gedit_document_class_init (GeditDocumentClass *klass)
GEDIT_TYPE_DOCUMENT_NEWLINE_TYPE, GEDIT_TYPE_DOCUMENT_NEWLINE_TYPE,
GEDIT_DOCUMENT_NEWLINE_TYPE_LF, GEDIT_DOCUMENT_NEWLINE_TYPE_LF,
G_PARAM_READWRITE | G_PARAM_READWRITE |
G_PARAM_CONSTRUCT |
G_PARAM_STATIC_NAME |
G_PARAM_STATIC_BLURB));
/**
* GeditDocument:compression-type:
*