From 7ea4bf5396bd0a6292992570eb6ede7147ecac19 Mon Sep 17 00:00:00 2001 From: Karl Mortensen Date: Thu, 26 Mar 2015 10:12:22 -0400 Subject: [PATCH] add help to Help menu --- .../autopsy/corecomponents/Bundle.properties | 2 + .../corecomponents/OfflineHelpAction.java | 108 ++++++++++++++++++ .../corecomponents/OnlineHelpAction.java | 2 +- build.xml | 7 +- 4 files changed, 116 insertions(+), 3 deletions(-) create mode 100644 Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/Bundle.properties b/Core/src/org/sleuthkit/autopsy/corecomponents/Bundle.properties index 00afd73af4..7290f77234 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/Bundle.properties +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/Bundle.properties @@ -29,6 +29,8 @@ URL_ON_IMG=http://www.sleuthkit.org/ URL_ON_HELP=http://sleuthkit.org/autopsy/docs/user-docs/3.1/ +FILE_FOR_LOCAL_HELP=file:/// +INDEX_FOR_LOCAL_HELP=/docs/index.html LBL_Close=Close DataContentViewerString.copyMenuItem.text=Copy DataContentViewerHex.copyMenuItem.text=Copy diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java new file mode 100644 index 0000000000..f2e755553a --- /dev/null +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/OfflineHelpAction.java @@ -0,0 +1,108 @@ +/* + * Autopsy Forensic Browser + * + * Copyright 2011-2015 Basis Technology Corp. + * Contact: carrier sleuthkit org + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.sleuthkit.autopsy.corecomponents; + +import java.awt.Desktop; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URI; +import org.netbeans.core.actions.HTMLViewAction; +import org.openide.awt.ActionID; +import org.openide.awt.ActionReference; +import org.openide.awt.ActionReferences; +import org.openide.awt.ActionRegistration; +import org.openide.awt.HtmlBrowser; +import org.openide.util.NbBundle; +import org.openide.util.NbBundle.Messages; +import java.util.logging.Level; +import java.util.logging.Logger; + +/** + * Implements a hyperlink to the Offline Documentation. + */ +@ActionID( + category = "Help", + id = "org.sleuthkit.autopsy.corecomponents.OfflineHelpAction" +) +@ActionRegistration( + displayName = "#CTL_OfflineHelpAction" +) +@ActionReferences({ + @ActionReference(path = "Menu/Help", position = 1), + @ActionReference(path = "Shortcuts", name = "F2") +}) +@Messages("CTL_OfflineHelpAction=Offline Autopsy Documentation") +public final class OfflineHelpAction implements ActionListener { + + private URI uri; + private static final Logger Logger = + org.sleuthkit.autopsy.coreutils.Logger.getLogger(AboutWindowPanel.class.getName()); + + @Override + public void actionPerformed(ActionEvent e) { + viewOfflineHelp(); + } + + /** + * Displays the Offline Documentation in the system browser. If not + * available, displays it in the built-in OpenIDE HTML Browser. + * + * Tested and working: Chrome, Firefox, IE + * Not tested: Opera, Safari + */ + private void viewOfflineHelp() { + String fileForHelp = ""; + String indexForHelp = ""; + String currentDirectory = ""; + + try { + // Match the form: file:///C:/some/directory/AutopsyXYZ/docs/index.html + fileForHelp = NbBundle.getMessage(OfflineHelpAction.class, "FILE_FOR_LOCAL_HELP"); + indexForHelp = NbBundle.getMessage(OfflineHelpAction.class, "INDEX_FOR_LOCAL_HELP"); + currentDirectory = System.getProperty("user.dir").replace("\\", "/").replace(" ", "%20"); //NON-NLS + uri = new URI(fileForHelp + currentDirectory + indexForHelp); + } catch (Exception ex) { + Logger.log(Level.SEVERE, "Unable to load Offline Documentation: " + + fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS + } + if (uri != null) { + // Display URL in the System browser + if (Desktop.isDesktopSupported()) { + Desktop desktop = Desktop.getDesktop(); + try { + desktop.browse(uri); + } catch (IOException ex) { + Logger.log(Level.SEVERE, "Unable to launch the system browser: " + + fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS + } + } else { + org.openide.awt.StatusDisplayer.getDefault().setStatusText( + NbBundle.getMessage(HTMLViewAction.class, "CTL_OpeningBrowser")); //NON-NLS + try { + HtmlBrowser.URLDisplayer.getDefault().showURL(uri.toURL()); + } catch (MalformedURLException ex) { + Logger.log(Level.SEVERE, "Unable to launch the built-in browser: " + + fileForHelp + currentDirectory + indexForHelp, ex); //NON-NLS + } + } + } + } +} diff --git a/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java b/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java index b0cd3171e6..d9190fa51b 100644 --- a/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java +++ b/Core/src/org/sleuthkit/autopsy/corecomponents/OnlineHelpAction.java @@ -51,7 +51,7 @@ import java.util.logging.Logger; @ActionReference(path = "Menu/Help", position = 0), @ActionReference(path = "Shortcuts", name = "F1") }) -@Messages("CTL_OnlineHelpAction=Online Documentation") +@Messages("CTL_OnlineHelpAction=Online Autopsy Documentation") public final class OnlineHelpAction implements ActionListener { private URI uri; diff --git a/build.xml b/build.xml index 41f550cab5..22abd3b0d7 100644 --- a/build.xml +++ b/build.xml @@ -69,9 +69,12 @@ - + + + + @@ -229,7 +232,7 @@ - +