~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/libstetic/editor/DateTimeEditor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using Gtk;
 
4
using Gdk;
 
5
using System.Text;
 
6
 
 
7
namespace Stetic.Editor
 
8
{
 
9
        public class DateTimeEditorCell: PropertyEditorCell
 
10
        {
 
11
                protected override string GetValueText ()
 
12
                {
 
13
                        return ((DateTime)Value).ToLongDateString ();
 
14
                }
 
15
                
 
16
                protected override IPropertyEditor CreateEditor (Gdk.Rectangle cell_area, Gtk.StateType state)
 
17
                {
 
18
                        return new DateTimeEditor ();
 
19
                }
 
20
        }
 
21
        
 
22
        public class DateTimeEditor: Gtk.HBox, IPropertyEditor
 
23
        {
 
24
                Gtk.Entry entry;
 
25
                DateTime time;
 
26
                
 
27
                public DateTimeEditor()
 
28
                {
 
29
                        entry = new Gtk.Entry ();
 
30
                        entry.Changed += OnChanged;
 
31
                        PackStart (entry, true, true, 0);
 
32
                        ShowAll ();
 
33
                }
 
34
                
 
35
                public void Initialize (PropertyDescriptor descriptor)
 
36
                {
 
37
                }
 
38
                
 
39
                public void AttachObject (object ob)
 
40
                {
 
41
                }
 
42
                
 
43
                public object Value {
 
44
                        get { return time; }
 
45
                        set {
 
46
                                time = (DateTime) value;
 
47
                                entry.Changed -= OnChanged;
 
48
                                entry.Text = time.ToString ("G");
 
49
                                entry.Changed += OnChanged;
 
50
                        }
 
51
                }
 
52
                
 
53
                void OnChanged (object o, EventArgs a)
 
54
                {
 
55
                        string s = entry.Text;
 
56
                        
 
57
                        foreach (string form in formats) {
 
58
                                try {
 
59
                                        time = DateTime.ParseExact (s, form, null);
 
60
                                        if (ValueChanged != null)
 
61
                                                ValueChanged (this, a);
 
62
                                        break;
 
63
                                } catch {
 
64
                                }
 
65
                        }
 
66
                }
 
67
                
 
68
                public event EventHandler ValueChanged;
 
69
                
 
70
                static string[] formats = {"u", "G", "g", "d", "T", "t"};
 
71
        }
 
72
}