diff --git a/megameklab/resources/megameklab/resources/Dialogs.properties b/megameklab/resources/megameklab/resources/Dialogs.properties index 6937df920..62efaf624 100644 --- a/megameklab/resources/megameklab/resources/Dialogs.properties +++ b/megameklab/resources/megameklab/resources/Dialogs.properties @@ -66,8 +66,8 @@ ConfigurationDialog.startup.text=MML Startup: ConfigurationDialog.startup.tooltip=Depending on the startup type selected, MML will start in the main menu or, alternatively, directly load the most recent unit or start with a new unit instead of the main menu. ConfigurationDialog.mekChassis.text=Mek Chassis Arrangement: ConfigurationDialog.mekChassis.tooltip=Meks with a Clan and an IS chassis name will print their chassis in the selected arrangement. Meks with no clan chassis name will always just print their chassis. -ConfigurationDialog.cbMulDndBehaviour.text=MUL file drag and drop behaviour: -ConfigurationDialog.cbMulDndBehaviour.tooltip=What should be done when a MUL file is dragged onto the MML window? +ConfigurationDialog.cbMulOpenBehaviour.text=MUL file open behaviour: +ConfigurationDialog.cbMulOpenBehaviour.tooltip=What should be done when a MUL file is dragged onto the MML window or opened with MML by the operating system? RecordSheetTask.printing=Printing RecordSheetTask.exporting=Exporting diff --git a/megameklab/src/megameklab/MegaMekLab.java b/megameklab/src/megameklab/MegaMekLab.java index b4f82fecc..098ca8f00 100644 --- a/megameklab/src/megameklab/MegaMekLab.java +++ b/megameklab/src/megameklab/MegaMekLab.java @@ -40,6 +40,7 @@ import megameklab.ui.StartupGUI; import megameklab.ui.dialog.UiLoader; import megameklab.util.CConfig; +import megameklab.util.UnitPrintManager; import megameklab.util.UnitUtil; public class MegaMekLab { @@ -74,7 +75,7 @@ public static void main(String... args) { MegaMek.initializeSuiteGraphicalSetups(MMLConstants.PROJECT_NAME); ToolTipManager.sharedInstance().setDismissDelay(1000000); ToolTipManager.sharedInstance().setReshowDelay(50); - startup(); + startup(args); } public static void initializeLogging(final String originProject) { @@ -89,7 +90,7 @@ public static String getUnderlyingInformation(final String originProject) { return MegaMek.getUnderlyingInformation(originProject, MMLConstants.PROJECT_NAME); } - private static void startup() { + private static void startup(String[] args) { EquipmentType.initializeTypes(); MekSummaryCache.getInstance(); CConfig.load(); @@ -103,6 +104,28 @@ private static void startup() { updateGuiScaling(); // also sets the look-and-feel + if (args.length == 1) { + try { + var name = args[0]; + logger.info("Trying to open file {}", name); + if (name.toLowerCase().endsWith(".blk") || name.endsWith(".mtf")) { + var file = new File(name); + Entity e = new MekFileParser(file).getEntity(); + if (!UnitUtil.validateUnit(e).isBlank()) { + PopupMessages.showUnitInvalidWarning(null, UnitUtil.validateUnit(e)); + } + UiLoader.loadUi(e, file.toString()); + return; + } else if (name.toLowerCase().endsWith(".mul")) { + UnitPrintManager.printMUL(new JFrame(), CConfig.getBooleanParam(CConfig.MISC_MUL_OPEN_BEHAVIOUR), new File(name)); + System.exit(0); + return; + } + } catch (Exception e) { + logger.warn(e); + } + } + // Create a startup frame and display it switch (CConfig.getStartUpType()) { case NEW_MEK -> UiLoader.loadUi(Entity.ETYPE_MEK, false, false); diff --git a/megameklab/src/megameklab/ui/dialog/settings/MiscSettingsPanel.java b/megameklab/src/megameklab/ui/dialog/settings/MiscSettingsPanel.java index 93ee203f1..698f4e183 100644 --- a/megameklab/src/megameklab/ui/dialog/settings/MiscSettingsPanel.java +++ b/megameklab/src/megameklab/ui/dialog/settings/MiscSettingsPanel.java @@ -58,7 +58,7 @@ public class MiscSettingsPanel extends JPanel { private final JCheckBox chkSkipSavePrompts = new JCheckBox(); private final JTextField txtUserDir = new JTextField(20); private final JSlider guiScale = new JSlider(); - private final MMComboBox cbMulDndBehaviour = new MMComboBox<>("MUL Drag and Drop behaviour", MulDndBehaviour.values()); + private final MMComboBox cbMulOpenBehaviour = new MMComboBox<>("MUL Drag and Drop behaviour", MulDndBehaviour.values()); MiscSettingsPanel(JFrame parent) { startUpMMComboBox.setRenderer(miscComboBoxRenderer); @@ -73,16 +73,16 @@ public class MiscSettingsPanel extends JPanel { startUpLine.add(Box.createHorizontalStrut(5)); startUpLine.add(startUpMMComboBox); - cbMulDndBehaviour.setRenderer(miscComboBoxRenderer); - cbMulDndBehaviour.setToolTipText(resources.getString("ConfigurationDialog.cbMulDndBehaviour.tooltip")); - cbMulDndBehaviour.setSelectedItem(CConfig.getBooleanParam(CConfig.MISC_MUL_DND_BEHAVIOUR) ? MulDndBehaviour.EXPORT : MulDndBehaviour.PRINT); - JLabel mulDndLabel = new JLabel(resources.getString("ConfigurationDialog.cbMulDndBehaviour.text")); - mulDndLabel.setToolTipText(resources.getString("ConfigurationDialog.cbMulDndBehaviour.tooltip")); + cbMulOpenBehaviour.setRenderer(miscComboBoxRenderer); + cbMulOpenBehaviour.setToolTipText(resources.getString("ConfigurationDialog.cbMulOpenBehaviour.tooltip")); + cbMulOpenBehaviour.setSelectedItem(CConfig.getBooleanParam(CConfig.MISC_MUL_OPEN_BEHAVIOUR) ? MulDndBehaviour.EXPORT : MulDndBehaviour.PRINT); + JLabel mulOpenLabel = new JLabel(resources.getString("ConfigurationDialog.cbMulOpenBehaviour.text")); + mulOpenLabel.setToolTipText(resources.getString("ConfigurationDialog.cbMulOpenBehaviour.tooltip")); - JPanel mulDndLine = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); - mulDndLine.add(mulDndLabel); - mulDndLine.add(Box.createHorizontalStrut(5)); - mulDndLine.add(cbMulDndBehaviour); + JPanel mulOpenLine = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); + mulOpenLine.add(mulOpenLabel); + mulOpenLine.add(Box.createHorizontalStrut(5)); + mulOpenLine.add(cbMulOpenBehaviour); chkSummaryFormatTRO.setText(resources.getString("ConfigurationDialog.chkSummaryFormatTRO.text")); chkSummaryFormatTRO.setToolTipText(resources.getString("ConfigurationDialog.chkSummaryFormatTRO.tooltip")); @@ -142,7 +142,7 @@ public class MiscSettingsPanel extends JPanel { JPanel gridPanel = new JPanel(new SpringLayout()); gridPanel.add(startUpLine); gridPanel.add(userDirLine); - gridPanel.add(mulDndLine); + gridPanel.add(mulOpenLine); gridPanel.add(chkSummaryFormatTRO); gridPanel.add(chkSkipSavePrompts); gridPanel.add(scaleLine); @@ -161,7 +161,7 @@ Map getMiscSettings() { ? MMLStartUp.SPLASH_SCREEN : startUpMMComboBox.getSelectedItem(); miscSettings.put(CConfig.MISC_STARTUP, startUp.name()); - miscSettings.put(CConfig.MISC_MUL_DND_BEHAVIOUR, String.valueOf(cbMulDndBehaviour.getSelectedItem() == MulDndBehaviour.EXPORT)); + miscSettings.put(CConfig.MISC_MUL_OPEN_BEHAVIOUR, String.valueOf(cbMulOpenBehaviour.getSelectedItem() == MulDndBehaviour.EXPORT)); // User directory and gui scale are stored in MM's client settings, not in CConfig, therefore not added here return miscSettings; } diff --git a/megameklab/src/megameklab/util/CConfig.java b/megameklab/src/megameklab/util/CConfig.java index 90137fc2b..018d1df4e 100644 --- a/megameklab/src/megameklab/util/CConfig.java +++ b/megameklab/src/megameklab/util/CConfig.java @@ -62,7 +62,7 @@ public final class CConfig { public static final String MISC_STARTUP = "StartupGui"; public static final String MISC_SUMMARY_FORMAT_TRO = "useTROFormat"; public static final String MISC_SKIP_SAFETY_PROMPTS = "skipSafetyPrompts"; - public static final String MISC_MUL_DND_BEHAVIOUR = "mulDndBehaviour"; + public static final String MISC_MUL_OPEN_BEHAVIOUR = "mulDndBehaviour"; public static final String GUI_PLAF = "lookAndFeel"; public static final String GUI_COLOR_WEAPONS = "Weapons"; diff --git a/megameklab/src/megameklab/util/MMLFileDropTarget.java b/megameklab/src/megameklab/util/MMLFileDropTarget.java index f4a3e0a02..4ca87d121 100644 --- a/megameklab/src/megameklab/util/MMLFileDropTarget.java +++ b/megameklab/src/megameklab/util/MMLFileDropTarget.java @@ -51,11 +51,11 @@ public synchronized void drop(DropTargetDropEvent event) { var file = files.get(0); var name = file.getName(); - if (name.endsWith(".mtf") || name.endsWith(".blk")) { + if (name.toLowerCase().endsWith(".mtf") || name.toLowerCase().endsWith(".blk")) { owner.getMMLMenuBar().loadFile(file); event.dropComplete(true); - } else if (name.endsWith(".mul")) { - UnitPrintManager.printMUL(owner.getFrame(), CConfig.getBooleanParam(CConfig.MISC_MUL_DND_BEHAVIOUR), file); + } else if (name.toLowerCase().endsWith(".mul")) { + UnitPrintManager.printMUL(owner.getFrame(), CConfig.getBooleanParam(CConfig.MISC_MUL_OPEN_BEHAVIOUR), file); event.dropComplete(true); } else { event.dropComplete(false);