Permalink
Browse files

Show recent tasks/activities in tray menu

  • Loading branch information...
1 parent db602ae commit 55f389ce90dabf9224730b26d5e736adf7fe6f85 Rustam committed Jun 7, 2012
Showing with 17 additions and 34 deletions.
  1. +16 −12 main/src/net/sf/timecult/TimeTracker.java
  2. +1 −22 main/src/net/sf/timecult/ui/swt/SWTMainWindow.java
View
28 main/src/net/sf/timecult/TimeTracker.java
@@ -20,8 +20,7 @@
package net.sf.timecult;
import java.io.File;
-import java.util.Calendar;
-import java.util.Vector;
+import java.util.*;
import net.sf.timecult.conf.AppPreferences;
import net.sf.timecult.conf.ConfigurationManager;
@@ -30,15 +29,7 @@
import net.sf.timecult.io.FileLockManager;
import net.sf.timecult.io.WorkspaceReader;
import net.sf.timecult.io.WorkspaceXMLWriter;
-import net.sf.timecult.model.ContainerFactory;
-import net.sf.timecult.model.Project;
-import net.sf.timecult.model.ProjectTreeItem;
-import net.sf.timecult.model.Task;
-import net.sf.timecult.model.TimeLog;
-import net.sf.timecult.model.TimeRecordFilter;
-import net.sf.timecult.model.Workspace;
-import net.sf.timecult.model.WorkspaceEvent;
-import net.sf.timecult.model.WorkspaceListener;
+import net.sf.timecult.model.*;
import net.sf.timecult.model.mem.LocalIdGenerator;
import net.sf.timecult.model.mem.MemContainerFactory;
import net.sf.timecult.model.mem.MemTimeLog;
@@ -510,7 +501,20 @@ public ConfigurationManager getConfigurationManager() {
public AppPreferences getAppPreferences() {
return AppPreferences.getInstance();
- }
+ }
+
+ public Task[] getRecentTasks(int maxNumber) {
+ List<Task> recentTasks = new ArrayList<Task>(maxNumber);
+ TimeRecord[] records = getTimeLog().getTimeRecords(null);
+ for (int i = records.length - 1; i >= 0; i--) {
+ Task recordedTask = records[i].getTask();
+ if (!recentTasks.contains(recordedTask)) {
+ recentTasks.add(recordedTask);
+ if (recentTasks.size() >= maxNumber) break;
+ }
+ }
+ return recentTasks.toArray(new Task[recentTasks.size()]);
+ }
// Private attributes
View
23 main/src/net/sf/timecult/ui/swt/SWTMainWindow.java
@@ -20,8 +20,6 @@
package net.sf.timecult.ui.swt;
import java.io.File;
-import java.util.Collection;
-import java.util.TreeMap;
import net.sf.timecult.AppInfo;
import net.sf.timecult.ResourceHelper;
@@ -291,27 +289,8 @@ public void handleEvent(Event evt) {
public Menu createInProgressStartMenu(MenuItem parentItem,
SelectionListener l) {
Menu startMenu = new Menu(parentItem);
- Task inProgressTasks[] = TimeTracker.getInstance().getWorkspace()
- .getTasksByStatus(new TaskStatus(TaskStatus.IN_PROGRESS));
- TreeMap<String, Task> sortedItems = new TreeMap<String, Task>();
- for (Task inProgressTask : inProgressTasks) {
- if (!(inProgressTask instanceof IdleTask)) {
- String sortKey = (inProgressTask instanceof Activity ? "2:" : "1:") + inProgressTask.getName();
- sortedItems.put(sortKey, inProgressTask);
- }
- }
- Collection<Task> tasks = sortedItems.values();
- boolean isInTaskGroup = false;
+ Task[] tasks = TimeTracker.getInstance().getRecentTasks(7);
for (Task task : tasks) {
- if (task instanceof Activity) {
- if (isInTaskGroup) {
- new MenuItem(startMenu, SWT.SEPARATOR);
- isInTaskGroup = false;
- }
- }
- else {
- isInTaskGroup = true;
- }
addTaskItem(startMenu, task, l);
}
return startMenu;

0 comments on commit 55f389c

Please sign in to comment.