Merge lp:~ryanriffle/writer/instant_style_apply into lp:writer

Proposed by Ryan Riffle
Status: Merged
Merged at revision: 75
Proposed branch: lp:~ryanriffle/writer/instant_style_apply
Merge into: lp:writer
Diff against target: 635 lines (+171/-116)
2 files modified
src/Utils/TextEditor.vala (+137/-85)
src/Widgets/TextToolBar.vala (+34/-31)
To merge this branch: bzr merge lp:~ryanriffle/writer/instant_style_apply
Reviewer Review Type Date Requested Status
Tuur Dutoit Approve
Review via email: mp+244681@code.launchpad.net

Description of the change

I made clicking bold, italic, and underline apply the style instead of having to select the text first. Also in TextToolbar I added focus_on_click = false to the other buttons aside from bold.

I had to change the way TextEditor.cursor_moved is called, because the notify caused cursor_moved_callback to be called before text_insert_callback was called, therefore resetting the styles. Also added a mouse click event because Gtk.TextView.move_cursor signal does not emit if the user clicks somewhere in the text.

To post a comment you must log in.
Revision history for this message
Ryan Riffle (ryanriffle) wrote :

I am not sure what the design should be. Whether you want to use a dictionary for the added members or a new TextStyle class. Just let me know and I can change it.

Revision history for this message
Ryan Riffle (ryanriffle) wrote :

Is this going to be reviewed?

Revision history for this message
Tuur Dutoit (tuur-dutoit-f) wrote :

Yes, of course. I'm sorry, I've been lazy the last few days (after exams...). Tomorrow I'll get some work done.

Revision history for this message
Tuur Dutoit (tuur-dutoit-f) wrote :

