Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSSTUDIO-1987 New "Unsaved Changes" confirmation dialog #2758

Merged
merged 16 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public class DisplayEditorInstance implements AppInstance
menu_node.setOnContextMenuRequested(event -> handleContextMenu(menu, event));
menu_node.setContextMenu(menu);

dock_item.addCloseCheck(this::okToClose);
dock_item.addClosedNotification(this::dispose);
}

Expand Down Expand Up @@ -465,7 +464,7 @@ void doSave(final JobMonitor monitor) throws Exception
else
{ // Save-As with proper file name
dock_item.setInput(proper.toURI());
if (! dock_item.save_as(monitor))
if (! dock_item.save_as(monitor, dock_item.getTabPane().getScene().getWindow()))
dock_item.setInput(orig_input);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;

import javafx.stage.Window;
import org.csstudio.display.builder.model.DisplayModel;
import org.csstudio.display.builder.model.Preferences;
import org.csstudio.display.builder.model.Widget;
Expand All @@ -33,6 +34,7 @@
import org.phoebus.framework.persistence.Memento;
import org.phoebus.framework.spi.AppDescriptor;
import org.phoebus.framework.spi.AppInstance;
import org.phoebus.ui.application.PhoebusApplication;
kasemir marked this conversation as resolved.
Show resolved Hide resolved
import org.phoebus.ui.dialog.ExceptionDetailsErrorDialog;
import org.phoebus.ui.docking.DockItem;
import org.phoebus.ui.docking.DockItemWithInput;
Expand Down Expand Up @@ -335,15 +337,18 @@ public void loadDisplayFile(final DisplayInfo info)

display_info = Optional.empty();

if (dock_item.prepareToClose())
Platform.runLater(() ->
{
final Parent parent = representation.getModelParent();
JFXRepresentation.getChildren(parent).clear();
boolean shouldClose = dock_item.okToClose().get();

close();
});
return;
if (shouldClose) {
dock_item.prepareToClose();
Platform.runLater(() ->
{
final Parent parent = representation.getModelParent();
JFXRepresentation.getChildren(parent).clear();

close();
});
}
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,4 @@ public void representModel(final Parent model_parent, final DisplayModel model)
app_instance.trackCurrentModel(model);
super.representModel(model_parent, model);
}

@Override
public void closeWindow(final DisplayModel model) throws Exception
{
// Is called from ScriptUtil, i.e. scripts, from background thread
final Parent model_parent = Objects.requireNonNull(model.getUserData(Widget.USER_DATA_TOOLKIT_PARENT));
if (model_parent.getProperties().get(DisplayRuntimeInstance.MODEL_PARENT_DISPLAY_RUNTIME) == app_instance)
{
// Prepare-to-close, which might take time and must be called off the UI thread
final DisplayRuntimeInstance instance = (DisplayRuntimeInstance) app_instance.getRepresentation().getModelParent().getProperties().get(DisplayRuntimeInstance.MODEL_PARENT_DISPLAY_RUNTIME);
if (instance != null)
instance.getDockItem().prepareToClose();
else
logger.log(Level.SEVERE, "Missing DisplayRuntimeInstance to prepare closing", new Exception("Stack Trace"));
// 'close' on the UI thread
execute(() -> app_instance.close());
}
else
throw new Exception("Wrong model");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,24 +141,6 @@ public static void openDisplay(final Widget widget, final String file, final Str
ActionUtil.handleAction(widget, open);
}

/** Close a display
*
* @param widget Widget within the display to close
*/
public static void closeDisplay(final Widget widget)
{
try
{
final DisplayModel model = widget.getTopDisplayModel();
final ToolkitRepresentation<Object, Object> toolkit = ToolkitRepresentation.getToolkit(model);
toolkit.closeWindow(model);
}
catch (Throwable ex)
{
logger.log(Level.WARNING, "Cannot close display", ex);
}
}

// ====================
// public alert dialog utils

Expand Down
20 changes: 20 additions & 0 deletions core/ui/src/main/java/org/phoebus/ui/application/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,26 @@ public class Messages
public static String TimeYear;
public static String TopResources;
public static String UnLockPane;
public static String UnsavedChanges;
public static String UnsavedChanges_clearButtonText;
public static String UnsavedChanges_close;
public static String UnsavedChanges_discardButtonText_discardAnd;
public static String UnsavedChanges_exit;
public static String UnsavedChanges_mainWindow;
public static String UnsavedChanges_replace;
public static String UnsavedChanges_saveButtonText;
public static String UnsavedChanges_saveButtonText_saveAnd;
public static String UnsavedChanges_saved;
public static String UnsavedChanges_saving;
public static String UnsavedChanges_savingFailed;
public static String UnsavedChanges_secondaryWindow;
public static String UnsavedChanges_selectAllButtonText;
public static String UnsavedChanges_theFollowingApplicationInstancesHaveUnsavedChanges;
public static String UnsavedChanges_wouldYouLikeToSaveAnyChangesBeforeClosingAllTabs;
public static String UnsavedChanges_wouldYouLikeToSaveAnyChangesBeforeClosingTheTabs;
public static String UnsavedChanges_wouldYouLikeToSaveAnyChangesBeforeClosingTheWindow;
public static String UnsavedChanges_wouldYouLikeToSaveAnyChangesBeforeExiting;
public static String UnsavedChanges_wouldYouLikeToSaveAnyChangesBeforeReplacingTheLayout;
public static String WebBrowser;
public static String Welcome;
public static String Window;
Expand Down
Loading
Loading