Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion core/ui/src/main/java/org/phoebus/ui/Preferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ public class Preferences
@Preference public static String default_save_path;
/** layout_dir */
@Preference public static String layout_dir;
/** layout_default */
/** layout_default absolute path*/
@Preference public static String layout_default;
/** layout_default absolute path*/
@Preference public static boolean save_layout_in_layout_dir;
/** print_landscape */
@Preference public static boolean print_landscape;
/** ok_severity_text_color */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -560,28 +560,7 @@ private void startUI(final MementoTree memento, final JobMonitor monitor) throws
Preferences.ui_monitor_period, TimeUnit.MILLISECONDS);

closeAllTabsMenuItem.acceleratorProperty().setValue(closeAllTabsKeyCombination);

//Load a custom layout at start if layout_default is defined in preferences
String layoutFileName = Preferences.layout_default;
if(layoutFileName != null && !layoutFileName.isBlank()) {
layoutFileName = !layoutFileName.endsWith(".memento")? layoutFileName + ".memento" :layoutFileName;
String layout_dir = Preferences.layout_dir;
File parentFolder = null;
File user = Locations.user();
if(layout_dir != null && !layout_dir.isBlank() && !layout_dir.contains("$(")) {
parentFolder = new File(user, layout_dir);
}
if(parentFolder == null) {
parentFolder = user;
}
File layoutFile = new File(parentFolder,layoutFileName );
if(layoutFile.exists()) {
startLayoutReplacement(layoutFile);
}
else {
logger.log(Level.WARNING, "Layout file " + layoutFileName + " is not found");
}
}

}

/**
Expand Down Expand Up @@ -798,9 +777,8 @@ void createLoadLayoutsMenu() {
}

// Get every momento file from the configured layout
String layout_dir = Preferences.layout_dir;
if (layout_dir != null && !layout_dir.isBlank() && !layout_dir.contains("$(")) {
final File layoutDir = new File(Locations.user(), layout_dir);
if (Preferences.layout_dir != null && !Preferences.layout_dir.isBlank()) {
final File layoutDir = new File(Preferences.layout_dir);
if (layoutDir.exists()) {
final File[] systemLayoutFiles = layoutDir.listFiles();
if (systemLayoutFiles != null) {
Expand Down Expand Up @@ -1317,9 +1295,10 @@ private void replaceLayout(final MementoTree memento) {
*/
private MementoTree loadDefaultMemento(final List<String> parameters, final JobMonitor monitor) {
monitor.beginTask(Messages.MonitorTaskPers, 1);
File memfile = XMLMementoTree.getDefaultFile();
MementoTree memTree = null;
File memfile = null;
try {
for (int i = 0; i < parameters.size(); ++i)
for (int i = 0; i < parameters.size(); ++i) {
if ("-layout".equals(parameters.get(i))) {
if (i >= parameters.size() - 1)
throw new Exception("Missing /path/to/Example.memento for -layout option");
Expand All @@ -1331,17 +1310,32 @@ private MementoTree loadDefaultMemento(final List<String> parameters, final JobM
parameters.remove(i);
break;
}
}
if(memfile == null) {//if no layout found in argument check preferences
//Load a custom layout at start if layout_default is defined in preferences
String layoutFileName = Preferences.layout_default;
if(layoutFileName != null && !layoutFileName.isBlank()) {
//layout is in absolute path and not based on layout_dir
layoutFileName = !layoutFileName.endsWith(".memento")? layoutFileName + ".memento" :layoutFileName;
memfile = new File(layoutFileName);
}
}

if(memfile == null) {// if still null get default one
memfile = XMLMementoTree.getDefaultFile();
}

if (memfile.canRead()) {
logger.log(Level.INFO, "Loading state from " + memfile);
return loadMemento(memfile);
memTree = loadMemento(memfile);
} else
logger.log(Level.WARNING, "Cannot load state from " + memfile + ", no such file");
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error restoring saved state from " + memfile, ex);
} finally {
monitor.done();
}
return null;
return memTree;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,22 +157,23 @@ private static void positionDialog(final Dialog<?> dialog, Stage stage)
private static boolean saveState(List<Stage> stagesToSave, final String layout)
{
final String memento_filename = layout + ".memento";
//Take in account layout dir and add Layout folder in the path
String layout_dir = Preferences.layout_dir;
File user = Locations.user();
File parentFolder = null;
if(layout_dir != null && !layout_dir.isEmpty() && !layout_dir.contains("$(")) {
parentFolder = new File(user , layout_dir);
if(!parentFolder.exists()) {
parentFolder.mkdir();
//By default save in user location folder
File tmpMementoFile = new File(Locations.user(), memento_filename);

//Save in layout_dir as absolute path if save_in_layout_dir is enable
boolean save_in_layout_dir = Preferences.save_layout_in_layout_dir;
if(save_in_layout_dir) {
String layout_dir = Preferences.layout_dir;
if(layout_dir != null && !layout_dir.isBlank() && !layout_dir.contains("$(")) {
File layoutDir = new File(layout_dir);
// the folder could be in read only
if(layoutDir.exists() && layoutDir.canWrite()) {
tmpMementoFile = new File(layoutDir, memento_filename);
}
}
}

if(parentFolder == null) {
parentFolder = user;
}

final File memento_file = new File(parentFolder, memento_filename);

final File memento_file = tmpMementoFile;

// File.exists() is blocking in nature.
// To combat this the phoebus application maintains a list of *.memento files that are in the default directory.
Expand All @@ -189,8 +190,11 @@ private static boolean saveState(List<Stage> stagesToSave, final String layout)
// Save in background thread
JobManager.schedule("Save " + memento_filename, monitor ->
{
MementoHelper.saveState(stagesToSave, memento_file, null, null, PhoebusApplication.INSTANCE.isMenuVisible(), PhoebusApplication.INSTANCE.isToolbarVisible(), PhoebusApplication.INSTANCE.isStatusbarVisible());

boolean menuVisible = PhoebusApplication.INSTANCE.isMenuVisible();
boolean toolbarVisible = PhoebusApplication.INSTANCE.isToolbarVisible();
boolean statusBarVisible = PhoebusApplication.INSTANCE.isStatusbarVisible();

MementoHelper.saveState(stagesToSave, memento_file, null, null,menuVisible, toolbarVisible, statusBarVisible);
// After the layout has been saved,
// update menu to include the newly saved layout
PhoebusApplication.INSTANCE.createLoadLayoutsMenu();
Expand Down
5 changes: 4 additions & 1 deletion core/ui/src/main/resources/phoebus_ui_preferences.properties
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,12 @@ default_save_path=
# Set the path to a folder with default layouts
layout_dir=

# Set default layout at start
# Set default layout at start absolutepath
layout_default=

# If enable layout are saved in layout_dir instead of default user location
save_layout_in_layout_dir=false

# Compute print scaling in 'landscape' mode?
# Landscape mode is generally most suited for printouts
# of displays or plots, because the monitor tends to be 'wide'.
Expand Down