On 13-10-07 01:06 PM, Thomas Martitz wrote:
Am 07.10.2013 21:53, schrieb Thomas Martitz:
Am 07.10.2013 12:27, schrieb v01d:
Hi,
I'm writing a simple plugin for geany (which I will call LiveDiff)
which allows for having
indicators inside the editor for changed/added/modified lines, which
is updated as you type. The base for comparing
the buffer can be either the version of the file on disk or (which I
will soon attempt to add) the latest version from the git repository,
if the file is versioned so.
This resembles what netbeans does (one something I really liked). So
far it works OK but there are some quirks.
I'm doing this out of spare time so dont expect a pretty serious
commitement to it. I will however make it available on github.

I wanted to ask regarding the ScitillaObject handling. Currently my
plugin needs to define RGBA markers (which are used to indicate the
diff results per-line).
What it is not really clear to me is that there appears to be one
ScintillaObject associated with each GeanyDocument. However, some
messages sent to the ScintillaObject (like changing the margin or
defining markers) appear to be global across all instances (unless I'm
mistaken). Is this so? What would be the proper handling? Is it ok to
repeat the definition of the markers for each editor?

Moreover, I'm not sure how to handle correctly the size of the RGBA
markers since it depends on the font size of the editor. I tried to
set the marker scale using the text_height to image height ratio, but
the marker still appears to be a bit taller than the line and this
creates some visual artifacts.


Hello,

[1] might be of interest for you. It does something very similar.

Regarding your other question, are you talking about the
"editor-notify" signal? Yes, that's not really per-document, I came
across this recently. The solution is to connect to "sci-notify" of
ScintillaObject directly, this will give a proper per-document signal
(the document-specific ScintillaObject pointer). However you need to
get the GeanyDocument pointer elsewhere. See how I did it here[2].

Some might consider this as a defect in Geany.

[1]: http://lists.geany.org/pipermail/devel/2010-June/002584.html
[2]:
https://github.com/kugel-/geany-plugins/commit/7f19c3035abf6f8a7fa66c7b4c1efe0851cb2f83




I need to correct myself. "editor-notify" is correctly per-document and
you can get the GeanyDocument pointer via the GeanyEditor pointer passed
to it. What I meant to say is that you cannot use "editor-notify" if you
need to attach user_data on a per-document basis. The user_data pointer
passed to plugin_signal_connect("editor-notify", ...) will be
overwritten on each successive all. My suggested workaround works for
this case. With sci-notify you can attach user_data on a per-document
basis.


As long as the Scintilla view doesn't switch document models, like some view recycling optimizations or split/multi view magic or something. I don't think anything actually does this at present, but it could in theory, without "breaking" the API, or it could even be done by another plugin.

Last time I needed to do this, I made a hash table that used g_direct_hash on the GeanyDocument pointer as the key, and the value was my custom/user data structure. Then I had a function that effectively did this:

    void *document_get_context(GeanyDocument *doc) {
      return g_hash_table_lookup(global_hash, doc);
    }

Then to keep it sync, I used code like this:

http://pastebin.geany.org/Y1O3d/

Where the dm_*() calls are keeping the hash table consistent with the current set of documents. It's kind of a lot of boiler-plate to attach data to a document, but it seems to work quite well :)

Cheers,
Matthew Brush
_______________________________________________
Devel mailing list
Devel@lists.geany.org
https://lists.geany.org/cgi-bin/mailman/listinfo/devel

Reply via email to