C# Class NppSharp.NppScript

Base class for all script objects. Any objects that wish to have their public methods made available as commands must inherit from this class.
Show file Open project: cmrazek/NppSharp

Public Methods

Method Description
Append ( string text ) : void

Appends text to the end of the document without affecting the selection.

CancelAutoCompletion ( ) : void

Cancels any active auto-completion.

Clear ( ) : void

Deletes the selected text.

ClearAll ( ) : void

Clears all text out of the document.

Copy ( ) : void

Copies the selected text to the clipboard.

Copy ( TextLocation start, TextLocation end ) : void

Copies the specified text range into the clipboard.

Copy ( TextLocation start, int numChars ) : void

Copies the specified text range into the clipboard.

Copy ( string text ) : void

Copies the provided string into the clipboard.

CopyAllowLine ( ) : void

Copies the selected text to the clipboard. If no text is selected, the current line is copied instead.

Cut ( ) : void

Cuts the selected text to the clipboard.

DockWindow ( IWin32Window window, string title, DockWindowAlignment alignment, int id ) : IDockWindow

Creates a docked window.

This window will not be restored the next time Notepad++ starts. The plugin must recreate the window during the 'Ready' event, if it wishes to have the window visible again.

Notepad++ will use the ID to remember the state for this docked window between sessions. If another docked window with the same ID had been opened previously with a different alignment, or the user had dragged the window to another side of the screen, then the docked window will appear in the previous location rather than the one specified here.

FindColumn ( int line, int column ) : TextLocation

Gets the position that corresponds to a line and column.

FocusEditor ( ) : void

Sets the focus to the current editor window.

GetActiveFileIndex ( EditorView view ) : int

Gets the current document index in the specified view.

GetDockWindow ( int id ) : IDockWindow

Gets the dock window object for the specified ID.

GetFileNames ( EditorView view ) : IEnumerable

Gets a list of open file names in the specified view.

To get a list of all open file names in both views, you can use the 'FileNames' property.

GetLanguageName ( int langId ) : string

Gets the name of a language, given the ID.

GetLineEndPos ( int line ) : TextLocation

Gets the ending position of the specified line, before any line-end characters.

GetLineLength ( int line ) : int

Gets the length of the specified line (excluding line-end characters).

GetLineStartPos ( int line ) : TextLocation

Gets the starting position of the specified line.

GetLineText ( int line ) : string

Gets the text for the specified line.

GetLineText ( int line, bool includeLineEndChars ) : string

Gets the text for the specified line, optionally including line-end characters.

GetText ( TextLocation start, TextLocation end ) : string

Gets the text for the specified range.

GetText ( TextLocation start, int numChars ) : string

Gets the text for the specified range.

GetWordEndPos ( TextLocation pos, bool onlyWordChars ) : TextLocation

Gets the position at the end of the current word.

GetWordStartPos ( TextLocation pos, bool onlyWordChars ) : TextLocation

Gets the position at the start of the current word.

GoTo ( TextLocation pos ) : void

Goes to the specified position and ensures it is visible.

GoToLine ( int line ) : void

Goes to the specified line and ensures it is visible.

Insert ( string text ) : void

Inserts text over the current selection. The caret is placed after the inserted text and scrolled into view.

LaunchFindInFiles ( string dir, string filters ) : void

Launches the 'Find in Files' dialog.

MenuCommand ( MenuCommand command ) : void

Triggers a menu item command.

MenuCommand ( int commandId ) : void

Triggers a menu item command.

MoveCaretInsideView ( ) : void

If the caret is outside the current view, it is moved to the nearest visible line. Any selection is lost.

MoveSelectedLinesDown ( ) : void

Moves the selected lines down one line, shifting the line below the selection.

MoveSelectedLinesUp ( ) : void

Moves the selected lines up one line, shifting the line above the selection.

OpenFile ( string fileName ) : bool

Opens a new file. If the file is already open, it will be made active.

Paste ( ) : void

Pastes the clipboard text over the selection.

PointToPos ( Point pt ) : TextLocation

Finds the position closest to a point on the screen.

PointToPosClose ( Point pt, TextLocation &location ) : bool

Finds the position closest to a point on the screen.

PosToPoint ( TextLocation pos ) : Point

Returns the x and y display location of the position.

RefreshCustomLexers ( ) : void

Refreshes the word-styles and folding on documents that use a custom lexer provided via NppSharp.

This function is useful if your lexers providing highlighting that can change, and need to be refreshed at certain events.

