Controlling my editor

A place where plug-in developers can share their knowledge and experience.
Post Reply
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Controlling my editor

Post by pepak »

OK, I have a plugin here which, at one point of its OpenPlugin call, opens an editor with some report. I would like to provide custom coloring for this editor. What possible approaches can I take? I found two:

1) Use the Colorer plugin. This is probably a better approach because it uses a standard plugin which is familiar to users, so they will be able to modify settings easily. Also, it only means that I have to provide a correct script, but don't have to program anything. The drawback is that (i) the users must have Colorer, and (ii) I would need to define and use an extension for my file (currently, I just use MkTemp to get an unique name).

2) Use EditorControl's ECTL_ADDCOLOR. This would allow for independent operation (I wouldn't need the Colorer) and I would not be limited by Colorer's abilities. On the other hand, I would like to only colorize my own editor and I just can't find an easy way to do it - it seems to me I would have to export ProcessEditorEvent and in every single call, use EditorControl.ECTL_GETINFO to get filename, then compare that filename to my temp file's name. Seems like a huge waste of cycles.

Did I overlook anything?
User avatar
HaRT
Moderator
Posts: 10822
Joined: Tue 30 Aug, 2005 17:21
Has thanked: 221 times
Been thanked: 358 times

Re: Controlling my editor

Post by HaRT »

pepak wrote:I would need to define and use an extension for my file
AFAIK, Colorer allows to determine coloring schema based on file content as well, in addition to name mask.
See http://colorer.sourceforge.net/hrc-ref/ ... .firstline.
Фар есть инструмент, а не нянька. © 2009 DrKnS
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Controlling my editor

Post by pepak »

I should have added that one reason why I am not entirely comfortable with Colorer is that eventually I will want to control the editor anyway. For example, I would like to add some special shortcuts to modify the contents (e.g. make CTRL+Y delete a whole paragraph rather than a single line, or enter a specific word if user presses a shortcut, stuff like that). Or prevent a modification of some content.

Unless I am overcome with laziness, I will want to do things like this, but of course I don't want to hog CPU time by doing useless checks for every single editor - most of which won't be my editors anyway.
User avatar
Centaur
Posts: 1083
Joined: Tue 05 Apr, 2005 20:09
Location: Novosibirsk, Russia
Been thanked: 2 times

Re: Controlling my editor

Post by Centaur »

I would strongly suggest that you mark your files with some signature at the top, and then have Colorer and [ESC] plugins recognize this signature. Then, provide a Colorer scheme to get the highlighting, and have [ESC] invoke your plugin functions by the means of file type-specific macros.

The main advantage of Colorer is that it is code already written, so you save some (probably significant) effort. Secondly, Colorer schemes are user-customizable.

If your modifications to editor behavior are so extensive that they would require overriding each and every key, you can keep a global set of editors that host files “belonging” to your plugin, hook ProcessEditorInput and/or ProcessEditorEvent, and check that EditorID is an element of this set. Useless checks are then minimal.
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Controlling my editor

Post by pepak »

I am still unsure about one thing: I want to open an editor in EF_NONMODAL, EF_IMMEDIATERETURN mode, and when the user finishes with the file, use it for further processing. This can be done through ProcessEditorEvent's event EF_CLOSE and then comparing Param (EditorID) with a stored EditorID. I am still unclear about getting that EditorID in the first place, though. Is it safe to get it via this code?

Code: Select all

Info.Editor(...);
Info.EditorControl(ECTL_GETINFO, &EditorInfo);
MyEditorID = EditorInfo.EditorID;
That is, can I safely assume that just after a new editor is created, a call to EditorControl->ECTL_GETINFO will reference that new editor and not some previously opened editor?
pepak
Posts: 604
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 17 times
Been thanked: 54 times

Re: Controlling my editor

Post by pepak »

Hmm, apparently that is not the case - I keep getting EditorID = 0 :-(
FileName matches, though, so apparently I do get a proper EditorInfo, it's just that its ID is left blank. I wonder why.
User avatar
t-rex
Страшный и ужасный
Posts: 4910
Joined: Tue 15 Mar, 2005 16:17
Location: Tel-Aviv
Has thanked: 1 time
Been thanked: 8 times
Contact:

Re: Controlling my editor

Post by t-rex »

Try to ACTL_COMMIT.
Post Reply

Return to “Plug-In Developers”