Class UnsavedFiles

java.lang.Object
com.iizigo.prop.UnsavedFiles

public final class UnsavedFiles extends Object
The files of the Module projects that are changed in the Designer and not saved, with or without an editor.

A file of a Module project is loaded with its project and stays in the project's property tree whether or not an editor shows it. It is changed without an editor when a rename makes its references follow, when a property inside it is renamed, moved or deleted in the IIZI Explorer, and when its editor is closed without saving. Each file is a workbench Saveable of its own (FilePropSaveable), told to the workbench as a source that is no workbench part. Eclipse counts such a Saveable for the enabled state of File > Save All and asks for it at the exit, but:

  • its Save All (WorkbenchPage.saveAllEditors) returns before it reaches the Saveables without a part when no workbench part is changed, so Save All was enabled and wrote nothing;
  • nothing asks for an evaluation of Save All's enabled state when such a Saveable becomes changed or saved, so the button did not follow;
  • the prompt of Close Project (IWorkbench.saveAll with the project as its filter) lists only the Saveables that a workbench part holds, so a project was closed without a word and the changes of every file without an editor were lost.
This class holds the collection the three repairs share - every file below a Module root whose Saveable is changed - and the repairs: an execution listener on the Save All command that saves, after Eclipse's handler, every file of every loaded Module project that is still changed, with the workbench's own saver; the evaluation FilePropSaveable asks for; and the question before a project is closed (askBeforeClose(IResource[])), asked by iiziGo's Close Project and Close Unrelated Projects (com.iizigo.navigator.CloseProjectActionProvider). The model of a project is dropped inside the workspace's notification of the close, where nothing can be asked, saved or stopped: the question stands in front of the action.

No change is lost without a word, whatever makes the Designer drop a changed file (CC-FIX-UNSAVED-EVERY-CLOSE). Where a user acts, the same question is asked first: before every other Close Project of Eclipse (com.iizigo.project.ModuleModelProvider), before a rename of a project and before a Delete that keeps the project's contents (askBeforeRefactoring(IProject[]); a Delete with the contents asks nothing). Where nobody can be asked - a project closed, renamed or deleted by code, a changed file deleted or loaded again from disk - the changed content is kept before it is dropped, and one warning names it (onProjectGoes(IProject, boolean), onFileGoes(PropCnr, String, boolean)): in the Local History of the file, without touching the file; for a deleted project, whose Local History Eclipse forgets, as copies in iiziGo's area of the workspace.

