Skip to content

Commit

Permalink
Merge pull request MegaMek#1694 from pavelbraginskiy/tabbed-ui
Browse files Browse the repository at this point in the history
Revert unsaved work detection
  • Loading branch information
IllianiCBT authored Jan 16, 2025
2 parents a59f166 + b844630 commit 2fa5233
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 169 deletions.
5 changes: 2 additions & 3 deletions megameklab/docs/history.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@ MEGAMEKLAB VERSION HISTORY:
0.50.03-SNAPSHOT
+ PR #1678: MHQ RFE #5604: save refit files from MHQ MekLab tab (MML side)
+ PR #1679: Adds Tabbed UI Improvements
+ PR #1685: Detect unsaved work
+ PR #1688: Fix font rendering of symbols on windows using gradle run
+ Fix #1687: Fix loading of FMU slots
+ PR #1675: Fixed protomek reference tables
+ PR #1673: Allow opening multiple units in tabs

0.50.02 (2024-12-30 2130 UTC)
+ PR #1654: Rename TroopSpace to InfantryCompartment
+ PR #1665: Inverted function call
+ Fix #1667: incorrect cargo bay minimum doors
+ PR #1671: Log jvm parameters
+ PR #1675: Fixed protomek reference tables
+ PR #1673: Allow opening multiple units in tabs

