static void Check(TextBoxEditor editor, string keys, TextSlice expected) { var clipboardProvider = new TestClipboardProvider(); editor.Interpret(keys); Assert.AreEqual(expected, editor.TextSlice, "Expected result of keystroke"); }
/// <summary> /// 获取编辑框 /// </summary> /// <returns></returns> public EditorBase GetEditor() { switch (Type) { case ConfigItemType.Check: CheckBoxEditor cbe = new CheckBoxEditor(); cbe.OnOffType = OnOffButtonType.Quadrate; return(cbe); case ConfigItemType.Combo: ComboBoxEditor cmb = new ComboBoxEditor(); cmb.BindValue(Items); return(cmb); case ConfigItemType.MText: TextBoxEditor mtxt = new TextBoxEditor(); mtxt.Multiline = true; mtxt.Height = 80; return(mtxt); case ConfigItemType.Number: NumbericEditor ntxt = new NumbericEditor(); return(ntxt); default: TextBoxEditor txt = new TextBoxEditor(); return(txt); } }
private void ComboBoxPath_SelectedIndexChanged(object sender, EventArgs e) // изменение в комбобоксе { selNum = comboBoxPath.SelectedIndex; // номер выбранной строки из списка путей TextBoxEditor.Clear(); // очистка бокса using (var sftp = new SftpClient(ServerIP, ServerPort, "root", PasswordRoot)) //переменная для подключения { try { sftp.Connect(); // попытка подключения if (sftp.IsConnected) // если подключились { if (comboBoxPath.SelectedItem == null) // проверяем поле ввода на нулевое значение { MessageBox.Show("Выберите существующий объект"); // если поле нулевое, то вывод сообщения } else { string FilePath = comboBoxPath.SelectedItem.ToString(); // преобразуем выбранный пункт в стринг TextBoxEditor.Text = sftp.ReadAllText(FilePath); // вывод содержимого в окно редактора TextBoxEditor.Select(); // меняем фокус на поле редактора } } } catch (SshAuthenticationException) // ошибка аутентификации (доступ запрещен (пароль)) { MessageBox.Show("Доступ запрещен." + "\r\n" + "Введите пароль!"); ButtonOpenServerConnector_Click(sender, e); } catch (ArgumentException) // ошибка в адреме { MessageBox.Show("Введен неопределенный адрес." + "\r\n" + "Введите HostName или IP сервера!"); ButtonOpenServerConnector_Click(sender, e); } catch (SocketException) // неизвестный хост { MessageBox.Show("Неизвестный Хост." + "\r\n" + "Введите правильный HostName или IP сервера!"); ButtonOpenServerConnector_Click(sender, e); } catch (SftpPathNotFoundException) { MessageBox.Show("Нет такого файла!"); // вывод описания ошибки подключения } catch (Exception ex) { MessageBox.Show(ex.Message); // вывод описания ошибки подключения } finally { sftp.Disconnect(); // отключаемся от сервера } } }
private void ButtonList_Click(object sender, EventArgs e)//получение списка доступных адресов { TextBoxEditor.Clear(); for (int i = 0; i < comboBoxPath.Items.Count; i++) // comboBoxPath.Items.Count - счетчик количества элементов в списке { TextBoxEditor.Text += GetItemText(i) + '\r' + '\n'; // вывод списка построчно comboBoxPath.Text = ""; // на всякий случай чистим Комбо } }
public void ClipboardAccess() { IClipboardProvider clipboardProvider = new TestClipboardProvider(); var editor = new TextBoxEditor(clipboardProvider); Assert.IsNull(clipboardProvider.GetText()); editor.Interpret("Hello World"); editor.SelectAll(); editor.Interpret("^C"); Assert.AreEqual("Hello World", clipboardProvider.GetText()); editor.Interpret("^V"); editor.Interpret("^V"); Assert.AreEqual("Hello WorldHello World", editor.TextSlice.Text); }
public void SimpleTyping() { var editor = new TextBoxEditor(new TestClipboardProvider()); Assert.AreEqual(editor.TextSlice, TextSlice.Empty); Check(editor, "A", "A"); Check(editor, "B", "AB"); Check(editor, Undo, "A"); Check(editor, Undo, ""); Check(editor, Undo, ""); Check(editor, Redo, "A"); Check(editor, Redo, "AB"); Check(editor, Redo, "AB"); }
protected void Page_Load(object sender, EventArgs e) { SqlConnection DB = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["JenzabarConnectionString"].ConnectionString); Portlet_Config Config = Portlet_Config.from_DB(ref DB); IList<TextBoxEditor> Editors = new List<TextBoxEditor>(); foreach (View_String Temp in Config.Values) { Panel Temp_Panel = new Panel(); Label Temp_Label = new Label(); TextBoxEditor Temp_Editor = new TextBoxEditor(); Temp_Panel.ID = Temp.ID; Temp_Label.Text = Temp.Description; Temp_Editor.InnerHtml = Temp.Body; Temp_Panel.Controls.Add(Temp_Label); Temp_Panel.Controls.Add(Temp_Editor); Main_Panel.Controls.Add(Temp_Panel); } }
internal static ITypeEditor CreateDefaultEditor(Type propertyType, TypeConverter typeConverter, PropertyItem propertyItem) { ITypeEditor editor = null; var context = new EditorTypeDescriptorContext(null, propertyItem.Instance, propertyItem.PropertyDescriptor); if ((typeConverter != null) && typeConverter.GetStandardValuesSupported(context) && typeConverter.GetStandardValuesExclusive(context) && (propertyType != typeof(bool)) && (propertyType != typeof(bool?))) //Bool type always have a BooleanConverter with standardValues : True/False. { var items = typeConverter.GetStandardValues(context); editor = new SourceComboBoxEditor(items, typeConverter); } else if (propertyType == typeof(string)) { editor = new TextBoxEditor(); } else if (propertyType == typeof(bool) || propertyType == typeof(bool?)) { editor = new CheckBoxEditor(); } else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?)) { editor = new DecimalUpDownEditor(); } else if (propertyType == typeof(double) || propertyType == typeof(double?)) { editor = new DoubleUpDownEditor(); } else if (propertyType == typeof(int) || propertyType == typeof(int?)) { editor = new IntegerUpDownEditor(); } else if (propertyType == typeof(short) || propertyType == typeof(short?)) { editor = new ShortUpDownEditor(); } else if (propertyType == typeof(long) || propertyType == typeof(long?)) { editor = new LongUpDownEditor(); } else if (propertyType == typeof(float) || propertyType == typeof(float?)) { editor = new SingleUpDownEditor(); } else if (propertyType == typeof(byte) || propertyType == typeof(byte?)) { editor = new ByteUpDownEditor(); } else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?)) { editor = new SByteUpDownEditor(); } else if (propertyType == typeof(uint) || propertyType == typeof(uint?)) { editor = new UIntegerUpDownEditor(); } else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?)) { editor = new ULongUpDownEditor(); } else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?)) { editor = new UShortUpDownEditor(); } else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { editor = new DateTimeUpDownEditor(); } else if ((propertyType == typeof(Color)) || (propertyType == typeof(Color?))) { editor = new ColorEditor(); } else if (propertyType.IsEnum) { editor = new EnumComboBoxEditor(); } else if (propertyType == typeof(TimeSpan) || propertyType == typeof(TimeSpan?)) { editor = new TimeSpanUpDownEditor(); } else if (propertyType == typeof(FontFamily) || propertyType == typeof(FontWeight) || propertyType == typeof(FontStyle) || propertyType == typeof(FontStretch)) { editor = new FontComboBoxEditor(); } else if (propertyType == typeof(Guid) || propertyType == typeof(Guid?)) { editor = new MaskedTextBoxEditor() { ValueDataType = propertyType, Mask = "AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA" } } ; else if (propertyType == typeof(char) || propertyType == typeof(char?)) { editor = new MaskedTextBoxEditor() { ValueDataType = propertyType, Mask = "&" } } ; else if (propertyType == typeof(object)) { // If any type of object is possible in the property, default to the TextBoxEditor. // Useful in some case (e.g., Button.Content). // Can be reconsidered but was the legacy behavior on the PropertyGrid. editor = new TextBoxEditor(); } else { var listType = ListUtilities.GetListItemType(propertyType); // A List of T if (listType != null) { if (!listType.IsPrimitive && !listType.Equals(typeof(String)) && !listType.IsEnum) { editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor(); } else { editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.PrimitiveTypeCollectionEditor(); } } else { var dictionaryType = ListUtilities.GetDictionaryItemsType(propertyType); var collectionType = ListUtilities.GetCollectionItemType(propertyType); // A dictionary of T or a Collection of T or an ICollection if ((dictionaryType != null) || (collectionType != null) || typeof(ICollection).IsAssignableFrom(propertyType)) { editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor(); } else { // If the type is not supported, check if there is a converter that supports // string conversion to the object type. Use TextBox in theses cases. // Otherwise, return a TextBlock editor since no valid editor exists. editor = (typeConverter != null && typeConverter.CanConvertFrom(typeof(string))) ? (ITypeEditor) new TextBoxEditor() : (ITypeEditor) new TextBlockEditor(); } } } return(editor); }
internal static ITypeEditor CreateDefaultEditor(Type propertyType, TypeConverter typeConverter) { ITypeEditor editor = null; if (propertyType == typeof(bool) || propertyType == typeof(bool?)) { editor = new CheckBoxEditor(); } else if (propertyType == typeof(decimal) || propertyType == typeof(decimal?)) { editor = new DecimalUpDownEditor(); } else if (propertyType == typeof(double) || propertyType == typeof(double?)) { editor = new DoubleUpDownEditor(); } else if (propertyType == typeof(int) || propertyType == typeof(int?)) { editor = new IntegerUpDownEditor(); } else if (propertyType == typeof(short) || propertyType == typeof(short?)) { editor = new ShortUpDownEditor(); } else if (propertyType == typeof(long) || propertyType == typeof(long?)) { editor = new LongUpDownEditor(); } else if (propertyType == typeof(float) || propertyType == typeof(float?)) { editor = new SingleUpDownEditor(); } else if (propertyType == typeof(byte) || propertyType == typeof(byte?)) { editor = new ByteUpDownEditor(); } else if (propertyType == typeof(sbyte) || propertyType == typeof(sbyte?)) { editor = new UpDownEditor <SByteUpDown, sbyte?>(); } else if (propertyType == typeof(uint) || propertyType == typeof(uint?)) { editor = new UpDownEditor <UIntegerUpDown, uint?>(); } else if (propertyType == typeof(ulong) || propertyType == typeof(ulong?)) { editor = new UpDownEditor <ULongUpDown, ulong?>(); } else if (propertyType == typeof(ushort) || propertyType == typeof(ushort?)) { editor = new UpDownEditor <UShortUpDown, ushort?>(); } else if (propertyType == typeof(DateTime) || propertyType == typeof(DateTime?)) { editor = new DateTimeUpDownEditor(); } else if ((propertyType == typeof(Color))) { editor = new ColorEditor(); } else if (propertyType.IsEnum) { editor = new EnumComboBoxEditor(); } else if (propertyType == typeof(TimeSpan)) { editor = new TimeSpanEditor(); } else if (propertyType == typeof(FontFamily) || propertyType == typeof(FontWeight) || propertyType == typeof(FontStyle) || propertyType == typeof(FontStretch)) { editor = new FontComboBoxEditor(); } else if (propertyType == typeof(object)) { // If any type of object is possible in the property, default to the TextBoxEditor. // Useful in some case (e.g., Button.Content). // Can be reconsidered but was the legacy behavior on the PropertyGrid. editor = new TextBoxEditor(); } else { Type listType = CollectionControl.GetListItemType(propertyType); if (listType != null) { if (!listType.IsPrimitive && !listType.Equals(typeof(String))) { editor = new Editors.CollectionEditor(); } else { editor = new Editors.PrimitiveTypeCollectionEditor(); } } else { // If the type is not supported, check if there is a converter that supports // string conversion to the object type. Use TextBox in theses cases. // Otherwise, return a TextBlock editor since no valid editor exists. editor = (typeConverter != null && typeConverter.CanConvertFrom(typeof(string))) ? (ITypeEditor) new TextBoxEditor() : (ITypeEditor) new TextBlockEditor(); } } return(editor); }
internal static FrameworkElement CreateDefaultEditor(PropertyItem propertyItem) { ITypeEditor editor = null; if (propertyItem.IsReadOnly) { editor = new TextBlockEditor(); } else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?)) { editor = new CheckBoxEditor(); } else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?)) { editor = new DecimalUpDownEditor(); } else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?)) { editor = new DoubleUpDownEditor(); } else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?)) { editor = new IntegerUpDownEditor(); } else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?)) { editor = new DateTimeUpDownEditor(); } else if ((propertyItem.PropertyType == typeof(Color))) { editor = new ColorEditor(); } else if (propertyItem.PropertyType.IsEnum) { editor = new EnumComboBoxEditor(); } else if (propertyItem.PropertyType == typeof(TimeSpan)) { editor = new TimeSpanEditor(); } else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch)) { editor = new FontComboBoxEditor(); } else if (propertyItem.PropertyType.IsGenericType) { if (propertyItem.PropertyType.GetInterface("IList") != null) { var t = propertyItem.PropertyType.GetGenericArguments()[0]; if (!t.IsPrimitive && !t.Equals(typeof(String))) { editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditor(); } else { editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.PrimitiveTypeCollectionEditor(); } } else { editor = new TextBlockEditor(); } } else { editor = new TextBoxEditor(); } return(editor.ResolveEditor(propertyItem)); }
internal static FrameworkElement CreateDefaultEditor(PropertyItem propertyItem) { ITypeEditor editor = null; if (propertyItem.IsReadOnly) { editor = new TextBlockEditor(); } else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?)) { editor = new CheckBoxEditor(); } else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal? )) { editor = new DecimalUpDownEditor(); } else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?)) { editor = new DoubleUpDownEditor(); } else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?)) { editor = new IntegerUpDownEditor(); } else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime? )) { editor = new DateTimeUpDownEditor(); } else if ((propertyItem.PropertyType == typeof(Color))) { editor = new ColorEditor(); } else if (propertyItem.PropertyType.IsEnum) { editor = new EnumComboBoxEditor(); } else if (propertyItem.PropertyType == typeof(TimeSpan)) { editor = new TimeSpanEditor(); } else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch)) { editor = new FontComboBoxEditor(); } else { Type listType = CollectionEditor.GetListItemType(propertyItem.PropertyType); if (listType != null) { if (!listType.IsPrimitive && !listType.Equals(typeof(String))) { editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.CollectionEditor(); } else { editor = new Xceed.Wpf.Toolkit.PropertyGrid.Editors.PrimitiveTypeCollectionEditor(); } } else { editor = new TextBoxEditor(); } } return(editor.ResolveEditor(propertyItem)); }
private PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid) { PropertyItem propertyItem = new PropertyItem(instance, property, grid); var binding = new Binding(property.Name) { Source = instance, ValidatesOnExceptions = true, ValidatesOnDataErrors = true, Mode = propertyItem.IsWriteable ? BindingMode.TwoWay : BindingMode.OneWay }; if (instance is ICustomTypeDescriptor) { binding.Source = (instance as ICustomTypeDescriptor).GetPropertyOwner(property); } propertyItem.SetBinding(PropertyItem.ValueProperty, binding); ITypeEditor editor = null; foreach (Attribute attr in propertyItem.PropertyDescriptor.Attributes) { if (attr is EditorAttribute) { editor = Activator.CreateInstance(Type.GetType((attr as EditorAttribute).EditorTypeName)) as ITypeEditor; if (editor != null) { editor.Attach(propertyItem); propertyItem.Editor = editor.ResolveEditor(); if (property is CustomizePropertyDescriptor) { propertyItem.Editor.IsEnabled = (property as CustomizePropertyDescriptor).IsEnabled; } return(propertyItem); } } } //check for custom editor if (CustomTypeEditors.Count > 0) { //first check if the custom editor is type based ICustomTypeEditor customEditor = CustomTypeEditors[propertyItem.PropertyType]; if (customEditor == null) { //must be property based customEditor = CustomTypeEditors[propertyItem.Name]; } if (customEditor != null) { editor = customEditor.Editor; } } try { //no custom editor found if (editor == null) { if (propertyItem.IsReadOnly) { editor = new TextBlockEditor(); } else if (propertyItem.PropertyType == typeof(bool) || propertyItem.PropertyType == typeof(bool?)) { editor = new CheckBoxEditor(); } else if (propertyItem.PropertyType == typeof(decimal) || propertyItem.PropertyType == typeof(decimal?)) { editor = new DecimalUpDownEditor(); } else if (propertyItem.PropertyType == typeof(double) || propertyItem.PropertyType == typeof(double?)) { editor = new DoubleUpDownEditor(); } else if (propertyItem.PropertyType == typeof(int) || propertyItem.PropertyType == typeof(int?)) { editor = new IntegerUpDownEditor(); } else if (propertyItem.PropertyType == typeof(DateTime) || propertyItem.PropertyType == typeof(DateTime?)) { editor = new DateTimeUpDownEditor(); } else if ((propertyItem.PropertyType == typeof(Color))) { editor = new ColorEditor(); } else if (propertyItem.PropertyType.IsEnum) { editor = new EnumEditor(); } else if (propertyItem.PropertyType == typeof(FontFamily) || propertyItem.PropertyType == typeof(FontWeight) || propertyItem.PropertyType == typeof(FontStyle) || propertyItem.PropertyType == typeof(FontStretch)) { editor = new FontComboBoxEditor(); } else if (propertyItem.PropertyType.IsGenericType) { if (propertyItem.PropertyType.GetInterface("IList") != null) { var t = propertyItem.PropertyType.GetGenericArguments()[0]; if (!t.IsPrimitive && !t.Equals(typeof(String))) { editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.CollectionEditor(); } else { editor = new Microsoft.Windows.Controls.PropertyGrid.Editors.PrimitiveTypeCollectionEditor(); } } else { editor = new TextBlockEditor(); } } else { editor = new TextBoxEditor(); } } } catch (Exception ex) { //TODO: handle this some how } editor.Attach(propertyItem); propertyItem.Editor = editor.ResolveEditor(); if (property is CustomizePropertyDescriptor) { propertyItem.Editor.IsEnabled = (property as CustomizePropertyDescriptor).IsEnabled; } return(propertyItem); }
static void Check(TextBoxEditor editor, string keys, string expectedText) { Check(editor, keys, expectedText, expectedText.Length, 0); }
static void Check(TextBoxEditor editor, string keys, string expectedText, int expectedStart, int expectedLength) { var slice = new TextSlice(expectedText, expectedStart, expectedLength, true); Check(editor, keys, slice); }