Ted2: Experimental Plugin System

About Monkey 2 Forums Monkey 2 Development Ted2: Experimental Plugin System

This topic contains 11 replies, has 5 voices, and was last updated by  cocon 2 years, 7 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #3220

    cocon
    Participant

    One of the latest commits to Ted2 was this experimental plugin system. It took me a few hours to wrap my head around this, so here is a micrography on how it works.

     

    #3451

    cocon
    Participant

    The last few days things are going very slow, I laid the groundwork however to create a bunch of Ted2 Plugins.

     

    https://github.com/coconcode/monkey2/tree/experimental-plugins

     

    The Plugins At This Moment:

    However I made some code changes to the original design.

    TextViewKeyEventFilter becomes PluginTextView
    This more of a naming convention since I thought that in the future there might be other plugins as well other than the text view. (e.g. PluginConsole, PluginExplorer, PluginAnything). This will create a nice mental grouping that will make sense, in comparison to rogue classes where each one has it’s own unique name and you can’t put them in a basket.

    Also I created the class TextViewFeatures (located in textviewplugin) to provide some shorthand methods for TextView objects, nothing more than a convenience wrapper class. It is also initialized as a private global so that it can be accessed easily.

    #3454

    cocon
    Participant

    Just a while ago I finished the LineComment Plugin, you can see it in action here:

    https://1drv.ms/v/s!AquVr9J7xRcsgW6UpLVLBF-r4iT-

    #3456

    Samah
    Participant

    Imo plugins in Lua. Then you can re-use existing libraries. Actually, I might even write a plugin that will execute Lua in the editor.

    #3459

    degac
    Participant

    @cocon: nice!

    #3522

    degac
    Participant

    One question.

    I’m still learning mojo/mojox & co… and I would like to add some changes to TED2. Some of these changes are already implemented in my own MaxIDE version. (I’m a lazy person, I find quite tedious typing too much !)

    I’d like (and I think others) to do something like this

    to have a sort of ‘automatic conversion’ to obtain this

    The next move should be the use of the old symbol syntax ($,#,% etc) – to handy sorry!

    But (of course there’s always a but …) I’m asking where is the ‘correct place/way’ to insert this checking/altering thing in the current TED2 structure (due to the latest changes with ‘plugin’ support I’m a little lost to be honest!)

    I’m still trying to understand how TextView is working – a change on a line is working without problems, but with more lines I get strange results!

    Thanks

    #3563

    nerobot
    Participant

    IMO, writing plugins for key processing isn’t usefull, because to use this plugins you must use PluginTextView, and so you will get working of all these keyfilters or nothing.

    What should I do if I want to add support for cpp-coding and replace some filters, for example, replace monkey comments to cpp comments?

    Thinking in this key, I plan to write base textview for all code langs (named CodeTextView). Inside this view I put specific key processing, codeformatter-plugin (capitalize and so on) – extendable for any langs, highlighter-plugin and keywords-plugin. These plugins will rely on the file type.

    This interface:

    helps us to check plugin for suitability for opened file.

    Also using of plugins has some limitations – if you need to get data from file while initialize plugin – inside of method New() – you get “Memory access violation” error.

    (in my case – I need to read keywords from json)

    Anyway, plugin system is great! 🙂

    (I’ll post my version when complete it)

    #3564

    nerobot
    Participant

    @degac, you can write your logic inside of

    ted2 / monkey2document.monkey2 / Monkey2DocumentView / OnKeyEvent()

    #3570

    nerobot
    Participant

    And how to control plugins collisions?

    For documents – if I write my own plugin for catch .cpp files I see that it does’t work because of plaintext plugin which catch cpp too.

    The same problem is facing if I want to write my own keys filter for keys which filters other plugin.

    #3604

    Mark Sibly
    Keymaster

    I’m asking where is the ‘correct place/way’ to insert this checking/altering thing in the current TED2 structure

    There should be a ‘Ted2TextView’ in there which is currently responsible for calling the textview plugins – this is probably a good place to start tinkering as there’s not much in there.

    Perhaps the TextViewKeyEventFilter plugin should be replaced with a simpler ‘TextViewPlugin’ that provides the same virtual methods as TextView, ie: OnKeyEvent, OnMouseEvent, OnRender? Perhaps not as easy to use as something more specific, but more flexbile (and you can always subclass it for a more specific superclass). TextViewPlugin could also perhaps provide a set of file types it’s applicable for (eg: there may be c++ specific textview plugins etc).

     

    Also using of plugins has some limitations – if you need to get data from file while initialize plugin – inside of method New() – you get “Memory access violation” er

    Will add an OnCreate() for this that gets called once everything’s up and running.

    And how to control plugins collisions?

    For document type plugins, there will need to be a way for the user to select the ‘default’ document type to be used when doing a plain ‘Open’. I can probably hack this into a menu somehow, although it probably belongs in a ‘real’ IDE options dialog – coming one day…

    For the file tree view RMB menu, an ‘Open With’ menu item could also be used to open documents with a different plugin.

    For textview plugins, you’re kind of boned aren’t you? Although it might also be an idea to think about plugin priorities?

    #3611

    nerobot
    Participant

    Thanks for OnCreate().

    Sort by priority can be useful. But all users want to use them plugins as primary and we’ll got ride of priority. 🙂

    I vote for adding priority.

    #3704

    cocon
    Participant

    @degac

    I would like to add some changes to TED2

    You can code anything you want in a “dummy” class (that accepts a string parameter in an update method) and I will be able to convert it to a text view plugin. I had in plans for something like this to create a super lazy variable instantiation, but I had forgot it, I noted it down btw in a TODO list.

    If you want to write the plugin write a new class as shown here:
    https://github.com/blitz-research/monkey2/blob/master/src/ted2/textviewkeyeventfilter.monkey2

    In my branch everything is put here:
    https://github.com/coconcode/monkey2/blob/experimental-plugins/src/ted2/plugintextview.monkey2

    @nerobot

    What should I do if I want to add support for cpp-coding and replace some filters

    At this moment the most easy way to solve it would be this, I consider later on to change the naming conventions back to the original.

    @Mark Sibly

    Perhaps the TextViewKeyEventFilter plugin should be replaced with a simpler

    This makes sense, since it would make plugins more powerful that way, can’t wait to try it.

     

     

    Now about the status of my work, here are plugins so far.

     

    The only plugin that suffers a bit “PluginTextView_MouseSelect” since you might try to move the mouse a little or release the shift key to actually see the text get selected. (Later on I might try experiement with some async code, perhaps with fibers or timers, who knows. I need that part executed 500ms later after the last event fired so the effect is done. Alternatively, perhaps making the UpdateCursor method of the TextView public and call it might work.)

     

    No more no less there are some other ongoing efforts for creation of cool plugins (if you know any other post it here), a good attempt for cross-contaminating codes.

    https://github.com/StrangeIsMyName/monkey2

    https://github.com/engor/Ted2Go

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.