From 23f3e580b5e2f8ff925a9b3eaeb437f8cd34ad68 Mon Sep 17 00:00:00 2001 From: Daniel Grunwald Date: Sun, 23 Sep 2007 18:06:31 +0000 Subject: [PATCH] Add sample project for text anchors. git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2685 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61 --- samples/TextEditorAnchors/AssemblyInfo.cs | 31 +++++ .../TextEditorAnchors/MainForm.Designer.cs | 120 ++++++++++++++++++ samples/TextEditorAnchors/MainForm.cs | 94 ++++++++++++++ samples/TextEditorAnchors/MainForm.resx | 120 ++++++++++++++++++ samples/TextEditorAnchors/Program.cs | 30 +++++ .../TextEditorAnchors.csproj | 48 +++++++ .../TextEditorAnchors/TextEditorAnchors.sln | 18 +++ 7 files changed, 461 insertions(+) create mode 100644 samples/TextEditorAnchors/AssemblyInfo.cs create mode 100644 samples/TextEditorAnchors/MainForm.Designer.cs create mode 100644 samples/TextEditorAnchors/MainForm.cs create mode 100644 samples/TextEditorAnchors/MainForm.resx create mode 100644 samples/TextEditorAnchors/Program.cs create mode 100644 samples/TextEditorAnchors/TextEditorAnchors.csproj create mode 100644 samples/TextEditorAnchors/TextEditorAnchors.sln diff --git a/samples/TextEditorAnchors/AssemblyInfo.cs b/samples/TextEditorAnchors/AssemblyInfo.cs new file mode 100644 index 0000000000..8489786d38 --- /dev/null +++ b/samples/TextEditorAnchors/AssemblyInfo.cs @@ -0,0 +1,31 @@ +#region Using directives + +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +#endregion + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TextEditorAnchors")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TextEditorAnchors")] +[assembly: AssemblyCopyright("")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all the values or you can use the default the Revision and +// Build Numbers by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.*")] diff --git a/samples/TextEditorAnchors/MainForm.Designer.cs b/samples/TextEditorAnchors/MainForm.Designer.cs new file mode 100644 index 0000000000..cb5e34a63e --- /dev/null +++ b/samples/TextEditorAnchors/MainForm.Designer.cs @@ -0,0 +1,120 @@ +// +// +// +// +// $Revision$ +// +namespace TextEditorAnchors +{ + partial class MainForm + { + /// + /// Designer variable used to keep track of non-visual components. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Disposes resources used by the form. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing) { + if (components != null) { + components.Dispose(); + } + } + base.Dispose(disposing); + } + + /// + /// This method is required for Windows Forms designer support. + /// Do not change the method contents inside the source code editor. The Forms designer might + /// not be able to load this method if it was changed manually. + /// + private void InitializeComponent() + { + this.splitContainer1 = new System.Windows.Forms.SplitContainer(); + this.textEditorControl = new ICSharpCode.TextEditor.TextEditorControl(); + this.anchorListBox = new System.Windows.Forms.ListBox(); + this.addAnchorButton = new System.Windows.Forms.Button(); + this.splitContainer1.Panel1.SuspendLayout(); + this.splitContainer1.Panel2.SuspendLayout(); + this.splitContainer1.SuspendLayout(); + this.SuspendLayout(); + // + // splitContainer1 + // + this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill; + this.splitContainer1.Location = new System.Drawing.Point(0, 0); + this.splitContainer1.Name = "splitContainer1"; + // + // splitContainer1.Panel1 + // + this.splitContainer1.Panel1.Controls.Add(this.textEditorControl); + this.splitContainer1.Panel1MinSize = 100; + // + // splitContainer1.Panel2 + // + this.splitContainer1.Panel2.Controls.Add(this.anchorListBox); + this.splitContainer1.Panel2.Controls.Add(this.addAnchorButton); + this.splitContainer1.Panel2MinSize = 50; + this.splitContainer1.Size = new System.Drawing.Size(556, 322); + this.splitContainer1.SplitterDistance = 340; + this.splitContainer1.TabIndex = 1; + // + // textEditorControl + // + this.textEditorControl.Dock = System.Windows.Forms.DockStyle.Fill; + this.textEditorControl.Location = new System.Drawing.Point(0, 0); + this.textEditorControl.Name = "textEditorControl"; + this.textEditorControl.Size = new System.Drawing.Size(340, 322); + this.textEditorControl.TabIndex = 0; + this.textEditorControl.Text = "Dies\r\nist ein\r\nmehrzeiliger\r\nText!"; + this.textEditorControl.TextChanged += new System.EventHandler(this.TextEditorControlTextChanged); + // + // anchorListBox + // + this.anchorListBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) + | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.anchorListBox.FormattingEnabled = true; + this.anchorListBox.IntegralHeight = false; + this.anchorListBox.Location = new System.Drawing.Point(2, 32); + this.anchorListBox.Name = "anchorListBox"; + this.anchorListBox.Size = new System.Drawing.Size(198, 278); + this.anchorListBox.TabIndex = 2; + this.anchorListBox.DoubleClick += new System.EventHandler(this.AnchorListBoxDoubleClick); + this.anchorListBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.AnchorListBoxKeyDown); + // + // addAnchorButton + // + this.addAnchorButton.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) + | System.Windows.Forms.AnchorStyles.Right))); + this.addAnchorButton.Location = new System.Drawing.Point(2, 3); + this.addAnchorButton.Name = "addAnchorButton"; + this.addAnchorButton.Size = new System.Drawing.Size(198, 23); + this.addAnchorButton.TabIndex = 0; + this.addAnchorButton.Text = "Add Anchor"; + this.addAnchorButton.UseVisualStyleBackColor = true; + this.addAnchorButton.Click += new System.EventHandler(this.AddAnchorButtonClick); + // + // MainForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(556, 322); + this.Controls.Add(this.splitContainer1); + this.Name = "MainForm"; + this.Text = "TextEditorAnchors"; + this.splitContainer1.Panel1.ResumeLayout(false); + this.splitContainer1.Panel2.ResumeLayout(false); + this.splitContainer1.ResumeLayout(false); + this.ResumeLayout(false); + } + private System.Windows.Forms.Button addAnchorButton; + private System.Windows.Forms.ListBox anchorListBox; + private System.Windows.Forms.SplitContainer splitContainer1; + private ICSharpCode.TextEditor.TextEditorControl textEditorControl; + } +} diff --git a/samples/TextEditorAnchors/MainForm.cs b/samples/TextEditorAnchors/MainForm.cs new file mode 100644 index 0000000000..057ee2e14a --- /dev/null +++ b/samples/TextEditorAnchors/MainForm.cs @@ -0,0 +1,94 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Windows.Forms; +using ICSharpCode.TextEditor; +using ICSharpCode.TextEditor.Document; + +namespace TextEditorAnchors +{ + /// + /// This program demonstrates how TextAnchor objects can be used to refer to locations + /// in the document and how they are updated when text is added/removed. + /// + public partial class MainForm : Form + { + public MainForm() + { + // + // The InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + } + + + void AddAnchorButtonClick(object sender, EventArgs e) + { + Caret caret = textEditorControl.ActiveTextAreaControl.Caret; + LineSegment line = textEditorControl.Document.GetLineSegment(caret.Line); + anchorListBox.Items.Add(new AnchorWrapper(line.CreateAnchor(caret.Column))); + } + + void AnchorListBoxKeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Delete) { + int index = anchorListBox.SelectedIndex; + if (index >= 0) { + anchorListBox.Items.RemoveAt(index); + if (index < anchorListBox.Items.Count) + anchorListBox.SelectedIndex = index; + else + anchorListBox.SelectedIndex = anchorListBox.Items.Count - 1; + } + } + } + + void AnchorListBoxDoubleClick(object sender, EventArgs e) + { + if (anchorListBox.SelectedIndex >= 0) { + AnchorWrapper w = (AnchorWrapper)anchorListBox.Items[anchorListBox.SelectedIndex]; + if (!w.Anchor.IsDeleted) { + textEditorControl.ActiveTextAreaControl.Caret.Position = w.Anchor.Location; + textEditorControl.Focus(); + } + } + } + + void TextEditorControlTextChanged(object sender, EventArgs e) + { + for (int i = 0; i < anchorListBox.Items.Count; i++) { + anchorListBox.Items[i] = anchorListBox.Items[i]; + } + } + + /// + /// Provide a ToString() implementation for TextAnchor + /// (the implementation in TextAnchor uses 0-based coordinates) + /// + sealed class AnchorWrapper + { + public readonly TextAnchor Anchor; + + public AnchorWrapper(TextAnchor anchor) + { + this.Anchor = anchor; + } + + public override string ToString() + { + if (Anchor.IsDeleted) + return "Anchor deleted"; + else + return "Line " + (Anchor.LineNumber+1) + ", Column " + (Anchor.ColumnNumber+1) + + " (Offset " + Anchor.Offset + ")"; + } + } + } +} diff --git a/samples/TextEditorAnchors/MainForm.resx b/samples/TextEditorAnchors/MainForm.resx new file mode 100644 index 0000000000..7080a7d118 --- /dev/null +++ b/samples/TextEditorAnchors/MainForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/samples/TextEditorAnchors/Program.cs b/samples/TextEditorAnchors/Program.cs new file mode 100644 index 0000000000..880d705971 --- /dev/null +++ b/samples/TextEditorAnchors/Program.cs @@ -0,0 +1,30 @@ +// +// +// +// +// $Revision$ +// + +using System; +using System.Windows.Forms; + +namespace TextEditorAnchors +{ + /// + /// Class with program entry point. + /// + internal sealed class Program + { + /// + /// Program entry point. + /// + [STAThread] + private static void Main(string[] args) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + + } +} diff --git a/samples/TextEditorAnchors/TextEditorAnchors.csproj b/samples/TextEditorAnchors/TextEditorAnchors.csproj new file mode 100644 index 0000000000..fce24cbc8c --- /dev/null +++ b/samples/TextEditorAnchors/TextEditorAnchors.csproj @@ -0,0 +1,48 @@ + + + {BC48E973-B9B5-4331-B67B-1609B1AF0B9B} + Debug + AnyCPU + WinExe + TextEditorAnchors + TextEditorAnchors + + + bin\Debug\ + True + Full + False + True + DEBUG;TRACE + + + bin\Release\ + False + None + True + False + TRACE + + + + + ..\..\bin\ICSharpCode.TextEditor.dll + + + + + + + + + + + + MainForm.cs + + + + MainForm.cs + + + \ No newline at end of file diff --git a/samples/TextEditorAnchors/TextEditorAnchors.sln b/samples/TextEditorAnchors/TextEditorAnchors.sln new file mode 100644 index 0000000000..60d713ac60 --- /dev/null +++ b/samples/TextEditorAnchors/TextEditorAnchors.sln @@ -0,0 +1,18 @@ + +Microsoft Visual Studio Solution File, Format Version 9.00 +# Visual Studio 2005 +# SharpDevelop 3.0.0.2677 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TextEditorAnchors", "TextEditorAnchors.csproj", "{BC48E973-B9B5-4331-B67B-1609B1AF0B9B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {BC48E973-B9B5-4331-B67B-1609B1AF0B9B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {BC48E973-B9B5-4331-B67B-1609B1AF0B9B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {BC48E973-B9B5-4331-B67B-1609B1AF0B9B}.Release|Any CPU.Build.0 = Release|Any CPU + {BC48E973-B9B5-4331-B67B-1609B1AF0B9B}.Release|Any CPU.ActiveCfg = Release|Any CPU + EndGlobalSection +EndGlobal