Permalink
Browse files

Merge commit '74dc856c857199cfeccf22807ebe84c694ec4129' into DotNet2

Conflicts:
	NppSharp/LexerWrapper.cpp
	Setup/NppSharpSetup.nsi
  • Loading branch information...
cmrazek committed Oct 7, 2012
2 parents a133a46 + 74dc856 commit 8b03d469ea955cb8522dc2c30ca7f320f2601234
@@ -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.1.0.0")];
+[assembly:AssemblyVersionAttribute("1.1.0.1")];
[assembly:ComVisible(false)];
View
@@ -106,7 +106,8 @@ namespace NppSharp
int state = line > 0 ? _doc->GetLineState(line - 1) : 0;
int codePage = _doc->CodePage();
LexerLine^ lineObj = gcnew LexerLine();
- int foldLevel = line > 0 ? (_doc->GetLevel(line - 1) & SC_FOLDLEVELNUMBERMASK) : SC_FOLDLEVELBASE;
+ int foldLevel = line > 0 ? (_doc->GetLevel(line - 1) >> 16) : SC_FOLDLEVELBASE;
+ int nextFoldLevel = foldLevel;
while (pszPos < pszEnd)
{
@@ -132,16 +133,17 @@ namespace NppSharp
_doc->SetLineState(line, state);
// Apply fold level state
+ // High 16-bits contains the fold level for the next line, so when the user starts typing on a line,
+ // it knows what the fold level should be without having to go back and look.
int foldStarts = lineObj->FoldStarts;
int foldEnds = lineObj->FoldEnds;
+ nextFoldLevel = foldLevel + foldStarts - foldEnds;
+ if (nextFoldLevel < SC_FOLDLEVELBASE) nextFoldLevel = SC_FOLDLEVELBASE;
- foldLevel -= foldEnds;
+ foldLevel = (nextFoldLevel << 16) | foldLevel;
if (foldStarts) foldLevel |= SC_FOLDLEVELHEADERFLAG;
- if (lineObj->IsBlank) foldLevel |= SC_FOLDLEVELWHITEFLAG;
_doc->SetLevel(line, foldLevel);
-
- foldLevel += foldStarts;
- foldLevel &= SC_FOLDLEVELNUMBERMASK;
+ foldLevel = nextFoldLevel;
// Advance to next line.
line++;
View
@@ -269,6 +269,10 @@ namespace NppSharp
(pNotify->modifiers & SCMOD_ALT) != 0,
(pNotify->modifiers & SCMOD_SHIFT) != 0);
break;
+
+ case SCN_MODIFIED:
+ g.npp->OnModified(pNotify);
+ break;
}
}
catch (Exception^ ex)
View
@@ -18,6 +18,7 @@
#include "NppInterface.h"
#include <vcclr.h>
#include "OutputWindow.h"
+#include "TextPtrA.h"
namespace NppSharp
{
@@ -215,6 +216,30 @@ namespace NppSharp
DoubleClick(this, gcnew DoubleClickEventArgs(pos, ctrl, alt, shift));
}
+ void NppInterface::OnModified(npp::SCNotification *pNotify)
+ {
+ if (pNotify->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT))
+ {
+ int codePage;
+ if (pNotify->nmhdr.hwndFrom == NULL) codePage = 0;
+ else codePage = ::SendMessageA((HWND)pNotify->nmhdr.hwndFrom, SCI_GETCODEPAGE, 0, 0);
+
+ TextPtrA^ textPtr = gcnew TextPtrA(pNotify->text, pNotify->length, codePage);
+
+ // ModifiedEventArgs(ModificationType type, string text, TextLocation location, bool userAction, bool undo, bool redo, int linesAdded)
+ ModifiedEventArgs^ e = gcnew ModifiedEventArgs(
+ (pNotify->modificationType & SC_MOD_INSERTTEXT) ? ModificationType::Insert : ModificationType::Delete,
+ textPtr,
+ TextLocation::FromByteOffset(pNotify->position),
+ (pNotify->modificationType & SC_PERFORMED_USER) != 0,
+ (pNotify->modificationType & SC_PERFORMED_UNDO) != 0,
+ (pNotify->modificationType & SC_PERFORMED_REDO) != 0,
+ pNotify->linesAdded);
+
+ Modification(this, e);
+ }
+ }
+
void NppInterface::ExecuteCommandByIndex(int cmdIndex)
{
if (cmdIndex < 0 || cmdIndex >= _commands->Count) return;
View
@@ -132,6 +132,7 @@ namespace NppSharp
void OnFileOrderChanged(unsigned int bufferId);
void OnCharAdded(int ch);
void OnDoubleClick(int pos, bool ctrl, bool alt, bool shift);
+ void OnModified(npp::SCNotification *pNotify);
virtual event NppEventHandler^ GetCommands;
virtual event NppEventHandler^ RegisterToolbarIcons;
@@ -152,6 +153,7 @@ namespace NppSharp
virtual event ExecuteCommandEventHandler^ CommandExecuted;
virtual event CharAddedEventHandler^ CharAdded;
virtual event DoubleClickEventHandler^ DoubleClick;
+ virtual event ModifiedEventHandler^ Modification;
virtual void ShowOutputWindow();
virtual void HideOutputWindow();
@@ -142,6 +142,7 @@
<ClInclude Include="LexerLine.h" />
<ClInclude Include="LexerWrapper.h" />
<ClInclude Include="OutputWindow.h" />
+ <ClInclude Include="TextPtrA.h" />
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp" />
@@ -162,6 +163,7 @@
<ClCompile Include="Npp_Lexer.cpp" />
<ClCompile Include="Npp_OutputWindow.cpp" />
<ClCompile Include="OutputWindow.cpp" />
+ <ClCompile Include="TextPtrA.cpp" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
@@ -96,6 +96,9 @@
<ClInclude Include="OutputWindow.h">
<Filter>OutputWindow</Filter>
</ClInclude>
+ <ClInclude Include="TextPtrA.h">
+ <Filter>Core</Filter>
+ </ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="AssemblyInfo.cpp">
@@ -143,5 +146,8 @@
<ClCompile Include="Npp_AutoCompletion.cpp">
<Filter>AutoCompletion</Filter>
</ClCompile>
+ <ClCompile Include="TextPtrA.cpp">
+ <Filter>Core</Filter>
+ </ClCompile>
</ItemGroup>
</Project>
View
@@ -0,0 +1,47 @@
+// NppSharp - C#/.NET Scripting Plugin for Notepad++
+// Copyright (C) 2012 Chris Mrazek
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#include "Stdafx.h"
+#include "TextPtrA.h"
+#include "ClrUtil.h"
+
+using namespace System::Runtime::InteropServices;
+
+namespace NppSharp
+{
+ TextPtrA::TextPtrA(const char* ptr, int length, int codePage)
+ : _ptr(ptr)
+ , _length(length)
+ , _codePage(codePage)
+ , _str(nullptr)
+ {
+ }
+
+ String^ TextPtrA::Text::get()
+ {
+ if (_str != nullptr) return _str;
+
+ if (_codePage == SC_CP_UTF8)
+ {
+ _str = NativeUtf8ToClrString(_ptr, _length);
+ }
+ else
+ {
+ _str = Marshal::PtrToStringAnsi((IntPtr)(void*)_ptr, _length);
+ }
+ return _str;
+ }
+}
View
@@ -0,0 +1,34 @@
+// NppSharp - C#/.NET Scripting Plugin for Notepad++
+// Copyright (C) 2012 Chris Mrazek
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#pragma once
+
+namespace NppSharp
+{
+ public ref class TextPtrA : public TextPtr
+ {
+ public:
+ TextPtrA(const char* ptr, int length, int codePage);
+
+ virtual property String^ Text { String^ get() override; }
+
+ private:
+ const char* _ptr;
+ int _length;
+ int _codePage;
+ String^ _str;
+ };
+}
View
@@ -187,6 +187,11 @@ public interface INpp
/// Triggered when the user double-clicks inside a document.
/// </summary>
event DoubleClickEventHandler DoubleClick;
+
+ /// <summary>
+ /// Triggered when the active document is modified.
+ /// </summary>
+ event ModifiedEventHandler Modification;
#endregion
#region Editor
@@ -975,6 +980,91 @@ public DoubleClickEventArgs(int pos, bool ctrl, bool alt, bool shift)
/// </summary>
public bool Shift { get; private set; }
}
+
+ /// <summary>
+ /// A type of document modification performed.
+ /// </summary>
+ public enum ModificationType
+ {
+ /// <summary>
+ /// Text was inserted into the document.
+ /// </summary>
+ Insert,
+
+ /// <summary>
+ /// Text was deleted from the document.
+ /// </summary>
+ Delete
+ }
+
+ /// <summary>
+ /// Handler for modified events.
+ /// </summary>
+ /// <param name="sender">Object that sends the event.</param>
+ /// <param name="e">Arguments provided for this event.</param>
+ public delegate void ModifiedEventHandler(object sender, ModifiedEventArgs e);
+
+ /// <summary>
+ /// Arguments for modified events.
+ /// </summary>
+ public class ModifiedEventArgs : EventArgs
+ {
+ /// <summary>
+ /// Gets the type of modification that occurred.
+ /// </summary>
+ public ModificationType ModificationType { get; private set; }
+
+ /// <summary>
+ /// Gets the text inserted or deleted.
+ /// </summary>
+ public TextPtr Text { get; private set; }
+
+ /// <summary>
+ /// Gets the location of the modification.
+ /// </summary>
+ public TextLocation Location { get; private set; }
+
+ /// <summary>
+ /// Gets a value indicating if this action was caused by the user.
+ /// </summary>
+ public bool UserAction { get; private set; }
+
+ /// <summary>
+ /// Gets a value indicating if this action is part of an undo process.
+ /// </summary>
+ public bool Undo { get; private set; }
+
+ /// <summary>
+ /// Gets a value indicating if this action is part of a redo process.
+ /// </summary>
+ public bool Redo { get; private set; }
+
+ /// <summary>
+ /// Gets the number of lines added by this modification.
+ /// </summary>
+ public int LinesAdded { get; private set; }
+
+ /// <summary>
+ /// Creates the event arguments object.
+ /// </summary>
+ /// <param name="type">The type of modification that occurred.</param>
+ /// <param name="text">The text inserted or deleted.</param>
+ /// <param name="location">The location of the modification.</param>
+ /// <param name="userAction">A flag indicating if this action was caused by the user.</param>
+ /// <param name="undo">A flag indicating if this action is part of an undo process.</param>
+ /// <param name="redo">A flag indicating if this action is part of a redo process.</param>
+ /// <param name="linesAdded">The number of lines added by this modification.</param>
+ public ModifiedEventArgs(ModificationType type, TextPtr text, TextLocation location, bool userAction, bool undo, bool redo, int linesAdded)
+ {
+ ModificationType = type;
+ Text = text;
+ Location = location;
+ UserAction = userAction;
+ Undo = undo;
+ Redo = redo;
+ LinesAdded = linesAdded;
+ }
+ }
#endregion
/// <summary>
View
@@ -885,6 +885,11 @@ public void MoveSelectedLinesDown()
/// </summary>
public event DoubleClickEventHandler DoubleClick;
+ /// <summary>
+ /// Triggered when the active document is modified.
+ /// </summary>
+ public event ModifiedEventHandler Modification;
+
internal void InitEvents()
{
INpp npp = Plugin.NppIntf;
@@ -905,6 +910,7 @@ internal void InitEvents()
npp.FileOrderChanged += OnFileOrderChanged;
npp.CharAdded += OnCharAdded;
npp.DoubleClick += OnDoubleClick;
+ npp.Modification += OnModification;
}
/// <summary>
@@ -1010,6 +1016,12 @@ internal void OnDoubleClick(object sender, DoubleClickEventArgs e)
DoubleClickEventHandler ev = DoubleClick;
if (ev != null) ev(this, e);
}
+
+ internal void OnModification(object sender, ModifiedEventArgs e)
+ {
+ ModifiedEventHandler ev = Modification;
+ if (ev != null) ev(this, e);
+ }
#endregion
#region Dock Window
@@ -76,6 +76,7 @@
<Compile Include="IDockWindow.cs" />
<Compile Include="ILexer.cs" />
<Compile Include="ILexerLine.cs" />
+ <Compile Include="TextPtr.cs" />
<Compile Include="LexerCommentsAttribute.cs" />
<Compile Include="LexerException.cs" />
<Compile Include="LexerStyle.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.1.0.0")]
-[assembly: AssemblyFileVersion("1.1.0.0")]
+[assembly: AssemblyVersion("1.1.0.1")]
+[assembly: AssemblyFileVersion("1.1.0.1")]
Oops, something went wrong.

0 comments on commit 8b03d46

Please sign in to comment.