ReloadFile ( bool withAlert ) : void

Reloads the current file.

ReloadFile ( string fileName, bool withAlert ) : void

Reloads a file given the file name. If the file is not already open, then this has no effect.

SaveAllFiles ( ) : bool

Saves all open documents.

SaveFile ( ) : bool

Saves the current document.

SaveFileAs ( string fileName ) : bool

Saves the current document to another file name.

SaveFileCopyAs ( string fileName ) : bool

Saves a copy of the current document to another file name.

SelectAll ( ) : void

Selects all text in the document. (The caret is not scrolled into view)

SetActiveFileIndex ( EditorView view, int index ) : void

Switches to the file in the specified view.

SetEmptySelection ( TextLocation pos ) : void

Removes the selection and sets the caret at pos. (The caret is not scrolled into view)

SetSelection ( TextLocation anchorPos, TextLocation currentPos ) : void

Sets the selection range. (The caret is scrolled into view)

ShowAutoCompletion ( int lengthEntered, IEnumerable list ) : void

Shows the AutoCompletion list.

ShowAutoCompletion ( int lengthEntered, IEnumerable list, bool ignoreCase ) : void

Shows the AutoCompletion list.

ShowError ( Exception ex ) : void

Displays an error message caused by an exception.

ShowError ( Exception ex, string message ) : void

Displays an error message caused by an exception, with additional text.

ShowError ( string message ) : void

Displays an error message.

SwitchToFile ( string fileName ) : bool

Switches to a file given the file name.

Protected Methods

Method Description
OnLoad ( ) : void

Called after the object has been created and initialized, but before the Notepad++ Ready notification.

Private Methods

Method Description
InitEvents ( ) : void
OnCharAdded ( object sender, CharAddedEventArgs e ) : void
OnDoubleClick ( object sender, DoubleClickEventArgs e ) : void
OnFileActivated ( object sender, FileEventArgs e ) : void
OnFileClosed ( object sender, FileEventArgs e ) : void
OnFileClosing ( object sender, FileEventArgs e ) : void
OnFileLoadFailed ( object sender, EventArgs e ) : void
OnFileLoading ( object sender, EventArgs e ) : void
OnFileOpened ( object sender, FileEventArgs e ) : void
OnFileOpening ( object sender, FileEventArgs e ) : void
OnFileOrderChanged ( object sender, FileEventArgs e ) : void
OnFileSaved ( object sender, FileEventArgs e ) : void
OnFileSaving ( object sender, FileEventArgs e ) : void
OnLanguageChanged ( object sender, LanguageTypeEventArgs e ) : void
OnModification ( object sender, ModifiedEventArgs e ) : void
OnReady ( object sender, EventArgs e ) : void
OnShutdown ( object sender, EventArgs e ) : void
OnStyleUpdate ( object sender, FileEventArgs e ) : void

Method Details

Append() public method

Appends text to the end of the document without affecting the selection.
public Append ( string text ) : void
text string The text to be appended.
return void

CancelAutoCompletion() public method

Cancels any active auto-completion.
public CancelAutoCompletion ( ) : void
return void

Clear() public method

Deletes the selected text.
public Clear ( ) : void
return void

ClearAll() public method

Clears all text out of the document.
public ClearAll ( ) : void
return void

Copy() public method

Copies the selected text to the clipboard.
public Copy ( ) : void
return void

Copy() public method

Copies the specified text range into the clipboard.
public Copy ( TextLocation start, TextLocation end ) : void
start TextLocation The starting position.
end TextLocation The ending position (exclusive).
return void

Copy() public method

Copies the specified text range into the clipboard.
public Copy ( TextLocation start, int numChars ) : void
start TextLocation The starting position.
numChars int The number of characters to be copied.
return void

Copy() public method

Copies the provided string into the clipboard.
public Copy ( string text ) : void
text string The text to be placed into to the clipboard.
return void

CopyAllowLine() public method

Copies the selected text to the clipboard. If no text is selected, the current line is copied instead.
public CopyAllowLine ( ) : void
return void

Cut() public method

Cuts the selected text to the clipboard.
public Cut ( ) : void
return void

DockWindow() public method

Creates a docked window.

This window will not be restored the next time Notepad++ starts. The plugin must recreate the window during the 'Ready' event, if it wishes to have the window visible again.

Notepad++ will use the ID to remember the state for this docked window between sessions. If another docked window with the same ID had been opened previously with a different alignment, or the user had dragged the window to another side of the screen, then the docked window will appear in the previous location rather than the one specified here.

