Browse Source

Implemented TextEditorSideBar for AvalonEdit.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4929 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 16 years ago
parent
commit
d4068f0087
  1. 6
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj
  2. 13
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs
  3. 9
      src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs
  4. 9
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs
  5. 39
      src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs
  6. 10
      src/Main/Base/Project/Src/Gui/Components/SideBar/TextEditorSideBar.cs

6
src/AddIns/DisplayBindings/AvalonEdit.AddIn/AvalonEdit.AddIn.csproj

@ -50,6 +50,7 @@
<Reference Include="System.Core"> <Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework> <RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="WindowsBase"> <Reference Include="WindowsBase">
<RequiredTargetFramework>3.0</RequiredTargetFramework> <RequiredTargetFramework>3.0</RequiredTargetFramework>
@ -116,5 +117,10 @@
<Page Include="Src\QuickClassBrowser.xaml"> <Page Include="Src\QuickClassBrowser.xaml">
<DependentUpon>QuickClassBrowser.cs</DependentUpon> <DependentUpon>QuickClassBrowser.cs</DependentUpon>
</Page> </Page>
<ProjectReference Include="..\..\..\Main\ICSharpCode.SharpDevelop.Widgets\Project\ICSharpCode.SharpDevelop.Widgets.csproj">
<Project>{8035765F-D51F-4A0C-A746-2FD100E19419}</Project>
<Name>ICSharpCode.SharpDevelop.Widgets</Name>
<Private>False</Private>
</ProjectReference>
</ItemGroup> </ItemGroup>
</Project> </Project>

13
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/AvalonEditViewContent.cs

@ -21,7 +21,8 @@ using System.Windows.Threading;
namespace ICSharpCode.AvalonEdit.AddIn namespace ICSharpCode.AvalonEdit.AddIn
{ {
public class AvalonEditViewContent : AbstractViewContent, IEditable, IMementoCapable, ITextEditorProvider, IPositionable, IParseInformationListener public class AvalonEditViewContent
: AbstractViewContent, IEditable, IMementoCapable, ITextEditorProvider, IPositionable, IParseInformationListener, IToolsHost
{ {
readonly CodeEditor codeEditor = new CodeEditor(); readonly CodeEditor codeEditor = new CodeEditor();
@ -33,6 +34,12 @@ namespace ICSharpCode.AvalonEdit.AddIn
file.ForceInitializeView(this); file.ForceInitializeView(this);
codeEditor.Document.Changed += textEditor_Document_Changed; codeEditor.Document.Changed += textEditor_Document_Changed;
codeEditor.CaretPositionChanged += CaretChanged; codeEditor.CaretPositionChanged += CaretChanged;
codeEditor.TextCopied += codeEditor_TextCopied;
}
void codeEditor_TextCopied(object sender, ICSharpCode.AvalonEdit.Editing.TextEventArgs e)
{
TextEditorSideBar.Instance.PutInClipboardRing(e.Text);
} }
void textEditor_Document_Changed(object sender, DocumentChangeEventArgs e) void textEditor_Document_Changed(object sender, DocumentChangeEventArgs e)
@ -248,5 +255,9 @@ namespace ICSharpCode.AvalonEdit.AddIn
})); }));
} }
#endregion #endregion
object IToolsHost.ToolsContent {
get { return TextEditorSideBar.Instance; }
}
} }
} }

9
src/AddIns/DisplayBindings/AvalonEdit.AddIn/Src/CodeEditor.cs

