Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/keenwrite.git

Add auto saving, delay killing ConTeXt process by 1 second

AuthorDaveJarvis <email>
Date2021-07-13 23:27:23 GMT-0700
Commit22105fd1266942dbc91149dcd6f84073e9e16b44
Parent1544e9b
Delta35 lines added, 0 lines removed, 35-line increase
src/main/resources/com/keenwrite/messages.properties
workspace.document.date.title=Timestamp
+workspace.editor=Editor
+workspace.editor.autosave=Autosave
+workspace.editor.autosave.desc=Amount of time to wait between saves, in seconds (0 means disabled).
+workspace.editor.autosave.title=Timeout
+
workspace.typeset=Typesetting
workspace.typeset.context=ConTeXt
src/main/java/com/keenwrite/preferences/Workspace.java
entry( KEY_DOC_DATE, asStringProperty( getDate() ) ),
+ entry( KEY_EDITOR_AUTOSAVE, asIntegerProperty( 30 ) ),
+
entry( KEY_R_SCRIPT, asStringProperty( "" ) ),
entry( KEY_R_DIR, asFileProperty( USER_DIRECTORY ) ),
private StringProperty asStringProperty( final String defaultValue ) {
return new SimpleStringProperty( defaultValue );
+ }
+
+ @SuppressWarnings( "SameParameterValue" )
+ private IntegerProperty asIntegerProperty( final int defaultValue ) {
+ return new SimpleIntegerProperty( defaultValue );
}
LocaleProperty.class, LocaleProperty::parseLocale,
SimpleBooleanProperty.class, Boolean::parseBoolean,
+ SimpleIntegerProperty.class, Integer::parseInt,
SimpleDoubleProperty.class, Double::parseDouble,
SimpleFloatProperty.class, Float::parseFloat,
assert key != null;
return (Boolean) valuesProperty( key ).getValue();
+ }
+
+ /**
+ * Returns the {@link Integer} preference value associated with the given
+ * {@link Key}. The caller must be sure that the given {@link Key} is
+ * associated with a value that matches the return type.
+ *
+ * @param key The {@link Key} associated with a preference value.
+ * @return The value associated with the given {@link Key}.
+ */
+ public int toInteger( final Key key ) {
+ assert key != null;
+ return (Integer) valuesProperty( key ).getValue();
}
assert ended != null;
return new Tokens( stringProperty( began ), stringProperty( ended ) );
+ }
+
+ @SuppressWarnings( "SameParameterValue" )
+ public IntegerProperty integerProperty( final Key key ) {
+ assert key != null;
+ return valuesProperty( key );
}
src/main/java/com/keenwrite/preferences/WorkspaceKeys.java
public static final Key KEY_DOC_COPYRIGHT = key( KEY_DOC, "copyright" );
+ public static final Key KEY_EDITOR = key( KEY_ROOT, "editor" );
+ public static final Key KEY_EDITOR_AUTOSAVE = key( KEY_EDITOR, "autosave" );
+
public static final Key KEY_R = key( KEY_ROOT, "r" );
public static final Key KEY_R_SCRIPT = key( KEY_R, "script" );