.NET Decompiler with support for PDB generation, ReadyToRun, Metadata (&more) - cross-platform!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

82 lines
1.6 KiB

// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Data;
using System.Windows;
namespace ICSharpCode.TreeView
{
class EditTextBox : TextBox
{
static EditTextBox()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(EditTextBox),
new FrameworkPropertyMetadata(typeof(EditTextBox)));
}
public EditTextBox()
{
Loaded += delegate { Init(); };
}
public SharpTreeViewItem Item { get; set; }
public SharpTreeNode Node {
get { return Item.Node; }
}
void Init()
{
Text = Node.LoadEditText();
Focus();
SelectAll();
}
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.Enter) {
Commit();
} else if (e.Key == Key.Escape) {
Node.IsEditing = false;
}
}
protected override void OnLostKeyboardFocus(KeyboardFocusChangedEventArgs e)
{
if (Node.IsEditing) {
Commit();
}
}
bool commiting;
void Commit()
{
if (!commiting) {
commiting = true;
Node.IsEditing = false;
if (!Node.SaveEditText(Text)) {
Item.Focus();
}
Node.RaisePropertyChanged("Text");
//if (Node.SaveEditText(Text)) {
// Node.IsEditing = false;
// Node.RaisePropertyChanged("Text");
//}
//else {
// Init();
//}
commiting = false;
}
}
}
}