Forum > Editor

[Solved] How to Add Google Search to popupmenu in Editor.

<< < (2/2)

balazsszekely:
@loaded

This is quite simple. Create a DesignTime only package, add the following code on the registration method:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
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.  ;D
May God increase your knowledge.

balazsszekely:
@loaded

You're welcome! Small correction: you should check if the string is empty before opening the browser:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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:
Master Getmem, yes, you are right as usual, I am making the relevant corrections.
There is so much to learn from you Masters !!!

Navigation

[0] Message Index

[*] Previous page

Go to full version