Implement Set as next message button
This commit is contained in:
parent
a7169b49cc
commit
f7314290db
@ -116,6 +116,29 @@ public class MainController implements Initializable {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void handleSetAsNextMessageButtonPress() {
|
||||||
|
Path stationDirPath = selectedStation.stationPath();
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (!Files.exists(stationDirPath)) {
|
||||||
|
Files.createDirectories(stationDirPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
Path nextMessagePath = stationDirPath.resolve("next-message.txt");
|
||||||
|
|
||||||
|
Files.write(nextMessagePath, messageTextArea.getText().getBytes());
|
||||||
|
} catch (IOException e) {
|
||||||
|
String message = "Failed to write next message to " + stationDirPath.toString();
|
||||||
|
logger.log(Level.SEVERE, message, e);
|
||||||
|
Alert alert = new Alert(Alert.AlertType.ERROR);
|
||||||
|
alert.setTitle("Exception");
|
||||||
|
alert.setHeaderText(null);
|
||||||
|
alert.setContentText(message);
|
||||||
|
alert.showAndWait();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void initialize(URL location, ResourceBundle resources) {
|
public void initialize(URL location, ResourceBundle resources) {
|
||||||
stationNameField.textProperty().bindBidirectional(selectedStationName);
|
stationNameField.textProperty().bindBidirectional(selectedStationName);
|
||||||
|
@ -86,7 +86,7 @@
|
|||||||
</TextArea>
|
</TextArea>
|
||||||
<FlowPane alignment="CENTER_RIGHT" prefHeight="34.0" prefWidth="620.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
<FlowPane alignment="CENTER_RIGHT" prefHeight="34.0" prefWidth="620.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0">
|
||||||
<children>
|
<children>
|
||||||
<Button mnemonicParsing="false" text="Set as next message" />
|
<Button mnemonicParsing="false" onMousePressed="#handleSetAsNextMessageButtonPress" text="Set as next message" />
|
||||||
</children>
|
</children>
|
||||||
</FlowPane>
|
</FlowPane>
|
||||||
</children>
|
</children>
|
||||||
|
@ -1,5 +1,8 @@
|
|||||||
package name.nathanmcrae.numbersstation;
|
package name.nathanmcrae.numbersstation;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalTime;
|
import java.time.LocalTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -40,6 +43,25 @@ public class StationSettings {
|
|||||||
name = newName;
|
name = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Path stationPath() {
|
||||||
|
String configHome = System.getenv("XDG_CONFIG_HOME");
|
||||||
|
Path directoryPath;
|
||||||
|
|
||||||
|
if (configHome != null && !configHome.isEmpty() && Paths.get(configHome).isAbsolute()) {
|
||||||
|
directoryPath = Paths.get(configHome, "numbers-station");
|
||||||
|
} else {
|
||||||
|
String userHome = System.getProperty("user.home");
|
||||||
|
directoryPath = Paths.get(userHome, ".config", "numbers-station");
|
||||||
|
}
|
||||||
|
|
||||||
|
String stationDirName = null;
|
||||||
|
try {
|
||||||
|
stationDirName = java.net.URLEncoder.encode(name, "UTF-8");
|
||||||
|
} catch(UnsupportedEncodingException e) {} // We know UTF-8 is supported
|
||||||
|
|
||||||
|
return directoryPath.resolve(stationDirName);
|
||||||
|
}
|
||||||
|
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user