Skip to content

Commit

Permalink
Add debugger menu item to open settings dir.
Browse files Browse the repository at this point in the history
Sometimes the user needs to get to their settings folder (e.g. to inspect,
share, or delete it), but it's buried deep somewhere they never go on their hard
drive. Add a menu item that opens the File Explorer at the location where the
settings are located.

Ideally users would never need this, but weird things happen and it's nice to
empower users to take care of it when they do.

Fixes #481.
  • Loading branch information
garfieldnate committed Jul 22, 2024
1 parent 6198d85 commit 33ea1fd
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,27 @@
/////////////////////////////////////////////////////////

import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.net.URI;
public class StartBrowser
import java.net.URISyntaxException;

public class DesktopActions
{
public static void openURL(String url) throws Exception
{
public static void openURL(String url) throws IOException, URISyntaxException {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.BROWSE)) {
Desktop.getDesktop().browse(new URI(url));
} else {
System.err.println("Opening websites URLs is not supported on this platform or machine");
throw new IOException("Opening websites URLs is not supported on this platform or machine");
}
}

public static void openFileOrDirectory(File file) throws IOException {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
Desktop desktop = Desktop.getDesktop();
desktop.open(file);
} else {
throw new IOException("Opening directories is not supported on this platform or machine");
}
}

Expand Down
29 changes: 29 additions & 0 deletions Java/Debugger/src/edu/umich/soar/debugger/menu/FileMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
********************************************************************************************/
package edu.umich.soar.debugger.menu;

import edu.umich.soar.debugger.general.AppProperties;
import edu.umich.soar.debugger.general.DesktopActions;
import org.eclipse.swt.widgets.Menu;

import sml.ClientAnalyzedXML;
Expand All @@ -19,6 +21,8 @@
import edu.umich.soar.debugger.doc.Document;
import edu.umich.soar.debugger.general.SaveLoad;

import java.io.File;

/********************************************************************************************
*
* The file menu
Expand Down Expand Up @@ -107,6 +111,15 @@ public void actionPerformed(ActionEvent e)
}
};

private final AbstractAction m_Open = new AbstractAction("&Browse settings files...")
{
@Override
public void actionPerformed(ActionEvent e)
{
openSettingsPerformed(e);
}
};

private final AbstractAction m_Exit = new AbstractAction("E&xit")
{
@Override
Expand Down Expand Up @@ -147,6 +160,8 @@ private BaseMenu makeMenu(Menu parent, String title)
menu.add(m_Load);
menu.add(m_Save);
menu.addSeparator();
menu.add(m_Open);
menu.addSeparator();
menu.add(m_Exit);

return menu;
Expand Down Expand Up @@ -333,6 +348,20 @@ public void loadPerformed(ActionEvent e)
}
}

public void openSettingsPerformed(ActionEvent event) {
File settingsDir = AppProperties.GetSettingsFilePath("");
try
{
DesktopActions.openFileOrDirectory(settingsDir);
}
catch (Exception e)
{
m_Frame.ShowMessageBox("Error opening directory " + settingsDir, e
.getLocalizedMessage());
}
}


/** Save the current window layout */
public void savePerformed(ActionEvent e)
{
Expand Down
4 changes: 2 additions & 2 deletions Java/Debugger/src/edu/umich/soar/debugger/menu/HelpMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import edu.umich.soar.debugger.MainFrame;
import edu.umich.soar.debugger.doc.Document;
import edu.umich.soar.debugger.general.OSName;
import edu.umich.soar.debugger.general.StartBrowser;
import edu.umich.soar.debugger.general.DesktopActions;

public class HelpMenu
{
Expand Down Expand Up @@ -143,7 +143,7 @@ private void open(String url)
{
try
{
StartBrowser.openURL(url);
DesktopActions.openURL(url);
}
catch (Exception e)
{
Expand Down

0 comments on commit 33ea1fd

Please sign in to comment.