~ted/ubuntu/lucid/tomboy/with-patch

« back to all changes in this revision

Viewing changes to Tomboy/NoteAddin.cs

Tags: upstream-0.7.2
Import upstream version 0.7.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
using System;
 
3
using System.Collections.Generic;
 
4
 
 
5
namespace Tomboy
 
6
{
 
7
        /// <summary>
 
8
        /// A NoteAddin extends the functionality of a note and a NoteWindow.
 
9
        /// If you wish to extend Tomboy in a more broad sense, perhaps you
 
10
        /// should create an ApplicationAddin.
 
11
        /// <summary>
 
12
        public abstract class NoteAddin : AbstractAddin
 
13
        {
 
14
                Note note;
 
15
 
 
16
                List<Gtk.MenuItem> tools_menu_items;
 
17
                List<Gtk.MenuItem> text_menu_items;
 
18
 
 
19
                public void Initialize (Note note)
 
20
                {
 
21
                        this.note = note;
 
22
                        this.note.Opened += OnNoteOpenedEvent;
 
23
 
 
24
                        Initialize ();
 
25
 
 
26
                        if (note.IsOpened)
 
27
                                OnNoteOpened ();
 
28
                }
 
29
 
 
30
                protected override void Dispose (bool disposing)
 
31
                {
 
32
                        if (disposing) {
 
33
                                if (tools_menu_items != null) {
 
34
                                        foreach (Gtk.Widget item in tools_menu_items)
 
35
                                                item.Destroy ();
 
36
                                }
 
37
 
 
38
                                if (text_menu_items != null) {
 
39
                                        foreach (Gtk.Widget item in text_menu_items)
 
40
                                                item.Destroy ();
 
41
                                }
 
42
 
 
43
                                Shutdown ();
 
44
                        }
 
45
 
 
46
                        note.Opened -= OnNoteOpenedEvent;
 
47
                }
 
48
                
 
49
                /// <summary>
 
50
                /// Called when the NoteAddin is attached to a Note
 
51
                /// </summary>
 
52
                public abstract void Initialize ();
 
53
                
 
54
                /// <summary>
 
55
                /// Called when a note is deleted and also when
 
56
                /// the addin is disabled.
 
57
                /// </summary>
 
58
                public abstract void Shutdown ();
 
59
                
 
60
                /// <summary>
 
61
                /// Called when the note is opened.
 
62
                /// </summary>
 
63
                public abstract void OnNoteOpened ();
 
64
 
 
65
                public Note Note
 
66
                {
 
67
                        get { return note; }
 
68
                }
 
69
 
 
70
                public bool HasBuffer
 
71
                {
 
72
                        get { return note.HasBuffer; }
 
73
                }
 
74
 
 
75
                public NoteBuffer Buffer
 
76
                {
 
77
                        get
 
78
                        {
 
79
                                if (IsDisposing && !HasBuffer)
 
80
                                        throw new InvalidOperationException ("Plugin is disposing already");
 
81
 
 
82
                                return note.Buffer; 
 
83
                        }
 
84
                }
 
85
 
 
86
                public bool HasWindow
 
87
                {
 
88
                        get { return note.HasWindow; }
 
89
                }
 
90
 
 
91
                public NoteWindow Window
 
92
                {
 
93
                        get
 
94
                        {
 
95
                                if (IsDisposing && !HasWindow)
 
96
                                        throw new InvalidOperationException ("Plugin is disposing already");
 
97
 
 
98
                                return note.Window; 
 
99
                        }
 
100
                }
 
101
 
 
102
                public NoteManager Manager
 
103
                {
 
104
                        get { return note.Manager; }
 
105
                }
 
106
 
 
107
                void OnNoteOpenedEvent (object sender, EventArgs args)
 
108
                {
 
109
                        OnNoteOpened ();
 
110
 
 
111
                        if (tools_menu_items != null) {
 
112
                                foreach (Gtk.Widget item in tools_menu_items) {
 
113
                                        if (item.Parent == null || 
 
114
                                            item.Parent != Window.PluginMenu)
 
115
                                                Window.PluginMenu.Add (item);
 
116
                                }
 
117
                        }
 
118
 
 
119
                        if (text_menu_items != null) {
 
120
                                foreach (Gtk.Widget item in text_menu_items) {
 
121
                                        if (item.Parent == null || 
 
122
                                            item.Parent != Window.TextMenu) {
 
123
                                                Window.TextMenu.Add (item);
 
124
                                                Window.TextMenu.ReorderChild (item, 7);
 
125
                                        }
 
126
                                }
 
127
                        }
 
128
                }
 
129
 
 
130
                public void AddPluginMenuItem (Gtk.MenuItem item)
 
131
                {
 
132
                        if (IsDisposing)
 
133
                                throw new InvalidOperationException ("Plugin is disposing already");
 
134
 
 
135
                        if (tools_menu_items == null)
 
136
                                tools_menu_items = new List<Gtk.MenuItem> ();
 
137
 
 
138
                        tools_menu_items.Add (item);
 
139
 
 
140
                        if (note.IsOpened)
 
141
                                Window.PluginMenu.Add (item);
 
142
                }
 
143
 
 
144
                public void AddTextMenuItem (Gtk.MenuItem item)
 
145
                {
 
146
                        if (IsDisposing)
 
147
                                throw new InvalidOperationException ("Plugin is disposing already");
 
148
 
 
149
                        if (text_menu_items == null)
 
150
                                text_menu_items = new List<Gtk.MenuItem> ();
 
151
 
 
152
                        text_menu_items.Add (item);
 
153
 
 
154
                        if (note.IsOpened) {
 
155
                                Window.TextMenu.Add (item);
 
156
                                Window.TextMenu.ReorderChild (item, 7);
 
157
                        }
 
158
                }
 
159
        }
 
160
}