~ubuntu-branches/ubuntu/lucid/tomboy/lucid-proposed

« back to all changes in this revision

Viewing changes to Tomboy/NoteBuffer.cs

Tags: upstream-0.5.6
Import upstream version 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
                        InsertText += TextInsertedEvent;
41
41
                        MarkSet += MarkSetEvent;
 
42
                        
 
43
                        TagApplied += OnTagApplied;
42
44
 
43
45
                        tags.TagChanged += OnTagChanged;
44
46
 
63
65
                        Gtk.TextIter select_start, select_end;
64
66
 
65
67
                        if (GetSelectionBounds (out select_start, out select_end)) {
 
68
                                // Ignore the bullet character
 
69
                                if (FindDepthTag(ref select_start) != null)
 
70
                                        select_start.LineOffset = 2;
 
71
 
66
72
                                if (select_start.BeginsTag (tag) || select_start.HasTag (tag))
67
73
                                        RemoveTag (tag, select_start, select_end);
68
74
                                else
103
109
                        }
104
110
                }
105
111
 
 
112
                public void OnTagApplied (object o, Gtk.TagAppliedArgs args)
 
113
                {       
 
114
                        if (!(args.Tag is DepthNoteTag)) {
 
115
                                // Remove the tag from any bullets in the selection
 
116
                                Undoer.FreezeUndo ();
 
117
                                Gtk.TextIter iter;
 
118
                                for (int i = args.StartChar.Line; i <= args.EndChar.Line; i++) {
 
119
                                        iter = GetIterAtLine(i);
 
120
                                        
 
121
                                        if (FindDepthTag (ref iter) != null) {
 
122
                                                Gtk.TextIter next = iter;
 
123
                                                next.ForwardChars (2);
 
124
                                                RemoveTag (args.Tag, iter, next);
 
125
                                        }
 
126
                                }
 
127
                                Undoer.ThawUndo ();
 
128
                        } else {
 
129
                                // Remove any existing tags when a depth tag is applied
 
130
                                Undoer.FreezeUndo ();
 
131
                                foreach (Gtk.TextTag tag in args.StartChar.Tags) {
 
132
                                        if (!(tag is DepthNoteTag)) {
 
133
                                                RemoveTag (tag, args.StartChar, args.EndChar);
 
134
                                        }
 
135
                                }
 
136
                                Undoer.ThawUndo ();
 
137
                        }
 
138
                }
 
139
 
106
140
                public bool IsActiveTag (string tag_name)
107
141
                {
108
142
                        Gtk.TextTag tag = TagTable.Lookup (tag_name);
109
143
                        Gtk.TextIter iter, select_end;
110
144
 
111
 
                        if (GetSelectionBounds (out iter, out select_end))
 
145
                        if (GetSelectionBounds (out iter, out select_end)) {
 
146
                                // Ignore the bullet character and look at the
 
147
                                // first character of the list item
 
148
                                if (FindDepthTag(ref iter) != null)
 
149
                                        iter.ForwardChars (2);
112
150
                                return iter.BeginsTag (tag) || iter.HasTag (tag);
113
 
                        else
 
151
                        } else {
114
152
                                return active_tags.Contains (tag);
 
153
                        }
115
154
                }
116
155
                
117
156
                // Returns true if the cursor is inside of a bulleted list
128
167
                        
129
168
                        return true;
130
169
                }
 
170
                
 
171
                // Returns true if the cursor is at a position that can
 
172
                // be made into a bulleted list
 
173
                public bool CanMakeBulletedList ()
 
174
                {
 
175
                        Gtk.TextMark insert_mark = InsertMark;
 
176
                        Gtk.TextIter iter = GetIterAtMark (insert_mark);
 
177
                        
 
178
                        if (iter.Line == 0)
 
179
                                return false;
 
180
                        
 
181
                        return true;                    
 
182
                }
131
183
 
132
184
                // Apply active_tags to inserted text
133
185
                void TextInsertedEvent (object sender, Gtk.InsertTextArgs args)
