~ubuntu-branches/ubuntu/feisty/monodevelop/feisty

« back to all changes in this revision

Viewing changes to Extras/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.PropertyGrid.Editors/StringEditor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-08-18 00:51:23 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060818005123-5iit07y0j7wjg55f
Tags: 0.11+svn20060818-0ubuntu1
* New SVN snapshot
  + Works with Gtk# 2.9.0
* debian/control:
  + Updated Build-Depends
* debian/patches/use_nunit2.2.dpatch,
  debian/patches/use_real_libs.dpatch:
  + Updated
* debian/patches/versioncontrol_buildfix.dpatch:
  + Fix build failure in the version control addin

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * StringEditor.cs - Visual editor for strings, or values that
 
3
 *      convert to/from strings.
 
4
 * 
 
5
 * Part of PropertyGrid - A Gtk# widget that displays and allows 
 
6
 * editing of all of an object's public properties 
 
7
 * 
 
8
 * Authors: 
 
9
 *  Michael Hutchinson <m.j.hutchinson@gmail.com>
 
10
 *  
 
11
 * Copyright (C) 2005 Michael Hutchinson
 
12
 *
 
13
 * This sourcecode is licenced under The MIT License:
 
14
 * 
 
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:
 
22
 * 
 
23
 * The above copyright notice and this permission notice shall be included in
 
24
 * all copies or substantial portions of the Software.
 
25
 *
 
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.
 
33
 */
 
34
 
 
35
using System;
 
36
using System.ComponentModel;
 
37
using Gtk;
 
38
 
 
39
namespace MonoDevelop.DesignerSupport.PropertyGrid.PropertyEditors
 
40
{
 
41
 
 
42
        [PropertyEditorType (typeof (string))]
 
43
        public class StringEditor : BaseEditor
 
44
        {
 
45
 
 
46
                public StringEditor (GridRow parentRow)
 
47
                        : base (parentRow)
 
48
                {
 
49
                }
 
50
 
 
51
                public override bool InPlaceEdit {
 
52
                        get { return true; }
 
53
                }
 
54
 
 
55
                public override Widget GetEditWidget ()
 
56
                {
 
57
                        Entry entry = new Entry ();
 
58
 
 
59
                        if (parentRow.PropertyValue == null)
 
60
                                entry.Text = null;
 
61
                        else
 
62
                                entry.Text = parentRow.PropertyDescriptor.Converter.ConvertToString (parentRow.PropertyValue);
 
63
                        
 
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);
 
70
 
 
71
                        return entry;
 
72
                }
 
73
 
 
74
                void entry_Changed (object sender, EventArgs e)
 
75
                {
 
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;
 
79
                        try {
 
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);
 
83
                        }
 
84
                        catch (Exception ex)
 
85
                        {
 
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
 
93
                                );
 
94
                        }
 
95
                }
 
96
 
 
97
                public override bool DialogueEdit {
 
98
                        get { return false; }
 
99
                }
 
100
        }
 
101
 
 
102
}