Browse files

Improvements for lexers and open file handling.

  • Loading branch information...
1 parent 527c374 commit 8be4c36718dd1e3c74ff8ddbcccacfb8e0d77684 @cmrazek committed Jul 14, 2012
View
2 NppSharp/AssemblyInfo.cpp
@@ -31,7 +31,7 @@ using namespace System::Security::Permissions;
// You can specify all the value or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly:AssemblyVersionAttribute("1.0.3.1")];
+[assembly:AssemblyVersionAttribute("1.0.3.2")];
[assembly:ComVisible(false)];
View
36 NppSharp/LexerWrapper.cpp
@@ -24,9 +24,12 @@
namespace NppSharp
{
+ std::list<LexerWrapper*> LexerWrapper::_activeLexers;
+
LexerWrapper::LexerWrapper(NppSharp::ILexer^ clrLexer)
: _clrLexer(clrLexer)
{
+ _activeLexers.push_back(this);
}
LexerWrapper::~LexerWrapper()
@@ -40,6 +43,7 @@ namespace NppSharp
void LexerWrapper::Release()
{
+ _activeLexers.remove(this);
delete this;
}
@@ -247,4 +251,36 @@ namespace NppSharp
{
return NULL;
}
+
+ void LexerWrapper::Refresh()
+ {
+ if (_doc)
+ {
+ _doc->StartStyling(0, 31);
+ _doc->ChangeLexerState(0, _doc->Length());
+ }
+ }
+
+ void LexerWrapper::RefreshAllLexers()
+ {
+ for (std::list<LexerWrapper*>::iterator i = _activeLexers.begin(), ii = _activeLexers.end(); i != ii; ++i)
+ {
+ try
+ {
+ (*i)->Refresh();
+ }
+#ifdef _DEBUG
+ catch (std::exception ex)
+ {
+ WriteOutputLine(OutputStyle::Error, String::Format("STD exception when refreshing lexer: {0}", gcnew String(ex.what())));
+ }
+#endif
+ catch (...)
+ {
+#ifdef _DEBUG
+ WriteOutputLine(OutputStyle::Error, "Exception when refreshing lexer.");
+#endif
+ }
+ }
+ }
}
View
7 NppSharp/LexerWrapper.h
@@ -38,11 +38,16 @@ namespace NppSharp
virtual void SCI_METHOD Fold(unsigned int startPos, int lengthDoc, int initStyle, npp::IDocument *pAccess);
virtual void * SCI_METHOD PrivateCall(int operation, void *pointer);
- NppSharp::ILexer^ GetLexer() { return _clrLexer; }
+ NppSharp::ILexer^ GetLexer() { return _clrLexer; }
+ void Refresh();
+
+ static void RefreshAllLexers();
private:
gcroot<NppSharp::ILexer^> _clrLexer;
npp::IDocument* _doc;
+
+ static std::list<LexerWrapper*> _activeLexers;
};
ref class LexerInfo
View
2 NppSharp/NppInterface.h
@@ -52,6 +52,7 @@ namespace NppSharp
virtual property String^ FileName { String^ get(); }
virtual property int FileCount { int get(); }
virtual property IEnumerable<String^>^ FileNames { IEnumerable<String^>^ get(); }
+ virtual IEnumerable<String^>^ GetFileNames(EditorView view);
virtual bool OpenFile(String^ fileName);
virtual property int ActiveFileIndex { int get(); void set(int); }
virtual int GetActiveFileIndex(EditorView view);
@@ -170,6 +171,7 @@ namespace NppSharp
// Lexer functions
virtual int AddLexer(Type^ lexerType, String^ name, String^ description);
+ virtual void RefreshCustomLexers();
int GetLexerCount();
String^ GetLexerName(int index);
String^ GetLexerDescription(int index);
View
35 NppSharp/Npp_Editor.cpp
@@ -132,6 +132,41 @@ namespace NppSharp
return list;
}
+ IEnumerable<String^>^ NppInterface::GetFileNames(EditorView view)
+ {
+ int numFiles;
+ unsigned int getOpenFileNamesMsg;
+
+ if (view == EditorView::Main)
+ {
+ numFiles = ::SendMessageW(_nppHandle, NPPM_GETNBOPENFILES, 0, PRIMARY_VIEW);
+ getOpenFileNamesMsg = NPPM_GETOPENFILENAMESPRIMARY;
+ }
+ else
+ {
+ numFiles = ::SendMessageW(_nppHandle, NPPM_GETNBOPENFILES, 0, SECOND_VIEW);
+ getOpenFileNamesMsg = NPPM_GETOPENFILENAMESSECOND;
+ }
+
+ wchar_t *pBuf = new wchar_t[numFiles * MAX_PATH];
+ wchar_t **ppFileNames = new wchar_t*[numFiles];
+
+ for (int i = 0; i < numFiles; i++)
+ {
+ ppFileNames[i] = pBuf + i * MAX_PATH;
+ }
+
+ numFiles = ::SendMessageW(_nppHandle, getOpenFileNamesMsg, (WPARAM)ppFileNames, numFiles);
+
+ List<String^>^ list = gcnew List<String^>(numFiles);
+ for (int i = 0; i < numFiles; i++) list->Add(gcnew String(ppFileNames[i]));
+
+ delete pBuf;
+ delete [] ppFileNames;
+
+ return list;
+ }
+
bool NppInterface::OpenFile(String^ fileName)
{
pin_ptr<const wchar_t> str = PtrToStringChars(fileName);
View
5 NppSharp/Npp_Lexer.cpp
@@ -57,6 +57,11 @@ namespace NppSharp
}
}
+ void NppInterface::RefreshCustomLexers()
+ {
+ LexerWrapper::RefreshAllLexers();
+ }
+
int NppInterface::GetLexerCount()
{
return _lexers->Count;
View
16 NppSharpCS/INpp.cs
@@ -226,11 +226,20 @@ public interface INpp
int FileCount { get; }
/// <summary>
- /// Gets a complete list of file names for open files.
+ /// Gets a complete list of file names for open files in both views.
/// </summary>
+ /// <remarks>To get a list of files open in a single view, you can use the GetFileNames method.</remarks>
IEnumerable<string> FileNames { get; }
/// <summary>
+ /// Gets a list of open file names in the specified view.
+ /// </summary>
+ /// <param name="view">The editor view to retrieve the list of open file names.</param>
+ /// <returns>A list of file names for the open files.</returns>
+ /// <remarks>To get a list of all open file names in both views, you can use the 'FileNames' property.</remarks>
+ IEnumerable<string> GetFileNames(EditorView view);
+
+ /// <summary>
/// Opens a new file. If the file is already open, it will be made active.
/// </summary>
/// <param name="fileName">The pathname of the file to be opened.</param>
@@ -682,6 +691,11 @@ public interface INpp
/// <param name="description">The description of the lexer to appear in the Notepad++ status bar.</param>
/// <returns>The zero-based index of the lexer object.</returns>
int AddLexer(Type lexerType, string name, string description);
+
+ /// <summary>
+ /// Refreshes the word-styles and folding on documents that use a custom lexer provided via NppSharp.
+ /// </summary>
+ void RefreshCustomLexers();
#endregion
}
View
28 NppSharpCS/NppScript.cs
@@ -193,14 +193,26 @@ public int FileCount
}
/// <summary>
- /// Gets a complete list of file names for open files.
+ /// Gets a complete list of file names for open files in both views.
/// </summary>
+ /// <remarks>To get a list of files open in a single view, you can use the GetFileNames method.</remarks>
public IEnumerable<string> FileNames
{
get { return Plugin.NppIntf.FileNames; }
}
/// <summary>
+ /// Gets a list of open file names in the specified view.
+ /// </summary>
+ /// <param name="view">The editor view to retrieve the list of open file names.</param>
+ /// <returns>A list of file names for the open files.</returns>
+ /// <remarks>To get a list of all open file names in both views, you can use the 'FileNames' property.</remarks>
+ public IEnumerable<string> GetFileNames(EditorView view)
+ {
+ return Plugin.NppIntf.GetFileNames(view);
+ }
+
+ /// <summary>
/// Opens a new file. If the file is already open, it will be made active.
/// </summary>
/// <param name="fileName">The pathname of the file to be opened.</param>
@@ -991,5 +1003,19 @@ public IDockWindow GetDockWindow(int id)
return Plugin.NppIntf.GetDockWindow(id);
}
#endregion
+
+ #region Lexers
+ /// <summary>
+ /// Refreshes the word-styles and folding on documents that use a custom lexer provided via NppSharp.
+ /// </summary>
+ /// <remarks>
+ /// This function is useful if your lexers providing highlighting that can change,
+ /// and need to be refreshed at certain events.
+ /// </remarks>
+ public void RefreshCustomLexers()
+ {
+ Plugin.NppIntf.RefreshCustomLexers();
+ }
+ #endregion
}
}
View
4 NppSharpCS/Properties/AssemblyInfo.cs
@@ -31,5 +31,5 @@
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
-[assembly: AssemblyVersion("1.0.3.1")]
-[assembly: AssemblyFileVersion("1.0.3.1")]
+[assembly: AssemblyVersion("1.0.3.2")]
+[assembly: AssemblyFileVersion("1.0.3.2")]
View
5 README
@@ -41,6 +41,5 @@ Version 1.0.4:
- DockWindow function now returns an IDockWindow object which can be used to show/hide the window.
Note: If you have existing .NET asemblies that call DockWindow(), you will need to recompile
your assembly with the updated version of NppSharpInterface.dll.
-- Added EditorWindow properties that can be used to directly access the Notepad++ editor window.
-- Added FocusEditor() to set the focus to the editor.
-- Added ConfigDirectory property.
+- Added new methods/properties:
+ EditorWindow, FocusEditor(), ConfigDirectory, RefreshAllLexers(), GetFileNames()
View
5 README.markdown
@@ -43,6 +43,5 @@ Version 1.0.4:
- DockWindow function now returns an IDockWindow object which can be used to show/hide the window.
Note: If you have existing .NET asemblies that call DockWindow(), you will need to recompile
your assembly with the updated version of NppSharpInterface.dll.
-- Added EditorWindow properties that can be used to directly access the Notepad++ editor window.
-- Added FocusEditor() to set the focus to the editor.
-- Added ConfigDirectory property.
+- Added new methods/properties:
+ EditorWindow, FocusEditor(), ConfigDirectory, RefreshAllLexers(), GetFileNames()
View
2 Setup/NppSharpSetup.nsi
@@ -3,7 +3,7 @@
;---------------------------------------------------------------------------------------------------
Name "NppSharp"
-OutFile "Output\NppSharp_Setup_1.0.3.1.exe"
+OutFile "Output\NppSharp_Setup_1.0.3.2.exe"
InstallDir "$PROGRAMFILES32\Notepad++"
;---------------------------------------------------------------------------------------------------

0 comments on commit 8be4c36

Please sign in to comment.