General discussion about plugins.

Browse, download and discuss plugins for Blumentals code editors
Post Reply
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

Here's a simple plugin script that illustrates the problem with "RegexMatchAll".
I just can't access the resulting matches in the variable "unitMatch" & "unitPosition", only get the length. :(

Code: Select all

function tester() {

	str = "width: 123.4px;height: 5px;";
        regEx = RegexMatchAll(str,"(\\d*\\.?\\d*)px", false, unitMatch, unitPosition);
	Script.Message("unitMatch Length: " + _t(Length(unitMatch)) ); // correctly returns 2
	Script.Message("unitPosition Length: " + _t(Length(unitPosition)) ); // correctly returns 2
	
       // Every attempt below just trows an error: Could not convert variant of type (Null) into type (Integer)
       // Script.Message(unitMatch[1]); // error
       // Script.Message(_t(unitMatch[1])); // error

      for (var i = 0; i < Length(unitMatch); i++) {
	// tst = unitMatch[i];  // error
      }
}
Script.RegisterAction("", "RegExTest", "", &tester);
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

I managed to figure out the format of the RegEx parameter (It have to be escaped and enclosed in quotes) after some trial and errors.
But I still can't iterate over results from the "RegexMatchAll()" function. :(

The WeBuilder Plugin documentation lacks a lot of information, specially about build-in functions.
I have found this site really helpful in discovering the "unknown" commands/functions.
http://www.delphibasics.co.uk/index.html
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: General discussion about plugins.

Post by Aivars »

Here's the regex sample: http://forums.blumentals.net/viewtopic. ... 173#p23173 - sorry that I wasn't able to answer sooner.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: General discussion about plugins.

Post by Aivars »

I see now that _v function is missing (has disappeared?) from the documentation. I'll find out what happened and if it can be restored.
Blumentals Software Programmer
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

Is it possible to "hide" an editor change from the Undo function?

In my DocBlock Comments plugin, I use the "document_before_save" event to update the class/function index when saving.

Currently when I select "Undo" after saving, it reverts the changes to the class/function index. And the next "Undo", undo the last code changes.
But I would like to have it jump directly to the undo of the last code changes. (So the changes made in the "document_before_save" event should be ignored/hidden from undo)
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: General discussion about plugins.

Post by Aivars »

As far as I know it's not possible, none of the direct text manipulation routines are exposed to plugins. However, I think the way it works makes sense, that the first undo reverts the changes made by the plugin.
Blumentals Software Programmer
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

Aivars wrote:As far as I know it's not possible, none of the direct text manipulation routines are exposed to plugins. However, I think the way it works makes sense, that the first undo reverts the changes made by the plugin.
Ok. But personally I don't like the "extra" undo caused by the plugin. :)

But maybe if I call Actions.Execute("ActUndo") first, and then inside the BeginEditing/EndEditing block, call Actions.Execute("ActRedo") just before I add the plugin output. That should "merge" the 2 changes into one.
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

Is it possible to create a "link" in console message using "Script.Message()", like when you do a "Find All" and you can click to go to the line?
If not then this is a feature request :D
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: General discussion about plugins.

Post by Aivars »

I'll add it to the requests then.
Blumentals Software Programmer
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

Is it possible to process JSON files using the FastScript engine in Webuilder?

I can see that Delphi has support for something called "TJSONObject", but I can't figure out how to use it in Webuilder plugins.
If it's possible, can you then provide a small example?
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: General discussion about plugins.

Post by Aivars »

It's not currently possible. My suggestion is to offload this kind of functionality to Chromium controls and do it in JavaScript, similarly how Emmet plugin does it.
Blumentals Software Programmer
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: General discussion about plugins.

Post by Aivars »

New functionality for 2016 Beta:

1) Script.RegisterAction and Script.RegisterDocumentAction now returns the name of the registered action
2) AutoCompleteLibrary.AddPHPEntry(LibraryName: string; ItemType: TPhpItemType; Name, Description, Inheritance: string; Scope: TPhpItemScope; IsStatic: Boolean; Arguments: string; ClassName, ClassExtends, Returns: string) - added ClassExtends parameter

New functions/attributes for 2016 Beta:

1) Actions.SetIcon(Actn: string; Icon: TBitmap)
2) function LoadFileToBitmap(InputFileName: string; BM: TBitmap): Boolean
3) Script.ProjectSettings.SelectedProjectFileTypes
4) Script.ProjectSettings.SelectedProjectExcludeFilters
5) Script.ProjectSettings.SelectedProjectAssetsBrowseDir
6) AutoComplete.Clear(Strings: TStrings) - AutoComplete class functions are meant to be called from "auto_complete" signal processing function (see below). Sample below.
7) AutoComplete.AddItem(Strings: TStrings; const CodeWord, Txt: string): Integer
8 ) AutoComplete.GetWordBeforeCursor(AdditionalChars: string): string
9 ) AutoComplete.Count(Strings: TStrings): Integer
10) AutoComplete.GetCodeWord(idx: Integer): string
11) AutoComplete.SetImageIndex(ItemIndex, ImgIndex: Integer)
12) AutoComplete.GetFunctionData(LookupType: string; var Name, ObjName, ObjClass, ObjSignature: string; var Param, Start: Integer)
13) AutoComplete.FormatActiveParam(s: string; Param: Integer): string

