开发者

How can I detect changes to text and selection from my Notepad++ plug-in?

Developing a Notepad++ plug-in using Delphi (using NPP's DelphiPluginTemplate as a basis), how do I create eve开发者_开发技巧nt handlers like onSelectionChanged, onChange, etc.?

I imagine creating a function like this and then registering it somehow with Notepad++:

procedure onTextChanged(...); stdcall;
begin
  ShowMessage('Text was changed');
end;
...
initialization
RegisterMyNotepadPlusPlusOnChangeEvent(onTextChanged);


Notepad++ doesn't appear to expose that information to plug-ins, but it does expose the underlying Scintilla edit control, which provides numerous notifications to its container window via wm_Notify messages.

When the selection changes, the notification code is scn_UpdateUI, and the updated field will include sc_Update_Selection.

When the text changes, the code is scn_Modified, and the modificationType field will indicate what was modified, which controls which other fields will have useful information.

Those messages are sent to the edit control's parent, which Notepad++ doesn't necessarily expose. It exposes the handles to two Scintilla controls, and you can call GetParent to find the window that it notifies. Then you can subclass it, providing your own replacement window procedure that handles the notification messages you're interested in and then forwards everything to the next window procedure in the subclass list.


use beNotified. it's enough to get information about changes. if you use default Delphi headers - you must change BeNotified in TnppPlugin from normal method to virtual. and override it in your class.

procedure TIHelpPlugin.BeNotified(sn: PSCNotification);
begin
  inherited;
  if NppData.NppHandle <> HWND(sn.nmhdr.hwndFrom) then begin
    case sn.nmhdr.code of
      SCN_UPDATEUI,SCN_MODIFIED,SCN_CHARADDED: begin
        onTextChanged(...);
      end;
    end;
  end;
end;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