public DockWindow ( IWin32Window window, string title, DockWindowAlignment alignment, int id ) : IDockWindow
window IWin32Window The form window that is to be docked.
title string The window title.
alignment DockWindowAlignment Window alignment, or floating.
id int An identifier for this docked window. /// The ID must be greater than zero.
return IDockWindow

FindColumn() public method

Gets the position that corresponds to a line and column.
public FindColumn ( int line, int column ) : TextLocation
line int The one-based line number.
column int The one-based column number.
return TextLocation

FocusEditor() public method

Sets the focus to the current editor window.
public FocusEditor ( ) : void
return void

GetActiveFileIndex() public method

Gets the current document index in the specified view.
public GetActiveFileIndex ( EditorView view ) : int
view EditorView The view in which the active file index will be retrieved.
return int

GetDockWindow() public method

Gets the dock window object for the specified ID.
public GetDockWindow ( int id ) : IDockWindow
id int The ID number for the dock window object.
return IDockWindow

GetFileNames() public method

Gets a list of open file names in the specified view.
To get a list of all open file names in both views, you can use the 'FileNames' property.
public GetFileNames ( EditorView view ) : IEnumerable
view EditorView The editor view to retrieve the list of open file names.
return IEnumerable

GetLanguageName() public method

Gets the name of a language, given the ID.
public GetLanguageName ( int langId ) : string
langId int The language ID.
return string

GetLineEndPos() public method

Gets the ending position of the specified line, before any line-end characters.
public GetLineEndPos ( int line ) : TextLocation
line int The one-based line number.
return TextLocation

GetLineLength() public method

Gets the length of the specified line (excluding line-end characters).
public GetLineLength ( int line ) : int
line int The one-based line number.
return int

GetLineStartPos() public method

Gets the starting position of the specified line.
public GetLineStartPos ( int line ) : TextLocation
line int The one-based line number.
return TextLocation

GetLineText() public method

Gets the text for the specified line.
public GetLineText ( int line ) : string
line int The one-based line number.
return string

GetLineText() public method

Gets the text for the specified line, optionally including line-end characters.
public GetLineText ( int line, bool includeLineEndChars ) : string
line int The one-based line number.
includeLineEndChars bool If true, the returned string will contain the line-end characters.
return string

GetText() public method

Gets the text for the specified range.
public GetText ( TextLocation start, TextLocation end ) : string
start TextLocation The starting position.
end TextLocation The ending position (exclusive).
return string

GetText() public method

Gets the text for the specified range.
public GetText ( TextLocation start, int numChars ) : string
start TextLocation The starting position.
numChars int The number of characters to retrieve.
return string

GetWordEndPos() public method

Gets the position at the end of the current word.
public GetWordEndPos ( TextLocation pos, bool onlyWordChars ) : TextLocation
pos TextLocation The starting position.
onlyWordChars bool If true, only word characters will be jumped. /// If false, all characters will be jumped.
return TextLocation

GetWordStartPos() public method

Gets the position at the start of the current word.
public GetWordStartPos ( TextLocation pos, bool onlyWordChars ) : TextLocation
pos TextLocation The starting position.
onlyWordChars bool If true, only word characters will be jumped. /// If false, all characters will be jumped.
return TextLocation

GoTo() public method

Goes to the specified position and ensures it is visible.
public GoTo ( TextLocation pos ) : void
pos TextLocation The position to go to.
return void

GoToLine() public method

Goes to the specified line and ensures it is visible.
public GoToLine ( int line ) : void
line int The line to go to.
return void

Insert() public method

Inserts text over the current selection. The caret is placed after the inserted text and scrolled into view.
public Insert ( string text ) : void
text string The text to be inserted.
return void

LaunchFindInFiles() public method

Launches the 'Find in Files' dialog.
public LaunchFindInFiles ( string dir, string filters ) : void
dir string The directory to be searched.
filters string The file filters to be searched.
return void

MenuCommand() public method

Triggers a menu item command.
public MenuCommand ( MenuCommand command ) : void
command MenuCommand The ID of the command to be triggered.
return void

MenuCommand() public method

Triggers a menu item command.
public MenuCommand ( int commandId ) : void
commandId int The ID of the command to be triggered.
return void

MoveCaretInsideView() public method

If the caret is outside the current view, it is moved to the nearest visible line. Any selection is lost.
public MoveCaretInsideView ( ) : void
return void

MoveSelectedLinesDown() public method

