Controlling my editor

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

Controlling my editor

Post by pepak » Thu 21 Aug, 2008 08:48

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: 8048
Joined: Tue 30 Aug, 2005 17:21
Location: Санкт-Петербург
Has thanked: 67 times
Been thanked: 100 times

Re: Controlling my editor

Post by HaRT » Thu 21 Aug, 2008 09:09

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: 327
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 3 times
Been thanked: 9 times

Re: Controlling my editor

Post by pepak » Thu 21 Aug, 2008 09:44

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

Re: Controlling my editor

Post by Centaur » Thu 21 Aug, 2008 10:02

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: 327
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 3 times
Been thanked: 9 times

Re: Controlling my editor

Post by pepak » Tue 28 Jul, 2009 08:20

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: 327
Joined: Sun 13 Jul, 2008 11:18
Has thanked: 3 times
Been thanked: 9 times

Re: Controlling my editor

Post by pepak » Tue 28 Jul, 2009 09:56

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: 4871
Joined: Tue 15 Mar, 2005 16:17
Location: Tel-Aviv
Contact:

Re: Controlling my editor

Post by t-rex » Tue 28 Jul, 2009 09:58

Try to ACTL_COMMIT.

Post Reply

Return to “Plug-In Developers”