*/
package jalview.gui;
-import java.util.Locale;
-
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.util.Enumeration;
import java.util.Hashtable;
import java.util.List;
+import java.util.Locale;
import java.util.Vector;
import javax.swing.ButtonGroup;
lastSaveSuccessful = new Jalview2XML().saveAlignment(this, file,
shortName);
+ Console.debug("lastSaveSuccessful=" + lastSaveSuccessful);
+ if (lastSaveSuccessful)
+ {
+ this.getViewport().setSavedUpToDate(true);
+ }
+
statusBar.setText(MessageManager.formatMessage(
"label.successfully_saved_to_file_in_format", new Object[]
{ file, format }));
+ (lastSaveSuccessful ? "" : "un")
+ "successfully");
}
+
+ Console.debug("lastSaveSuccessful=" + lastSaveSuccessful);
+ if (lastSaveSuccessful)
+ {
+ AlignFrame.this.getViewport().setSavedUpToDate(true);
+ }
}
}
};
import java.io.File;
import java.util.Date;
+import java.util.List;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import com.formdev.flatlaf.extras.FlatDesktop;
+import jalview.api.AlignmentViewPanel;
import jalview.bin.Console;
+import jalview.datamodel.AlignmentI;
+import jalview.datamodel.SequenceI;
+import jalview.gui.AlignFrame;
+import jalview.gui.Desktop;
import jalview.io.BackupFiles;
+import jalview.project.Jalview2XML;
import jalview.util.MessageManager;
import jalview.util.Platform;
Console.debug("Non interactive quit -- not confirming");
confirmQuit = false;
}
- /*
- else if (undostack is empty) {
+ else if (Jalview2XML.allSavedUpToDate())
+ {
Console.debug("Nothing changed -- not confirming quit");
- confirmQuit = false
+ confirmQuit = false;
}
- */
else
{
confirmQuit = jalview.bin.Cache
// the save time to finish!
if (confirmQuit)
{
- answer = frameOnTop(MessageManager.getString("label.quit_jalview"),
+ answer = frameOnTop(
+ new StringBuilder(
+ MessageManager.getString("label.quit_jalview"))
+ .append(" ")
+ .append(MessageManager
+ .getString("label.unsaved_changes"))
+ .toString(),
MessageManager.getString("action.quit"),
JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE);
}
}
// check for saves in progress
- int waitForSave = 5000; // MAKE THIS BETTER
- int waitIncrement = 2000;
+ int waitForSave = 1000; // MAKE THIS BETTER
+ AlignFrame[] afArray = Desktop.getAlignFrames();
+ if (afArray == null || afArray.length == 0)
+ {
+ // no change
+ }
+ else
+ {
+ int size = 0;
+ for (int i = 0; i < afArray.length; i++)
+ {
+ AlignFrame af = afArray[i];
+ List<AlignmentViewPanel> avpList = (List<AlignmentViewPanel>) af
+ .getAlignPanels();
+ for (AlignmentViewPanel avp : avpList)
+ {
+ AlignmentI a = avp.getAlignment();
+ List<SequenceI> sList = a.getSequences();
+ for (SequenceI s : sList)
+ {
+ size += s.getLength();
+ }
+ }
+ }
+ waitForSave = size;
+ Console.debug("Set waitForSave to " + waitForSave);
+ }
+ int waitIncrement = 3000;
long startTime = new Date().getTime();
boolean saving = BackupFiles.hasSavesInProgress();
if (saving)
{
StringBuilder messageSB = new StringBuilder(
MessageManager.getString("label.save_in_progress"));
+ messageSB.append(":");
+ boolean any = false;
for (File file : BackupFiles.savesInProgressFiles())
{
- messageSB.append("\n");
+ messageSB.append("\n- ");
messageSB.append(file.getName());
+ any = true;
+ }
+ if (!any)
+ {
+ messageSB.append("\n");
+ messageSB.append(MessageManager.getString("label.unknown"));
}
int waitLonger = interactive ? JOptionPane.YES_OPTION
: JOptionPane.NO_OPTION;
MessageManager.getString("action.wait"));
if (waitLonger == JOptionPane.YES_OPTION) // wait
{
- Console.debug("*** YES answer=" + waitLonger);
// do wait stuff
saving = !waitForSave(waitIncrement);
}
else if (waitLonger == JOptionPane.NO_OPTION) // force quit
{
- Console.debug("*** NO answer=" + waitLonger);
// do a force quit
return returnResponse(QResponse.FORCE_QUIT); // shouldn't reach this
}
else if (waitLonger == JOptionPane.CANCEL_OPTION) // cancel quit
{
- Console.debug("*** CANCEL answer=" + waitLonger);
return returnResponse(QResponse.CANCEL_QUIT);
}
else
private static final String UTF_8 = "UTF-8";
/**
+ * used in decision if quit confirmation should be issued
+ */
+ private static boolean stateSavedUpToDate = false;
+
+ /**
* prefix for recovering datasets for alignments with multiple views where
* non-existent dataset IDs were written for some views
*/
{
AlignFrame[] frames = Desktop.getAlignFrames();
+ setStateSavedUpToDate(true);
+
if (Cache.getDefault("DEBUG_DELAY_SAVE", false))
{
int n = 20;
FileOutputStream fos = new FileOutputStream(
doBackup ? backupfiles.getTempFilePath() : jarFile);
+ if (Cache.getDefault("DEBUG_DELAY_SAVE", false))
+ {
+ int n = 20;
+ int i = 0;
+ while (i < n)
+ {
+ Console.debug("***** debugging save sleep " + i + "/" + n);
+ try
+ {
+ Thread.sleep(1000);
+ } catch (InterruptedException e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ i++;
+ }
+ }
+
JarOutputStream jout = new JarOutputStream(fos);
List<AlignFrame> frames = new ArrayList<>();
return colour;
}
+
+ public static void setStateSavedUpToDate(boolean s)
+ {
+ Console.debug("Setting overall stateSavedUpToDate to " + s);
+ stateSavedUpToDate = s;
+ }
+
+ public static boolean stateSavedUpToDate()
+ {
+ Console.debug("Returning overall stateSavedUpToDate value: "
+ + stateSavedUpToDate);
+ return stateSavedUpToDate;
+ }
+
+ public static boolean allSavedUpToDate()
+ {
+ if (stateSavedUpToDate()) // nothing happened since last project save
+ return true;
+
+ AlignFrame[] frames = Desktop.getAlignFrames();
+ for (int i = 0; i < frames.length; i++)
+ {
+ if (frames[i] == null)
+ continue;
+ if (!frames[i].getViewport().savedUpToDate())
+ return false; // at least one alignment is not individually saved
+ }
+ return true;
+ }
}
*/
package jalview.viewmodel;
+import java.awt.Color;
+import java.beans.PropertyChangeSupport;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.BitSet;
+import java.util.Deque;
+import java.util.HashMap;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
import jalview.analysis.Conservation;
import jalview.analysis.TreeModel;
import jalview.api.AlignmentViewPanel;
import jalview.api.FeaturesDisplayedI;
import jalview.api.ViewStyleI;
+import jalview.bin.Console;
import jalview.commands.CommandI;
import jalview.datamodel.AlignedCodonFrame;
import jalview.datamodel.AlignmentAnnotation;
import jalview.datamodel.SequenceCollectionI;
import jalview.datamodel.SequenceGroup;
import jalview.datamodel.SequenceI;
+import jalview.project.Jalview2XML;
import jalview.renderer.ResidueShader;
import jalview.renderer.ResidueShaderI;
import jalview.schemes.ColourSchemeI;
import jalview.workers.ConsensusThread;
import jalview.workers.StrucConsensusThread;
-import java.awt.Color;
-import java.beans.PropertyChangeSupport;
-import java.util.ArrayDeque;
-import java.util.ArrayList;
-import java.util.BitSet;
-import java.util.Deque;
-import java.util.HashMap;
-import java.util.Hashtable;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
/**
* base class holding visualization and analysis attributes and common logic for
* an active alignment view displayed in the GUI
protected Deque<CommandI> redoList = new ArrayDeque<>();
/**
+ * used to determine if quit should be confirmed
+ */
+ private boolean savedUpToDate = true;
+
+ /**
* alignment displayed in the viewport. Please use get/setter
*/
protected AlignmentI alignment;
{
this.historyList.push(command);
broadcastCommand(command, false);
+ setSavedUpToDate(false);
+ Jalview2XML.setStateSavedUpToDate(false);
}
}
return (alignment.getHiddenColumns().getVisContigsIterator(start, end,
false));
}
+
+ public void setSavedUpToDate(boolean s)
+ {
+ Console.debug(
+ "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
+ savedUpToDate = s;
+ }
+
+ public boolean savedUpToDate()
+ {
+ Console.debug("Returning " + this.getViewId() + " savedUpToDate value: "
+ + savedUpToDate);
+ return savedUpToDate;
+ }
}