@ -193,10 +193,19 @@ namespace ICSharpCode.AvalonEdit.AddIn
textEditor.TextArea.TextView.MouseRightButtonDown += TextViewMouseRightButtonDown; textEditor.TextArea.TextView.MouseRightButtonDown += TextViewMouseRightButtonDown;
textEditor.TextArea.TextView.ContextMenuOpening += TextViewContextMenuOpening; textEditor.TextArea.TextView.ContextMenuOpening += TextViewContextMenuOpening;
textEditor.TextArea.TextCopied += textEditor_TextArea_TextCopied;
return textEditor; return textEditor;
} }
public event EventHandler<TextEventArgs> TextCopied;
void textEditor_TextArea_TextCopied(object sender, TextEventArgs e)
{
if (TextCopied != null)
TextCopied(this, e);
}
protected virtual void DisposeTextEditor(TextEditor textEditor) protected virtual void DisposeTextEditor(TextEditor textEditor)
{ {
// detach IconBarMargin from IconBarManager // detach IconBarMargin from IconBarManager

9
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/EditingCommandHandler.cs

@ -307,6 +307,10 @@ namespace ICSharpCode.AvalonEdit.Editing
static void CopySelectedText(TextArea textArea) static void CopySelectedText(TextArea textArea)
{ {
Clipboard.SetDataObject(textArea.Selection.CreateDataObject(textArea), true); Clipboard.SetDataObject(textArea.Selection.CreateDataObject(textArea), true);
string text = textArea.Selection.GetText(textArea.Document);
text = NewLineFinder.NormalizeNewLines(text, Environment.NewLine);
textArea.OnTextCopied(new TextEventArgs(text));
} }
const string LineSelectedType = "MSDEVLineSelect"; // This is the type VS 2003 and 2005 use for flagging a whole line copy const string LineSelectedType = "MSDEVLineSelect"; // This is the type VS 2003 and 2005 use for flagging a whole line copy
@ -316,7 +320,8 @@ namespace ICSharpCode.AvalonEdit.Editing
ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength); ISegment wholeLine = new SimpleSegment(line.Offset, line.TotalLength);
string text = textArea.Document.GetText(wholeLine); string text = textArea.Document.GetText(wholeLine);
// Ensure we use the appropriate newline sequence for the OS // Ensure we use the appropriate newline sequence for the OS
DataObject data = new DataObject(NewLineFinder.NormalizeNewLines(text, Environment.NewLine)); text = NewLineFinder.NormalizeNewLines(text, Environment.NewLine);
DataObject data = new DataObject(text);
// Also copy text in HTML format to clipboard - good for pasting text into Word // Also copy text in HTML format to clipboard - good for pasting text into Word
// or to the SharpDevelop forums. // or to the SharpDevelop forums.
@ -328,6 +333,8 @@ namespace ICSharpCode.AvalonEdit.Editing
data.SetData(LineSelectedType, lineSelected, false); data.SetData(LineSelectedType, lineSelected, false);
Clipboard.SetDataObject(data, true); Clipboard.SetDataObject(data, true);
textArea.OnTextCopied(new TextEventArgs(text));
} }
static void CanPaste(object target, CanExecuteRoutedEventArgs args) static void CanPaste(object target, CanExecuteRoutedEventArgs args)

39
src/Libraries/AvalonEdit/ICSharpCode.AvalonEdit/Editing/TextArea.cs

@ -781,5 +781,44 @@ namespace ICSharpCode.AvalonEdit.Editing
{ {
return textView.Services.GetService(serviceType); return textView.Services.GetService(serviceType);
} }
/// <summary>
/// Occurs when text inside the TextArea was copied.
/// </summary>
public event EventHandler<TextEventArgs> TextCopied;
internal void OnTextCopied(TextEventArgs e)
{
if (TextCopied != null)
TextCopied(this, e);
}
}
/// <summary>
/// EventArgs with text.
/// </summary>
[Serializable]
public class TextEventArgs : EventArgs
{
string text;
/// <summary>
/// Gets the text.
/// </summary>
public string Text {
get {
return text;
}
}
/// <summary>
/// Creates a new TextEventArgs instance.
/// </summary>
public TextEventArgs(string text)
{
if (text == null)
throw new ArgumentNullException("text");
this.text = text;
}
} }
} }

10
src/Main/Base/Project/Src/Gui/Components/SideBar/TextEditorSideBar.cs

@ -167,5 +167,15 @@ namespace ICSharpCode.SharpDevelop.Gui
return el; return el;
} }
protected override object StartItemDrag(SideTabItem draggedItem)
{
if (this.ActiveTab.ChoosedItem != draggedItem && this.ActiveTab.Items.Contains(draggedItem)) {
this.ActiveTab.ChoosedItem = draggedItem;
}
var dataObject = new System.Windows.DataObject();
dataObject.SetText(draggedItem.Tag.ToString());
return dataObject;
}
} }
} }

Loading…
Cancel
Save