Skip to content
Snippets Groups Projects
Commit c517eb4e authored by Richard Cordovano's avatar Richard Cordovano
Browse files

Merge pull request #1510 from sidheshenator/open_recent_cases_fix

Open recent cases fix
parents 4090ae0c 0cbed2d9
No related branches found
No related tags found
No related merge requests found
......@@ -18,9 +18,6 @@
*/
package org.sleuthkit.autopsy.casemodule;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.EventQueue;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.io.File;
......@@ -201,10 +198,10 @@ private void openCase() {
try {
if (caseName.equals("") || casePath.equals("") || (!new File(casePath).exists())) {
JOptionPane.showMessageDialog(null,
NbBundle.getMessage(this.getClass(),
NbBundle.getMessage(OpenRecentCasePanel.class,
"OpenRecentCasePanel.openCase.msgDlg.caseDoesntExist.msg",
caseName),
NbBundle.getMessage(this.getClass(),
NbBundle.getMessage(OpenRecentCasePanel.class,
"OpenRecentCasePanel.openCase.msgDlg.err"),
JOptionPane.ERROR_MESSAGE);
RecentCases.getInstance().removeRecentCase(caseName, casePath); // remove the recent case if it doesn't exist anymore
......@@ -266,10 +263,10 @@ public String getColumnName(int column) {
switch (column) {
case 0:
colName = NbBundle.getMessage(this.getClass(), "OpenRecentCasePanel.colName.caseName");
colName = NbBundle.getMessage(OpenRecentCasePanel.class, "OpenRecentCasePanel.colName.caseName");
break;
case 1:
colName = NbBundle.getMessage(this.getClass(), "OpenRecentCasePanel.colName.path");
colName = NbBundle.getMessage(OpenRecentCasePanel.class, "OpenRecentCasePanel.colName.path");
break;
default:
;
......
......@@ -29,6 +29,7 @@
import java.util.List;
import java.util.logging.Level;
import javax.swing.JMenuItem;
import org.apache.commons.lang.ArrayUtils;
import org.openide.util.HelpCtx;
import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction;
......@@ -44,7 +45,7 @@
*/
final class RecentCases extends CallableSystemAction implements Presenter.Menu {
static final int LENGTH = 5;
static final int LENGTH = 6;
static final String NAME_PROP_KEY = "LBL_RecentCase_Name"; //NON-NLS
static final String PATH_PROP_KEY = "LBL_RecentCase_Path"; //NON-NLS
static final RecentCase BLANK_RECENTCASE = new RecentCase("", "");
......@@ -364,17 +365,28 @@ public void removeRecentCase(String name, String path) {
/**
* Gets the recent case names.
*
* @return caseNames An array String[LENGTH], newest case first, with any
* extra spots filled with ""
* @return caseNames An array String[LENGTH - 1], newest case first, with any
* extra spots filled with ""
*/
public String[] getRecentCaseNames() {
String[] caseNames = new String[LENGTH];
Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator();
int i = 0;
String currentCaseName = null;
try {
currentCaseName = Case.getCurrentCase().getName();
} catch (IllegalStateException ex) {
// in case there is no current case.
}
while (mostRecentFirst.hasNext()) {
caseNames[i] = mostRecentFirst.next().name;
i++;
String name = mostRecentFirst.next().name;
if ((currentCaseName != null && !name.equals(currentCaseName)) || currentCaseName == null) {
// exclude currentCaseName from the caseNames[]
caseNames[i] = name;
i++;
}
}
while (i < caseNames.length) {
......@@ -382,23 +394,34 @@ public String[] getRecentCaseNames() {
i++;
}
return caseNames;
// return last 5 case names
return (String[]) ArrayUtils.subarray(caseNames, 0, LENGTH - 1);
}
/**
* Gets the recent case paths.
*
* @return casePaths An array String[LENGTH], newest case first, with any
* extra spots filled with ""
* @return casePaths An array String[LENGTH - 1], newest case first, with any
* extra spots filled with ""
*/
public String[] getRecentCasePaths() {
String[] casePaths = new String[LENGTH];
String currentCasePath = null;
try {
currentCasePath = Case.getCurrentCase().getConfigFilePath();
} catch (IllegalStateException ex) {
// in case there is no current case.
}
Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator();
int i = 0;
while (mostRecentFirst.hasNext()) {
casePaths[i] = mostRecentFirst.next().path;
i++;
String path = mostRecentFirst.next().path;
if ((currentCasePath != null && !path.equals(currentCasePath)) || currentCasePath == null) {
// exclude currentCasePath from the casePaths[]
casePaths[i] = path;
i++;
}
}
while (i < casePaths.length) {
......@@ -406,7 +429,8 @@ public String[] getRecentCasePaths() {
i++;
}
return casePaths;
// return last 5 case paths
return (String[]) ArrayUtils.subarray(casePaths, 0, LENGTH - 1);
}
/**
......@@ -424,7 +448,7 @@ public void performAction() {
@Override
public String getName() {
//return NbBundle.getMessage(RecentCases.class, "CTL_RecentCases");
return NbBundle.getMessage(this.getClass(), "RecentCases.getName.text");
return NbBundle.getMessage(RecentCases.class, "RecentCases.getName.text");
}
/**
......
......@@ -33,11 +33,10 @@ class UpdateRecentCases extends JMenuItem implements DynamicMenuContent {
int length;
static boolean hasRecentCase = false;
/**
* the constructor
*/
UpdateRecentCases() {
length = RecentCases.LENGTH;
/** the constructor */
UpdateRecentCases(){
// display last 5 cases.
length = RecentCases.LENGTH - 1;
}
/**
......@@ -69,13 +68,13 @@ public JComponent[] getMenuPresenters() {
if (hasRecentCase) {
comps[length] = new JSeparator();
JMenuItem clearMenu = new JMenuItem(
NbBundle.getMessage(this.getClass(), "UpdateRecentCases.menuItem.clearRecentCases.text"));
NbBundle.getMessage(UpdateRecentCases.class, "UpdateRecentCases.menuItem.clearRecentCases.text"));
clearMenu.addActionListener(SystemAction.get(RecentCases.class));
comps[length + 1] = clearMenu;
} // otherwise, just create a disabled empty menu
else {
comps = new JComponent[1];
JMenuItem emptyMenu = new JMenuItem(NbBundle.getMessage(this.getClass(), "UpdateRecentCases.menuItem.empty"));
JMenuItem emptyMenu = new JMenuItem(NbBundle.getMessage(UpdateRecentCases.class, "UpdateRecentCases.menuItem.empty"));
emptyMenu.addActionListener(new RecentItems("", ""));
comps[0] = emptyMenu;
comps[0].setEnabled(false);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment