[gedit-list] File loading and saving in GtkSourceView



Hi everyone,

Here are my thoughts on how to implement the file loading and saving in 
GtkSourceView (currently available in GeditDocument).

First, as pbor said, the GIO conventions for async operations should be 
followed, also for reporting the progress.

gedit stores some files metadata, such as the encoding, the syntax 
highlighting mode, the cursor position, and maybe others. Some of these 
metadata can be useful in GtkSourceView, but as a first step it is 
simpler to keep this in gedit.

GeditDocument knows its location (a GFile), and currently it is not 
possible to save the document to another file without changing the 
location property. In gsv, there should be a property with the default 
location, and being able to save the buffer to another location 
independently.

It should also be possible to change the encoding of opened files, but 
it's more on the gedit side. Just keep this in mind.

API idea
--------

Have a GtkSourceFile class, a subclass of GFile.

(as a side note, I'm not sure it is possible to subclass GFile, because 
it is an interface... It's more logical to have a is-a relationship, but 
if it's not possible, another solution is to have a location property in 
GtkSourceFile, with the has-a relationship)

GtkSourceFile would have the following properties:
- encoding
- newline-type
- compression-type
- buffer (construct-only)

GtkSourceBuffer would have a "file" property, for the default location.  
The property can be NULL for a new buffer.

GtkSourceFile would have functions for loading and saving the file 
into/from the buffer.

GtkSourceBuffer and GtkSourceFile would have a one-to-many relationship: 
the buffer can have a default file, and the buffer can be saved in other 
files.

This has the advantage to not inflate GtkSourceBuffer too much (just one 
more property), and have a flexible API.

GtkSourceFile can be extended later with the content-type, the 
mime-type, functions for displaying the file name in various ways, 
sending a signal when the file is externally modified (with a 
GFileMonitor), etc.

Another API idea
----------------

More like the gedit API.

In GtkSourceBuffer, have the following properties:
- location (a GFile)
- encoding
- newline-type
- compression-type

Have a GtkSourceBufferLoader and Saver classes, with a buffer parameter.  
Take the above properties as default values, but duplicate the 
properties to be able to change them independently of the buffer.

Or merge the loader and saver into GtkSourceFileOperation or something 
like that.

-----

I prefer the first idea with GtkSourceFile :-) What do you think? Did I 
miss something in the requirements? If not, I'll take the GtkSourceFile 
path, and see how it goes.

Cheers,
Sébastien


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]