Browse Source

Add sample project for text anchors.

git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@2685 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61
shortcuts
Daniel Grunwald 18 years ago
parent
commit
23f3e580b5
  1. 31
      samples/TextEditorAnchors/AssemblyInfo.cs
  2. 120
      samples/TextEditorAnchors/MainForm.Designer.cs
  3. 94
      samples/TextEditorAnchors/MainForm.cs
  4. 120
      samples/TextEditorAnchors/MainForm.resx
  5. 30
      samples/TextEditorAnchors/Program.cs
  6. 48
      samples/TextEditorAnchors/TextEditorAnchors.csproj
  7. 18
      samples/TextEditorAnchors/TextEditorAnchors.sln

31
samples/TextEditorAnchors/AssemblyInfo.cs

@ -0,0 +1,31 @@ @@ -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.*")]

120
samples/TextEditorAnchors/MainForm.Designer.cs generated

@ -0,0 +1,120 @@ @@ -0,0 +1,120 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="${USER} Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
namespace TextEditorAnchors
{
partial class MainForm
{
/// <summary>
/// Designer variable used to keep track of non-visual components.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Disposes resources used by the form.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing) {
if (components != null) {
components.Dispose();
}
}
base.Dispose(disposing);
}
/// <summary>
/// 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.
/// </summary>
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;
}
}

94
samples/TextEditorAnchors/MainForm.cs

@ -0,0 +1,94 @@ @@ -0,0 +1,94 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="Daniel Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using ICSharpCode.TextEditor;
using ICSharpCode.TextEditor.Document;
namespace TextEditorAnchors
{
/// <summary>
/// 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.
/// </summary>
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];
}
}
/// <summary>
/// Provide a ToString() implementation for TextAnchor
/// (the implementation in TextAnchor uses 0-based coordinates)
/// </summary>
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 + ")";
}
}
}
}

120
samples/TextEditorAnchors/MainForm.resx

@ -0,0 +1,120 @@ @@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

30
samples/TextEditorAnchors/Program.cs

@ -0,0 +1,30 @@ @@ -0,0 +1,30 @@
// <file>
// <copyright see="prj:///doc/copyright.txt"/>
// <license see="prj:///doc/license.txt"/>
// <owner name="${USER} Grunwald" email="daniel@danielgrunwald.de"/>
// <version>$Revision$</version>
// </file>
using System;
using System.Windows.Forms;
namespace TextEditorAnchors
{
/// <summary>
/// Class with program entry point.
/// </summary>
internal sealed class Program
{
/// <summary>
/// Program entry point.
/// </summary>
[STAThread]
private static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
}
}

48
samples/TextEditorAnchors/TextEditorAnchors.csproj

@ -0,0 +1,48 @@ @@ -0,0 +1,48 @@
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ProjectGuid>{BC48E973-B9B5-4331-B67B-1609B1AF0B9B}</ProjectGuid>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<OutputType>WinExe</OutputType>
<RootNamespace>TextEditorAnchors</RootNamespace>
<AssemblyName>TextEditorAnchors</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<OutputPath>bin\Debug\</OutputPath>
<DebugSymbols>True</DebugSymbols>
<DebugType>Full</DebugType>
<Optimize>False</Optimize>
<CheckForOverflowUnderflow>True</CheckForOverflowUnderflow>
<DefineConstants>DEBUG;TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
<OutputPath>bin\Release\</OutputPath>
<DebugSymbols>False</DebugSymbols>
<DebugType>None</DebugType>
<Optimize>True</Optimize>
<CheckForOverflowUnderflow>False</CheckForOverflowUnderflow>
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.Targets" />
<ItemGroup>
<Reference Include="ICSharpCode.TextEditor">
<HintPath>..\..\bin\ICSharpCode.TextEditor.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="AssemblyInfo.cs" />
<Compile Include="MainForm.cs" />
<Compile Include="MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<EmbeddedResource Include="MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
</Project>

18
samples/TextEditorAnchors/TextEditorAnchors.sln

@ -0,0 +1,18 @@ @@ -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
Loading…
Cancel
Save