Merge lp:~ryanriffle/writer/instant_style_apply into lp:writer
- instant_style_apply
- Merge into trunk
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 |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Tuur Dutoit | Approve | ||
Review via email:
|
Commit message
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.
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ryan Riffle (ryanriffle) wrote : | # |
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Ryan Riffle (ryanriffle) wrote : | # |
Is this going to be reviewed?
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
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
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
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
1 | === modified file 'src/Utils/TextEditor.vala' | |||
2 | --- src/Utils/TextEditor.vala 2014-10-26 10:41:33 +0000 | |||
3 | +++ src/Utils/TextEditor.vala 2014-12-14 05:22:00 +0000 | |||
4 | @@ -30,73 +30,110 @@ | |||
5 | 30 | 30 | ||
6 | 31 | namespace Writer { | 31 | namespace Writer { |
7 | 32 | public class TextEditor : TextBuffer { | 32 | public class TextEditor : TextBuffer { |
9 | 33 | 33 | ||
10 | 34 | public TextView text_view; | 34 | public TextView text_view; |
12 | 35 | 35 | public bool style_bold; | |
13 | 36 | public bool style_italic; | ||
14 | 37 | public bool style_underline; | ||
15 | 38 | public bool style_strikethrough; | ||
16 | 39 | |||
17 | 36 | public signal void cursor_moved (); | 40 | public signal void cursor_moved (); |
18 | 37 | public signal void text_inserted (); | 41 | public signal void text_inserted (); |
20 | 38 | 42 | ||
21 | 39 | public TextEditor () { | 43 | public TextEditor () { |
22 | 40 | setup_tagtable (this); | 44 | setup_tagtable (this); |
23 | 41 | text_view = new TextView.with_buffer (this); | 45 | text_view = new TextView.with_buffer (this); |
26 | 42 | 46 | ||
27 | 43 | this.notify["cursor-position"].connect (cursor_moved_callback); | 47 | style_bold = false; |
28 | 48 | style_italic = false; | ||
29 | 49 | style_underline = false; | ||
30 | 50 | style_strikethrough = false; | ||
31 | 51 | |||
32 | 52 | text_view.move_cursor.connect (cursor_moved_callback); | ||
33 | 53 | text_view.button_release_event.connect (editor_clicked_callback); | ||
34 | 44 | this.insert_text.connect_after (text_inserted_callback); | 54 | this.insert_text.connect_after (text_inserted_callback); |
36 | 45 | 55 | ||
37 | 46 | text_view.key_press_event.connect (key_press_callback); | 56 | text_view.key_press_event.connect (key_press_callback); |
38 | 47 | text_view.pixels_below_lines = 20; | 57 | text_view.pixels_below_lines = 20; |
39 | 48 | } | 58 | } |
41 | 49 | 59 | ||
42 | 50 | // Get a TextTagTable with all the default tags | 60 | // Get a TextTagTable with all the default tags |
43 | 51 | private void setup_tagtable (TextBuffer buffer) { | 61 | private void setup_tagtable (TextBuffer buffer) { |
45 | 52 | 62 | ||
46 | 53 | buffer.create_tag ("bold", "weight", 700); | 63 | buffer.create_tag ("bold", "weight", 700); |
47 | 54 | buffer.create_tag ("italic", "style", Pango.Style.ITALIC); | 64 | buffer.create_tag ("italic", "style", Pango.Style.ITALIC); |
48 | 55 | buffer.create_tag ("underline", "underline", Pango.Underline.SINGLE); | 65 | buffer.create_tag ("underline", "underline", Pango.Underline.SINGLE); |
49 | 56 | buffer.create_tag ("strikethrough", "strikethrough", true); | 66 | buffer.create_tag ("strikethrough", "strikethrough", true); |
51 | 57 | 67 | ||
52 | 58 | buffer.create_tag ("align-left", "justification", Gtk.Justification.LEFT); | 68 | buffer.create_tag ("align-left", "justification", Gtk.Justification.LEFT); |
53 | 59 | buffer.create_tag ("align-center", "justification", Gtk.Justification.CENTER); | 69 | buffer.create_tag ("align-center", "justification", Gtk.Justification.CENTER); |
54 | 60 | buffer.create_tag ("align-right", "justification", Gtk.Justification.RIGHT); | 70 | buffer.create_tag ("align-right", "justification", Gtk.Justification.RIGHT); |
55 | 61 | buffer.create_tag ("align-fill", "justification", Gtk.Justification.FILL); | 71 | buffer.create_tag ("align-fill", "justification", Gtk.Justification.FILL); |
57 | 62 | 72 | ||
58 | 63 | } | 73 | } |
61 | 64 | 74 | ||
62 | 65 | 75 | ||
63 | 66 | /* | 76 | /* |
64 | 67 | * Styles (apply, remove, check) | 77 | * Styles (apply, remove, check) |
65 | 68 | */ | 78 | */ |
67 | 69 | 79 | ||
68 | 70 | public void apply_style (string name) { | 80 | public void apply_style (string name) { |
69 | 71 | if (has_selection) | 81 | if (has_selection) |
70 | 72 | get_selection_range ().apply_style (name); | 82 | get_selection_range ().apply_style (name); |
71 | 83 | |||
72 | 84 | if (name == "bold") | ||
73 | 85 | style_bold = true; | ||
74 | 86 | else if (name == "italic") | ||
75 | 87 | style_italic = true; | ||
76 | 88 | else if (name == "underline") | ||
77 | 89 | style_underline = true; | ||
78 | 90 | else if (name == "strikethrough") | ||
79 | 91 | style_strikethrough = true; | ||
80 | 73 | } | 92 | } |
82 | 74 | 93 | ||
83 | 75 | public void remove_style (string name) { | 94 | public void remove_style (string name) { |
84 | 76 | if (has_selection) | 95 | if (has_selection) |
85 | 77 | get_selection_range ().remove_style (name); | 96 | get_selection_range ().remove_style (name); |
86 | 97 | |||
87 | 98 | if (name == "bold") | ||
88 | 99 | style_bold = false; | ||
89 | 100 | else if (name == "italic") | ||
90 | 101 | style_italic = false; | ||
91 | 102 | else if (name == "underline") | ||
92 | 103 | style_underline = false; | ||
93 | 104 | else if (name == "strikethrough") | ||
94 | 105 | style_strikethrough = false; | ||
95 | 78 | } | 106 | } |
97 | 79 | 107 | ||
98 | 80 | public void toggle_style (string name) { | 108 | public void toggle_style (string name) { |
99 | 81 | if (has_selection) | 109 | if (has_selection) |
100 | 82 | get_selection_range ().toggle_style (name); | 110 | get_selection_range ().toggle_style (name); |
101 | 111 | |||
102 | 112 | if (name == "bold") | ||
103 | 113 | style_bold = !style_bold; | ||
104 | 114 | else if (name == "italic") | ||
105 | 115 | style_italic = !style_italic; | ||
106 | 116 | else if (name == "underline") | ||
107 | 117 | style_underline = !style_underline; | ||
108 | 118 | else if (name == "strikethrough") | ||
109 | 119 | style_strikethrough = !style_strikethrough; | ||
110 | 83 | } | 120 | } |
112 | 84 | 121 | ||
113 | 85 | public bool has_style (string name) { | 122 | public bool has_style (string name) { |
114 | 86 | if (has_selection) | 123 | if (has_selection) |
115 | 87 | return get_selection_range ().has_style (name); | 124 | return get_selection_range ().has_style (name); |
116 | 88 | else | 125 | else |
117 | 89 | return iter_has_style (get_cursor (), name); | 126 | return iter_has_style (get_cursor (), name); |
118 | 90 | } | 127 | } |
121 | 91 | 128 | ||
122 | 92 | 129 | ||
123 | 93 | public Gtk.Justification get_justification () { | 130 | public Gtk.Justification get_justification () { |
124 | 94 | if (has_selection) | 131 | if (has_selection) |
125 | 95 | return get_selection_range ().get_justification (); | 132 | return get_selection_range ().get_justification (); |
126 | 96 | else | 133 | else |
127 | 97 | return get_justification_at_iter (get_cursor ()); | 134 | return get_justification_at_iter (get_cursor ()); |
128 | 98 | } | 135 | } |
130 | 99 | 136 | ||
131 | 100 | public Gtk.Justification get_justification_at_iter (TextIter iter) { | 137 | public Gtk.Justification get_justification_at_iter (TextIter iter) { |
132 | 101 | if (iter_has_style (iter, "align-center")) | 138 | if (iter_has_style (iter, "align-center")) |
133 | 102 | return Gtk.Justification.CENTER; | 139 | return Gtk.Justification.CENTER; |
134 | @@ -107,14 +144,14 @@ | |||
135 | 107 | else | 144 | else |
136 | 108 | return Gtk.Justification.LEFT; | 145 | return Gtk.Justification.LEFT; |
137 | 109 | } | 146 | } |
139 | 110 | 147 | ||
140 | 111 | public int get_justification_as_int () { | 148 | public int get_justification_as_int () { |
141 | 112 | if (has_selection) | 149 | if (has_selection) |
142 | 113 | return get_selection_range ().get_justification_as_int (); | 150 | return get_selection_range ().get_justification_as_int (); |
143 | 114 | else | 151 | else |
144 | 115 | return get_justification_as_int_at_iter (get_cursor ()); | 152 | return get_justification_as_int_at_iter (get_cursor ()); |
145 | 116 | } | 153 | } |
147 | 117 | 154 | ||
148 | 118 | public int get_justification_as_int_at_iter (TextIter iter) { | 155 | public int get_justification_as_int_at_iter (TextIter iter) { |
149 | 119 | if (iter_has_style (iter, "align-center")) | 156 | if (iter_has_style (iter, "align-center")) |
150 | 120 | return 1; | 157 | return 1; |
151 | @@ -125,82 +162,82 @@ | |||
152 | 125 | else | 162 | else |
153 | 126 | return 0; | 163 | return 0; |
154 | 127 | } | 164 | } |
156 | 128 | 165 | ||
157 | 129 | public void set_justification (string align) { | 166 | public void set_justification (string align) { |
158 | 130 | get_paragraph (get_cursor ()).set_justification (align); | 167 | get_paragraph (get_cursor ()).set_justification (align); |
159 | 131 | } | 168 | } |
162 | 132 | 169 | ||
163 | 133 | 170 | ||
164 | 134 | public void set_font (FontDescription font) { | 171 | public void set_font (FontDescription font) { |
165 | 135 | get_selection_range ().set_font (font); | 172 | get_selection_range ().set_font (font); |
166 | 136 | } | 173 | } |
168 | 137 | 174 | ||
169 | 138 | public void set_font_from_string (string font) { | 175 | public void set_font_from_string (string font) { |
170 | 139 | get_selection_range ().set_font_from_string (font); | 176 | get_selection_range ().set_font_from_string (font); |
171 | 140 | } | 177 | } |
174 | 141 | 178 | ||
175 | 142 | 179 | ||
176 | 143 | public void set_font_color (Gdk.Color color) { | 180 | public void set_font_color (Gdk.Color color) { |
177 | 144 | get_selection_range ().set_font_color (color); | 181 | get_selection_range ().set_font_color (color); |
178 | 145 | } | 182 | } |
180 | 146 | 183 | ||
181 | 147 | public void set_font_color_from_string (string color) { | 184 | public void set_font_color_from_string (string color) { |
182 | 148 | get_selection_range ().set_font_color_from_string (color); | 185 | get_selection_range ().set_font_color_from_string (color); |
183 | 149 | } | 186 | } |
187 | 150 | 187 | ||
188 | 151 | 188 | ||
189 | 152 | 189 | ||
190 | 153 | /* | 190 | /* |
191 | 154 | * Inserts | 191 | * Inserts |
192 | 155 | */ | 192 | */ |
194 | 156 | 193 | ||
195 | 157 | public void insert_comment () { | 194 | public void insert_comment () { |
196 | 158 | print ("Insert Comment\n"); | 195 | print ("Insert Comment\n"); |
197 | 159 | } | 196 | } |
199 | 160 | 197 | ||
200 | 161 | public void insert_image () { | 198 | public void insert_image () { |
201 | 162 | print ("Insert Image\n"); | 199 | print ("Insert Image\n"); |
202 | 163 | } | 200 | } |
204 | 164 | 201 | ||
205 | 165 | public void insert_link () { | 202 | public void insert_link () { |
206 | 166 | print ("Insert Link\n"); | 203 | print ("Insert Link\n"); |
207 | 167 | } | 204 | } |
209 | 168 | 205 | ||
210 | 169 | public void insert_table (int cols, int rows) { | 206 | public void insert_table (int cols, int rows) { |
211 | 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); |
212 | 171 | } | 208 | } |
215 | 172 | 209 | ||
216 | 173 | 210 | ||
217 | 174 | public void insert_line () { | 211 | public void insert_line () { |
218 | 175 | TextIter insert_cursor = get_cursor (); | 212 | TextIter insert_cursor = get_cursor (); |
219 | 176 | insert_line_at_iter (insert_cursor); | 213 | insert_line_at_iter (insert_cursor); |
220 | 177 | } | 214 | } |
222 | 178 | 215 | ||
223 | 179 | public void insert_paragraph () { | 216 | public void insert_paragraph () { |
224 | 180 | TextIter cursor = get_cursor (); | 217 | TextIter cursor = get_cursor (); |
225 | 181 | insert_paragraph_at_iter (cursor); | 218 | insert_paragraph_at_iter (cursor); |
226 | 182 | } | 219 | } |
228 | 183 | 220 | ||
229 | 184 | public void insert_line_at_iter (TextIter iter) { | 221 | public void insert_line_at_iter (TextIter iter) { |
230 | 185 | //TODO | 222 | //TODO |
231 | 186 | // Cursor does not move to next line | 223 | // Cursor does not move to next line |
232 | 187 | // Only happens when inserting at the end of the buffer | 224 | // Only happens when inserting at the end of the buffer |
233 | 188 | // Bug reported in GTK+ | 225 | // Bug reported in GTK+ |
235 | 189 | 226 | ||
236 | 190 | insert (ref iter, "\u2028", -1); | 227 | insert (ref iter, "\u2028", -1); |
237 | 191 | } | 228 | } |
239 | 192 | 229 | ||
240 | 193 | public void insert_paragraph_at_iter (TextIter iter) { | 230 | public void insert_paragraph_at_iter (TextIter iter) { |
241 | 194 | insert (ref iter, "\n", -1); | 231 | insert (ref iter, "\n", -1); |
242 | 195 | } | 232 | } |
247 | 196 | 233 | ||
248 | 197 | 234 | ||
249 | 198 | 235 | ||
250 | 199 | 236 | ||
251 | 200 | /* | 237 | /* |
252 | 201 | * paragraphs | 238 | * paragraphs |
253 | 202 | */ | 239 | */ |
255 | 203 | 240 | ||
256 | 204 | // Moves iter to the start of the paragraph it is located in | 241 | // Moves iter to the start of the paragraph it is located in |
257 | 205 | public TextIter get_paragraph_start (TextIter iter) { | 242 | public TextIter get_paragraph_start (TextIter iter) { |
258 | 206 | iter.backward_find_char ((char) => { | 243 | iter.backward_find_char ((char) => { |
259 | @@ -211,7 +248,7 @@ | |||
260 | 211 | }, null); | 248 | }, null); |
261 | 212 | return iter; | 249 | return iter; |
262 | 213 | } | 250 | } |
264 | 214 | 251 | ||
265 | 215 | // Moves iter to the end of the paragraph it is located in | 252 | // Moves iter to the end of the paragraph it is located in |
266 | 216 | public TextIter get_paragraph_end (TextIter iter) { | 253 | public TextIter get_paragraph_end (TextIter iter) { |
267 | 217 | iter.forward_find_char ((char) => { | 254 | iter.forward_find_char ((char) => { |
268 | @@ -222,121 +259,136 @@ | |||
269 | 222 | }, null); | 259 | }, null); |
270 | 223 | return iter; | 260 | return iter; |
271 | 224 | } | 261 | } |
273 | 225 | 262 | ||
274 | 226 | public TextRange get_paragraph (TextIter iter) { | 263 | public TextRange get_paragraph (TextIter iter) { |
275 | 227 | TextIter start = get_paragraph_start (iter); | 264 | TextIter start = get_paragraph_start (iter); |
276 | 228 | TextIter end = get_paragraph_end (iter); | 265 | TextIter end = get_paragraph_end (iter); |
278 | 229 | 266 | ||
279 | 230 | return new TextRange (this, start, end); | 267 | return new TextRange (this, start, end); |
280 | 231 | } | 268 | } |
285 | 232 | 269 | ||
286 | 233 | 270 | ||
287 | 234 | 271 | ||
288 | 235 | 272 | ||
289 | 236 | /* | 273 | /* |
290 | 237 | * Search | 274 | * Search |
291 | 238 | */ | 275 | */ |
293 | 239 | 276 | ||
294 | 240 | public void search (string text) { | 277 | public void search (string text) { |
295 | 241 | if (text.length > 0) | 278 | if (text.length > 0) |
296 | 242 | search_string (text); | 279 | search_string (text); |
297 | 243 | else | 280 | else |
298 | 244 | clear_search (); | 281 | clear_search (); |
299 | 245 | } | 282 | } |
301 | 246 | 283 | ||
302 | 247 | public void search_string (string text) { | 284 | public void search_string (string text) { |
303 | 248 | print ("Searching for: %s\n", text); | 285 | print ("Searching for: %s\n", text); |
304 | 249 | } | 286 | } |
306 | 250 | 287 | ||
307 | 251 | public void clear_search () { | 288 | public void clear_search () { |
308 | 252 | print ("Clearing search"); | 289 | print ("Clearing search"); |
309 | 253 | } | 290 | } |
313 | 254 | 291 | ||
314 | 255 | 292 | ||
315 | 256 | 293 | ||
316 | 257 | /* | 294 | /* |
317 | 258 | * Utilities | 295 | * Utilities |
318 | 259 | */ | 296 | */ |
320 | 260 | 297 | ||
321 | 261 | public TextIter get_cursor () { | 298 | public TextIter get_cursor () { |
322 | 262 | TextIter iter; | 299 | TextIter iter; |
323 | 263 | get_iter_at_mark (out iter, get_insert ()); | 300 | get_iter_at_mark (out iter, get_insert ()); |
324 | 264 | return iter; | 301 | return iter; |
325 | 265 | } | 302 | } |
327 | 266 | 303 | ||
328 | 267 | public TextRange get_cursor_as_range () { | 304 | public TextRange get_cursor_as_range () { |
329 | 268 | var cursor = get_cursor (); | 305 | var cursor = get_cursor (); |
330 | 269 | return new TextRange (this, cursor, cursor); | 306 | return new TextRange (this, cursor, cursor); |
331 | 270 | } | 307 | } |
333 | 271 | 308 | ||
334 | 272 | public TextRange get_selection_range () { | 309 | public TextRange get_selection_range () { |
335 | 273 | TextIter start; TextIter end; | 310 | TextIter start; TextIter end; |
336 | 274 | get_selection_bounds (out start, out end); | 311 | get_selection_bounds (out start, out end); |
337 | 275 | return new TextRange (this, start, end); | 312 | return new TextRange (this, start, end); |
338 | 276 | } | 313 | } |
340 | 277 | 314 | ||
341 | 278 | public bool iter_has_tag (TextIter iter, TextTag tag) { | 315 | public bool iter_has_tag (TextIter iter, TextTag tag) { |
342 | 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); |
343 | 280 | } | 317 | } |
345 | 281 | 318 | ||
346 | 282 | public bool iter_has_style (TextIter iter, string name) { | 319 | public bool iter_has_style (TextIter iter, string name) { |
347 | 283 | var tag = tag_table.lookup (name); | 320 | var tag = tag_table.lookup (name); |
348 | 284 | return iter_has_tag (iter, tag); | 321 | return iter_has_tag (iter, tag); |
349 | 285 | } | 322 | } |
351 | 286 | 323 | ||
352 | 287 | public TextIter copy_iter (TextIter iter) { | 324 | public TextIter copy_iter (TextIter iter) { |
353 | 288 | TextIter copy; | 325 | TextIter copy; |
354 | 289 | get_iter_at_offset (out copy, iter.get_offset ()); | 326 | get_iter_at_offset (out copy, iter.get_offset ()); |
355 | 290 | return copy; | 327 | return copy; |
356 | 291 | } | 328 | } |
362 | 292 | 329 | ||
363 | 293 | 330 | ||
364 | 294 | 331 | ||
365 | 295 | 332 | private void update_styles () { | |
366 | 296 | 333 | var iter = get_cursor(); | |
367 | 334 | |||
368 | 335 | style_bold = iter_has_style (iter, "bold"); | ||
369 | 336 | style_italic = iter_has_style (iter, "italic"); | ||
370 | 337 | style_underline = iter_has_style (iter, "underline"); | ||
371 | 338 | style_strikethrough = iter_has_style (iter, "strikethrough"); | ||
372 | 339 | } | ||
373 | 340 | |||
374 | 297 | /* | 341 | /* |
375 | 298 | * Signal callbacks | 342 | * Signal callbacks |
376 | 299 | */ | 343 | */ |
378 | 300 | 344 | ||
379 | 301 | private void cursor_moved_callback () { | 345 | private void cursor_moved_callback () { |
380 | 302 | // Emit 'cursor_moved' signal | 346 | // Emit 'cursor_moved' signal |
381 | 347 | update_styles (); | ||
382 | 303 | cursor_moved (); | 348 | cursor_moved (); |
383 | 304 | } | 349 | } |
385 | 305 | 350 | ||
386 | 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) { |
387 | 307 | TextIter previous; | 352 | TextIter previous; |
388 | 308 | get_iter_at_offset (out previous, cursor.get_offset () - length); | 353 | get_iter_at_offset (out previous, cursor.get_offset () - length); |
391 | 309 | 354 | ||
392 | 310 | if (iter_has_style (previous, "bold")) | 355 | if (style_bold) |
393 | 311 | apply_tag_by_name ("bold", previous, cursor); | 356 | apply_tag_by_name ("bold", previous, cursor); |
395 | 312 | if (iter_has_style (previous, "italic")) | 357 | if (style_italic) |
396 | 313 | apply_tag_by_name ("italic", previous, cursor); | 358 | apply_tag_by_name ("italic", previous, cursor); |
398 | 314 | if (iter_has_style (previous, "underline")) | 359 | if (style_underline) |
399 | 315 | apply_tag_by_name ("underline", previous, cursor); | 360 | apply_tag_by_name ("underline", previous, cursor); |
401 | 316 | if (iter_has_style (previous, "strikethrough")) | 361 | if (style_strikethrough) |
402 | 317 | apply_tag_by_name ("strikethrough", previous, cursor); | 362 | apply_tag_by_name ("strikethrough", previous, cursor); |
405 | 318 | 363 | ||
406 | 319 | 364 | ||
407 | 320 | // Emit signals | 365 | // Emit signals |
408 | 321 | text_inserted (); | 366 | text_inserted (); |
409 | 322 | cursor_moved (); | 367 | cursor_moved (); |
410 | 323 | } | 368 | } |
412 | 324 | 369 | ||
413 | 325 | private bool key_press_callback (EventKey event) { | 370 | private bool key_press_callback (EventKey event) { |
414 | 326 | if (Gdk.keyval_name (event.keyval) == "Return") { | 371 | if (Gdk.keyval_name (event.keyval) == "Return") { |
415 | 327 | ModifierType modifiers = Gtk.accelerator_get_default_mod_mask (); | 372 | ModifierType modifiers = Gtk.accelerator_get_default_mod_mask (); |
417 | 328 | 373 | ||
418 | 329 | if ((event.state & modifiers) == Gdk.ModifierType.SHIFT_MASK) | 374 | if ((event.state & modifiers) == Gdk.ModifierType.SHIFT_MASK) |
419 | 330 | insert_line (); | 375 | insert_line (); |
420 | 331 | else | 376 | else |
421 | 332 | insert_paragraph (); | 377 | insert_paragraph (); |
423 | 333 | 378 | ||
424 | 334 | return true; | 379 | return true; |
425 | 335 | } | 380 | } |
427 | 336 | else { | 381 | else { |
428 | 337 | return false; | 382 | return false; |
429 | 338 | } | 383 | } |
430 | 339 | } | 384 | } |
432 | 340 | 385 | ||
433 | 386 | private bool editor_clicked_callback (EventButton event) { | ||
434 | 387 | update_styles (); | ||
435 | 388 | cursor_moved (); | ||
436 | 389 | |||
437 | 390 | return false; | ||
438 | 391 | } | ||
439 | 392 | |||
440 | 341 | } | 393 | } |
441 | 342 | } | ||
442 | 343 | \ No newline at end of file | 394 | \ No newline at end of file |
443 | 395 | } | ||
444 | 344 | 396 | ||
445 | === modified file 'src/Widgets/TextToolBar.vala' | |||
446 | --- src/Widgets/TextToolBar.vala 2014-12-07 19:18:49 +0000 | |||
447 | +++ src/Widgets/TextToolBar.vala 2014-12-14 05:22:00 +0000 | |||
448 | @@ -29,7 +29,7 @@ | |||
449 | 29 | 29 | ||
450 | 30 | namespace Writer.Widgets { | 30 | namespace Writer.Widgets { |
451 | 31 | public class TextToolBar : Gtk.Toolbar { | 31 | public class TextToolBar : Gtk.Toolbar { |
453 | 32 | 32 | ||
454 | 33 | private TextEditor editor; | 33 | private TextEditor editor; |
455 | 34 | public FontButton font_button; | 34 | public FontButton font_button; |
456 | 35 | public ColorButton font_color_button; | 35 | public ColorButton font_color_button; |
457 | @@ -42,20 +42,20 @@ | |||
458 | 42 | public ModeButton align_button; | 42 | public ModeButton align_button; |
459 | 43 | public Gtk.SeparatorToolItem item_separator; | 43 | public Gtk.SeparatorToolItem item_separator; |
460 | 44 | public Popover insert_popover; | 44 | public Popover insert_popover; |
462 | 45 | 45 | ||
463 | 46 | public TextToolBar (TextEditor editor) { | 46 | public TextToolBar (TextEditor editor) { |
464 | 47 | this.get_style_context ().add_class ("writer-toolbar"); | 47 | this.get_style_context ().add_class ("writer-toolbar"); |
466 | 48 | 48 | ||
467 | 49 | this.editor = editor; | 49 | this.editor = editor; |
468 | 50 | editor.cursor_moved.connect (cursor_moved); | 50 | editor.cursor_moved.connect (cursor_moved); |
470 | 51 | 51 | ||
471 | 52 | setup_ui (); | 52 | setup_ui (); |
472 | 53 | } | 53 | } |
474 | 54 | 54 | ||
475 | 55 | public void setup_ui () { | 55 | public void setup_ui () { |
477 | 56 | 56 | ||
478 | 57 | // Make Widgets | 57 | // Make Widgets |
480 | 58 | 58 | ||
481 | 59 | var paragraph_combobox = new Gtk.ComboBoxText (); | 59 | var paragraph_combobox = new Gtk.ComboBoxText (); |
482 | 60 | paragraph_combobox.append ("Paragraph", ("Paragraph")); | 60 | paragraph_combobox.append ("Paragraph", ("Paragraph")); |
483 | 61 | paragraph_combobox.append ("Title", ("Title")); | 61 | paragraph_combobox.append ("Title", ("Title")); |
484 | @@ -67,7 +67,7 @@ | |||
485 | 67 | paragraph_combobox.set_active_id ("Paragraph"); | 67 | paragraph_combobox.set_active_id ("Paragraph"); |
486 | 68 | var paragraph_item = new ToolItem (); | 68 | var paragraph_item = new ToolItem (); |
487 | 69 | paragraph_item.add (paragraph_combobox); | 69 | paragraph_item.add (paragraph_combobox); |
489 | 70 | 70 | ||
490 | 71 | var font_item = new ToolItem (); | 71 | var font_item = new ToolItem (); |
491 | 72 | font_button = new Gtk.FontButton (); | 72 | font_button = new Gtk.FontButton (); |
492 | 73 | font_button.use_font = true; | 73 | font_button.use_font = true; |
493 | @@ -80,7 +80,7 @@ | |||
494 | 80 | 80 | ||
495 | 81 | var font_color_item = new Gtk.ToolItem (); | 81 | var font_color_item = new Gtk.ToolItem (); |
496 | 82 | font_color_item.add (font_color_button); | 82 | font_color_item.add (font_color_button); |
498 | 83 | 83 | ||
499 | 84 | var styles_item = new ToolItem (); | 84 | var styles_item = new ToolItem (); |
500 | 85 | var styles_buttons = new ButtonGroup (); | 85 | var styles_buttons = new ButtonGroup (); |
501 | 86 | bold_button = new Gtk.ToggleButton (); | 86 | bold_button = new Gtk.ToggleButton (); |
502 | @@ -89,16 +89,19 @@ | |||
503 | 89 | styles_buttons.pack_start (bold_button); | 89 | styles_buttons.pack_start (bold_button); |
504 | 90 | italic_button = new Gtk.ToggleButton (); | 90 | italic_button = new Gtk.ToggleButton (); |
505 | 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)); |
506 | 92 | italic_button.focus_on_click = false; | ||
507 | 92 | styles_buttons.pack_start (italic_button); | 93 | styles_buttons.pack_start (italic_button); |
508 | 93 | underline_button = new Gtk.ToggleButton (); | 94 | underline_button = new Gtk.ToggleButton (); |
509 | 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)); |
510 | 96 | underline_button.focus_on_click = false; | ||
511 | 95 | styles_buttons.pack_start (underline_button); | 97 | styles_buttons.pack_start (underline_button); |
512 | 96 | strikethrough_button = new Gtk.ToggleButton (); | 98 | strikethrough_button = new Gtk.ToggleButton (); |
513 | 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)); |
514 | 100 | strikethrough_button.focus_on_click = false; | ||
515 | 98 | styles_buttons.pack_start (strikethrough_button); | 101 | styles_buttons.pack_start (strikethrough_button); |
516 | 99 | styles_item.add (styles_buttons); | 102 | styles_item.add (styles_buttons); |
517 | 100 | 103 | ||
519 | 101 | 104 | ||
520 | 102 | var align_item = new ToolItem (); | 105 | var align_item = new ToolItem (); |
521 | 103 | align_button = new ModeButton (); | 106 | align_button = new ModeButton (); |
522 | 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)); |
523 | @@ -106,7 +109,7 @@ | |||
524 | 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)); |
525 | 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)); |
526 | 108 | align_item.add (align_button); | 111 | align_item.add (align_button); |
528 | 109 | 112 | ||
529 | 110 | var indent_button = new ButtonGroup (); | 113 | var indent_button = new ButtonGroup (); |
530 | 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); |
531 | 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); |
532 | @@ -114,9 +117,9 @@ | |||
533 | 114 | indent_button.add (indent_less_button); | 117 | indent_button.add (indent_less_button); |
534 | 115 | var indent_item = new Gtk.ToolItem (); | 118 | var indent_item = new Gtk.ToolItem (); |
535 | 116 | indent_item.add (indent_button); | 119 | indent_item.add (indent_button); |
537 | 117 | 120 | ||
538 | 118 | item_separator = new Gtk.SeparatorToolItem (); | 121 | item_separator = new Gtk.SeparatorToolItem (); |
540 | 119 | 122 | ||
541 | 120 | //TODO: Set 'Insert' as title, not as Entry | 123 | //TODO: Set 'Insert' as title, not as Entry |
542 | 121 | // It looks like this isn't supported by GTK+ | 124 | // It looks like this isn't supported by GTK+ |
543 | 122 | // WTF!? | 125 | // WTF!? |
544 | @@ -129,8 +132,8 @@ | |||
545 | 129 | insert_menu.set_active (0); | 132 | insert_menu.set_active (0); |
546 | 130 | var insert_item = new Gtk.ToolItem (); | 133 | var insert_item = new Gtk.ToolItem (); |
547 | 131 | insert_item.add (insert_menu); | 134 | insert_item.add (insert_menu); |
550 | 132 | 135 | ||
551 | 133 | 136 | ||
552 | 134 | //Set border_width on ToolItems | 137 | //Set border_width on ToolItems |
553 | 135 | paragraph_item.border_width = 5; | 138 | paragraph_item.border_width = 5; |
554 | 136 | font_item.border_width = 5; | 139 | font_item.border_width = 5; |
555 | @@ -139,7 +142,7 @@ | |||
556 | 139 | align_item.border_width = 5; | 142 | align_item.border_width = 5; |
557 | 140 | indent_item.border_width = 5; | 143 | indent_item.border_width = 5; |
558 | 141 | insert_item.border_width = 5; | 144 | insert_item.border_width = 5; |
560 | 142 | 145 | ||
561 | 143 | // Add Widgets | 146 | // Add Widgets |
562 | 144 | this.add (paragraph_item); | 147 | this.add (paragraph_item); |
563 | 145 | this.add (font_item); | 148 | this.add (font_item); |
564 | @@ -149,15 +152,15 @@ | |||
565 | 149 | this.add (indent_item); | 152 | this.add (indent_item); |
566 | 150 | this.add (item_separator); | 153 | this.add (item_separator); |
567 | 151 | this.add (insert_item); | 154 | this.add (insert_item); |
571 | 152 | 155 | ||
572 | 153 | 156 | ||
573 | 154 | 157 | ||
574 | 155 | // Connect signals | 158 | // Connect signals |
576 | 156 | 159 | ||
577 | 157 | align_button.mode_changed.connect (() => { | 160 | align_button.mode_changed.connect (() => { |
578 | 158 | change_align (align_button.selected); | 161 | change_align (align_button.selected); |
579 | 159 | }); | 162 | }); |
581 | 160 | 163 | ||
582 | 161 | font_button.font_set.connect (() => { | 164 | font_button.font_set.connect (() => { |
583 | 162 | editor.set_font_from_string (font_button.get_font_name ()); | 165 | editor.set_font_from_string (font_button.get_font_name ()); |
584 | 163 | }); | 166 | }); |
585 | @@ -166,7 +169,7 @@ | |||
586 | 166 | font_color_button.get_color (out color); | 169 | font_color_button.get_color (out color); |
587 | 167 | editor.set_font_color (color); | 170 | editor.set_font_color (color); |
588 | 168 | }); | 171 | }); |
590 | 169 | 172 | ||
591 | 170 | bold_button.button_press_event.connect ((event) => { | 173 | bold_button.button_press_event.connect ((event) => { |
592 | 171 | if (event.type == EventType.BUTTON_PRESS) | 174 | if (event.type == EventType.BUTTON_PRESS) |
593 | 172 | editor.toggle_style ("bold"); | 175 | editor.toggle_style ("bold"); |
594 | @@ -187,16 +190,16 @@ | |||
595 | 187 | editor.toggle_style ("strikethrough"); | 190 | editor.toggle_style ("strikethrough"); |
596 | 188 | return false; | 191 | return false; |
597 | 189 | }); | 192 | }); |
599 | 190 | 193 | ||
600 | 191 | } | 194 | } |
605 | 192 | 195 | ||
606 | 193 | 196 | ||
607 | 194 | 197 | ||
608 | 195 | 198 | ||
609 | 196 | /* | 199 | /* |
610 | 197 | * Signal callbacks | 200 | * Signal callbacks |
611 | 198 | */ | 201 | */ |
613 | 199 | 202 | ||
614 | 200 | public void change_align (int index) { | 203 | public void change_align (int index) { |
615 | 201 | switch (index) { | 204 | switch (index) { |
616 | 202 | case 1: | 205 | case 1: |
617 | @@ -209,15 +212,15 @@ | |||
618 | 209 | editor.set_justification ("left"); break; | 212 | editor.set_justification ("left"); break; |
619 | 210 | } | 213 | } |
620 | 211 | } | 214 | } |
622 | 212 | 215 | ||
623 | 213 | public void cursor_moved () { | 216 | public void cursor_moved () { |
624 | 214 | bold_button.active = editor.has_style ("bold"); | 217 | bold_button.active = editor.has_style ("bold"); |
625 | 215 | italic_button.active = editor.has_style ("italic"); | 218 | italic_button.active = editor.has_style ("italic"); |
626 | 216 | underline_button.active = editor.has_style ("underline"); | 219 | underline_button.active = editor.has_style ("underline"); |
627 | 217 | strikethrough_button.active = editor.has_style ("strikethrough"); | 220 | strikethrough_button.active = editor.has_style ("strikethrough"); |
629 | 218 | 221 | ||
630 | 219 | align_button.selected = editor.get_justification_as_int (); | 222 | align_button.selected = editor.get_justification_as_int (); |
632 | 220 | 223 | ||
633 | 221 | //TODO | 224 | //TODO |
634 | 222 | // Update font and color buttons | 225 | // Update font and color buttons |
635 | 223 | } | 226 | } |
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.