That's very good, I'm merging it in.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/Utils/TextEditor.vala'
--- src/Utils/TextEditor.vala 2014-10-26 10:41:33 +0000
+++ src/Utils/TextEditor.vala 2014-12-14 05:22:00 +0000
@@ -30,73 +30,110 @@
3030
31namespace Writer {31namespace Writer {
32 public class TextEditor : TextBuffer {32 public class TextEditor : TextBuffer {
33 33
34 public TextView text_view;34 public TextView text_view;
35 35 public bool style_bold;
36 public bool style_italic;
37 public bool style_underline;
38 public bool style_strikethrough;
39
36 public signal void cursor_moved ();40 public signal void cursor_moved ();
37 public signal void text_inserted ();41 public signal void text_inserted ();
38 42
39 public TextEditor () {43 public TextEditor () {
40 setup_tagtable (this);44 setup_tagtable (this);
41 text_view = new TextView.with_buffer (this);45 text_view = new TextView.with_buffer (this);
42 46
43 this.notify["cursor-position"].connect (cursor_moved_callback);47 style_bold = false;
48 style_italic = false;
49 style_underline = false;
50 style_strikethrough = false;
51
52 text_view.move_cursor.connect (cursor_moved_callback);
53 text_view.button_release_event.connect (editor_clicked_callback);
44 this.insert_text.connect_after (text_inserted_callback);54 this.insert_text.connect_after (text_inserted_callback);
45 55
46 text_view.key_press_event.connect (key_press_callback);56 text_view.key_press_event.connect (key_press_callback);
47 text_view.pixels_below_lines = 20;57 text_view.pixels_below_lines = 20;
48 }58 }
49 59
50 // Get a TextTagTable with all the default tags60 // Get a TextTagTable with all the default tags
51 private void setup_tagtable (TextBuffer buffer) {61 private void setup_tagtable (TextBuffer buffer) {
52 62
53 buffer.create_tag ("bold", "weight", 700);63 buffer.create_tag ("bold", "weight", 700);
54 buffer.create_tag ("italic", "style", Pango.Style.ITALIC);64 buffer.create_tag ("italic", "style", Pango.Style.ITALIC);
55 buffer.create_tag ("underline", "underline", Pango.Underline.SINGLE);65 buffer.create_tag ("underline", "underline", Pango.Underline.SINGLE);
56 buffer.create_tag ("strikethrough", "strikethrough", true);66 buffer.create_tag ("strikethrough", "strikethrough", true);
57 67
58 buffer.create_tag ("align-left", "justification", Gtk.Justification.LEFT);68 buffer.create_tag ("align-left", "justification", Gtk.Justification.LEFT);
59 buffer.create_tag ("align-center", "justification", Gtk.Justification.CENTER);69 buffer.create_tag ("align-center", "justification", Gtk.Justification.CENTER);
60 buffer.create_tag ("align-right", "justification", Gtk.Justification.RIGHT);70 buffer.create_tag ("align-right", "justification", Gtk.Justification.RIGHT);
61 buffer.create_tag ("align-fill", "justification", Gtk.Justification.FILL);71 buffer.create_tag ("align-fill", "justification", Gtk.Justification.FILL);
62 72
63 }73 }
64 74
65 75
66 /*76 /*
67 * Styles (apply, remove, check)77 * Styles (apply, remove, check)
68 */78 */
69 79
70 public void apply_style (string name) {80 public void apply_style (string name) {
71 if (has_selection)81 if (has_selection)
72 get_selection_range ().apply_style (name);82 get_selection_range ().apply_style (name);
83
84 if (name == "bold")
85 style_bold = true;
86 else if (name == "italic")
87 style_italic = true;
88 else if (name == "underline")
89 style_underline = true;
90 else if (name == "strikethrough")
91 style_strikethrough = true;
73 }92 }
74 93
75 public void remove_style (string name) {94 public void remove_style (string name) {
76 if (has_selection)95 if (has_selection)
77 get_selection_range ().remove_style (name);96 get_selection_range ().remove_style (name);
97
98 if (name == "bold")
99 style_bold = false;
100 else if (name == "italic")
101 style_italic = false;
102 else if (name == "underline")
103 style_underline = false;
104 else if (name == "strikethrough")
105 style_strikethrough = false;
78 }106 }
79 107
80 public void toggle_style (string name) {108 public void toggle_style (string name) {
81 if (has_selection)109 if (has_selection)
82 get_selection_range ().toggle_style (name);110 get_selection_range ().toggle_style (name);
111
112 if (name == "bold")
113 style_bold = !style_bold;
114 else if (name == "italic")
115 style_italic = !style_italic;
116 else if (name == "underline")
117 style_underline = !style_underline;
118 else if (name == "strikethrough")
119 style_strikethrough = !style_strikethrough;
83 }120 }
84 121
85 public bool has_style (string name) {122 public bool has_style (string name) {
86 if (has_selection)123 if (has_selection)
87 return get_selection_range ().has_style (name);124 return get_selection_range ().has_style (name);
88 else125 else
89 return iter_has_style (get_cursor (), name);126 return iter_has_style (get_cursor (), name);
90 }127 }
91 128
92 129
93 public Gtk.Justification get_justification () {130 public Gtk.Justification get_justification () {
94 if (has_selection)131 if (has_selection)
95 return get_selection_range ().get_justification ();132 return get_selection_range ().get_justification ();
96 else133 else
97 return get_justification_at_iter (get_cursor ());134 return get_justification_at_iter (get_cursor ());
98 }135 }
99 136
100 public Gtk.Justification get_justification_at_iter (TextIter iter) {137 public Gtk.Justification get_justification_at_iter (TextIter iter) {
101 if (iter_has_style (iter, "align-center"))138 if (iter_has_style (iter, "align-center"))
102 return Gtk.Justification.CENTER;139 return Gtk.Justification.CENTER;
@@ -107,14 +144,14 @@
107 else144 else
108 return Gtk.Justification.LEFT;145 return Gtk.Justification.LEFT;
109 }146 }
110 147
111 public int get_justification_as_int () {148 public int get_justification_as_int () {
112 if (has_selection)149 if (has_selection)
113 return get_selection_range ().get_justification_as_int ();150 return get_selection_range ().get_justification_as_int ();
114 else151 else
115 return get_justification_as_int_at_iter (get_cursor ());152 return get_justification_as_int_at_iter (get_cursor ());
116 }153 }
117 154
118 public int get_justification_as_int_at_iter (TextIter iter) {155 public int get_justification_as_int_at_iter (TextIter iter) {
119 if (iter_has_style (iter, "align-center"))156 if (iter_has_style (iter, "align-center"))
120 return 1;157 return 1;
@@ -125,82 +162,82 @@
125 else162 else
126 return 0;163 return 0;
127 }164 }
128 165
129 public void set_justification (string align) {166 public void set_justification (string align) {
130 get_paragraph (get_cursor ()).set_justification (align);167 get_paragraph (get_cursor ()).set_justification (align);
131 }168 }
132 169
133 170
134 public void set_font (FontDescription font) {171 public void set_font (FontDescription font) {
135 get_selection_range ().set_font (font);172 get_selection_range ().set_font (font);
136 }173 }
137 174
138 public void set_font_from_string (string font) {175 public void set_font_from_string (string font) {
139 get_selection_range ().set_font_from_string (font);176 get_selection_range ().set_font_from_string (font);
140 }177 }
141 178
142 179
143 public void set_font_color (Gdk.Color color) {180 public void set_font_color (Gdk.Color color) {
144 get_selection_range ().set_font_color (color);181 get_selection_range ().set_font_color (color);
145 }182 }
146 183
147 public void set_font_color_from_string (string color) {184 public void set_font_color_from_string (string color) {
148 get_selection_range ().set_font_color_from_string (color);185 get_selection_range ().set_font_color_from_string (color);
149 }186 }
150 187
151 188
152 189
153 /*190 /*
154 * Inserts191 * Inserts
155 */192 */
156 193
157 public void insert_comment () {194 public void insert_comment () {
158 print ("Insert Comment\n");195 print ("Insert Comment\n");
159 }196 }
160 197
161 public void insert_image () {198 public void insert_image () {
162 print ("Insert Image\n");199 print ("Insert Image\n");
163 }200 }
164 201
165 public void insert_link () {202 public void insert_link () {
166 print ("Insert Link\n");203 print ("Insert Link\n");
167 }204 }
168 205
169 public void insert_table (int cols, int rows) {206 public void insert_table (int cols, int rows) {
170 print ("Insert Table of %d columns by %d rows\n", cols, rows);207 print ("Insert Table of %d columns by %d rows\n", cols, rows);
171 }208 }
172 209
173 210
174 public void insert_line () {211 public void insert_line () {
175 TextIter insert_cursor = get_cursor ();212 TextIter insert_cursor = get_cursor ();
176 insert_line_at_iter (insert_cursor);213 insert_line_at_iter (insert_cursor);
177 }214 }
178 215
179 public void insert_paragraph () {216 public void insert_paragraph () {
180 TextIter cursor = get_cursor ();217 TextIter cursor = get_cursor ();
181 insert_paragraph_at_iter (cursor);218 insert_paragraph_at_iter (cursor);
182 }219 }
183 220
184 public void insert_line_at_iter (TextIter iter) {221 public void insert_line_at_iter (TextIter iter) {
185 //TODO222 //TODO
186 // Cursor does not move to next line223 // Cursor does not move to next line
187 // Only happens when inserting at the end of the buffer224 // Only happens when inserting at the end of the buffer
188 // Bug reported in GTK+225 // Bug reported in GTK+
189 226
190 insert (ref iter, "\u2028", -1);227 insert (ref iter, "\u2028", -1);
191 }228 }
192 229
193 public void insert_paragraph_at_iter (TextIter iter) {230 public void insert_paragraph_at_iter (TextIter iter) {
194 insert (ref iter, "\n", -1);231 insert (ref iter, "\n", -1);
195 }232 }
196 233
197 234
198 235
199 236
200 /*237 /*
201 * paragraphs238 * paragraphs
202 */239 */
203 240
204 // Moves iter to the start of the paragraph it is located in241 // Moves iter to the start of the paragraph it is located in
205 public TextIter get_paragraph_start (TextIter iter) {242 public TextIter get_paragraph_start (TextIter iter) {
206 iter.backward_find_char ((char) => {243 iter.backward_find_char ((char) => {
@@ -211,7 +248,7 @@
211 }, null);248 }, null);
212 return iter;249 return iter;
213 }250 }
214 251
215 // Moves iter to the end of the paragraph it is located in252 // Moves iter to the end of the paragraph it is located in
216 public TextIter get_paragraph_end (TextIter iter) {253 public TextIter get_paragraph_end (TextIter iter) {
217 iter.forward_find_char ((char) => {254 iter.forward_find_char ((char) => {
@@ -222,121 +259,136 @@
222 }, null);259 }, null);
223 return iter;260 return iter;
224 }261 }
225 262
226 public TextRange get_paragraph (TextIter iter) {263 public TextRange get_paragraph (TextIter iter) {
227 TextIter start = get_paragraph_start (iter);264 TextIter start = get_paragraph_start (iter);
228 TextIter end = get_paragraph_end (iter);265 TextIter end = get_paragraph_end (iter);
229 266
230 return new TextRange (this, start, end);267 return new TextRange (this, start, end);
231 }268 }
232 269
233 270
234 271
235 272
236 /*273 /*
237 * Search274 * Search
238 */275 */
239 276
240 public void search (string text) {277 public void search (string text) {
241 if (text.length > 0)278 if (text.length > 0)
242 search_string (text);279 search_string (text);
243 else280 else
244 clear_search ();281 clear_search ();
245 }282 }
246 283
247 public void search_string (string text) {284 public void search_string (string text) {
248 print ("Searching for: %s\n", text);285 print ("Searching for: %s\n", text);
249 }286 }
250 287
251 public void clear_search () {288 public void clear_search () {
252 print ("Clearing search");289 print ("Clearing search");
253 }290 }
254 291
255 292
256 293
257 /*294 /*
258 * Utilities295 * Utilities
259 */296 */
260 297
261 public TextIter get_cursor () {298 public TextIter get_cursor () {
262 TextIter iter;299 TextIter iter;
263 get_iter_at_mark (out iter, get_insert ());300 get_iter_at_mark (out iter, get_insert ());
264 return iter;301 return iter;
265 }302 }
266 303
267 public TextRange get_cursor_as_range () {304 public TextRange get_cursor_as_range () {
268 var cursor = get_cursor ();305 var cursor = get_cursor ();
269 return new TextRange (this, cursor, cursor);306 return new TextRange (this, cursor, cursor);
270 }307 }
271 308
272 public TextRange get_selection_range () {309 public TextRange get_selection_range () {
273 TextIter start; TextIter end;310 TextIter start; TextIter end;
274 get_selection_bounds (out start, out end);311 get_selection_bounds (out start, out end);
275 return new TextRange (this, start, end);312 return new TextRange (this, start, end);
276 }313 }
277 314
278 public bool iter_has_tag (TextIter iter, TextTag tag) {315 public bool iter_has_tag (TextIter iter, TextTag tag) {
279 return iter.has_tag (tag) || iter.begins_tag (tag) || iter.ends_tag (tag);316 return iter.has_tag (tag) || iter.begins_tag (tag) || iter.ends_tag (tag);
280 }317 }
281 318
282 public bool iter_has_style (TextIter iter, string name) {319 public bool iter_has_style (TextIter iter, string name) {
283 var tag = tag_table.lookup (name);320 var tag = tag_table.lookup (name);
284 return iter_has_tag (iter, tag);321 return iter_has_tag (iter, tag);
285 }322 }
286 323
287 public TextIter copy_iter (TextIter iter) {324 public TextIter copy_iter (TextIter iter) {
288 TextIter copy;325 TextIter copy;
289 get_iter_at_offset (out copy, iter.get_offset ());326 get_iter_at_offset (out copy, iter.get_offset ());
290 return copy;327 return copy;
291 }328 }
292 329
293 330
294 331
295 332 private void update_styles () {
296 333 var iter = get_cursor();
334
335 style_bold = iter_has_style (iter, "bold");
336 style_italic = iter_has_style (iter, "italic");
337 style_underline = iter_has_style (iter, "underline");
338 style_strikethrough = iter_has_style (iter, "strikethrough");
339 }
340
297 /*341 /*
298 * Signal callbacks342 * Signal callbacks
299 */343 */
300 344
301 private void cursor_moved_callback () {345 private void cursor_moved_callback () {
302 // Emit 'cursor_moved' signal346 // Emit 'cursor_moved' signal
347 update_styles ();
303 cursor_moved ();348 cursor_moved ();
304 }349 }
305 350
306 private void text_inserted_callback (TextIter cursor, string new_text, int length) {351 private void text_inserted_callback (TextIter cursor, string new_text, int length) {
307 TextIter previous;352 TextIter previous;
308 get_iter_at_offset (out previous, cursor.get_offset () - length);353 get_iter_at_offset (out previous, cursor.get_offset () - length);
309 354
310 if (iter_has_style (previous, "bold"))355 if (style_bold)
311 apply_tag_by_name ("bold", previous, cursor);356 apply_tag_by_name ("bold", previous, cursor);
312 if (iter_has_style (previous, "italic"))357 if (style_italic)
313 apply_tag_by_name ("italic", previous, cursor);358 apply_tag_by_name ("italic", previous, cursor);
314 if (iter_has_style (previous, "underline"))359 if (style_underline)
315 apply_tag_by_name ("underline", previous, cursor);360 apply_tag_by_name ("underline", previous, cursor);
316 if (iter_has_style (previous, "strikethrough"))361 if (style_strikethrough)
317 apply_tag_by_name ("strikethrough", previous, cursor);362 apply_tag_by_name ("strikethrough", previous, cursor);
318 363
319 364
320 // Emit signals365 // Emit signals
321 text_inserted ();366 text_inserted ();
322 cursor_moved ();367 cursor_moved ();
323 }368 }
324 369
325 private bool key_press_callback (EventKey event) {370 private bool key_press_callback (EventKey event) {
326 if (Gdk.keyval_name (event.keyval) == "Return") {371 if (Gdk.keyval_name (event.keyval) == "Return") {
327 ModifierType modifiers = Gtk.accelerator_get_default_mod_mask ();372 ModifierType modifiers = Gtk.accelerator_get_default_mod_mask ();
328 373
329 if ((event.state & modifiers) == Gdk.ModifierType.SHIFT_MASK)374 if ((event.state & modifiers) == Gdk.ModifierType.SHIFT_MASK)
330 insert_line ();375 insert_line ();
331 else376 else
332 insert_paragraph ();377 insert_paragraph ();
333 378
334 return true;379 return true;
335 }380 }
336 else { 381 else {
337 return false;382 return false;
338 }383 }
339 }384 }
340 385
386 private bool editor_clicked_callback (EventButton event) {
387 update_styles ();
388 cursor_moved ();
389
390 return false;
391 }
392
341 }393 }
342}
343\ No newline at end of file394\ No newline at end of file
395}
344396
=== modified file 'src/Widgets/TextToolBar.vala'
--- src/Widgets/TextToolBar.vala 2014-12-07 19:18:49 +0000
+++ src/Widgets/TextToolBar.vala 2014-12-14 05:22:00 +0000
@@ -29,7 +29,7 @@
2929
30namespace Writer.Widgets {30namespace Writer.Widgets {
31 public class TextToolBar : Gtk.Toolbar {31 public class TextToolBar : Gtk.Toolbar {
32 32
33 private TextEditor editor;33 private TextEditor editor;
34 public FontButton font_button;34 public FontButton font_button;
35 public ColorButton font_color_button;35 public ColorButton font_color_button;
@@ -42,20 +42,20 @@
42 public ModeButton align_button;42 public ModeButton align_button;
43 public Gtk.SeparatorToolItem item_separator;43 public Gtk.SeparatorToolItem item_separator;
44 public Popover insert_popover;44 public Popover insert_popover;
45 45
46 public TextToolBar (TextEditor editor) {46 public TextToolBar (TextEditor editor) {
47 this.get_style_context ().add_class ("writer-toolbar");47 this.get_style_context ().add_class ("writer-toolbar");
48 48
49 this.editor = editor;49 this.editor = editor;
50 editor.cursor_moved.connect (cursor_moved);50 editor.cursor_moved.connect (cursor_moved);
51 51
52 setup_ui ();52 setup_ui ();
53 }53 }
54 54
55 public void setup_ui () {55 public void setup_ui () {
56 56
57 // Make Widgets57 // Make Widgets
58 58
59 var paragraph_combobox = new Gtk.ComboBoxText ();59 var paragraph_combobox = new Gtk.ComboBoxText ();
60 paragraph_combobox.append ("Paragraph", ("Paragraph"));60 paragraph_combobox.append ("Paragraph", ("Paragraph"));
61 paragraph_combobox.append ("Title", ("Title"));61 paragraph_combobox.append ("Title", ("Title"));
@@ -67,7 +67,7 @@
67 paragraph_combobox.set_active_id ("Paragraph");67 paragraph_combobox.set_active_id ("Paragraph");
68 var paragraph_item = new ToolItem ();68 var paragraph_item = new ToolItem ();
69 paragraph_item.add (paragraph_combobox);69 paragraph_item.add (paragraph_combobox);
70 70
71 var font_item = new ToolItem ();71 var font_item = new ToolItem ();
72 font_button = new Gtk.FontButton ();72 font_button = new Gtk.FontButton ();
73 font_button.use_font = true;73 font_button.use_font = true;
@@ -80,7 +80,7 @@
8080
81 var font_color_item = new Gtk.ToolItem ();81 var font_color_item = new Gtk.ToolItem ();
82 font_color_item.add (font_color_button);82 font_color_item.add (font_color_button);
83 83
84 var styles_item = new ToolItem ();84 var styles_item = new ToolItem ();
85 var styles_buttons = new ButtonGroup ();85 var styles_buttons = new ButtonGroup ();
86 bold_button = new Gtk.ToggleButton ();86 bold_button = new Gtk.ToggleButton ();
@@ -89,16 +89,19 @@
89 styles_buttons.pack_start (bold_button);89 styles_buttons.pack_start (bold_button);
90 italic_button = new Gtk.ToggleButton ();90 italic_button = new Gtk.ToggleButton ();
91 italic_button.add (new Image.from_icon_name ("format-text-italic-symbolic", Gtk.IconSize.BUTTON));91 italic_button.add (new Image.from_icon_name ("format-text-italic-symbolic", Gtk.IconSize.BUTTON));
92 italic_button.focus_on_click = false;
92 styles_buttons.pack_start (italic_button);93 styles_buttons.pack_start (italic_button);
93 underline_button = new Gtk.ToggleButton ();94 underline_button = new Gtk.ToggleButton ();
94 underline_button.add (new Image.from_icon_name ("format-text-underline-symbolic", Gtk.IconSize.BUTTON));95 underline_button.add (new Image.from_icon_name ("format-text-underline-symbolic", Gtk.IconSize.BUTTON));
96 underline_button.focus_on_click = false;
95 styles_buttons.pack_start (underline_button);97 styles_buttons.pack_start (underline_button);
96 strikethrough_button = new Gtk.ToggleButton ();98 strikethrough_button = new Gtk.ToggleButton ();
97 strikethrough_button.add (new Image.from_icon_name ("format-text-strikethrough-symbolic", Gtk.IconSize.BUTTON));99 strikethrough_button.add (new Image.from_icon_name ("format-text-strikethrough-symbolic", Gtk.IconSize.BUTTON));
100 strikethrough_button.focus_on_click = false;
98 styles_buttons.pack_start (strikethrough_button);101 styles_buttons.pack_start (strikethrough_button);
99 styles_item.add (styles_buttons);102 styles_item.add (styles_buttons);
100103
101 104
102 var align_item = new ToolItem ();105 var align_item = new ToolItem ();
103 align_button = new ModeButton ();106 align_button = new ModeButton ();
104 align_button.append (new Gtk.Image.from_icon_name ("format-justify-left-symbolic", Gtk.IconSize.BUTTON));107 align_button.append (new Gtk.Image.from_icon_name ("format-justify-left-symbolic", Gtk.IconSize.BUTTON));
@@ -106,7 +109,7 @@
106 align_button.append (new Gtk.Image.from_icon_name ("format-justify-right-symbolic", Gtk.IconSize.BUTTON));109 align_button.append (new Gtk.Image.from_icon_name ("format-justify-right-symbolic", Gtk.IconSize.BUTTON));
107 align_button.append (new Gtk.Image.from_icon_name ("format-justify-fill-symbolic", Gtk.IconSize.BUTTON));110 align_button.append (new Gtk.Image.from_icon_name ("format-justify-fill-symbolic", Gtk.IconSize.BUTTON));
108 align_item.add (align_button);111 align_item.add (align_button);
109 112
110 var indent_button = new ButtonGroup ();113 var indent_button = new ButtonGroup ();
111 var indent_more_button = new Button.from_icon_name ("format-indent-more-symbolic", Gtk.IconSize.BUTTON);114 var indent_more_button = new Button.from_icon_name ("format-indent-more-symbolic", Gtk.IconSize.BUTTON);
112 var indent_less_button = new Button.from_icon_name ("format-indent-less-symbolic", Gtk.IconSize.BUTTON);115 var indent_less_button = new Button.from_icon_name ("format-indent-less-symbolic", Gtk.IconSize.BUTTON);
@@ -114,9 +117,9 @@
114 indent_button.add (indent_less_button);117 indent_button.add (indent_less_button);
115 var indent_item = new Gtk.ToolItem ();118 var indent_item = new Gtk.ToolItem ();
116 indent_item.add (indent_button);119 indent_item.add (indent_button);
117 120
118 item_separator = new Gtk.SeparatorToolItem ();121 item_separator = new Gtk.SeparatorToolItem ();
119 122
120 //TODO: Set 'Insert' as title, not as Entry123 //TODO: Set 'Insert' as title, not as Entry
121 // It looks like this isn't supported by GTK+124 // It looks like this isn't supported by GTK+
122 // WTF!?125 // WTF!?
@@ -129,8 +132,8 @@
129 insert_menu.set_active (0);132 insert_menu.set_active (0);
130 var insert_item = new Gtk.ToolItem ();133 var insert_item = new Gtk.ToolItem ();
131 insert_item.add (insert_menu);134 insert_item.add (insert_menu);
132 135
133 136
134 //Set border_width on ToolItems137 //Set border_width on ToolItems
135 paragraph_item.border_width = 5;138 paragraph_item.border_width = 5;
136 font_item.border_width = 5;139 font_item.border_width = 5;
@@ -139,7 +142,7 @@
139 align_item.border_width = 5;142 align_item.border_width = 5;
140 indent_item.border_width = 5;143 indent_item.border_width = 5;
141 insert_item.border_width = 5;144 insert_item.border_width = 5;
142 145
143 // Add Widgets146 // Add Widgets
144 this.add (paragraph_item);147 this.add (paragraph_item);
145 this.add (font_item);148 this.add (font_item);
@@ -149,15 +152,15 @@
149 this.add (indent_item);152 this.add (indent_item);
150 this.add (item_separator);153 this.add (item_separator);
151 this.add (insert_item);154 this.add (insert_item);
152 155
153 156
154 157
155 // Connect signals158 // Connect signals
156 159
157 align_button.mode_changed.connect (() => {160 align_button.mode_changed.connect (() => {
158 change_align (align_button.selected);161 change_align (align_button.selected);
159 });162 });
160 163
161 font_button.font_set.connect (() => {164 font_button.font_set.connect (() => {
162 editor.set_font_from_string (font_button.get_font_name ());165 editor.set_font_from_string (font_button.get_font_name ());
163 });166 });
@@ -166,7 +169,7 @@
166 font_color_button.get_color (out color);169 font_color_button.get_color (out color);
167 editor.set_font_color (color);170 editor.set_font_color (color);
168 });171 });
169 172
170 bold_button.button_press_event.connect ((event) => {173 bold_button.button_press_event.connect ((event) => {
171 if (event.type == EventType.BUTTON_PRESS)174 if (event.type == EventType.BUTTON_PRESS)
172 editor.toggle_style ("bold");175 editor.toggle_style ("bold");
@@ -187,16 +190,16 @@
187 editor.toggle_style ("strikethrough");190 editor.toggle_style ("strikethrough");
188 return false;191 return false;
189 });192 });
190 193
191 }194 }
192 195
193 196
194 197
195 198
196 /*199 /*
197 * Signal callbacks200 * Signal callbacks
198 */201 */
199 202
200 public void change_align (int index) {203 public void change_align (int index) {
201 switch (index) {204 switch (index) {
202 case 1:205 case 1:
@@ -209,15 +212,15 @@
209 editor.set_justification ("left"); break;212 editor.set_justification ("left"); break;
210 }213 }
211 }214 }
212 215
213 public void cursor_moved () {216 public void cursor_moved () {
214 bold_button.active = editor.has_style ("bold");217 bold_button.active = editor.has_style ("bold");
215 italic_button.active = editor.has_style ("italic");218 italic_button.active = editor.has_style ("italic");
216 underline_button.active = editor.has_style ("underline");219 underline_button.active = editor.has_style ("underline");
217 strikethrough_button.active = editor.has_style ("strikethrough");220 strikethrough_button.active = editor.has_style ("strikethrough");
218 221
219 align_button.selected = editor.get_justification_as_int ();222 align_button.selected = editor.get_justification_as_int ();
220 223
221 //TODO224 //TODO
222 // Update font and color buttons225 // Update font and color buttons
223 }226 }

Subscribers

People subscribed via source and target branches

to all changes: