Skip to content
This repository
Browse code

Show recent tasks/activities in tray menu

  • Loading branch information...
commit 55f389ce90dabf9224730b26d5e736adf7fe6f85 1 parent db602ae
Rustam authored
28 main/src/net/sf/timecult/TimeTracker.java
@@ -20,8 +20,7 @@
20 20 package net.sf.timecult;
21 21
22 22 import java.io.File;
23   -import java.util.Calendar;
24   -import java.util.Vector;
  23 +import java.util.*;
25 24
26 25 import net.sf.timecult.conf.AppPreferences;
27 26 import net.sf.timecult.conf.ConfigurationManager;
@@ -30,15 +29,7 @@
30 29 import net.sf.timecult.io.FileLockManager;
31 30 import net.sf.timecult.io.WorkspaceReader;
32 31 import net.sf.timecult.io.WorkspaceXMLWriter;
33   -import net.sf.timecult.model.ContainerFactory;
34   -import net.sf.timecult.model.Project;
35   -import net.sf.timecult.model.ProjectTreeItem;
36   -import net.sf.timecult.model.Task;
37   -import net.sf.timecult.model.TimeLog;
38   -import net.sf.timecult.model.TimeRecordFilter;
39   -import net.sf.timecult.model.Workspace;
40   -import net.sf.timecult.model.WorkspaceEvent;
41   -import net.sf.timecult.model.WorkspaceListener;
  32 +import net.sf.timecult.model.*;
42 33 import net.sf.timecult.model.mem.LocalIdGenerator;
43 34 import net.sf.timecult.model.mem.MemContainerFactory;
44 35 import net.sf.timecult.model.mem.MemTimeLog;
@@ -510,7 +501,20 @@ public ConfigurationManager getConfigurationManager() {
510 501
511 502 public AppPreferences getAppPreferences() {
512 503 return AppPreferences.getInstance();
513   - }
  504 + }
  505 +
  506 + public Task[] getRecentTasks(int maxNumber) {
  507 + List<Task> recentTasks = new ArrayList<Task>(maxNumber);
  508 + TimeRecord[] records = getTimeLog().getTimeRecords(null);
  509 + for (int i = records.length - 1; i >= 0; i--) {
  510 + Task recordedTask = records[i].getTask();
  511 + if (!recentTasks.contains(recordedTask)) {
  512 + recentTasks.add(recordedTask);
  513 + if (recentTasks.size() >= maxNumber) break;
  514 + }
  515 + }
  516 + return recentTasks.toArray(new Task[recentTasks.size()]);
  517 + }
514 518
515 519
516 520 // Private attributes
23 main/src/net/sf/timecult/ui/swt/SWTMainWindow.java
@@ -20,8 +20,6 @@
20 20 package net.sf.timecult.ui.swt;
21 21
22 22 import java.io.File;
23   -import java.util.Collection;
24   -import java.util.TreeMap;
25 23
26 24 import net.sf.timecult.AppInfo;
27 25 import net.sf.timecult.ResourceHelper;
@@ -291,27 +289,8 @@ public void handleEvent(Event evt) {
291 289 public Menu createInProgressStartMenu(MenuItem parentItem,
292 290 SelectionListener l) {
293 291 Menu startMenu = new Menu(parentItem);
294   - Task inProgressTasks[] = TimeTracker.getInstance().getWorkspace()
295   - .getTasksByStatus(new TaskStatus(TaskStatus.IN_PROGRESS));
296   - TreeMap<String, Task> sortedItems = new TreeMap<String, Task>();
297   - for (Task inProgressTask : inProgressTasks) {
298   - if (!(inProgressTask instanceof IdleTask)) {
299   - String sortKey = (inProgressTask instanceof Activity ? "2:" : "1:") + inProgressTask.getName();
300   - sortedItems.put(sortKey, inProgressTask);
301   - }
302   - }
303   - Collection<Task> tasks = sortedItems.values();
304   - boolean isInTaskGroup = false;
  292 + Task[] tasks = TimeTracker.getInstance().getRecentTasks(7);
305 293 for (Task task : tasks) {
306   - if (task instanceof Activity) {
307   - if (isInTaskGroup) {
308   - new MenuItem(startMenu, SWT.SEPARATOR);
309   - isInTaskGroup = false;
310   - }
311   - }
312   - else {
313   - isInTaskGroup = true;
314   - }
315 294 addTaskItem(startMenu, task, l);
316 295 }
317 296 return startMenu;

0 comments on commit 55f389c

Please sign in to comment.
Something went wrong with that request. Please try again.