Skip to content

Commit 104f492

Browse files
committed
Choose todo archive based on todo name
1 parent 0837cd1 commit 104f492

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

app/src/main/java/net/gsantner/markor/model/AppSettings.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@
4949
import java.util.Locale;
5050
import java.util.Map;
5151
import java.util.Set;
52+
import java.util.regex.Matcher;
53+
import java.util.regex.Pattern;
5254

5355
import other.de.stanetz.jpencconverter.PasswordStore;
5456

@@ -441,11 +443,25 @@ public void setLastTodoDoneName(final String path, final String name) {
441443
}
442444
}
443445

446+
private static final Pattern TODOTXT_STRIP_SUFFIX_PATTERN = Pattern.compile("(?i)(?:^|[-._])todo\\.txt$");
447+
444448
public String getLastTodoDoneName(final String path) {
445-
final String def = getLastTodoUsedArchiveFilename();
446449
if (!fexists(path)) {
447-
return def;
450+
return getLastTodoUsedArchiveFilename();
448451
} else {
452+
// If possible, derive archive name from todofile name.
453+
String def;
454+
455+
Matcher m = TODOTXT_STRIP_SUFFIX_PATTERN.matcher(fbasename(path));
456+
if (m.find()) {
457+
def = "." + m.replaceFirst(".todo.archive.txt");
458+
if (def.startsWith("..")) {
459+
def = def.substring(1);
460+
}
461+
} else {
462+
def = getLastTodoUsedArchiveFilename();
463+
}
464+
449465
return getString(PREF_PREFIX_TODO_DONE_NAME + path, def);
450466
}
451467
}

app/src/main/java/net/gsantner/opoc/model/GsSharedPreferencesPropertyBackend.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -622,4 +622,8 @@ public static boolean ne(final String str) {
622622
public static boolean fexists(final String fp) {
623623
return ne(fp) && (new File(fp)).exists();
624624
}
625+
626+
public static String fbasename(final String fp) {
627+
return new File(fp).getName();
628+
}
625629
}

0 commit comments

Comments
 (0)