Skip to content
This repository was archived by the owner on May 3, 2018. It is now read-only.

Commit d9a32a4

Browse files
author
KJ
committed
- Added the ability to do basic formatting (title, subtitle, headers, etc)
- New ComboMenu widget - Pulled App/Document CSS out and made extra changes
1 parent 3c0d3a8 commit d9a32a4

File tree

8 files changed

+229
-29
lines changed

8 files changed

+229
-29
lines changed

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,8 @@
7070
/write
7171
/appresources
7272
/README.md~
73+
/resources/app.css~
74+
/resources/document.css~
75+
/src/Widgets/ComboMenu.vala~
76+
/build/src/CMakeFiles/write.dir/Widgets/ComboMenu.c.o
77+
/build/src/Widgets/ComboMenu.c

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Write
1+
Wmidorrite
22
=====
33

44
elementaryOS Writing application

resources/app.css

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,4 @@
4040
border: 0px none;
4141
}
4242

43-
.context-toolbar GraniteWidgetsModeButton GtkButton GtkImage:hover
44-
{
45-
padding: 0px;
46-
margin: 0px;
47-
border: 0px none;
48-
}
43+
/*.context-toolbar WriteComboMenu GtkCellRendererText { padding-right: 40px; }*/

resources/document.css

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,16 @@ body
8080
bottom: 0.75in;
8181
}
8282
#container .page:hover { cursor: text; }
83-
#zoom_control { position: fixed; bottom: 10px; right: 10px; width: 120px; }
83+
#zoom_control { position: fixed; bottom: 10px; right: 10px; width: 120px; }
84+
85+
/** Default document styles **/
86+
body, p { font: 12pt "Droid Sans", Arial, sans-serif; }
87+
h1 { font: 44pt "Raleway", Arial, sans-serif; font-weight: 100; }
88+
h2 { font: 20pt "Raleway", Arial, sans-serif; font-weight: 500; color: darkgray; }
89+
h3 { font: 20pt bold "Open Sans", Arial, sans-serif; }
90+
h4 { font: 16pt "Open Sans", Arial, sans-serif; font-weight: 300; }
91+
h5 { font: 12pt "Open Sans", Arial, sans-serif; font-weight: 500; color: darkgray; }
92+
h6 { font: 12pt "Droid Sans", Arial, sans-serif; font-weight: bold; }
93+
94+
table { border: 1px solid; width: 100%; }
95+
table tr td { border: 1px solid; padding: 4px; }

src/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ vala_precompile(VALA_C
3939

4040
Widgets/Toolbar.vala
4141
Widgets/MultiModeButton.vala
42+
Widgets/ComboMenu.vala
4243

4344
UI/DocumentToolbar.vala
4445
UI/DocumentView.vala

src/UI/ContextToolbar.vala

Lines changed: 143 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -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)

src/UI/DocumentView.vala

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ namespace Write
9494

9595
ZoomControl = Document.get_element_by_id("zoom_control") as DOM.HTMLInputElement;
9696
//ZoomControl.add_event_listener("change", (GLib.Callback)zoom, true, null);
97+
98+
// Tell the document to go to do all edits with styles
99+
Document.exec_command("styleWithCSS", false, "true");
100+
Document.exec_command("enableInlineTableEditing", false, "true");
101+
Document.exec_command("enableObjectResizing", false, "true");
97102
}
98103
catch (Error error)
99104
{
@@ -110,7 +115,7 @@ namespace Write
110115
bool underline = Document.query_command_state("Underline");
111116
bool strike = Document.query_command_state("Strikethrough");
112117
bool super = Document.query_command_state("Superscript");
113-
Context.SelectFormats(bold, italic, underline, strike, super);
118+
Context.SelectStyles(bold, italic, underline, strike, super);
114119

115120
bool justifyLeft = Document.query_command_state("justifyLeft");
116121
bool justifyCenter = Document.query_command_state("justifyCenter");
@@ -125,6 +130,9 @@ namespace Write
125130
Context.SelectAlignment(2);
126131
else if (justify)
127132
Context.SelectAlignment(3);
133+
134+
string format = Document.query_command_value("FormatBlock");
135+
Context.SelectFormat(format);
128136
}
129137

130138
/*private void zoom()

src/Widgets/ComboMenu.vala

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/***
2+
Copyright (C) 2013-2014 Activities Developers
3+
4+
This program or library is free software; you can redistribute it
5+
and/or modify it under the terms of the GNU Lesser General Public
6+
License as published by the Free Software Foundation; either
7+
version 3 of the License, or (at your option) any later version.
8+
9+
This library is distributed in the hope that it will be useful,
10+
but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
Lesser General Public License for more details.
13+
14+
You should have received a copy of the GNU Lesser General
15+
Public License along with this library; if not, write to the
16+
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17+
Boston, MA 02110-1301 USA.
18+
19+
Authored by: KJ Lawrence <[email protected]>
20+
***/
21+
22+
namespace Write
23+
{
24+
/**
25+
* Simple wrapper Widget for ComboBoxText
26+
*
27+
* Turns the widget into a simple Menu, where the first
28+
* item is always shown even when another is selected and
29+
* an event is thrown for any other menu item selected.
30+
*/
31+
public class ComboMenu : Gtk.ComboBoxText
32+
{
33+
public signal void item_selected (int index);
34+
35+
/**
36+
* Creates a new Toolbar.
37+
* @param css_class Style to apply to toolbar
38+
* @param size Size to apply to icons
39+
* @param spacing Spacing to put between each button
40+
*/
41+
public ComboMenu(string title)
42+
{
43+
append_text(title);
44+
active = 0;
45+
46+
changed.connect(() =>
47+
{
48+
if (active == 0)
49+
return;
50+
51+
item_selected(active);
52+
active = 0;
53+
});
54+
}
55+
}
56+
}

0 commit comments

Comments
 (0)