New signals for 2016 Beta:

1) update_code_type (Params: AType: Integer) - signal sent when cursor traverses between different code types (e.g. from HTML into JavaScript etc) or on actions that might change the code type, it's not always guaranteed to change.
2) auto_complete (Params: CodeType, ACType: Integer; Strings: TStrings; AKey: Char; var AllowPopup, ShowImages: boolean) - signal sent on AutoComplete popup. Use Strings parameter with AutoComplete class functions that require it.
3) show_hint (Params: CodeType: Integer; var Hint: string; AKey: Char; var AllowHint: Boolean) - signal sent on code hint (when cursor is inside function brackets and/or ctrl+shift+space is pressed)

New type/enums for 2016 Beta:

1) pscTrait added to TPhpItemScope

AutoComplete and Code Hint sample:

Code: Select all

function OnAutoComplete(CodeType, ACType, Strings, AKey, AllowPopup, ShowImages) {

  //debug stuff for trying out different AC types
  //ACType will be different for PHP functions, properties, classes, JS objects, methods, HTML tags, attributes etc
  
  //Script.Message("ACType: " + _t(ACType));
  
  if (Strings.Count > 0) {
    Script.Message("Sample item:" + Strings[0]);
  }

  if (ACType == 19) {
    //add a hyphotetical PHP global function
    AutoComplete.AddItem(Strings, "awesomefunction", "int{\\rtf\\b awesomefunction} (string $someparam, string $secondparam)");
    
  } else if (ACType == 18) {
    //add a hypthetical PHP global variable
    AutoComplete.AddItem(Strings, "$CONFIG", "$CONFIG");
  
  } else if (ACType == 4) {
    //add this experimental HTML tag
    var i = AutoComplete.AddItem(Strings, "shadow", "shadow");
    AutoComplete.SetImageIndex(i, 8);
  }
  
}


function OnShowHint(CodeType, Hint, AKey, AllowHint) {

  //Script.Message(_t(CodeType) + ":" + Hint);

  if ((CodeType == 6) && (Hint == "")) {
    var Name = "";
    var ObjName = "";
    var ObjClass = "";
    var ObjSignature = "";
    var Param = 0;
    var Start = 0;
    AutoComplete.GetFunctionData("PHP", Name, ObjName, ObjClass, ObjSignature, Param, Start);
    
    //Script.Message(Name + ":" + ObjName + ":" + ObjClass + ":" + ObjSignature);
    //Script.Message(_t(Param) + ":" + _t(Start));
    
    if ((Name == "awesomefunction") && (ObjName == "") && (ObjSignature == "")) {
      Hint = "{\\colortbl\\red128\\green128\\blue128}int awesomefunction ( string $someparam, string $secondparam )\r\n{\\cf0 Do something awesome}\r\n{\\cf0 Added by: Auto complete plugin }";
      Hint = AutoComplete.FormatActiveParam(Hint, Param);
      AllowHint = true;
    }
  }
  
}


Script.ConnectSignal("auto_complete", &OnAutoComplete);
Script.ConnectSignal("show_hint", &OnShowHint);
Blumentals Software Programmer
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

Thanks for the list of new commands and example.

Could you also provide an example of "Actions.SetIcon" and "LoadFileToBitmap" usage?
There are 10 types of people in the world: Those who understand binary and those who don't.
User avatar
Aivars
Blumentals Software Developer
Posts: 2462
Joined: Thu Aug 22, 2002 1:40 pm
Location: Latvia

Re: General discussion about plugins.

Post by Aivars »

Example for LoadFileToBitmap and SetIcon:

Code: Select all

var Act = Script.RegisterDocumentAction("", "Align selection", "Ctrl+Alt+A", &AutoAlign);
var bmp = new TBitmap;
if (LoadFileToBitmap(Script.Path + "align.png", bmp)) {
  Actions.SetIcon(Act, bmp);
}
delete bmp;
Sample align.png attached.
Attachments
align.png
align.png (1.45 KiB) Viewed 350565 times
Blumentals Software Programmer
User avatar
pmk65
Posts: 678
Joined: Sun Dec 20, 2009 9:58 pm
Location: Copenhagen, Denmark

Re: General discussion about plugins.

Post by pmk65 »

Thanks. That really helped. :)

I noticed a bug? when I added icons. As the old 2015 version doesn't support icons, I added a version check.
Maybe it's because of the plugin compiling, but I get an error on the line with "LoadFileToBitmap()", when I install the plugin on 2015.
Is it not possible to use the version number to exclude code?

Code: Select all

var act[4];
act[0] = Script.RegisterDocumentAction(...);
act[1] = Script.RegisterDocumentAction(...);
act[2] = Script.RegisterDocumentAction(...);
act[3] = Script.RegisterDocumentAction(...);

if (StrToFloat(Webuilder.Version) >= 14) {
    var bmp = new TBitmap;
    // In Webuilder 2015 I get a "Compile error: Too many actual parameters" on the next line
    if (LoadFileToBitmap(Script.Path + "image.png", bmp)) {
        for (var i=0;i<Length(act);i++) {
            Actions.SetIcon(act[i], bmp);
        }
    }
    delete bmp;
}
There are 10 types of people in the world: Those who understand binary and those who don't.
Post Reply