Current open case not displayed in Open Recent Cases

This commit is contained in:
sidheshenator 2015-07-07 11:18:49 -04:00
parent 9a989506e7
commit c53636c8ef
3 changed files with 35 additions and 13 deletions

View File

@ -18,9 +18,6 @@
*/ */
package org.sleuthkit.autopsy.casemodule; 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.ActionListener;
import java.awt.event.KeyEvent; import java.awt.event.KeyEvent;
import java.io.File; import java.io.File;

View File

@ -30,6 +30,7 @@ import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import javax.swing.JMenuItem; import javax.swing.JMenuItem;
import org.apache.commons.lang.ArrayUtils;
import org.openide.util.HelpCtx; import org.openide.util.HelpCtx;
import org.openide.util.NbBundle; import org.openide.util.NbBundle;
import org.openide.util.actions.CallableSystemAction; import org.openide.util.actions.CallableSystemAction;
@ -45,7 +46,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
*/ */
final class RecentCases extends CallableSystemAction implements Presenter.Menu { 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 NAME_PROP_KEY = "LBL_RecentCase_Name"; //NON-NLS
static final String PATH_PROP_KEY = "LBL_RecentCase_Path"; //NON-NLS static final String PATH_PROP_KEY = "LBL_RecentCase_Path"; //NON-NLS
static final RecentCase BLANK_RECENTCASE = new RecentCase("", ""); static final RecentCase BLANK_RECENTCASE = new RecentCase("", "");
@ -358,7 +359,7 @@ import org.sleuthkit.autopsy.coreutils.Logger;
/** /**
* Gets the recent case names. * Gets the recent case names.
* *
* @return caseNames An array String[LENGTH], newest case first, with any * @return caseNames An array String[LENGTH - 1], newest case first, with any
* extra spots filled with "" * extra spots filled with ""
*/ */
public String[] getRecentCaseNames() { public String[] getRecentCaseNames() {
@ -366,41 +367,64 @@ import org.sleuthkit.autopsy.coreutils.Logger;
Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator(); Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator();
int i = 0; int i = 0;
String currentCaseName = null;
try {
currentCaseName = Case.getCurrentCase().getName();
} catch (IllegalStateException ex) {
// in case there is no current case.
}
while (mostRecentFirst.hasNext()) { while (mostRecentFirst.hasNext()) {
caseNames[i] = mostRecentFirst.next().name; String name = mostRecentFirst.next().name;
if ((currentCaseName != null && !name.equals(currentCaseName)) || currentCaseName == null) {
// exclude currentCaseName from the caseNames[]
caseNames[i] = name;
i++; i++;
} }
}
while (i < caseNames.length) { while (i < caseNames.length) {
caseNames[i] = ""; caseNames[i] = "";
i++; i++;
} }
return caseNames; // return last 5 case names
return (String[]) ArrayUtils.subarray(caseNames, 0, LENGTH - 1);
} }
/** /**
* Gets the recent case paths. * Gets the recent case paths.
* *
* @return casePaths An array String[LENGTH], newest case first, with any * @return casePaths An array String[LENGTH - 1], newest case first, with any
* extra spots filled with "" * extra spots filled with ""
*/ */
public String[] getRecentCasePaths() { public String[] getRecentCasePaths() {
String[] casePaths = new String[LENGTH]; String[] casePaths = new String[LENGTH];
String currentCasePath = null;
try {
currentCasePath = Case.getCurrentCase().getName();
} catch (IllegalStateException ex) {
// in case there is no current case.
}
Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator(); Iterator<RecentCase> mostRecentFirst = recentCases.descendingIterator();
int i = 0; int i = 0;
while (mostRecentFirst.hasNext()) { while (mostRecentFirst.hasNext()) {
casePaths[i] = mostRecentFirst.next().path; String path = mostRecentFirst.next().path;
if ((currentCasePath != null && !path.equals(currentCasePath)) || currentCasePath == null) {
// exclude currentCasePath from the casePaths[]
casePaths[i] = path;
i++; i++;
} }
}
while (i < casePaths.length) { while (i < casePaths.length) {
casePaths[i] = ""; casePaths[i] = "";
i++; i++;
} }
return casePaths; // return last 5 case paths
return (String[]) ArrayUtils.subarray(casePaths, 0, LENGTH - 1);
} }
/** /**

View File

@ -36,7 +36,8 @@ import org.openide.util.actions.SystemAction;
/** the constructor */ /** the constructor */
UpdateRecentCases(){ UpdateRecentCases(){
length = RecentCases.LENGTH; // display last 5 cases.
length = RecentCases.LENGTH - 1;
} }
/** /**