Left,\r
Right,\r
}\r
+\r
+ /// <summary>\r
+ /// インデントの方法を表す\r
+ /// </summary>\r
+ public enum IndentMode\r
+ {\r
+ Tab,\r
+ Space,\r
+ }\r
+\r
/// <summary>\r
/// ユーザー側からの処理を担当するクラス。一部を除き、こちらで行われた操作はアンドゥの対象になります\r
/// </summary>\r
}\r
\r
/// <summary>\r
+ /// インデントの方法を表す\r
+ /// </summary>\r
+ public IndentMode IndentMode\r
+ {\r
+ get;\r
+ set;\r
+ }\r
+\r
+ /// <summary>\r
/// 選択範囲の開始位置\r
/// </summary>\r
/// <remarks>SelectionLengthが0の場合、キャレット位置を表します</remarks>\r
this.DoInputString(ch.ToString());\r
}\r
\r
+ string GetIndentSpace(int col_index)\r
+ {\r
+ int space_count = this.View.TabStops - (col_index % this.View.TabStops);\r
+ return new string(Enumerable.Repeat(' ',space_count).ToArray());\r
+ }\r
+\r
/// <summary>\r
/// キャレット位置に文字列を挿入し、その分だけキャレットを進める。isInsertModeの値により動作が変わります\r
/// </summary>\r
/// <param name="fromTip"></param>\r
public void DoInputString(string str,bool fromTip = false)\r
{\r
+ TextPoint CaretPos = this.View.CaretPostion;\r
+\r
+ if (str == "\t" && this.IndentMode == IndentMode.Space)\r
+ str = this.GetIndentSpace(CaretPos.col);\r
+\r
if (this.View.InsertPoint != null)\r
{\r
this.ReplaceBeforeSelectionArea(this.View.Selections, 0, str);\r
\r
int index = this.View.GetIndexFromLayoutLine(this.View.CaretPostion);\r
int length = 0;\r
- TextPoint CaretPos = this.View.CaretPostion;\r
if (this.View.InsertMode == false && index < this.Document.Length && this.Document[index] != Document.NewLine)\r
{\r
string lineString = this.View.LayoutLines[CaretPos.row];\r
if (this.RectSelection || this.SelectionLength == 0)\r
return;\r
int selectionStart = this.SelectionStart;\r
- string text = this.InsertLineHead(GetTextFromLineSelectArea(this.View.Selections), "\t");\r
+ string insertStr = this.IndentMode == IndentMode.Space ? this.GetIndentSpace(0) : "\t";\r
+ string text = this.InsertLineHead(GetTextFromLineSelectArea(this.View.Selections), insertStr);\r
this.RepleaceSelectionArea(this.View.Selections,text);\r
this.Select(selectionStart, text.Length);\r
}\r
if (this.RectSelection || this.SelectionLength == 0)\r
return;\r
int selectionStart = this.SelectionStart;\r
- string text = this.RemoveLineHead(GetTextFromLineSelectArea(this.View.Selections), "\t");\r
+ string insertStr = this.IndentMode == IndentMode.Space ? this.GetIndentSpace(0) : "\t";\r
+ string text = this.RemoveLineHead(GetTextFromLineSelectArea(this.View.Selections), insertStr);\r
this.RepleaceSelectionArea(this.View.Selections, text);\r
this.Select(selectionStart, text.Length);\r
}\r
public static void OnPropertyChanged(object sender, DependencyPropertyChangedEventArgs e)\r
{\r
FooTextBox source = (FooTextBox)sender;\r
+ if (e.Property.Equals(IndentModeProperty))\r
+ source.Controller.IndentMode = source.IndentMode;\r
if (e.Property.Equals(SelectionProperty) && !source.nowCaretMove)\r
source._Controller.Select(source.Selection.Index,source.Selection.Length);\r
if (e.Property.Equals(CaretPostionPropertyKey) && !source.nowCaretMove)\r
}\r
\r
/// <summary>\r
+ /// インデントの方法を表す\r
+ /// </summary>\r
+ public IndentMode IndentMode\r
+ {\r
+ get { return (IndentMode)GetValue(IndentModeProperty); }\r
+ set { SetValue(IndentModeProperty, value); }\r
+ }\r
+\r
+ /// <summary>\r
+ /// IndentModeの依存プロパティを表す\r
+ /// </summary>\r
+ public static readonly DependencyProperty IndentModeProperty =\r
+ DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab,OnPropertyChanged));\r
+\r
+ /// <summary>\r
/// 選択範囲を表す\r
/// </summary>\r
/// <remarks>\r
{\r
switch (e.Property.Name)\r
{\r
+ case "IndentMode":\r
+ this._Controller.IndentMode = this.IndentMode;\r
+ break;\r
case "Selection":\r
if(!this.nowCaretMove)\r
this.Select(this.Selection.Index, this.Selection.Length);\r
}\r
\r
/// <summary>\r
+ /// インデントの方法を表す\r
+ /// </summary>\r
+ public IndentMode IndentMode\r
+ {\r
+ get { return (IndentMode)GetValue(IndentModeProperty); }\r
+ set { SetValue(IndentModeProperty, value); }\r
+ }\r
+\r
+ /// <summary>\r
+ /// IndentModeの依存プロパティを表す\r
+ /// </summary>\r
+ public static readonly DependencyProperty IndentModeProperty =\r
+ DependencyProperty.Register("IndentMode", typeof(IndentMode), typeof(FooTextBox), new PropertyMetadata(IndentMode.Tab));\r
+\r
+ /// <summary>\r
/// 選択範囲を表す\r
/// </summary>\r
/// <remarks>\r
<MenuItem Header="URL Mark" Name="URLMark" Click="URLMark_Click" IsCheckable="True"/>
<MenuItem Header="GenerateFolding" Click="MenuItem_Click_9"/>
<MenuItem Header="Set Padding" Click="MenuItem_Click_11"/>
+ <MenuItem Header="Indent As Space" Click="MenuItem_Click_13" IsCheckable="True" Name="SpaceIndent"/>
</MenuItem>
</Menu>
<MyNamespace:FooTextBox x:Name="fooTextBox" Grid.Row="1"/>
this.fooTextBox.PerfomLayouts();
this.fooTextBox.Refresh();
}
+
+ private void MenuItem_Click_13(object sender, RoutedEventArgs e)
+ {
+ if(this.fooTextBox.IndentMode == IndentMode.Space)
+ {
+ this.SpaceIndent.IsChecked = false;
+ this.fooTextBox.IndentMode = IndentMode.Tab;
+ }
+ else
+ {
+ this.SpaceIndent.IsChecked = true;
+ this.fooTextBox.IndentMode = IndentMode.Space;
+ }
+ }
}
public class TextRangeConveter : System.Windows.Data.IValueConverter
{
public event InsertModeChangeEventHandler InsetModeChange;\r
\r
/// <summary>\r
+ /// インデントモードを表す\r
+ /// </summary>\r
+ [DefaultValue(IndentMode.Tab)]\r
+ public IndentMode IndentMode\r
+ {\r
+ get\r
+ {\r
+ return this.Controller.IndentMode;\r
+ }\r
+ set\r
+ {\r
+ this.Controller.IndentMode = value;\r
+ }\r
+ }\r
+\r
+ /// <summary>\r
/// テキスト描写に使用するアンチエイリアシングモードを表す\r
/// </summary>\r
[BrowsableAttribute(false)]\r