153
205
                }
154
206
                
155
207
                public bool AddNewline()
156
 
                {                       
 
208
                {       
 
209
                        if (!CanMakeBulletedList())
 
210
                                return false;
 
211
                                
157
212
                        Gtk.TextMark insert_mark = InsertMark;
158
213
                        Gtk.TextIter iter = GetIterAtMark (insert_mark);
159
214
                        iter.LineOffset = 0;
595
650
 
596
651
                public void IncreaseCursorDepth ()
597
652
                {
598
 
                        Gtk.TextMark insert_mark = InsertMark;
599
 
                        Gtk.TextIter insert_iter = GetIterAtMark (insert_mark);
600
 
 
601
 
                        insert_iter.LineOffset = 0;
602
 
 
603
 
                        IncreaseDepth (ref insert_iter);
 
653
                        ChangeCursorDepth (true);
604
654
                }
605
655
                
606
656
                public void DecreaseCursorDepth ()
607
657
                {
608
 
                        Gtk.TextMark insert_mark = InsertMark;
609
 
                        Gtk.TextIter insert_iter = GetIterAtMark (insert_mark);
610
 
                        
611
 
                        DecreaseDepth (ref insert_iter);
 
658
                        ChangeCursorDepth (false);
 
659
                }
 
660
                
 
661
                void ChangeCursorDepth(bool increase)
 
662
                {
 
663
                        Gtk.TextIter start;
 
664
                        Gtk.TextIter end;
 
665
                        
 
666
                        GetSelectionBounds (out start, out end);
 
667
                        
 
668
                        Gtk.TextIter curr_line;
 
669
                        
 
670
                        int start_line = start.Line;
 
671
                        int end_line = end.Line;
 
672
                        
 
673
                        for (int i = start_line; i <= end_line; i++) {
 
674
                                curr_line = GetIterAtLine(i);
 
675
                                if (increase)
 
676
                                        IncreaseDepth (ref curr_line);
 
677
                                else
 
678
                                        DecreaseDepth (ref curr_line);
 
679
                        }               
612
680
                }
613
681
                
614
682
                public void InsertBullet (ref Gtk.TextIter iter, int depth)
645
713
                
646
714
                public void IncreaseDepth (ref Gtk.TextIter start)
647
715
                {
 
716
                        if (!CanMakeBulletedList())
 
717
                                return;
 
718
                                
648
719
                        Gtk.TextIter end;
649
720
 
650
721
                        start = GetIterAtLineOffset (start.Line, 0);
676
747
                                
677
748
                public void DecreaseDepth (ref Gtk.TextIter start)
678
749
                {
 
750
                        if (!CanMakeBulletedList())
 
751
                                return;
 
752
                                                
679
753
                        Gtk.TextIter end;
680
754
 
681
755
                        start = GetIterAtLineOffset (start.Line, 0);
930
1004
                                bool end_of_depth_line = line_has_depth && next_iter.EndsLine ();
931
1005
 
932
1006
                                bool next_line_has_depth = false;
933
 
                                if (iter.Line < buffer.LineCount) {
 
1007
                                if (iter.Line < buffer.LineCount - 1) {
934
1008
                                        Gtk.TextIter next_line = buffer.GetIterAtLine(iter.Line+1);
935
1009
                                        next_line_has_depth =
936
1010
                                                ((NoteBuffer)buffer).FindDepthTag(ref next_line) != null;
996
1070
                                if (end_of_depth_line && !next_line_has_depth) {
997
1071
                                        for (int i = prev_depth; i > -1; i--) {
998
1072
                                                // Close <list>
999
 
                                                xml.WriteEndElement ();
 
1073
                                                xml.WriteFullEndElement ();
1000
1074
                                                // Close <list-item>
1001
 
                                                xml.WriteEndElement ();
 
1075
                                                xml.WriteFullEndElement ();
1002
1076
                                        }
1003
1077
                                                        
1004
1078
                                        prev_depth = -1;