bool disposed = false;
FooTextBoxAutomationPeer peer;
bool nowCaretMove = false;
+ Document _Document;
static FooTextBox()
{
this.Render.ShowTab = this.ShowTab;
this.Document = new Document();
- this.Document.LayoutLines.Render = this.Render;
this.View = new EditView(this.Document, this.Render, new Padding(5, 5, 5, 5));
this.View.SrcChanged += View_SrcChanged;
this._Controller = new Controller(this.Document, this.View);
this._Controller.SelectionChanged += new EventHandler(Controller_SelectionChanged);
- //Viewを作成した後に追加しないと例外が発生する
- this.Document.Update += new DocumentUpdateEventHandler(Document_Update);
-
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, CopyCommand, CanExecute));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, CutCommand, CanExecute));
this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, PasteCommand, CanExecute));
return;
if(e.type == UpdateType.Replace)
TextStoreHelper.NotifyTextChanged(this.textStore, e.startIndex, e.removeLength, e.insertLength);
- this.peer.OnNotifyTextChanged();
+ if(this.peer != null)
+ this.peer.OnNotifyTextChanged();
}
void timer_Tick(object sender, EventArgs e)
/// </summary>
public Document Document
{
- get;
- private set;
+ get
+ {
+ return this._Document;
+ }
+ set
+ {
+ int oldLength = 0;
+ if(this._Document != null)
+ {
+ this._Document.Update -= new DocumentUpdateEventHandler(Document_Update);
+ oldLength = this._Document.Length;
+ }
+
+ this._Document = value;
+ this._Document.LayoutLines.Render = this.Render;
+ this._Document.Update += new DocumentUpdateEventHandler(Document_Update);
+ //初期化が終わっていればすべて存在する
+ if(this.Controller != null && this.View != null && this.textStore != null)
+ {
+ this.Controller.Document = value;
+ this.View.Document = value;
+ this.Controller.AdjustCaret();
+ this.textStore.NotifyTextChanged(oldLength, value.Length);
+ this.Refresh();
+ }
+ }
}
/// <summary>
<MenuItem Header="Set Padding" Click="MenuItem_Click_11"/>
<MenuItem Header="Indent As Space" Click="MenuItem_Click_13" IsCheckable="True" Name="SpaceIndent"/>
</MenuItem>
+ <MenuItem Header="Test">
+ <MenuItem Header="Document1" Click="MenuItem_Click_14"/>
+ <MenuItem Header="Document2" Click="MenuItem_Click_15"/>
+ </MenuItem>
</Menu>
<MyNamespace:FooTextBox x:Name="fooTextBox" Grid.Row="1"/>
<StackPanel Grid.Row="2" Orientation="Horizontal">
public partial class MainWindow : Window
{
System.Threading.CancellationTokenSource cancleTokenSrc = new System.Threading.CancellationTokenSource();
+
+ List<Document> Documents = new List<Document>();
+
public MainWindow()
{
InitializeComponent();
this.fooTextBox.FoldingStrategy = new CharFoldingMethod('{', '}');
this.fooTextBox.Document.Update += Document_Update;
this.Enable.IsChecked = true;
-
+
+ this.Documents.Add(this.fooTextBox.Document);
+ this.Documents.Add(new Document());
+
this.Closed += MainWindow_Closed;
}
this.fooTextBox.IndentMode = IndentMode.Space;
}
}
+
+ private void MenuItem_Click_14(object sender, RoutedEventArgs e)
+ {
+ this.fooTextBox.Document = this.Documents[0];
+ MessageBox.Show("Current Document is Document1");
+ }
+
+ private void MenuItem_Click_15(object sender, RoutedEventArgs e)
+ {
+ this.fooTextBox.Document = this.Documents[1];
+ MessageBox.Show("Current Document is Document2");
+ }
}
public class TextRangeConveter : System.Windows.Data.IValueConverter
{