4
Copyright (c) 2014 Tuur Dutoit
6
Permission is hereby granted, free of charge, to any person obtaining a copy
7
of this software and associated documentation files (the "Software"), to deal
8
in the Software without restriction, including without limitation the rights
9
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
copies of the Software, and to permit persons to whom the Software is
11
furnished to do so, subject to the following conditions:
13
The above copyright notice and this permission notice shall be included in all
14
copies or substantial portions of the Software.
16
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28
using Granite.Widgets;
30
namespace Writer.Widgets {
31
public class EditorToolBar : Gtk.Toolbar {
33
private Editor editor;
34
public FontButton font_button;
35
public ColorButton font_color_button;
36
public ToggleButton bold_button;
37
public ToggleButton italic_button;
38
public ToggleButton underline_button;
39
public ToggleButton strikethrough_button;
40
public Button indent_more_button;
41
public Button indent_less_button;
42
public ModeButton align_button;
43
public Popover insert_popover;
45
public EditorToolBar (Editor editor) {
46
this.get_style_context ().add_class ("writer-toolbar");
49
editor.cursor_moved.connect (cursor_moved);
54
public void setup_ui () {
58
var paragraph_combobox = new Gtk.ComboBoxText ();
59
paragraph_combobox.append ("Paragraph", ("Paragraph"));
60
paragraph_combobox.append ("Title", ("Title"));
61
paragraph_combobox.append ("Subtitle", ("Subtitle"));
62
paragraph_combobox.append ("Bullet List", ("Bullet List"));
63
paragraph_combobox.append ("Dashed List", ("Dashed List"));
64
paragraph_combobox.append ("Numbered List", ("Numbered List"));
65
paragraph_combobox.append ("Two-Column", ("Two-Column"));
66
paragraph_combobox.set_active_id ("Paragraph");
67
var paragraph_item = new ToolItem ();
68
paragraph_item.add (paragraph_combobox);
70
var font_item = new ToolItem ();
71
font_button = new Gtk.FontButton ();
72
font_button.use_font = true;
73
font_button.use_size = true;
74
font_item.add (font_button);
76
font_color_button = new Gtk.ColorButton ();
77
font_color_button.use_alpha = false;
78
font_color_button.set_title ("Choose a Font Color");
80
var font_color_item = new Gtk.ToolItem ();
81
font_color_item.add (font_color_button);
83
var styles_item = new ToolItem ();
84
var styles_buttons = new ButtonGroup ();
85
bold_button = new Gtk.ToggleButton ();
86
bold_button.add (new Image.from_icon_name ("format-text-bold-symbolic", Gtk.IconSize.MENU));
87
bold_button.focus_on_click = false;
88
styles_buttons.pack_start (bold_button);
89
italic_button = new Gtk.ToggleButton ();
90
italic_button.add (new Image.from_icon_name ("format-text-italic-symbolic", Gtk.IconSize.BUTTON));
91
styles_buttons.pack_start (italic_button);
92
underline_button = new Gtk.ToggleButton ();
93
underline_button.add (new Image.from_icon_name ("format-text-underline-symbolic", Gtk.IconSize.BUTTON));
94
styles_buttons.pack_start (underline_button);
95
strikethrough_button = new Gtk.ToggleButton ();
96
strikethrough_button.add (new Image.from_icon_name ("format-text-strikethrough-symbolic", Gtk.IconSize.BUTTON));
97
styles_buttons.pack_start (strikethrough_button);
98
styles_item.add (styles_buttons);
101
var align_item = new ToolItem ();
102
align_button = new ModeButton ();
103
align_button.append (new Gtk.Image.from_icon_name ("format-justify-left-symbolic", Gtk.IconSize.BUTTON));
104
align_button.append (new Gtk.Image.from_icon_name ("format-justify-center-symbolic", Gtk.IconSize.BUTTON));
105
align_button.append (new Gtk.Image.from_icon_name ("format-justify-right-symbolic", Gtk.IconSize.BUTTON));
106
align_button.append (new Gtk.Image.from_icon_name ("format-justify-fill-symbolic", Gtk.IconSize.BUTTON));
107
align_item.add (align_button);
109
var indent_button = new ButtonGroup ();
110
var indent_more_button = new Button.from_icon_name ("format-indent-more-symbolic", Gtk.IconSize.BUTTON);
111
var indent_less_button = new Button.from_icon_name ("format-indent-less-symbolic", Gtk.IconSize.BUTTON);
112
indent_button.add (indent_more_button);
113
indent_button.add (indent_less_button);
114
var indent_item = new Gtk.ToolItem ();
115
indent_item.add (indent_button);
117
var insert_button = new Gtk.Button.with_label ("Insert");
118
insert_popover = new Gtk.Popover (insert_button);
119
var insert_popover_content = new Gtk.Grid ();
120
insert_popover_content.column_spacing = 6;
121
insert_popover_content.row_spacing = 12;
122
var comment_button = new Gtk.Button.with_label ("Comment");
123
insert_popover_content.attach (comment_button, 0, 0, 1, 1);
124
var picture_button = new Gtk.Button.with_label ("Picture");
125
insert_popover_content.attach (picture_button, 1, 0, 1, 1);
126
var link_button = new Gtk.Button.with_label ("Link");
127
insert_popover_content.attach (link_button, 2, 0, 1, 1);
128
var table_chooser = new TableChooser ();
129
insert_popover_content.attach (table_chooser, 0, 1, 3, 1);
131
insert_popover.set_position (Gtk.PositionType.BOTTOM);
132
insert_popover.set_border_width (12);
133
insert_popover.add (insert_popover_content);
134
insert_popover.show_all ();
135
insert_popover.hide ();
137
var insert_item = new Gtk.ToolItem ();
138
insert_item.add (insert_button);
141
//Set border_width on ToolItems
142
paragraph_item.border_width = 5;
143
font_item.border_width = 5;
144
font_color_item.border_width = 5;
145
styles_item.border_width = 5;
146
align_item.border_width = 5;
147
indent_item.border_width = 5;
148
insert_item.border_width = 5;
151
this.add (paragraph_item);
152
this.add (font_item);
153
this.add (font_color_item);
154
this.add (styles_item);
155
this.add (align_item);
156
this.add (indent_item);
157
this.add (insert_item);
163
insert_button.clicked.connect (() => {
164
insert_popover.show ();
167
comment_button.clicked.connect (editor.insert_comment);
168
picture_button.clicked.connect (editor.insert_image);
169
link_button.clicked.connect (editor.insert_link);
170
table_chooser.selected.connect (editor.insert_table);
172
align_button.mode_changed.connect (() => {
173
change_align (align_button.selected);
176
font_button.font_set.connect (() => {
177
editor.set_font_from_string (font_button.get_font_name ());
179
font_color_button.color_set.connect (() => {
181
font_color_button.get_color (out color);
182
editor.set_font_color (color);
185
bold_button.button_press_event.connect ((event) => {
186
if (event.type == EventType.BUTTON_PRESS)
187
editor.toggle_style ("bold");
190
italic_button.button_press_event.connect ((event) => {
191
if (event.type == EventType.BUTTON_PRESS)
192
editor.toggle_style ("italic");
195
underline_button.button_press_event.connect ((event) => {
196
if (event.type == EventType.BUTTON_PRESS)
197
editor.toggle_style ("underline");
200
strikethrough_button.button_press_event.connect ((event) => {
201
if (event.type == EventType.BUTTON_PRESS)
202
editor.toggle_style ("strikethrough");
215
public void change_align (int index) {
218
editor.set_justification ("center"); break;
220
editor.set_justification ("right"); break;
222
editor.set_justification ("fill"); break;
224
editor.set_justification ("left"); break;
228
public void cursor_moved () {
229
bold_button.active = editor.has_style ("bold");
230
italic_button.active = editor.has_style ("italic");
231
underline_button.active = editor.has_style ("underline");
232
strikethrough_button.active = editor.has_style ("strikethrough");
234
align_button.selected = editor.get_justification_as_int ();
237
// Update font and color buttons
b'\\ No newline at end of file'