Skip to content

Commit

Permalink
#506 #504 Remove all usage of STR template, store last import location
Browse files Browse the repository at this point in the history
  • Loading branch information
davetcc committed Sep 7, 2024
1 parent a56bed9 commit c660795
Show file tree
Hide file tree
Showing 27 changed files with 268 additions and 127 deletions.
15 changes: 9 additions & 6 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions .idea/runConfigurations/TcMenuDesigner_Single_Test.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions embeddedJavaExample/pom.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- it is safe to edit this file, it will not be replaced by TcMenu designer unless you delete it --><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.thecoderscorner.menuexample</groupId>
<artifactId>EmbeddedJavaDemo</artifactId>
<name>EmbeddedJavaDemo</name>
<artifactId>embeddedJavaExample</artifactId>
<name>embeddedJavaExample</name>
<description>An application built with TcMenu Designer</description>
<version>0.0.1-SNAPSHOT</version>

Expand Down
2 changes: 1 addition & 1 deletion tcMenuGenerator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<compilerArgs>--enable-preview</compilerArgs>
<!--compilerArgs>enable-preview</compilerArgs-->
</configuration>
</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,15 @@ public void start(Stage primaryStage) throws Exception {
appContext = new MenuEditorConfig();
INSTANCE = this;
} catch(Exception ex) {
String msg;
if(ex.getMessage().contains("Database lock acquisition failure")) {
msg = "Please check if designer is already running, or you have opened the database in the .tcmenu directory.";
} else {
msg = "App did not start due to " + ex.getMessage() + ". See log for more details.";
}
System.getLogger(MenuEditorApp.class.getSimpleName()).log(ERROR, "Failed loading config", ex);
AlertUtil.showAlertAndWait(AlertType.ERROR,"Could not load designer",
"App did not start due to " + ex.getMessage() + ". See log for more details.",
msg,
ButtonType.CLOSE);
primaryStage.close(); // make sure the app closes here.
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public Integer call() {
.map(form -> getFirstByNameAndUuid(appContext.getEcDataStore(), project, form)).toList();
} catch(Exception ex) {
enabledFormObjects = List.of();
System.err.println(STR."WARNING: Forms \{project.getOptions().getListOfEmbeddedForms()} didn't load");
System.err.printf("WARNING: Forms %s didn't load\n", project.getOptions().getListOfEmbeddedForms());
System.err.println("IMPORTANT: Conversion will continue but forms will be missing from the build");
if(verbose) {
ex.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public static String userSelectedProject() {

public static void userDidSelectProject(File projectFile) {
userSelectedProject.set(projectFile.getAbsolutePath());
System.out.println(STR."Designer is starting with project \{userSelectedProject.get()}");
System.out.println("Designer is starting with project " + userSelectedProject.get());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public CodeGenerator getCodeGeneratorFor(EmbeddedPlatform platform, CodeGenerato
} else if (javaPlatforms.contains(platform)) {
return new EmbeddedJavaGenerator(configStorage, platform);
} else {
throw new IllegalArgumentException(STR."No such board type: \{platform}");
throw new IllegalArgumentException("No such board type: " + platform);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public boolean startConversion(Path directory, List<CodePluginItem> codeGenerato
this.localeHandler = handler;
namingGenerator = new VariableNameGenerator(menuTree, options.isNamingRecursive());
this.previousPluginFiles = previousPluginFiles;
logLine(INFO, STR."Starting \{embeddedPlatform.getBoardId()} generate into : \{directory}");
logLine(INFO, "Starting " + embeddedPlatform.getBoardId() + " generate into : " + directory);

hasRemotePlugins = codeGenerators.stream()
.anyMatch(p -> p.getSubsystem() == SubSystem.REMOTE && !p.getId().equals(NO_REMOTE_ID));
Expand Down Expand Up @@ -381,7 +381,7 @@ private String toEmbeddedCppValue(MenuItem item, Object defaultValue) throws TcM
return toEmbeddedCppTextValue(tmi, s);
}
case String _ -> {
return STR."\"\{defaultValue}\"";
return "\"" + defaultValue + "\"";
}
case PortableColor c when item instanceof Rgb32MenuItem rgbItem -> {
if (rgbItem.isIncludeAlphaChannel()) {
Expand Down Expand Up @@ -474,7 +474,7 @@ protected void generateSource(List<CodePluginItem> generators, String cppFile,
logLine(INFO, "Writing out source CPP file: " + cppFile);

writer.write(COMMENT_HEADER);
writer.write(STR."// Generated for \{embeddedPlatform} by TcMenu \{configStore.getVersion()} on \{ISO_INSTANT.format(clock.instant())}.");
writer.write("// Generated for %s by TcMenu %s on %s.".formatted(embeddedPlatform, configStore.getVersion(), ISO_INSTANT.format(clock.instant())));
writer.append(TWO_LINES);

writer.write("#include <tcMenu.h>" + LINE_BREAK);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.thecoderscorner.menu.editorui.gfxui.imgedit.SimpleImageEditor;
import com.thecoderscorner.menu.editorui.gfxui.imgedit.SimpleImagePane;
import com.thecoderscorner.menu.editorui.gfxui.pixmgr.*;
import com.thecoderscorner.menu.editorui.storage.ConfigurationStorage;
import com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI;
import com.thecoderscorner.menu.editorui.util.SafeNavigator;
import javafx.event.ActionEvent;
Expand All @@ -30,6 +31,7 @@
import java.util.Optional;

import static com.thecoderscorner.menu.editorui.gfxui.imgedit.SimpleImageEditor.EditingMode.BITMAP_EDITOR;
import static com.thecoderscorner.menu.editorui.storage.ConfigurationStorage.ConfigImportType;
import static com.thecoderscorner.menu.editorui.util.AlertUtil.showAlertAndWait;

public class CreateBitmapWidgetController {
Expand All @@ -45,12 +47,12 @@ public class CreateBitmapWidgetController {
public GridPane imageGridPane;

private CurrentProjectEditorUI editorUI;
private String homeDirectory;
private final List<LoadedImage> loadedImages = new ArrayList<>();
private ConfigurationStorage storage;

public void initialise(CurrentProjectEditorUI editorUI, String homeDirectory) {
public void initialise(CurrentProjectEditorUI editorUI, ConfigurationStorage storage) {
this.editorUI = editorUI;
this.homeDirectory = homeDirectory;
this.storage = storage;

variableField.textProperty().addListener((_, _, _) -> refreshButtonStates());

Expand Down Expand Up @@ -169,8 +171,9 @@ public void onLoadImage(ActionEvent ignoredActionEvent) {
try(var is = new BufferedInputStream(new FileInputStream(maybeFile.get()))) {
Image img = new Image(is);
putImageIntoAvailableSlot(img);
storage.setImportDirectory(ConfigImportType.BITMAP, Path.of(maybeFile.get()).getParent().toString());
} catch (Exception ex) {
logger.log(System.Logger.Level.ERROR, STR."Image load from file failure \{maybeFile.get()}", ex);
logger.log(System.Logger.Level.ERROR, "Image load from file failure " + maybeFile.get(), ex);
editorUI.alertOnError("Error loading image", ex.getMessage());
}
}
Expand All @@ -185,7 +188,7 @@ public void onCreateWidget(ActionEvent ignoredActionEvent) {
}
catch (Exception e) {
logger.log(System.Logger.Level.ERROR, "Could not put file content on clipboard", e);
editorUI.alertOnError("Not exported to Clipboard", STR."Not exported to Clipboard \{e.getMessage()}");
editorUI.alertOnError("Not exported to Clipboard", "Not exported to Clipboard " + e.getMessage());
}
return;
}
Expand All @@ -196,7 +199,7 @@ public void onCreateWidget(ActionEvent ignoredActionEvent) {
exportSuccessful(maybeName.get());
} catch (Exception e) {
logger.log(System.Logger.Level.ERROR, "File could not be written", e);
editorUI.alertOnError("Not exported to file", STR."Not exported to file \{e.getMessage()}");
editorUI.alertOnError("Not exported to file", "Not exported to file " + e.getMessage());
}
}
}
Expand Down Expand Up @@ -229,7 +232,7 @@ public void onCreateBitmaps(ActionEvent ignoredActionEvent) {
}
catch (Exception e) {
logger.log(System.Logger.Level.ERROR, "Could not put file content on clipboard", e);
editorUI.alertOnError("Not exported to Clipboard", STR."Not exported to Clipboard \{e.getMessage()}");
editorUI.alertOnError("Not exported to Clipboard", "Not exported to Clipboard " + e.getMessage());
}
return;
}
Expand All @@ -240,22 +243,22 @@ public void onCreateBitmaps(ActionEvent ignoredActionEvent) {
exportSuccessful(maybeName.get());
} catch (Exception e) {
logger.log(System.Logger.Level.ERROR, "File could not be written", e);
editorUI.alertOnError("File not written", STR."Error while writing file \{e.getMessage()}");
editorUI.alertOnError("File not written", "Error while writing file " + e.getMessage());
}
}
}

private Optional<Path> getInitialDir() {
if(editorUI.getCurrentProject().getFileName().equals("New")) {
return Optional.of(Path.of(homeDirectory));
return Optional.of(Path.of(storage.getImportDirectory(ConfigImportType.BITMAP)));
} else {
return Optional.of(Path.of(editorUI.getCurrentProject().getFileName()).getParent());
}
}

private void exportSuccessful(String where) {
showAlertAndWait(Alert.AlertType.INFORMATION, STR."\{variableField.getText()} successfully exported",
STR."\{variableField.getText()} was successfully exported to \{where}", ButtonType.CLOSE);
showAlertAndWait(Alert.AlertType.INFORMATION, variableField.getText() + " successfully exported",
"%s was successfully exported to %s".formatted(variableField.getText(), where), ButtonType.CLOSE);
}

LoadedImage createBitmap(BitmapImportPopup popup) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
package com.thecoderscorner.menu.editorui.gfxui;

import com.thecoderscorner.menu.editorui.dialog.BaseDialogSupport;
import com.thecoderscorner.menu.editorui.storage.ConfigurationStorage;
import com.thecoderscorner.menu.editorui.uimodel.CurrentProjectEditorUI;
import javafx.stage.Stage;

public class CreateBitmapWidgetToolDialog extends BaseDialogSupport<CreateBitmapWidgetController> {
private final String homeDirectory;
private CurrentProjectEditorUI editorUI;
private final CurrentProjectEditorUI editorUI;
private final ConfigurationStorage storage;

public CreateBitmapWidgetToolDialog(Stage mainStage, CurrentProjectEditorUI editorUI, String homeDirectory) {
public CreateBitmapWidgetToolDialog(Stage mainStage, CurrentProjectEditorUI editorUI, ConfigurationStorage storage) {
this.editorUI = editorUI;
this.homeDirectory = homeDirectory;
this.storage = storage;
tryAndCreateDialog(mainStage, "/ui/ImageToNativeBitmapConverter.fxml", bundle.getString("bitmap.create.title"), true, 0.96);
}

@Override
protected void initialiseController(CreateBitmapWidgetController controller) throws Exception {
controller.initialise(editorUI, homeDirectory);
controller.initialise(editorUI, storage);
}
}
Loading

0 comments on commit c660795

Please sign in to comment.