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

« back to all changes in this revision

Viewing changes to Tomboy/Plugins/FixedWidth.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2007-07-16 10:26:35 UTC
  • mfrom: (1.1.21 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20070716102635-0wzk26jo50csob7b
Tags: 0.7.2-0ubuntu1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Add a 'fixed width' item to the font styles menu.
2
 
// (C) 2006 Ryan Lortie <desrt@desrt.ca>, LGPL 2.1 or later.
3
 
// vim:set sw=8 noet:
4
 
 
5
 
using Mono.Unix;
6
 
using System;
7
 
using Gtk;
8
 
 
9
 
using Tomboy;
10
 
 
11
 
class FixedWidthTag : NoteTag
12
 
{
13
 
        public FixedWidthTag () 
14
 
                : base ("monospace") 
15
 
        {
16
 
        }
17
 
 
18
 
        public override void Initialize (string element_name)
19
 
        {
20
 
                base.Initialize (element_name);
21
 
                Family = "monospace";
22
 
                CanGrow = true;
23
 
                CanUndo = true;
24
 
        }
25
 
}
26
 
 
27
 
class FixedWidthMenuItem : CheckMenuItem
28
 
{
29
 
        NotePlugin Plugin;
30
 
        bool event_freeze;
31
 
 
32
 
        public FixedWidthMenuItem (NotePlugin plugin) 
33
 
                : base ("<span font_family='monospace'>" +
34
 
                        Catalog.GetString ("_Fixed Width") +
35
 
                        "</span>")
36
 
        {
37
 
                ((Label) Child).UseUnderline = true;
38
 
                ((Label) Child).UseMarkup = true;
39
 
 
40
 
                Plugin = plugin;
41
 
                Plugin.Window.TextMenu.Shown += MenuShown;
42
 
 
43
 
                ShowAll();
44
 
        }
45
 
 
46
 
        protected void MenuShown (object sender, EventArgs e)
47
 
        {
48
 
                event_freeze = true;
49
 
                Active = Plugin.Buffer.IsActiveTag ("monospace");
50
 
                event_freeze = false;
51
 
        }
52
 
 
53
 
        protected override void OnActivated ()
54
 
        {
55
 
                if (!event_freeze)
56
 
                        Plugin.Buffer.ToggleActiveTag ("monospace");
57
 
 
58
 
                base.OnActivated();
59
 
        }
60
 
 
61
 
        protected override void OnDestroyed ()
62
 
        {
63
 
                if (Plugin.HasWindow)
64
 
                        Plugin.Window.TextMenu.Shown -= MenuShown;
65
 
 
66
 
                base.OnDestroyed();
67
 
        }
68
 
}
69
 
 
70
 
[PluginInfo(
71
 
        "Fixed Width Plugin", Defines.VERSION,
72
 
        PluginInfoAttribute.OFFICIAL_AUTHOR,
73
 
        "Adds fixed-width font style.",
74
 
        WebSite = Defines.TOMBOY_WEBSITE
75
 
        )]
76
 
public class FixedWidthPlugin : NotePlugin
77
 
{
78
 
        TextTag tag;
79
 
 
80
 
        protected override void Initialize ()
81
 
        {
82
 
                // If a tag of this name already exists, don't install.
83
 
                if (Note.TagTable.Lookup ("monospace") == null) {
84
 
                        tag = new FixedWidthTag ();
85
 
                        Note.TagTable.Add (tag);
86
 
                }
87
 
        }
88
 
 
89
 
        protected override void Shutdown ()
90
 
        {
91
 
                // Remove the tag only if we installed it.
92
 
                if (tag != null)
93
 
                        Note.TagTable.Remove (tag);
94
 
        }
95
 
 
96
 
        protected override void OnNoteOpened () 
97
 
        {
98
 
                // Add here instead of in Initialize to avoid creating unopened
99
 
                // notes' windows/buffers.
100
 
                AddTextMenuItem (new FixedWidthMenuItem (this));
101
 
        }
102
 
}