@@ -42,8 +42,12 @@ namespace Write
4242 public class ContextToolbar : Toolbar
4343 {
4444 Write . Window Window { get ; private set ; }
45- MultiModeButton FormatButtons { get ; private set ; }
45+ MultiModeButton StyleButtons { get ; private set ; }
4646 Granite . Widgets . ModeButton JustifyButtons { get ; private set ; }
47+ Gtk . ComboBoxText FormatCombo { get ; private set ; }
48+ ComboMenu InsertCombo { get ; private set ; }
49+
50+ private bool manualFormatChange = false ;
4751
4852 /**
4953 * Initializes the main window toolbar for the application
@@ -53,15 +57,14 @@ namespace Write
5357 base (" context-toolbar" );
5458 Window = window;
5559
60+ setup_formatting_combo();
5661 setup_styles();
5762 setup_alignments();
63+ setup_insert_combo();
5864 }
5965
6066 private void setup_styles ()
61- {
62- FormatButtons = new MultiModeButton ();
63- FormatButtons . mode_changed. connect(handle_format_change);
64-
67+ {
6568 var boldLabel = new Gtk .Label (" <b>B</b>" );
6669 boldLabel. use_markup = true ;
6770 boldLabel. name = " bold" ;
@@ -88,13 +91,15 @@ namespace Write
8891 superLabel. tooltip_text = " Superscript Selection" ;
8992
9093 // Add all the labels to the styles multimode
91- FormatButtons . append(boldLabel);
92- FormatButtons . append(italicLabel);
93- FormatButtons . append(underlineLabel);
94- FormatButtons . append(strikethroughLabel);
95- FormatButtons . append(superLabel);
94+ StyleButtons = new MultiModeButton ();
95+ StyleButtons . append(boldLabel);
96+ StyleButtons . append(italicLabel);
97+ StyleButtons . append(underlineLabel);
98+ StyleButtons . append(strikethroughLabel);
99+ StyleButtons . append(superLabel);
100+ StyleButtons . mode_changed. connect(handle_style_change);
96101
97- add_left(FormatButtons );
102+ add_left(StyleButtons );
98103 }
99104
100105 private void setup_alignments ()
@@ -134,18 +139,82 @@ namespace Write
134139 JustifyButtons . append(justifyCenterButton);
135140 JustifyButtons . append(justifyRightButton);
136141 JustifyButtons . append(justifyButton);
137-
142+ JustifyButtons . mode_changed . connect(handle_alignment_change);
138143
139144 add_left(JustifyButtons );
140- JustifyButtons . mode_changed. connect(handle_alignment_change);
141145 }
142146 catch (Error error)
143147 {
144148 stdout. printf(" Unable to load alignment images. " + error. message);
145149 }
146150 }
147151
148- private void handle_format_change (Gtk .Widget widget )
152+ private void setup_insert_combo ()
153+ {
154+ InsertCombo = new ComboMenu (" Insert " ); // ToDO: Use real CSS to pad this
155+ InsertCombo . append_text(" Image" );
156+ InsertCombo . append_text(" Table" );
157+ InsertCombo . item_selected. connect(handle_insert_change);
158+
159+ add_right(InsertCombo );
160+ }
161+
162+ private void setup_formatting_combo ()
163+ {
164+ FormatCombo = new Gtk .ComboBoxText ();
165+ FormatCombo . append_text(" Normal Text" );
166+ FormatCombo . append_text(" Title" );
167+ FormatCombo . append_text(" Subtitle" );
168+ FormatCombo . append_text(" Header 1" );
169+ FormatCombo . append_text(" Header 2" );
170+ FormatCombo . append_text(" Header 3" );
171+ FormatCombo . append_text(" Pre-Format" );
172+ FormatCombo . append_text(" Quote" );
173+ FormatCombo . active = 0 ;
174+ FormatCombo . changed. connect(handle_format_change);
175+
176+ add_left(FormatCombo );
177+ }
178+
179+ private void handle_format_change ()
180+ {
181+ if (manualFormatChange)
182+ {
183+ manualFormatChange = false ;
184+ return ;
185+ }
186+
187+ var Document = Window . View . Document ;
188+ switch (FormatCombo . active)
189+ {
190+ case 0 :
191+ Document . exec_command(" formatBlock" , false , " p" );
192+ break ;
193+ case 1 :
194+ Document . exec_command(" formatBlock" , false , " H1" );
195+ break ;
196+ case 2 :
197+ Document . exec_command(" formatBlock" , false , " h2" );
198+ break ;
199+ case 3 :
200+ Document . exec_command(" formatBlock" , false , " h3" );
201+ break ;
202+ case 4 :
203+ Document . exec_command(" formatBlock" , false , " h4" );
204+ break ;
205+ case 5 :
206+ Document . exec_command(" formatBlock" , false , " h5" );
207+ break ;
208+ case 6 :
209+ Document . exec_command(" formatBlock" , false , " blockquote" );
210+ break ;
211+ case 7 :
212+ Document . exec_command(" formatBlock" , false , " pre" );
213+ break ;
214+ }
215+ }
216+
217+ private void handle_style_change (Gtk .Widget widget )
149218 {
150219 var Document = Window . View . Document ;
151220 Document . exec_command(widget. name, false , " null" );
@@ -157,13 +226,67 @@ namespace Write
157226 Document . exec_command(widget. name, false , " null" );
158227 }
159228
160- public void SelectFormats (bool bold = false , bool italic = false , bool underline = false , bool strike = false , bool super = false )
229+ private void handle_insert_change (int index )
230+ {
231+ var Document = Window . View . Document ;
232+ switch (index)
233+ {
234+ case 1 :
235+ Document . exec_command(" insertHTML" , false , " " " <table><tr><td></td><td></td></tr><tr><td></td><td></td></tr></table>" " " );
236+ break ;
237+ default:
238+ break ;
239+ }
240+ }
241+
242+ public void SelectFormat (string format )
243+ {
244+ int newActive = 0 ;
245+ switch (format)
246+ {
247+ case " p" :
248+ newActive = 0 ;
249+ break ;
250+ case " h1" :
251+ newActive = 1 ;
252+ break ;
253+ case " h2" :
254+ newActive = 2 ;
255+ break ;
256+ case " h3" :
257+ newActive = 3 ;
258+ break ;
259+ case " h4" :
260+ newActive = 4 ;
261+ break ;
262+ case " h5" :
263+ newActive = 5 ;
264+ break ;
265+ case " blockquote" :
266+ newActive = 6 ;
267+ break ;
268+ case " pre" :
269+ newActive = 7 ;
270+ break ;
271+ default:
272+ newActive = 0 ;
273+ break ;
274+ }
275+
276+ if (newActive != FormatCombo . active)
277+ {
278+ manualFormatChange = true ;
279+ FormatCombo . active = newActive;
280+ }
281+ }
282+
283+ public void SelectStyles (bool bold = false , bool italic = false , bool underline = false , bool strike = false , bool super = false )
161284 {
162- FormatButtons . set_active(0 , bold, false );
163- FormatButtons . set_active(1 , italic, false );
164- FormatButtons . set_active(2 , underline, false );
165- FormatButtons . set_active(3 , strike, false );
166- FormatButtons . set_active(4 , super, false );
285+ StyleButtons . set_active(0 , bold, false );
286+ StyleButtons . set_active(1 , italic, false );
287+ StyleButtons . set_active(2 , underline, false );
288+ StyleButtons . set_active(3 , strike, false );
289+ StyleButtons . set_active(4 , super, false );
167290 }
168291
169292 public void SelectAlignment (int alignment )
0 commit comments