[Solved] How to Add Google Search to popupmenu in Editor. lazarus / 9-Editor ---------------------------------------------------------------------- loaded · 2022-01-15 08:42 Hi All, Can I add items to the popup menu on the editor? In the menu I added; What do I need to do to be able to use the selected text on the editor in Google Searches? ---------------------------------------------------------------------- winni · 2022-01-15 09:11 Hi! A simple solution: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses ...,LCLIntf; procedure TForm1.Button1Click(Sender: TObject);var s : string;    i: integer;begins := edit1.text;for i := 1 to length(s) do   if s[i] = #32 then s[i] := '+';openUrl('https://www.google.com/search?q='+s);end;               Winni ---------------------------------------------------------------------- loaded · 2022-01-15 09:16 Thank you very much for reply winni. Yes it can be done with external code, but I want the IDE to do it. ---------------------------------------------------------------------- Thaddy · 2022-01-15 09:29 Michael van Canneyt wrote a tutorial on how to extend the Lazarus IDE. See https://www.freepascal.org/~michael/articles/lazide3/lazide3.pdf It is rather old, though. I have no idea how current it is. ---------------------------------------------------------------------- loaded · 2022-01-15 09:36 Thank you very much for reply Thaddy. Yes this looks like a nice resource, I hope it helps me achieve what I want. ---------------------------------------------------------------------- balazsszekely · 2022-01-15 09:53 @loaded This is quite simple. Create a DesignTime only package, add the following code on the registration method: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses MenuIntf, SrcEditorIntf, LCLIntf;   procedure DoOnMenuClick;var  Str: String;  I: Integer;begin  Str := SourceEditorManagerIntf.ActiveSourceWindow.ActiveEditor.Selection;  //apply winni sugestion here  for I := 1 to length(Str) do    if Str[I] = #32 then      Str[I] := '+';  OpenUrl('https://www.google.com/search?q=' + Str);end; procedure Register;var  IDEMenuItem: TIDEMenuItem;  M: TMethod;begin  IDEMenuItem := TIDEMenuItem.Create('Google search...');  M.Data := nil;  M.Code := @DoOnMenuClick;  IDEMenuItem.OnClick := TNotifyEvent(M);  SourceEditorMenuRoot.AddFirst(IDEMenuItem);end; Compile then install the package. PS: Actually this is very good idea. It should be implemented in Lazarus trunk, directly in sourceeditor not in a package of course. ---------------------------------------------------------------------- loaded · 2022-01-15 11:11 Master Getmem, once again I express my gratitude to you. Numbers are not enough to say thank you anymore. Thanks to you, I both solved my problem and made me sweat a bit, but I wrote my first package. Maybe it will help someone; I'm attaching the package I wrote here, it may be an amateur, don't laugh.  May God increase your knowledge. ---------------------------------------------------------------------- balazsszekely · 2022-01-15 11:31 @loaded You're welcome! Small correction: you should check if the string is empty before opening the browser: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses Dialogs;  procedure DoOnMenuClick(Sender: TObject);var  Str: String;  I: Integer;begin  Str := SourceEditorManagerIntf.ActiveSourceWindow.ActiveEditor.Selection;  if Trim(Str) = '' then //add this  begin    MessageDlg('Please select something first!', mtInformation, [mbOk], 0);    Exit;  end;  //apply winni sugestion here  for I := 1 to length(Str) do    if Str[I] = #32 then      Str[I] := '+';  OpenUrl('https://www.google.com/search?q=' + Str);end; Also instead of google use DuckDuckGo. ---------------------------------------------------------------------- loaded · 2022-01-15 11:55 Master Getmem, yes, you are right as usual, I am making the relevant corrections. There is so much to learn from you Masters !!!