Added code style menu

pull/200/head
M66B 4 years ago
parent 14b761ea4b
commit b3045c0a9e

@ -176,6 +176,8 @@ public class StyleHelper {
IndentSpan[] indents = edit.getSpans(start, end, IndentSpan.class);
popupMenu.getMenu().findItem(R.id.menu_style_indentation_decrease).setEnabled(indents.length > 0);
popupMenu.getMenu().findItem(R.id.menu_style_code).setEnabled(BuildConfig.DEBUG);
popupMenu.insertIcons(context);
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@ -206,6 +208,8 @@ public class StyleHelper {
return setIndentation(item);
} else if (groupId == R.id.group_style_strikethrough) {
return setStrikeThrough(item);
} else if (groupId == R.id.group_style_code) {
return setCode(item);
} else if (groupId == R.id.group_style_clear) {
return clear(item);
}
@ -221,12 +225,16 @@ public class StyleHelper {
Float size;
if (item.getItemId() == R.id.menu_style_size_small)
size = 0.8f;
size = HtmlHelper.FONT_SMALL;
else if (item.getItemId() == R.id.menu_style_size_large)
size = 1.25f;
size = HtmlHelper.FONT_LARGE;
else
size = null;
return _setSize(size);
}
private boolean _setSize(Float size) {
RelativeSizeSpan[] spans = edit.getSpans(start, end, RelativeSizeSpan.class);
for (RelativeSizeSpan span : spans) {
int s = edit.getSpanStart(span);
@ -483,6 +491,10 @@ public class StyleHelper {
String[] names = anchor.getResources().getStringArray(R.array.fontNameValues);
String face = (id < names.length ? names[id] : null);
return _setFont(face);
}
private boolean _setFont(String face) {
TypefaceSpan[] spans = edit.getSpans(start, end, TypefaceSpan.class);
for (TypefaceSpan span : spans) {
int s = edit.getSpanStart(span);
@ -604,6 +616,12 @@ public class StyleHelper {
return true;
}
private boolean setCode(MenuItem item) {
_setSize(HtmlHelper.FONT_SMALL);
_setFont("monospace");
return true;
}
private boolean clear(MenuItem item) {
Log.breadcrumb("style", "action", "clear");

@ -142,8 +142,17 @@
</group>
<group
android:id="@+id/group_style_clear"
android:id="@+id/group_style_code"
android:orderInCategory="10">
<item
android:id="@+id/menu_style_code"
android:icon="@drawable/baseline_code_24"
android:title="@string/title_style_code" />
</group>
<group
android:id="@+id/group_style_clear"
android:orderInCategory="11">
<item
android:id="@+id/menu_style_clear"
android:icon="@drawable/twotone_format_clear_24"

@ -1123,6 +1123,7 @@
<string name="title_style_blockquote">Block quote</string>
<string name="title_style_indentation">Indentation</string>
<string name="title_style_strikethrough">Strikethrough</string>
<string name="title_style_code" translatable="false">Code</string>
<string name="title_style_clear">Clear formatting</string>
<string name="title_style_link">Insert link</string>

Loading…
Cancel
Save