Author:
Christopher Mindus
  • Method Summary

    Modifier and Type
    Method
    Description
    static boolean
    Asks, before projects are closed, which of their changed files are to be saved, and saves them.
    static boolean
    Asks, before a refactoring renames projects or deletes them from the workspace, which of their changed files are saved, and saves them: askBeforeClose(IResource[]), run in the SWT thread.
    Gets the files of a Module project that are changed and not saved: every file below the Module root that has a Saveable and whose Saveable is dirty, with or without an editor.
    get(IProject[] projects)
    Gets the files of projects that are changed and not saved.
    Gets the files of every loaded Module project that are changed and not saved.
    static List<IResource>
    getClosable(List<? extends IResource> projects, IResource[] asked)
    Gets the projects among projects that may be closed after askBeforeClose(IResource[]) was answered for some of them: a project that was asked for, and a project that holds no changed file.
    static List<Saveable>
    Gets the Saveables of files.
    static boolean
    isAsked(IProject project)
    Whether iiziGo's own close action has asked for a project in the run it is in.
    static void
    onFileGoes(PropCnr dropped, String what, boolean deleted)
    Keeps the changed content of the files in or below a property that the Designer drops - a file or a folder that was deleted, a file that changed on disk and is loaded again - in the Local History of each file, and logs one warning.
    static void
    onProjectGoes(IProject project, boolean remove)
    Keeps the changed content of the files of a project that is about to be closed, deleted, renamed or moved, and logs ONE warning that names the project, each file and how the content is restored.
    static boolean
    save(List<FilePropCnr> files, IShellProvider shellProvider, IRunnableContext runnableContext)
    Saves files with the workbench's own saver (SaveablesList.saveModels): in the SWT thread, under the progress of the runnable context, a failure reported to the user by the workbench.
    static void
    Tells the projects that iiziGo's own Close Project or Close Unrelated Projects has asked for, for the time of its run: Eclipse's change validation, which the action reaches next, does not ask for them once more (com.iizigo.project.ModuleModelProvider).
    static void
    Tells that the user deletes a Module project WITH its contents on disk: what is not saved goes with the files, nothing is asked, kept or logged for it (the owner's ruling).
  • Method Details

    • get

      public static List<FilePropCnr> get(ModuleModel model)
      Gets the files of a Module project that are changed and not saved: every file below the Module root that has a Saveable and whose Saveable is dirty, with or without an editor.
      Parameters:
      model - The Module model, null for none.
      Returns:
      The files, empty for none.
    • get

      public static List<FilePropCnr> get(IProject[] projects)
      Gets the files of projects that are changed and not saved.
      Parameters:
      projects - The projects; one that is no loaded Module project has no such file.
      Returns:
      The files, empty for none.
    • getAll

      public static List<FilePropCnr> getAll()
      Gets the files of every loaded Module project that are changed and not saved.
      Returns:
      The files, empty for none.
    • getSaveables

      public static List<Saveable> getSaveables(List<FilePropCnr> files)
      Gets the Saveables of files.
      Parameters:
      files - The files.
      Returns:
      The Saveables, in the order of the files.
    • save

      public static boolean save(List<FilePropCnr> files, IShellProvider shellProvider, IRunnableContext runnableContext)
      Saves files with the workbench's own saver (SaveablesList.saveModels): in the SWT thread, under the progress of the runnable context, a failure reported to the user by the workbench.
      Parameters:
      files - The files.
      shellProvider - The provider of the shell of a message, e.g. the workbench window.
      runnableContext - The context that shows the progress, e.g. the workbench window.
      Returns:
      true when the files were saved, false when the save was canceled.
    • askBeforeClose

      public static boolean askBeforeClose(IResource[] projects)
      Asks, before projects are closed, which of their changed files are to be saved, and saves them. The prompt is the workbench's own ("Save Resources": a check list with every file checked, Save and Cancel; for a single file Save, Don't Save and Cancel), the one the exit shows for the same files, and the files are saved by the workbench's own saver. It lists every changed file of the Module projects among the projects, with or without an editor, and with them what Eclipse's Close Project would ask for by itself (the changed editors of the projects, a Java editor too), so that one dialog asks for everything.

      Nothing is asked when no file of a Module project among the projects is changed: Eclipse's own prompt then stands as it is. Called in the SWT thread (an action's run; a quick fix, which Eclipse runs there).

      Parameters:
      projects - The projects that are about to be closed.
      Returns:
      true to go on with the close - nothing was to be asked, or the user chose what to save -, false when the user canceled: the projects stay open.
    • getClosable

      public static List<IResource> getClosable(List<? extends IResource> projects, IResource[] asked)
      Gets the projects among projects that may be closed after askBeforeClose(IResource[]) was answered for some of them: a project that was asked for, and a project that holds no changed file. A project that was not asked for and holds a changed file is left out, so that it is never closed without a word.
      Parameters:
      projects - The projects that are about to be closed.
      asked - The projects askBeforeClose(IResource[]) was called with.
      Returns:
      The projects that may be closed.
    • setAskedByAction

      public static void setAskedByAction(IResource[] projects)
      Tells the projects that iiziGo's own Close Project or Close Unrelated Projects has asked for, for the time of its run: Eclipse's change validation, which the action reaches next, does not ask for them once more (com.iizigo.project.ModuleModelProvider).
      Parameters:
      projects - The projects that were asked for, null when the run ends.
    • isAsked

      public static boolean isAsked(IProject project)
      Whether iiziGo's own close action has asked for a project in the run it is in.
      Parameters:
      project - The project.
      Returns:
      true when the user has answered for the project in this run.
    • askBeforeRefactoring

      public static boolean askBeforeRefactoring(IProject[] projects)
      Asks, before a refactoring renames projects or deletes them from the workspace, which of their changed files are saved, and saves them: askBeforeClose(IResource[]), run in the SWT thread.

      A refactoring checks its conditions in a thread of its dialog that holds the workspace root rule. That thread hands the question to the SWT thread and waits for it; while it waits, the workbench gives the SWT thread the rules the waiting thread holds (Eclipse's UILockListener), so the workbench's saver saves there as it does for a close. Called in the SWT thread - a refactoring performed by code - the question is asked at once.

      Parameters:
      projects - The projects that are about to be renamed or deleted.
      Returns:
      true to go on - nothing was to be asked, or the user chose what to save -, false when the user canceled.
    • setDeletedWithContents

      public static void setDeletedWithContents(IProject project)
      Tells that the user deletes a Module project WITH its contents on disk: what is not saved goes with the files, nothing is asked, kept or logged for it (the owner's ruling). Told by the delete participant.
      Parameters:
      project - The project.
    • onProjectGoes

      public static void onProjectGoes(IProject project, boolean remove)
      Keeps the changed content of the files of a project that is about to be closed, deleted, renamed or moved, and logs ONE warning that names the project, each file and how the content is restored. Called by the Project Manager inside the workspace's notification, before it drops the project's model: nothing can be asked or saved there, and nobody was asked when a plug-in or a script closes, deletes or moves the project. After a question that the user answered with Don't Save the content is kept all the same.
      • A close: the content goes into the Local History of each file.
      • A delete or a rename - the workspace tells both alike: the content goes into the Local History, which a rename carries along; a delete makes Eclipse forget it, so the content of a deleted project is written as copies into iiziGo's area of the workspace (.metadata/.plugins/com.iizigo/unsaved). The warning is logged when the workspace has told which of the two it was.

      Nothing is done while iiziGo exits: the exit has asked for the changed files itself.

      Parameters:
      project - The project.
      remove - true for a delete or a rename, false for a close.
    • onFileGoes

      public static void onFileGoes(PropCnr dropped, String what, boolean deleted)
      Keeps the changed content of the files in or below a property that the Designer drops - a file or a folder that was deleted, a file that changed on disk and is loaded again - in the Local History of each file, and logs one warning. Called by the Module model inside the workspace's notification, where nobody can be asked.
      Parameters:
      dropped - The file's or the folder's property.
      what - What happens, the start of the warning's sentence, e.g. "File '/A/b' is deleted".
      deleted - true when the files are gone: the content is then restored with Restore from Local History of the folder.