pluma like "External Tools" in my gambas :) :)

Feel free to talk about non programming issues here.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

I've only been and done it.

I added External tools to my ScriptEd editor as it's really useful.

now i've finally managed to do the same with Gambas :D
https://gitlab.com/bsteers4/gambas/-/tr ... rnal-Tools

It works well :)

it creates a dir to store the scripts in $HOME/.local/share/gambas3/

Data can be passed to the scripts with tokens...
Tokens
"$GB_FILEPATH": "Full File path",
"$GB_FILENAME": "The file name",
"$GB_DIRECTORY": "The files Directory",
"$GB_SELECTED": "Selected text",
"$GB_ALLTEXT": "All Text"

results from the script can be inserted into document or replace the whole text if it's been processed.
Undo will still work if you error :)

Here it is in action translating my selected text to French :)
(Tokens are prefixed SE_ in clip, i changed it to GB_)



it needs a bit of error handling , it currently pops a warning if the active document is a form but that is all. I want it to work on most type of opened documents. (not sure how many other workspace views might not be text)

But dang this will be useful.
If at first you don't succeed , try doing something differently.
BruceS
justlostintime
Posts: 3
Joined: Wednesday 10th July 2019 6:30am

Re: pluma like "External Tools" in my gambas :) :)

Post by justlostintime »

Hi Bruce,

How does it integrate into the ide, will i have to do a merge every time the IDE is updated?

It is something I have been looking for, How are the plugins executed from the IDE?

Thanks for your work on this!
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

Hi Brian, modifications to the IDE code are minimal.

I added a menu to FMain.form
{ mnuRunExtTool Menu
      Action = "external-tools"
      Text = ("External Tools") & "..."
      Picture = Picture["icon:/small/properties"]
    }
I added an action for the menu click in FMain.class
 Case "external-tools"
      FExternalTools.Run
(this is only run if you have no tools added, once you have tools added the menu becomes a parent for another menu and the tools manager link will then be in there)

I added 2 commands to the FEditor.class _init() method to load the tools config and make the menus on startup.
  CExternalTools.GetTools
  CExternalTools.AddMenus
Everything else is dealt with by the added FExternalTools.class and CExternlalTools.class


To have it you'd need to modify your own git branch. Just set the upstream to the main gambas gitlab (i assume you know how to do that?) then you can 'git pull upstream master' to keep up to date with Bens changes.

Make a branch from master and i can send a merge request if you like. then you could examine the diff and apply the changes in your own way.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

justlostintime wrote: Thursday 20th January 2022 7:02pm Hi Bruce,

How does it integrate into the ide, will i have to do a merge every time the IDE is updated?

It is something I have been looking for, How are the plugins executed from the IDE?

Thanks for your work on this!
To add further to integration.

My last explanation says how it adds the Tools manager to the gambas IDE,
this is how it runs the tools...

Each tool set saves as a script file in the settings folder.

When a tool is run the Project.ActiveWindow is checked for either a FEditor (gambas code) object or a FTextEditor (other text).
with access to that i have access to many functions. that's how it gets the file name/text/selected text/etc and is the object to use .Insert() on to insert any text. also with this pointer i have been able to add some options like Save document first, Format code and reload.

When run a tool script file is read and any tokens replaced in the text with the data then saved as a temp file and executed/then deleted.
if option to insert results is used then result is inserted.
If at first you don't succeed , try doing something differently.
BruceS
justlostintime
Posts: 3
Joined: Wednesday 10th July 2019 6:30am

Re: pluma like "External Tools" in my gambas :) :)

Post by justlostintime »

Have you thought about loading gambas scripts as plugins for the tools.
Once loaded as a plugin the scripts would have direct access to all parts of the ide.
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

justlostintime wrote: Friday 21st January 2022 3:18am Have you thought about loading gambas scripts as plugins for the tools.
Once loaded as a plugin the scripts would have direct access to all parts of the ide.
I think that's going a bit high tech , i like this low-brow thing i have done, it's not too invasive on the IDE, just a menu and a way to export/import to and from the source text.

i think plugins with direct access to the ide will screw Bens life up with problems/bugs that are out of his control/understanding because of sketchy code (like mine lol :) )..

Not saying it's not a good idea m8, i've shown you how to integrate something like this into the IDE here but you probably know more about integrating scripts into already running apps than i do so I'll leave it with you :)

I think a side-goal here , as well as having a really handy feature for custom actions, is to help ease Bens load, the External Tools feature could turn a whole lot of "can you make gambas do this?" requests into , "Yes, it already can, just make an External Tool command"

But i sense he is VERY reluctant to have things that mess about with IDE at a code level , I do it, my bruces-patched branch has the Bonus-Tweaks / custom component launcher feature (pretty sure Ben hates it, but i love it) that shows custom components as they look in the IDE as opposed to the normal just a box with it's name. But when working on a component it causes various problems especially when adding/removing properties, the properties change in the loaded project but the IDE still has the old version loaded so raises errors. you just have to compile the control and re-start gambas.
Going off point a bit there though, the point was as i'm mucking around with the IDE i am causing problems that someone who didn't understand might get on the bugtracker and report a bug to Ben. So wouldn't want that.

Just something i think to be aware of if adding things to customize the IDE, especially things that access internal objects.

I could push this to a merge request and see if Ben likes it or not (the concept, not the code, pretty sure he'll be horrified at my code lol, he just understands how to do things properly better than all of us)

But he could take the merge and clean it up to be all gambas perfect, who knows eh? :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

Ive negated the need for the code sorting addon i did now as i can run the code sorter through the External Tools feature.
:D
Last edited by BruceSteers on Thursday 27th January 2022 5:25am, edited 2 times in total.
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

I've just added Clipboard options.
I also made it detect if your script is bash or gambas and the editor is a TextEditor with highlighting and stuff.

now I can use the $GB_CLIPBOARD token to use the clipboard contents in the script.

Also the result of the script can be copied to the clipboard.

8-)

I just wrote a quick gbs script...
#!/usr/bin/env gbs3

Dim sText As String = Trim(UnQuote($GB_SELECTED))

Dim aVar As String[], iPos As Integer = InStr(sText, " = ")

If Not iPos Then 
 Print "error with string " & sText
 Quit 1
Endif

 aVar = [Mid(sText, iPos + 3), Left(sText, iPos)]

Print aVar.Join(" = ")
And have set the tool to use the Selected text.

So now I can select some text like...
Settings["MycheckValue"] = cbxMyValue.Value
Then selecting the external tool spins it around and copies it to the clipboard so i can pop up to Form_Open() and paste...
cbxMyValue.Value = Settings["MycheckValue"]

(been wanting something like that for a while, every time i'm writing my options code)

Aah the possibilities :)
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

already thinking of having so many tools i'll need to implement menu trees
If at first you don't succeed , try doing something differently.
BruceS
User avatar
BruceSteers
Posts: 1505
Joined: Thursday 23rd July 2020 5:20pm
Location: Isle of Wight
Contact:

Re: pluma like "External Tools" in my gambas :) :)

Post by BruceSteers »

A bit of a re-write happened. (mostly)

Changed many things like a Treeview now and you can add folders/submenus

GUI looks lush , it adopts your IDE Theme for the text editor.

Getting ready to submit for merge now :)
Screenshot at 2022-01-27 05-12-22.png

That gives me this menu...
Untitled.png
Last edited by BruceSteers on Thursday 27th January 2022 8:45am, edited 1 time in total.
If at first you don't succeed , try doing something differently.
BruceS
Post Reply