Dave Jarvis' Repositories

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

Isolate updating definition pane to single location

AuthorDaveJarvis <email>
Date2020-06-02 16:14:13 GMT-0700
Commitf5ae4f99793ab08d2e83bc651a7936181d586221
Parentfbe5ba4
Delta25 lines added, 79 lines removed, 54-line decrease
src/main/resources/com/scrivenvar/messages.properties
-#
-# Copyright 2017 Karl Tauber and White Magic Software, Ltd.
-#
-# All rights reserved.
-#
-# Redistribution and use in source and binary forms, with or without
-# modification, are permitted provided that the following conditions are met:
-#
-# * Redistributions of source code must retain the above copyright
-# notice, this list of conditions and the following disclaimer.
-#
-# * Redistributions in binary form must reproduce the above copyright
-# notice, this list of conditions and the following disclaimer in the
-# documentation and/or other materials provided with the distribution.
-#
-# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#
-
# ########################################################################
-#
# Main Application Window
-#
# ########################################################################
Main.menu.edit.redo=_Redo
Main.menu.edit.find=_Find
-Main.menu.edit.find.replace=Re_place
Main.menu.edit.find.next=Find _Next
-Main.menu.edit.find.previous=Find _Previous
Main.menu.insert=_Insert
# ########################################################################
-#
# Status Bar
-#
# ########################################################################
Main.statusbar.text.offset=offset
Main.statusbar.line=Line {0} of {1}, ${Main.statusbar.text.offset} {2}
Main.statusbar.state.default=OK
Main.statusbar.parse.error={0} (near ${Main.statusbar.text.offset} {1})
# ########################################################################
-#
# Definition Pane and its Tree View
-#
# ########################################################################
Definition.menu.create=Create
Definition.menu.rename=Rename
Definition.menu.remove=Delete
Definition.menu.add.default=Undefined
# ########################################################################
-#
+# Failure messages with respect to YAML files.
+# ########################################################################
+yaml.error.open=Could not open YAML file (ensure non-empty file).
+yaml.error.unresolvable=Too much indirection for: '{0}' = '{1}'.
+yaml.error.missing=Empty definition value for key '{0}'.
+
+# ########################################################################
# File Editor
-#
# ########################################################################
FileEditor.untitled=Untitled
FileEditor.loadFailed.message=Failed to load ''{0}''.\n\nReason: {1}
FileEditor.loadFailed.title=Load
FileEditor.saveFailed.message=Failed to save ''{0}''.\n\nReason: {1}
FileEditor.saveFailed.title=Save
# ########################################################################
-#
# File Open
-#
# ########################################################################
# ########################################################################
-#
# Alert Dialog
-#
# ########################################################################
Alert.file.close.title=Close
Alert.file.close.text=Save changes to {0}?
# ########################################################################
-#
# Definition Pane
-#
# ########################################################################
Pane.definition.node.root.title=Definitions
# Controls ###############################################################
# ########################################################################
-#
# Browse Directory
-#
# ########################################################################
BrowseDirectoryButton.chooser.title=Browse for local folder
BrowseDirectoryButton.tooltip=${BrowseDirectoryButton.chooser.title}
# ########################################################################
-#
# Browse File
-#
# ########################################################################
BrowseFileButton.chooser.title=Browse for local file
BrowseFileButton.chooser.allFilesFilter=All Files
BrowseFileButton.tooltip=${BrowseFileButton.chooser.title}
# Dialogs ################################################################
# ########################################################################
-#
# Image
-#
# ########################################################################
# ########################################################################
-#
# Hyperlink
-#
# ########################################################################
Dialog.link.title=Link
Dialog.link.previewLabel.text=Markdown Preview\:
Dialog.link.textLabel.text=Link Text\:
Dialog.link.titleLabel.text=Title (tooltip)\:
Dialog.link.urlLabel.text=Link URL\:
# ########################################################################
-#
# About
-#
# ########################################################################
Dialog.about.title=About
Dialog.about.header=${Main.title}
Dialog.about.content=Copyright 2020 White Magic Software, Ltd.\n\nBased on Markdown Writer FX by Karl Tauber
# R ################################################################
# ########################################################################
-#
# R Script
-#
# ########################################################################
Dialog.r.script.title=R Startup Script
Dialog.r.script.content=Provide R statements to run prior to interpreting R statements embedded in the document.
# ########################################################################
-#
# R Directory
-#
# ########################################################################
Dialog.r.directory.title=Bootstrap Working Directory
Dialog.r.directory.header=Value for $application.r.working.directory$.
# Options ################################################################
# ########################################################################
-#
# Options Dialog
-#
# ########################################################################
OptionsDialog.title=Options
OptionsDialog.generalTab.text=General
OptionsDialog.markdownTab.text=Markdown
# ########################################################################
-#
# General Options Pane
-#
# ########################################################################
# ########################################################################
-#
# Markdown Options Pane
-#
# ########################################################################
src/main/java/com/scrivenvar/definition/yaml/YamlParser.java
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator;
+import com.scrivenvar.Messages;
import com.scrivenvar.decorators.VariableDecorator;
import com.scrivenvar.decorators.YamlVariableDecorator;
import org.yaml.snakeyaml.DumperOptions;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
-import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Map;
*/
public static final String SEPARATOR = ".";
- public static final char SEPARATOR_CHAR = SEPARATOR.charAt( 0 );
private final static int GROUP_DELIMITED = 1;
private Map<String, String> references;
- public YamlParser( final InputStream in ) throws IOException {
+ public YamlParser( final InputStream in ) {
process( in );
}
*
* @param in The input stream containing YAML content.
- * @throws IOException Could not read the stream.
*/
- private void process( final InputStream in ) throws IOException {
- final ObjectNode root = (ObjectNode) getObjectMapper().readTree( in );
- setDocumentRoot( root );
- process( root );
+ private void process( final InputStream in ) {
+ setError( Messages.get( "Main.statusbar.state.default" ) );
+
+ try {
+ final ObjectNode root = (ObjectNode) getObjectMapper().readTree( in );
+ setDocumentRoot( root );
+ process( root );
+ } catch( final Exception e ) {
+ setDocumentRoot( new ObjectMapper().createObjectNode() );
+ setError( Messages.get( "yaml.error.open" ) );
+ }
}
resolve( fieldValue.asText() );
} catch( StackOverflowError e ) {
- setError( "Unresolvable: " + node.textValue() + " = " + fieldValue );
+ final String msg = Messages.get(
+ "yaml.error.unresolvable", node.textValue(), fieldValue );
+ setError( msg );
}
}
*/
private void missing( final String delimited ) {
- setError( MessageFormat.format( "Missing value for '{0}'.", delimited ) );
+ setError( Messages.get( "yaml.error.missing", delimited ) );
}
src/main/java/com/scrivenvar/definition/FileDefinitionSource.java
public abstract class FileDefinitionSource extends AbstractDefinitionSource {
- private Path mPath;
+ private final Path mPath;
/**
* Constructs a new file definition source that can read and write data in the
* hierarchical format contained within the file location specified by the
* path.
*
* @param path Must not be null.
*/
public FileDefinitionSource( final Path path ) {
- setPath( path );
- }
-
- private void setPath( final Path path ) {
mPath = path;
}