Moves the selected lines down one line, shifting the line below the selection.
public MoveSelectedLinesDown ( ) : void
return void

MoveSelectedLinesUp() public method

Moves the selected lines up one line, shifting the line above the selection.
public MoveSelectedLinesUp ( ) : void
return void

OnLoad() protected method

Called after the object has been created and initialized, but before the Notepad++ Ready notification.
protected OnLoad ( ) : void
return void

OpenFile() public method

Opens a new file. If the file is already open, it will be made active.
public OpenFile ( string fileName ) : bool
fileName string The pathname of the file to be opened.
return bool

Paste() public method

Pastes the clipboard text over the selection.
public Paste ( ) : void
return void

PointToPos() public method

Finds the position closest to a point on the screen.
public PointToPos ( Point pt ) : TextLocation
pt Point The client coordinates of the point to test.
return TextLocation

PointToPosClose() public method

Finds the position closest to a point on the screen.
public PointToPosClose ( Point pt, TextLocation &location ) : bool
pt Point The client coordinates of the point to test.
location TextLocation An out parameter to receive the found location.
return bool

PosToPoint() public method

Returns the x and y display location of the position.
public PosToPoint ( TextLocation pos ) : Point
pos TextLocation The position to find.
return Point

RefreshCustomLexers() public method

Refreshes the word-styles and folding on documents that use a custom lexer provided via NppSharp.
This function is useful if your lexers providing highlighting that can change, and need to be refreshed at certain events.
public RefreshCustomLexers ( ) : void
return void

ReloadFile() public method

Reloads the current file.
public ReloadFile ( bool withAlert ) : void
withAlert bool If true, Notepad++ will show an alert box to confirm.
return void

ReloadFile() public method

Reloads a file given the file name. If the file is not already open, then this has no effect.
public ReloadFile ( string fileName, bool withAlert ) : void
fileName string The pathname of the file to be reloaded.
withAlert bool If true, Notepad++ will show an alert box to confirm.
return void

SaveAllFiles() public method

Saves all open documents.
public SaveAllFiles ( ) : bool
return bool

SaveFile() public method

Saves the current document.
public SaveFile ( ) : bool
return bool

SaveFileAs() public method

Saves the current document to another file name.
public SaveFileAs ( string fileName ) : bool
fileName string The pathname of the file to be written.
return bool

SaveFileCopyAs() public method

Saves a copy of the current document to another file name.
public SaveFileCopyAs ( string fileName ) : bool
fileName string The pathname of the file to be written.
return bool

SelectAll() public method

Selects all text in the document. (The caret is not scrolled into view)
public SelectAll ( ) : void
return void

SetActiveFileIndex() public method

Switches to the file in the specified view.
public SetActiveFileIndex ( EditorView view, int index ) : void
view EditorView The view in which the file is to be switched.
index int Zero-based index of the view to switch to.
return void

SetEmptySelection() public method

Removes the selection and sets the caret at pos. (The caret is not scrolled into view)
public SetEmptySelection ( TextLocation pos ) : void
pos TextLocation The new start/end position for the selection.
return void

SetSelection() public method

Sets the selection range. (The caret is scrolled into view)
public SetSelection ( TextLocation anchorPos, TextLocation currentPos ) : void
anchorPos TextLocation The selection anchor position.
currentPos TextLocation The selection current position.
return void

ShowAutoCompletion() public method

Shows the AutoCompletion list.
public ShowAutoCompletion ( int lengthEntered, IEnumerable list ) : void
lengthEntered int The number of characters already entered by the user.
list IEnumerable The list of words.
return void

ShowAutoCompletion() public method

Shows the AutoCompletion list.
public ShowAutoCompletion ( int lengthEntered, IEnumerable list, bool ignoreCase ) : void
lengthEntered int The number of characters already entered by the user.
list IEnumerable The list of words.
ignoreCase bool Ignore case?
return void

ShowError() public method

Displays an error message caused by an exception.
public ShowError ( Exception ex ) : void
ex System.Exception The exception that caused the error.
return void

ShowError() public method

Displays an error message caused by an exception, with additional text.
public ShowError ( Exception ex, string message ) : void
ex System.Exception The exception that caused the error (will be displayed in details tab).
message string Additional text to be displayed in message tab.
return void

ShowError() public method

Displays an error message.
public ShowError ( string message ) : void
message string The message to be displayed.
return void

SwitchToFile() public method

Switches to a file given the file name.
public SwitchToFile ( string fileName ) : bool
fileName string The pathname of the file to be brought current.
return bool