JAL-1988 Make sensible choices if only the opening file has been opened, and alter... merge/JAL-1988_JAL-3772+JAL-3416+JAL-4054+JAL-4064
authorBen Soares <b.soares@dundee.ac.uk>
Mon, 30 Jan 2023 12:17:27 +0000 (12:17 +0000)
committerBen Soares <b.soares@dundee.ac.uk>
Mon, 30 Jan 2023 12:17:27 +0000 (12:17 +0000)
resources/lang/Messages.properties
resources/lang/Messages_es.properties
src/jalview/bin/Jalview.java
src/jalview/gui/QuitHandler.java
src/jalview/io/DataSourceType.java
src/jalview/io/FileLoader.java
src/jalview/viewmodel/AlignmentViewport.java

index a406f33..23bb966 100644 (file)
@@ -36,6 +36,7 @@ action.force_quit = Force quit
 label.quit_jalview = Are you sure you want to quit Jalview?
 label.wait_for_save = Wait for save
 label.unsaved_changes = There are unsaved changes.
+label.unsaved_alignments = There are unsaved alignments.
 label.save_in_progress = Some files are still saving:
 label.unknown = Unknown
 label.quit_after_saving = Jalview will quit after saving.
index b50226a..9eb084d 100644 (file)
@@ -36,6 +36,7 @@ action.force_quit = Forzar la salida
 label.quit_jalview = ¿Estás seguro de que quieres salir de Jalview?
 label.wait_for_save = Esperar a guardar
 label.unsaved_changes = Hay cambios sin guardar.
+label.unsaved_alignments = Hay alineamientos sin guardar.
 label.save_in_progress = Algunos archivos aún se están guardando:
 label.unknown = desconocido
 label.quit_after_saving = Jalview se cerrará después de guardar.
index 071d700..cb078b8 100755 (executable)
@@ -880,8 +880,6 @@ public class Jalview
      * @j2sIgnore
      */
     {
-      boolean defaultStartupFile = Cache.getDefault("STARTUP_FILE",
-              null) == null;
       file = Cache.getDefault("STARTUP_FILE",
               Cache.getDefault("www.jalview.org", "https://www.jalview.org")
                       + "/examples/exampleFile_2_7.jvp");
@@ -895,7 +893,6 @@ public class Jalview
         file.replace("2_7.jar", "2_7.jvp");
         // and remove the stale setting
         Cache.removeProperty("STARTUP_FILE");
-        defaultStartupFile = true;
       }
 
       protocol = AppletFormatAdapter.checkProtocol(file);
@@ -917,11 +914,10 @@ public class Jalview
 
       startUpAlframe = fileLoader.LoadFileWaitTillLoaded(file, protocol,
               format);
-      if (defaultStartupFile)
-      {
-        Console.debug("Resetting up-to-date flag for startup file");
-        startUpAlframe.getViewport().setSavedUpToDate(true);
-      }
+      // don't ask to save when quitting if only the startup file has been
+      // opened
+      Console.debug("Resetting up-to-date flag for startup file");
+      startUpAlframe.getViewport().setSavedUpToDate(true);
       // extract groovy arguments before anything else.
     }
 
