2
* StringEditor.cs - Visual editor for strings, or values that
3
* convert to/from strings.
5
* Part of PropertyGrid - A Gtk# widget that displays and allows
6
* editing of all of an object's public properties
9
* Michael Hutchinson <m.j.hutchinson@gmail.com>
11
* Copyright (C) 2005 Michael Hutchinson
13
* This sourcecode is licenced under The MIT License:
15
* Permission is hereby granted, free of charge, to any person obtaining
16
* a copy of this software and associated documentation files (the
17
* "Software"), to deal in the Software without restriction, including
18
* without limitation the rights to use, copy, modify, merge, publish,
19
* distribute, sublicense, and/or sell copies of the Software, and to permit
20
* persons to whom the Software is furnished to do so, subject to the
21
* following conditions:
23
* The above copyright notice and this permission notice shall be included in
24
* all copies or substantial portions of the Software.
26
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
27
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
29
* NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
30
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
31
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
32
* USE OR OTHER DEALINGS IN THE SOFTWARE.
36
using System.ComponentModel;
39
namespace MonoDevelop.DesignerSupport.PropertyGrid.PropertyEditors
42
[PropertyEditorType (typeof (string))]
43
public class StringEditor : BaseEditor
46
public StringEditor (GridRow parentRow)
51
public override bool InPlaceEdit {
55
public override Widget GetEditWidget ()
57
Entry entry = new Entry ();
59
if (parentRow.PropertyValue == null)
62
entry.Text = parentRow.PropertyDescriptor.Converter.ConvertToString (parentRow.PropertyValue);
64
entry.HasFrame = false;
65
entry.WidthRequest = 30; //Don't artificially inflate the width. It expands anyway.
66
//TODO: Is entry.Changed too responsive?
67
//entry.Changed += new EventHandler (entry_Changed);
68
entry.Destroyed += new EventHandler (entry_Changed);
69
entry.Activated += new EventHandler (entry_Changed);
74
void entry_Changed (object sender, EventArgs e)
76
//Catching all exceptions is bad, but converter can throw all sorts of exception
77
//with invalid entries. We just want to ignore bad entries.
78
string text = ((Entry) sender).Text;
80
//if value was null and new value is empty, leave as null
81
if (!(text == "" && parentRow.PropertyValue== null))
82
parentRow.PropertyValue = parentRow.PropertyDescriptor.Converter.ConvertFromString (((Entry) sender).Text);
86
//we want to give a helpful error message: even if we ignore these exceptions
87
//most of the time, the error may still be useful when debugging controls
88
System.Diagnostics.Trace.WriteLine (
89
"PropertyGrid String Editor: TypeConverter could not convert string \"" + text +
90
"\" to " + parentRow.PropertyDescriptor.PropertyType.ToString () +
91
" for property \"" + parentRow.PropertyDescriptor.DisplayName + "\".\n" +
92
"Error details: "+ ex.Message
97
public override bool DialogueEdit {