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

Re: Allow missing components (or detect them in project)


On Sat, 17 Jan 2026 at 13:43, Benoît Minisini <
benoit.minisini@xxxxxxxxxxxxxxxx> wrote:

> Le 12/01/2026 à 14:52, Bruce Steers a écrit :
>
> >
> > Eek. that last part sounds scary.
> > Sometimes Inheritance is just not enough.
> > For example my Keystroke macro recorder for TextEditor only works
> > because i create a fake Key.class called MKey.class and use a direct
> > copy of the View_Keypress() event modified to use MKey.class not
> Key.class.
> > This cannot be done via Inheritance because the View_Keypress event
> > contains Private variables not accessible with Inheritance.
> > (although i'm sure gb.form.editor isn't a dependency for anything)
>
> Why don't you just use an event observer to catch the keyboard events on
> the editor?
>
> And in that cas which private variable would you need?
>
> --
> Benoît Minisini.


It's not the getting of the event it's the giving.

I duplicate the TextEditor/View_Keypress() code and rename it to
Public Sub _MacroKeyPress(MKey As MacroKey)

All "Key" references in the copied method are then changed to "MKey"
(except for static constants)

Because TextEditor keypress event handles "all" key events i can virtually
control sending any key by simply using MKey.Shortcut syntax

So the keystroke recorder lists a sequence of Key.Shortcut strings
When played back it sends the strokes to the TextEditor._MacroKeyPress
method as MacroKey objects.
fake keys processed like a normal Key object. the only calls outside of the
key event method are to the TextEditor_Mode_xx.OnKeypress methods, (so i
also duplicate those classes to use MKey)

    Dim hKey As MacroKey = New MacroKey(["Ctrl+Shift+T")
    TextEditor1._MacroKeyPress(hKey)
It works beautifully. :)

But the View_Keypress method has too many internal private references to be
cloned/hacked through inheritance. (plus the mode files)
I found after trying many many different things the only option was to copy
View_Keypress as _MacroKeyPress and do a similar thing to the mode files.

My fork has the keystroke recorder build in to gb.form.editor if you want
to see the code. (it's the ONLY change in my fork outside of the IDE, i've
made no other component modifications, i just had no other choice for the
reasons mentioned above)
https://gitlab.com/bsteers4/gambas/-/blob/bruces-patched/comp/src/gb.form.editor/.src/TextEditor.class?ref_type=heads#L2510
https://gitlab.com/bsteers4/gambas/-/tree/bruces-patched/comp/src/gb.form.editor/.src/KeyMacros?ref_type=heads
https://gitlab.com/bsteers4/gambas/-/blob/bruces-patched/comp/src/gb.form.editor/.src/TextEditorMode.class?ref_type=heads#L302
Ctrl+F7 starts or stops it recording, Ctrl+Insert plays it back,  I've used
it a number of times, super useful.
It's just a bit buggy when using CloseStrings/CloseBraces/etc. I'm about to
revisit the code with my new editor.
(also the keystroke recorder works the same on wayland)

This was the reason we spoke many moons ago about the possibility of making
a fake key class. it would be super useful, more useful than
Desktop.SendKey.
imagine Control.SendKey(Shortcut As String) , ooh the possibilities.

I think removing our ability to import components and modify them will be a
shame.
For some components renaming the classes and renaming all the references to
the classes within the classes can be a pain.

Plus other advantages like knowing my program will not break when using a
components still evolving like TextEditor.
I still have issues sometimes when you change something in gb.highlight
because i could not import gb.highlight (i tried, many problems)
"If" i could have imported gb.highlight then the TextEditor/Highlight
compatibility would have been stable until i update it.

gb.form.terminal is another component fully imported into a few of my
programs due to extensive tweaks that needed more than inheritance.
(like disabling that automatic color adapting because my scripts won't show
the color they're supposed to ;)
but i am sure there are no components that depend on terminal or texteditor
so Settings.class was my only issue but with those i CAN use inheritance.

I don't know how else gambas is being used around the world but maybe many
have imported components to tweak a few things more to their liking without
bothering you?
Qué será, será

Respects
BruceS

Follow-Ups:
Re: Allow missing components (or detect them in project)Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
References:
Allow missing components (or detect them in project)Bruce Steers <bsteers4@xxxxxxxxx>
Re: Allow missing components (or detect them in project)Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: Allow missing components (or detect them in project)Bruce Steers <bsteers4@xxxxxxxxx>
Re: Allow missing components (or detect them in project)Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>
Re: Allow missing components (or detect them in project)Bruce Steers <bsteers4@xxxxxxxxx>
Re: Allow missing components (or detect them in project)Benoît Minisini <benoit.minisini@xxxxxxxxxxxxxxxx>