~writer-devs/writer/trunk

« back to all changes in this revision

Viewing changes to src/Widgets/TextToolBar.vala

  • Committer: Tuur Dutoit
  • Date: 2014-12-19 21:26:52 UTC
  • mfrom: (74.1.1 instant_style_apply)
  • Revision ID: me@tuurdutoit.be-20141219212652-57jdqncb38kwa1qb
MergeĀ ~ryanriffle/writer/instant_style_apply

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
 
30
30
namespace Writer.Widgets {
31
31
    public class TextToolBar : Gtk.Toolbar {
32
 
    
 
32
 
33
33
        private TextEditor editor;
34
34
        public FontButton font_button;
35
35
        public ColorButton font_color_button;
42
42
        public ModeButton align_button;
43
43
        public Gtk.SeparatorToolItem item_separator;
44
44
        public Popover insert_popover;
45
 
    
 
45
 
46
46
        public TextToolBar (TextEditor editor) {
47
47
            this.get_style_context ().add_class ("writer-toolbar");
48
 
            
 
48
 
49
49
            this.editor = editor;
50
50
            editor.cursor_moved.connect (cursor_moved);
51
 
    
 
51
 
52
52
            setup_ui ();
53
53
        }
54
 
        
 
54
 
55
55
        public void setup_ui () {
56
 
        
 
56
 
57
57
            // Make Widgets
58
 
            
 
58
 
59
59
            var paragraph_combobox = new Gtk.ComboBoxText ();
60
60
                paragraph_combobox.append ("Paragraph", ("Paragraph"));
61
61
                paragraph_combobox.append ("Title", ("Title"));
67
67
                paragraph_combobox.set_active_id ("Paragraph");
68
68
            var paragraph_item = new ToolItem ();
69
69
                paragraph_item.add (paragraph_combobox);
70
 
                
 
70
 
71
71
            var font_item = new ToolItem ();
72
72
                font_button = new Gtk.FontButton ();
73
73
                font_button.use_font = true;
80
80
 
81
81
            var font_color_item = new Gtk.ToolItem ();
82
82
                font_color_item.add (font_color_button);
83
 
                
 
83
 
84
84
            var styles_item = new ToolItem ();
85
85
                var styles_buttons = new ButtonGroup ();
86
86
                    bold_button = new Gtk.ToggleButton ();
89
89
                        styles_buttons.pack_start (bold_button);
90
90
                    italic_button = new Gtk.ToggleButton ();
91
91
                        italic_button.add (new Image.from_icon_name ("format-text-italic-symbolic", Gtk.IconSize.BUTTON));
 
92
                        italic_button.focus_on_click = false;
92
93
                        styles_buttons.pack_start (italic_button);
93
94
                    underline_button = new Gtk.ToggleButton ();
94
95
                        underline_button.add (new Image.from_icon_name ("format-text-underline-symbolic", Gtk.IconSize.BUTTON));
 
96
                        underline_button.focus_on_click = false;
95
97
                        styles_buttons.pack_start (underline_button);
96
98
                    strikethrough_button = new Gtk.ToggleButton ();
97
99
                        strikethrough_button.add (new Image.from_icon_name ("format-text-strikethrough-symbolic", Gtk.IconSize.BUTTON));
 
100
                        strikethrough_button.focus_on_click = false;
98
101
                        styles_buttons.pack_start (strikethrough_button);
99
102
                styles_item.add (styles_buttons);
100
103
 
101
 
                
 
104
 
102
105
            var align_item = new ToolItem ();
103
106
                align_button = new ModeButton ();
104
107
                    align_button.append (new Gtk.Image.from_icon_name ("format-justify-left-symbolic", Gtk.IconSize.BUTTON));
106
109
                    align_button.append (new Gtk.Image.from_icon_name ("format-justify-right-symbolic", Gtk.IconSize.BUTTON));
107
110
                    align_button.append (new Gtk.Image.from_icon_name ("format-justify-fill-symbolic", Gtk.IconSize.BUTTON));
108
111
                align_item.add (align_button);
109
 
            
 
112
 
110
113
            var indent_button = new ButtonGroup ();
111
114
                var indent_more_button = new Button.from_icon_name ("format-indent-more-symbolic", Gtk.IconSize.BUTTON);
112
115
                var indent_less_button = new Button.from_icon_name ("format-indent-less-symbolic", Gtk.IconSize.BUTTON);
114
117
                indent_button.add (indent_less_button);
115
118
            var indent_item = new Gtk.ToolItem ();
116
119
                indent_item.add (indent_button);
117
 
            
 
120
 
118
121
            item_separator = new Gtk.SeparatorToolItem ();
119
 
            
 
122
 
120
123
            //TODO: Set 'Insert' as title, not as Entry
121
124
            //       It looks like this isn't supported by GTK+
122
125
            //       WTF!?
129
132
                insert_menu.set_active (0);
130
133
            var insert_item = new Gtk.ToolItem ();
131
134
                insert_item.add (insert_menu);
132
 
            
133
 
            
 
135
 
 
136
 
134
137
            //Set border_width on ToolItems
135
138
            paragraph_item.border_width = 5;
136
139
            font_item.border_width = 5;
139
142
            align_item.border_width = 5;
140
143
            indent_item.border_width = 5;
141
144
            insert_item.border_width = 5;
142
 
            
 
145
 
143
146
            // Add Widgets
144
147
            this.add (paragraph_item);
145
148
            this.add (font_item);
149
152
            this.add (indent_item);
150
153
            this.add (item_separator);
151
154
            this.add (insert_item);
152
 
            
153
 
            
154
 
            
 
155
 
 
156
 
 
157
 
155
158
            // Connect signals
156
 
            
 
159
 
157
160
            align_button.mode_changed.connect (() => {
158
161
                change_align (align_button.selected);
159
162
            });
160
 
            
 
163
 
161
164
            font_button.font_set.connect (() => {
162
165
                editor.set_font_from_string (font_button.get_font_name ());
163
166
            });
166
169
                font_color_button.get_color (out color);
167
170
                editor.set_font_color (color);
168
171
            });
169
 
            
 
172
 
170
173
            bold_button.button_press_event.connect ((event) => {
171
174
                if (event.type == EventType.BUTTON_PRESS)
172
175
                    editor.toggle_style ("bold");
187
190
                    editor.toggle_style ("strikethrough");
188
191
                return false;
189
192
            });
190
 
            
 
193
 
191
194
        }
192
 
        
193
 
        
194
 
        
195
 
        
 
195
 
 
196
 
 
197
 
 
198
 
196
199
        /*
197
200
         * Signal callbacks
198
201
         */
199
 
        
 
202
 
200
203
        public void change_align (int index) {
201
204
            switch (index) {
202
205
                case 1:
209
212
                    editor.set_justification ("left"); break;
210
213
            }
211
214
        }
212
 
         
 
215
 
213
216
        public void cursor_moved () {
214
217
            bold_button.active = editor.has_style ("bold");
215
218
            italic_button.active = editor.has_style ("italic");
216
219
            underline_button.active = editor.has_style ("underline");
217
220
            strikethrough_button.active = editor.has_style ("strikethrough");
218
 
            
 
221
 
219
222
            align_button.selected = editor.get_justification_as_int ();
220
 
            
 
223
 
221
224
            //TODO
222
225
            // Update font and color buttons
223
226
        }