Skip to content

Commit

Permalink
Merge branch 'master' into select_lines
Browse files Browse the repository at this point in the history
  • Loading branch information
gsantner authored Oct 26, 2024
2 parents 900b987 + 46d0267 commit 406b7cb
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.gsantner.markor.format.plaintext.PlaintextActionButtons;
import net.gsantner.markor.format.todotxt.TodoTxtActionButtons;
import net.gsantner.markor.format.wikitext.WikitextActionButtons;
import net.gsantner.markor.format.orgmode.OrgmodeActionButtons;
import net.gsantner.opoc.util.GsCollectionUtils;

import java.util.ArrayList;
Expand Down Expand Up @@ -133,6 +134,8 @@ private void extractActionData() {
_textActions = new WikitextActionButtons(this, null);
} else if (documentType == R.string.pref_key__asciidoc__reorder_actions) {
_textActions = new AsciidocActionButtons(this, null);
} else if (documentType == R.string.pref_key__orgmode__reorder_actions) {
_textActions = new OrgmodeActionButtons(this, null);
} else { // Default to Plaintext
_textActions = new PlaintextActionButtons(this, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@ public List<ActionItem> getFormatActionList() {
new ActionItem(R.string.abid_common_deindent, R.drawable.ic_format_indent_decrease_black_24dp, R.string.deindent),
new ActionItem(R.string.abid_common_insert_link, R.drawable.ic_link_black_24dp, R.string.insert_link),
new ActionItem(R.string.abid_common_insert_image, R.drawable.ic_image_black_24dp, R.string.insert_image),
new ActionItem(R.string.abid_common_insert_audio, R.drawable.ic_keyboard_voice_black_24dp, R.string.audio)
new ActionItem(R.string.abid_common_insert_audio, R.drawable.ic_keyboard_voice_black_24dp, R.string.audio),
new ActionItem(R.string.abid_orgmode_bold, R.drawable.ic_format_bold_black_24dp, R.string.bold),
new ActionItem(R.string.abid_orgmode_italic, R.drawable.ic_format_italic_black_24dp, R.string.italic),
new ActionItem(R.string.abid_orgmode_strikeout, R.drawable.ic_format_strikethrough_black_24dp, R.string.strikeout),
new ActionItem(R.string.abid_orgmode_underline, R.drawable.ic_format_underlined_black_24dp, R.string.underline),
new ActionItem(R.string.abid_orgmode_code_inline, R.drawable.ic_code_black_24dp, R.string.inline_code)
);
}

Expand All @@ -45,4 +50,33 @@ protected void renumberOrderedList() {
// Use markdown format for orgmode too
AutoTextFormatter.renumberOrderedList(_hlEditor.getText(), MarkdownReplacePatternGenerator.formatPatterns);
}

@Override
public boolean onActionClick(final @StringRes int action) {
switch (action) {
case R.string.abid_orgmode_bold: {
runSurroundAction("*");
return true;
}
case R.string.abid_orgmode_italic: {
runSurroundAction("/");
return true;
}
case R.string.abid_orgmode_strikeout: {
runSurroundAction("+");
return true;
}
case R.string.abid_orgmode_underline: {
runSurroundAction("_");
return true;
}
case R.string.abid_orgmode_code_inline: {
runSurroundAction("=");
return true;
}
default: {
return runCommonAction(action);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
package net.gsantner.markor.format.orgmode;

import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Typeface;

import net.gsantner.markor.frontend.textview.SyntaxHighlighterBase;
import net.gsantner.markor.model.AppSettings;

import java.util.regex.Pattern;

public class OrgmodeSyntaxHighlighter extends SyntaxHighlighterBase {

public final static String COMMON_EMPHASIS_PATTERN = "(?<=(\\n|^|\\s|\\{|\\())([%s])(?=\\S)(.*?)\\S\\2(?=(\\n|$|\\s|\\.|,|:|;|-|\\}|\\)))";
public final static Pattern BOLD = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "*"));
public final static Pattern ITALICS = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "/"));
public final static Pattern STRIKETHROUGH = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "+"));
public final static Pattern UNDERLINE = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "_"));
public final static Pattern CODE_INLINE = Pattern.compile(String.format(COMMON_EMPHASIS_PATTERN, "=~"));
public final static Pattern HEADING = Pattern.compile("(?m)^(\\*+)\\s(.*?)(?=\\n|$)");
public final static Pattern BLOCK = Pattern.compile("(?m)(?<=#\\+BEGIN_.{1,15}$\\s)[\\s\\S]*?(?=#\\+END)");
public final static Pattern PREAMBLE = Pattern.compile("(?m)^(#\\+)(.*?)(?=\\n|$)");
Expand Down Expand Up @@ -44,6 +51,12 @@ protected void generateSpans() {
createColorSpanForMatches(PREAMBLE, ORG_COLOR_DIM);
createColorSpanForMatches(COMMENT, ORG_COLOR_DIM);
createColorBackgroundSpan(BLOCK, ORG_COLOR_BLOCK);

createStyleSpanForMatches(BOLD, Typeface.BOLD);
createStyleSpanForMatches(ITALICS, Typeface.ITALIC);
createStrikeThroughSpanForMatches(STRIKETHROUGH);
createColoredUnderlineSpanForMatches(UNDERLINE, Color.BLACK);
createMonospaceSpanForMatches(CODE_INLINE);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public class GsFileBrowserListAdapter extends RecyclerView.Adapter<GsFileBrowser
public static final File VIRTUAL_STORAGE_RECENTS = new File(VIRTUAL_STORAGE_ROOT, "Recent");
public static final File VIRTUAL_STORAGE_FAVOURITE = new File(VIRTUAL_STORAGE_ROOT, "Favourites");
public static final File VIRTUAL_STORAGE_POPULAR = new File(VIRTUAL_STORAGE_ROOT, "Popular");
public static final File VIRTUAL_STORAGE_APP_DATA_PRIVATE = new File(VIRTUAL_STORAGE_ROOT, "appdata-private");
public static final File VIRTUAL_STORAGE_APP_DATA_PRIVATE = new File(VIRTUAL_STORAGE_ROOT, "AppData (data partition)");
private static final File GO_BACK_SIGNIFIER = new File("__GO_BACK__");
private static final StrikethroughSpan STRIKE_THROUGH_SPAN = new StrikethroughSpan();
public static final String EXTRA_CURRENT_FOLDER = "EXTRA_CURRENT_FOLDER";
Expand Down Expand Up @@ -151,19 +151,14 @@ public Map<File, File> getVirtualFolders() {
}

for (final File file : ContextCompat.getExternalFilesDirs(_context, null)) {
final File remap = new File(VIRTUAL_STORAGE_ROOT, "appdata-public (" + file.getName() + ")");
//noinspection DataFlowIssue
final File remap = new File(VIRTUAL_STORAGE_ROOT, "AppData (" + file.getParentFile().toString().replace("/", "-").substring(1) + ")");
map.put(remap, file);
}

for (final Pair<File, String> p : cu.getAppDataPublicDirs(_context, false, true, false)) {
final File remap = new File(VIRTUAL_STORAGE_ROOT, "sdcard (" + p.second + ")");
map.put(remap, p.first);
}

map.put(VIRTUAL_STORAGE_RECENTS, VIRTUAL_STORAGE_RECENTS);
map.put(VIRTUAL_STORAGE_POPULAR, VIRTUAL_STORAGE_POPULAR);
map.put(VIRTUAL_STORAGE_FAVOURITE, VIRTUAL_STORAGE_FAVOURITE);
map.put(VIRTUAL_STORAGE_EMULATED, VIRTUAL_STORAGE_EMULATED);

return map;
}
Expand Down Expand Up @@ -211,7 +206,7 @@ public void onBindViewHolder(@NonNull FilesystemViewerViewHolder holder, int pos
if (isCurrentFolderVirtual() && "index.html".equals(filename)) {
titleText += " [" + currentFolderName + "]";
}
if (currentFolderName.equals("storage") && _dopt.storageMaps.containsValue(displayFile)){
if (currentFolderName.equals("storage") && _dopt.storageMaps.containsValue(displayFile)) {
titleText = GsCollectionUtils.reverse(_dopt.storageMaps).get(displayFile).getName();
}

Expand Down Expand Up @@ -695,11 +690,28 @@ private void loadFolder(final File folder, final File show) {

// This function is not called on the main thread, so post to the UI thread
private synchronized void _loadFolder(final @NonNull File folder, final @Nullable File toShow) {

final boolean folderChanged = !folder.equals(_currentFolder);

final List<File> newData = new ArrayList<>();

// Make sure /storage/emulated/0 is browsable, even though filesystem says it's not accessible
if (folder.equals(new File("/"))) {
newData.add(VIRTUAL_STORAGE_ROOT);
} else if (folder.equals(VIRTUAL_STORAGE_ROOT)) {
newData.add(VIRTUAL_STORAGE_EMULATED);

// SD Card and other external storage directories that are also not listable
for (final Pair<File, String> p : GsContextUtils.instance.getAppDataPublicDirs(_context, false, true, false)) {
File f = p.first;
while (f.getParentFile() != null && !f.getParentFile().getName().equals("storage")) {
f = f.getParentFile();
}
newData.add(f);
}
} else if (folder.equals(VIRTUAL_STORAGE_EMULATED)) {
newData.add(new File(folder, "0"));
}


if (folder.equals(VIRTUAL_STORAGE_RECENTS)) {
newData.addAll(_dopt.recentFiles);
} else if (folder.equals(VIRTUAL_STORAGE_POPULAR)) {
Expand All @@ -715,17 +727,6 @@ private synchronized void _loadFolder(final @NonNull File folder, final @Nullabl
newData.addAll(_virtualMapping.keySet());
}

// Add all emulated folders under /storage/emulated
if (VIRTUAL_STORAGE_EMULATED.equals(folder)) {
newData.add(new File(folder, "0"));
for (int i = 1; i < 10; i++) {
final File f = new File(folder, String.valueOf(i));
if (GsFileUtils.canCreate(f)) {
newData.add(f);
}
}
}

if (folder.getAbsolutePath().equals("/")) {
newData.add(new File(folder, VIRTUAL_STORAGE_ROOT.getName()));
}
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/net/gsantner/opoc/util/GsFileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,8 @@ private static String gatherMimeType(final File file) {
return "text/markdown";
} else if (ext.matches("(te?xt)|(taskpaper)")) {
return "text/plain";
} else if (ext.matches("org")) {
return "text/org";
} else if (ext.matches("webp")) {
return "image/webp";
} else if (ext.matches("jpe?g")) {
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/string-not_translatable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,13 @@ work. If not, see <https://creativecommons.org/publicdomain/zero/1.0/>.
<string name="abid_todotxt_due_date" translatable="false">abid_todotxt_due_date</string>
<string name="abid_todotxt_sort_todo" translatable="false">abid_todotxt_sort_todo</string>


<string name="abid_orgmode_bold" translatable="false">abid_orgmode_bold</string>
<string name="abid_orgmode_italic" translatable="false">abid_orgmode_italic</string>
<string name="abid_orgmode_strikeout" translatable="false">abid_orgmode_strikeout</string>
<string name="abid_orgmode_underline" translatable="false">abid_orgmode_underline</string>
<string name="abid_orgmode_code_inline" translatable="false">abid_orgmode_code_inline</string>


<string name="jekyll_post" translatable="false">Jekyll Post</string>
<string name="wikitext" translatable="false">Wikitext / Zim</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@

<!-- Android V28 options; ignore IDE warnings -->
<item name="android:dialogCornerRadius" tools:targetApi="p">@dimen/dialog_corner_radius</item>

<!-- android-35 Disable window size overlap -->
<item name="android:windowOptOutEdgeToEdgeEnforcement">true</item>
</style>

<style name="AppTheme.PreferenceTheme" parent="PreferenceThemeOverlay.v14.Material">
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.text.SimpleDateFormat

buildscript {
ext {
version_gradle_tools = '8.5.1'
version_gradle_tools = '8.6.0'
version_plugin_kotlin = "1.3.72"
enable_plugin_kotlin = false

Expand Down

0 comments on commit 406b7cb

Please sign in to comment.