0.50.01 (2024-11-10 1800 UTC)
+ PR #1608, #1611: Respecting Trademarks (Mech to Mek)
Expand Down
3 changes: 1 addition & 2 deletions megameklab/src/megameklab/ui/MegaMekLabMainUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import megamek.common.Entity;
import megamek.common.Mounted;
import megamek.common.preference.PreferenceManager;
import megameklab.util.EntityChangedUtil;
import megameklab.MMLConstants;
import megameklab.MegaMekLab;
import megameklab.ui.util.ExitOnWindowClosingListener;
Expand Down Expand Up @@ -84,7 +83,7 @@ public void setVisible(boolean b) {

@Override
public boolean safetyPrompt() {
if (CConfig.getBooleanParam(CConfig.MISC_SKIP_SAFETY_PROMPTS) || !EntityChangedUtil.hasEntityChanged(this)) {
if (CConfig.getBooleanParam(CConfig.MISC_SKIP_SAFETY_PROMPTS)) {
return true;
} else {
int savePrompt = JOptionPane.showConfirmDialog(this,
Expand Down
44 changes: 3 additions & 41 deletions megameklab/src/megameklab/ui/MegaMekLabTabbedUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,17 @@
import megamek.client.ui.swing.util.UIUtil;
import megamek.common.Entity;
import megamek.common.preference.PreferenceManager;
import megameklab.util.EntityChangedUtil;
import megameklab.MMLConstants;
import megameklab.MegaMekLab;
import megameklab.ui.dialog.UiLoader;
import megameklab.ui.mek.BMMainUI;
import megameklab.ui.util.ExitOnWindowClosingListener;
import megameklab.ui.util.MegaMekLabFileSaver;
import megameklab.ui.util.TabStateUtil;
import megameklab.util.CConfig;
import megameklab.util.MMLFileDropTransferHandler;
import megameklab.util.UnitUtil;

import javax.swing.*;
import javax.swing.Timer;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
Expand Down Expand Up @@ -93,11 +90,6 @@ public MegaMekLabTabbedUI(MegaMekLabMainUI... entities) {
// Enable opening unit and mul files by drag-and-drop
setTransferHandler(new MMLFileDropTransferHandler(this));

// If you can think of a way to detect when the user makes a change to the entity, let me know.
// I can't, so we just poll the entity for changed to set the "unsaved work" indicator periodically
// --Pavel Braginskiy (cat /dev/random)
new Timer(500, e -> checkChanged(tabs.getSelectedIndex())).start();

// Remember the size and position of the window from last time MML was launched
pack();
restrictToScreenSize();
Expand Down Expand Up @@ -132,7 +124,6 @@ public void setTabName(String tabName) {
// ClosableTab is a label with the unit name, and a close button.
// If we didn't need that close button, this could be tabs.setTitleAt
tabs.setTabComponentAt(tabs.getSelectedIndex(), new EditorTab(tabName, currentEditor()) );
checkChanged(tabs.getSelectedIndex());
}

/**
Expand Down Expand Up @@ -160,7 +151,6 @@ private void addTab(MegaMekLabMainUI editor) {
tabs.addTab(editor.getEntity().getDisplayName(), editor.getContentPane());
// See EditorTab later in this file for what's going on here.
tabs.setTabComponentAt(tabs.getTabCount() - 1, new EditorTab(editor.getEntity().getDisplayName(), editor));
checkChanged(tabs.getTabCount() - 1);

if (newTab != null) {
tabs.addTab("+", newTab.getContentPane());
Expand Down Expand Up @@ -245,31 +235,12 @@ private boolean exitPrompt() {
if (CConfig.getBooleanParam(CConfig.MISC_SKIP_SAFETY_PROMPTS)) {
return true;
}
// No editors have changes, no need to prompt for saving
if (editors.stream().limit(editors.size() - 1).noneMatch(EntityChangedUtil::hasEntityChanged)) {
return true;
}
int savePrompt = JOptionPane.showConfirmDialog(this,
"All unsaved changes to open units will be discarded. Save the units first?",
"All unsaved changes to open units will be discarded. Are you sure you would like to exit?",
"Save Units Before Proceeding?",
JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.YES_NO_OPTION,
JOptionPane.WARNING_MESSAGE);
if (savePrompt == JOptionPane.NO_OPTION) {
return true;
}
// For each editor with unsaved changes, switch to that editor and save it.
if (savePrompt == JOptionPane.YES_OPTION) {
return editors.stream().limit(editors.size() - 1)
.filter(EntityChangedUtil::hasEntityChanged)
.noneMatch(editor -> {
tabs.setSelectedComponent(editor.getContentPane());
// paintImmediately means that the user can see which unit they're about to pick a file for
// because it updates the UI without waiting for this method to return
tabs.paintImmediately(tabs.getBounds());
return !menuBar.saveUnit();
});
}
return false;
return savePrompt == JOptionPane.YES_OPTION;
}

@Override
Expand Down Expand Up @@ -394,15 +365,6 @@ public boolean safetyPrompt() {
public void stateChanged(ChangeEvent e) {
if (e.getSource() == tabs) {
refreshMenuBar();
checkChanged(checkChangedTab);
checkChangedTab = tabs.getSelectedIndex();
}
}

private int checkChangedTab = 0;
private void checkChanged(int tabIndex) {
if (tabs.getTabCount() >= tabIndex + 1 && tabs.getTabComponentAt(tabIndex) instanceof EditorTab et) {
et.markChanged(EntityChangedUtil.hasEntityChanged(editors.get(tabIndex)));
}
}

Expand Down
6 changes: 0 additions & 6 deletions megameklab/src/megameklab/ui/util/MegaMekLabFileSaver.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import megameklab.ui.PopupMessages;
import megameklab.ui.dialog.MMLFileChooser;
import megameklab.util.CConfig;
import megameklab.util.EntityChangedUtil;

import javax.swing.*;
import javax.swing.filechooser.FileNameExtensionFilter;
Expand Down Expand Up @@ -122,11 +121,6 @@ private String saveUnitTo(JFrame ownerFrame, File file, Entity entity) {
BLKFile.encode(file.getPath(), entity);
}

if (ownerFrame instanceof MegaMekLabMainUI mui) {
// Since we've saved the entity, update the entity being compared against to determine if the user has unsaved work.
EntityChangedUtil.editorSaved(mui);
}

PopupMessages.showUnitSavedMessage(ownerFrame, entity, file);
return file.toString();
} catch (Exception ex) {
Expand Down
1 change: 1 addition & 0 deletions megameklab/src/megameklab/ui/util/TabStateUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public static List<MegaMekLabMainUI> loadTabState() throws IOException {

try {
Entity loadedUnit = new MekFileParser(newFile).getEntity();
UnitUtil.updateLoadedUnit(loadedUnit);

var metaFile = new File(entityFile.getAbsolutePath().replaceFirst("\\.tmp$", ".meta"));
if (metaFile.exists()) {
Expand Down
117 changes: 0 additions & 117 deletions megameklab/src/megameklab/util/EntityChangedUtil.java

This file was deleted.

0 comments on commit 2fa5233

Please sign in to comment.