@@ -1126,7 +1122,8 @@ public class Jalview
     {
       try
       {
-        UIManager.setLookAndFeel("com.formdev.flatlaf.FlatMacLightLaf");
+        UIManager.setLookAndFeel(
+                "com.formdev.flatlaf.themes.FlatMacLightLaf");
         set = true;
         Console.debug("Using FlatMacLightLaf");
       } catch (ClassNotFoundException | InstantiationException
@@ -1155,7 +1152,7 @@ public class Jalview
       Console.debug("Using FlatMacLightLaf");
       set = true;
     }
-    else if (SystemInfo.isWindows)
+    if (!set)
     {
       try
       {
index 77eed81..bedddd1 100644 (file)
@@ -40,6 +40,18 @@ public class QuitHandler
     NULL, QUIT, CANCEL_QUIT, FORCE_QUIT
   };
 
+  public static enum Message
+  {
+    UNSAVED_CHANGES, UNSAVED_ALIGNMENTS
+  };
+
+  protected static Message message = Message.UNSAVED_CHANGES;
+
+  public static void setMessage(Message m)
+  {
+    message = m;
+  }
+
   private static ExecutorService executor = Executors.newFixedThreadPool(3);
 
   public static QResponse setQuitHandler()
@@ -145,16 +157,17 @@ public class QuitHandler
 
     if (confirmQuit)
     {
+      String messageString = MessageManager
+              .getString(message == Message.UNSAVED_ALIGNMENTS
+                      ? "label.unsaved_alignments"
+                      : "label.unsaved_changes");
       JvOptionPane.newOptionDialog()
               .setResponseHandler(JOptionPane.YES_OPTION, defaultOkQuit)
               .setResponseHandler(JOptionPane.NO_OPTION, cancelQuit)
               .showDialogOnTopAsync(
                       new StringBuilder(MessageManager
-                              .getString("label.quit_jalview"))
-                              .append("\n")
-                              .append(MessageManager
-                                      .getString("label.unsaved_changes"))
-                              .toString(),
+                              .getString("label.quit_jalview")).append("\n")
+                              .append(messageString).toString(),
                       MessageManager.getString("action.quit"),
                       JOptionPane.YES_NO_OPTION,
                       JOptionPane.QUESTION_MESSAGE, null, new Object[]
index 7e2aeab..6d00a7d 100644 (file)
@@ -23,4 +23,9 @@ package jalview.io;
 public enum DataSourceType
 {
   FILE, URL, PASTE, CLASSLOADER, RELATIVE_URL;
+
+  public boolean isDynamic()
+  {
+    return this != FILE;
+  }
 }
index ffeb53d..5d290b6 100755 (executable)
@@ -41,6 +41,7 @@ import jalview.gui.AlignFrame;
 import jalview.gui.AlignViewport;
 import jalview.gui.Desktop;
 import jalview.gui.JvOptionPane;
+import jalview.gui.QuitHandler;
 import jalview.json.binding.biojson.v1.ColourSchemeMapper;
 import jalview.project.Jalview2XML;
 import jalview.schemes.ColourSchemeI;
@@ -311,6 +312,7 @@ public class FileLoader implements Runnable
                   MessageManager.getString("label.couldnt_read_data"),
                   JvOptionPane.WARNING_MESSAGE);
         }
+        this.setShouldBeSaved();
         return;
       }
       // TODO: cache any stream datasources as a temporary file (eg. PDBs
@@ -465,7 +467,6 @@ public class FileLoader implements Runnable
             {
               alignFrame.setFileName(file, format);
               alignFrame.setFileObject(selectedFile); // BH 2018 SwingJS
-              alignFrame.getViewport().setSavedUpToDate(true);
             }
             if (proxyColourScheme != null)
             {
@@ -613,6 +614,7 @@ public class FileLoader implements Runnable
       Desktop.instance.stopLoading();
     }
 
+    this.setShouldBeSaved();
   }
 
   /**
@@ -638,4 +640,21 @@ public class FileLoader implements Runnable
     return tempStructFile.toString();
   }
 
+  /*
+   * set whether quit should ask to save when just loaded this source
+   */
+  private void setShouldBeSaved()
+  {
+    if (protocol == null)
+      return;
+    AlignFrame af = this.alignFrame;
+    if (af == null)
+      return;
+    AlignViewport avp = af.getViewport();
+    if (avp == null)
+      return;
+    avp.setSavedUpToDate(!protocol.isDynamic(),
+            QuitHandler.Message.UNSAVED_ALIGNMENTS);
+  }
+
 }
index 5a4ceb9..e8048e0 100644 (file)
@@ -58,6 +58,7 @@ import jalview.datamodel.Sequence;
 import jalview.datamodel.SequenceCollectionI;
 import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
+import jalview.gui.QuitHandler;
 import jalview.project.Jalview2XML;
 import jalview.renderer.ResidueShader;
 import jalview.renderer.ResidueShaderI;
@@ -3108,9 +3109,15 @@ public abstract class AlignmentViewport
 
   public void setSavedUpToDate(boolean s)
   {
+    setSavedUpToDate(s, QuitHandler.Message.UNSAVED_CHANGES);
+  }
+
+  public void setSavedUpToDate(boolean s, QuitHandler.Message m)
+  {
     Console.debug(
             "Setting " + this.getViewId() + " setSavedUpToDate to " + s);
     savedUpToDate = s;
+    QuitHandler.setMessage(m);
   }
 
   public boolean savedUpToDate()