diff --git a/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java b/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java index 131a366ed4..d40450df8d 100644 --- a/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java +++ b/src/main/java/net/rptools/maptool/client/ui/MapToolFrame.java @@ -36,6 +36,7 @@ import javax.swing.Timer; import javax.swing.border.BevelBorder; import javax.swing.filechooser.FileFilter; +import javax.swing.filechooser.FileNameExtensionFilter; import javax.swing.tree.TreePath; import javax.swing.tree.TreeSelectionModel; import javax.xml.parsers.ParserConfigurationException; @@ -885,6 +886,10 @@ public JFileChooser getSavePropsFileChooser() { savePropsFileChooser = new JFileChooser(); savePropsFileChooser.setCurrentDirectory(AppPreferences.saveDirectory.get()); savePropsFileChooser.addChoosableFileFilter(propertiesFilter); + savePropsFileChooser.setFileFilter(propertiesFilter); + savePropsFileChooser.setFileFilter(new FileNameExtensionFilter("JSON", "json")); + savePropsFileChooser.setFileFilter(new FileNameExtensionFilter("Text", "txt")); + savePropsFileChooser.setFileFilter(savePropsFileChooser.getChoosableFileFilters()[0]); savePropsFileChooser.setDialogTitle(I18N.getText("msg.title.exportProperties")); } savePropsFileChooser.setAcceptAllFileFilterUsed(true); diff --git a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java index 2038204e7c..cc1a5d4ec6 100644 --- a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java +++ b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/CampaignPropertiesDialog.java @@ -17,11 +17,13 @@ import static org.apache.commons.text.WordUtils.capitalize; import static org.apache.commons.text.WordUtils.uncapitalize; +import com.google.protobuf.util.JsonFormat; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.io.File; +import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -47,6 +49,7 @@ import net.rptools.maptool.model.LightSource; import net.rptools.maptool.model.ShapeType; import net.rptools.maptool.model.SightType; +import net.rptools.maptool.server.proto.CampaignPropertiesDto; import net.rptools.maptool.util.LightSyntax; import net.rptools.maptool.util.PersistenceUtil; import net.rptools.maptool.util.SightSyntax; @@ -171,7 +174,7 @@ private void initAddRepoButton() { button.addActionListener( e -> { String newRepo = getNewServerTextField().getText(); - if (newRepo == null || newRepo.length() == 0) { + if (newRepo == null || newRepo.isEmpty()) { return; } // TODO: Check for uniqueness @@ -415,6 +418,7 @@ private void initExportButton() { // END HACK JFileChooser chooser = MapTool.getFrame().getSavePropsFileChooser(); + boolean tryAgain = true; while (tryAgain) { if (chooser.showSaveDialog(MapTool.getFrame()) != JFileChooser.APPROVE_OPTION) { @@ -440,8 +444,21 @@ private void initExportButton() { } } try { - PersistenceUtil.saveCampaignProperties(campaign, chooser.getSelectedFile()); - MapTool.showInformation("Properties Saved."); + if (selectedFile.getName().endsWith(".mtprops")) { + PersistenceUtil.saveCampaignProperties(campaign, chooser.getSelectedFile()); + MapTool.showInformation("Properties Saved."); + } else { + MapTool.showMessage( + "CampaignPropertiesDialog.export.message", + "msg.title.exportProperties", + JOptionPane.INFORMATION_MESSAGE, + null); + CampaignPropertiesDto campaignPropertiesDto = + MapTool.getCampaign().getCampaignProperties().toDto(); + FileOutputStream fos = new FileOutputStream(chooser.getSelectedFile()); + fos.write(JsonFormat.printer().print(campaignPropertiesDto).getBytes()); + } + } catch (IOException ioe) { MapTool.showError("Could not save properties: ", ioe); } diff --git a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java index 29b501a8ba..c3af732ba0 100644 --- a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java +++ b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesManagementPanel.java @@ -300,10 +300,15 @@ public void initPropertyAddButton() { finalizeCellEditing(); JTable propertiesTable = getTokenPropertiesTable(); var model = getTokenPropertiesTableModel(); - model.addProperty(); + // selected row is -1 for no selection causing property to be appended to list + // instead of inserted + int selectedRow = propertiesTable.getSelectedRow(); + model.addProperty(selectedRow); int count = model.getRowCount(); propertiesTable.scrollRectToVisible( - propertiesTable.getCellRect(count - 1, 0, true)); + propertiesTable.getCellRect( + selectedRow == -1 ? count - 1 : selectedRow, 0, true)); + propertiesTable.repaint(); })); button.setEnabled(false); } diff --git a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java index 159083f65d..fad4743b20 100644 --- a/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java +++ b/src/main/java/net/rptools/maptool/client/ui/campaignproperties/TokenPropertiesTableModel.java @@ -142,7 +142,7 @@ public void setValueAt(Object aValue, int rowIndex, int columnIndex) { } /** Adds a new token property, with a generated name. */ - public void addProperty() { + public void addProperty(int selectedRow) { var properties = tokenTypeMap.get(tokenType); // First find a unique name, there are so few entries we don't have to worry @@ -160,7 +160,12 @@ public void addProperty() { if (free) { var prop = new TokenProperty(newName); - properties.add(prop); + // append if there is no selection, otherwise insert at selectedRow + if (selectedRow == -1) { + properties.add(prop); + } else { + properties.add(selectedRow, prop); + } break; } seq++; diff --git a/src/main/resources/net/rptools/maptool/language/i18n.properties b/src/main/resources/net/rptools/maptool/language/i18n.properties index 2a52ce3242..e28a6e524e 100644 --- a/src/main/resources/net/rptools/maptool/language/i18n.properties +++ b/src/main/resources/net/rptools/maptool/language/i18n.properties @@ -812,6 +812,7 @@ CampaignPropertiesDialog.button.importPredefined = Import Predefined CampaignPropertiesDialog.button.importPredefined.tooltip = Import predefined properties and settings for the selected system CampaignPropertiesDialog.button.import.tooltip = Import predefined properties from a file CampaignPropertiesDialog.button.export.tooltip = Export campaign properties to file +CampaignPropertiesDialog.export.message = Campaign properties will be exported in JSON format and cannot be imported. CampaignPropertiesDialog.combo.importPredefined.tooltip = System to import properties for CampaignPropertiesDialog.button.import = Import Predefined campaignPropertiesDialog.newTokenTypeName = Enter the name for the new token type