private void OnTomboyTrayMenuShown(object sender, EventArgs args)
        {
            // Add in the top tasks
            // TODO: Read the number of todo items to show from Preferences
            int max_size  = 5;
            int list_size = 0;

            Gtk.MenuItem item;

            // Filter the tasks to the ones that are incomplete
            Gtk.TreeModelFilter store_filter =
                new Gtk.TreeModelFilter(TasksApplicationAddin.DefaultTaskManager.Tasks, null);
            store_filter.VisibleFunc = FilterTasks;

            // TODO: Sort the tasks to order by due date and priority
            //   store_sort = new Gtk.TreeModelSort (store_filter);
            //   store_sort.DefaultSortFunc =
            //    new Gtk.TreeIterCompareFunc (TaskSortFunc);

            //   tree.Model = store_sort;

            //   int cnt = tree.Model.IterNChildren ();

            //   task_count.Text = string.Format (
            //    Catalog.GetPluralString("Total: {0} task",
            //       "Total: {0} tasks",
            //       cnt),
            //    cnt);


            // List the top "max_size" tasks
            Gtk.TreeIter          iter;
            Gtk.SeparatorMenuItem separator;

            // Determine whether the icon is near the top/bottom of the screen
            int position;

            //if (!Tomboy.Tray.MenuOpensUpward ())
            position = 0;
            //else
            //	position = tomboy_tray_menu.Children.Length - 7;

            separator = new Gtk.SeparatorMenuItem();
            tomboy_tray_menu.Insert(separator, position++);
            separator.Show();
            top_tasks.Add(separator);

            item = new Gtk.MenuItem(Catalog.GetString("To Do List"));
            tomboy_tray_menu.Insert(item, position++);
            item.ShowAll();
            top_tasks.Add(item);
            item.Activated += OnOpenTodoList;

            if (store_filter.GetIterFirst(out iter))
            {
                do
                {
                    Task task = store_filter.GetValue(iter, 0) as Task;
                    item = new TomboyTaskMenuItem(task);
                    tomboy_tray_menu.Insert(item, list_size + position);
                    item.ShowAll();
                    top_tasks.Add(item);
                    list_size++;
                } while (store_filter.IterNext(ref iter) && list_size < max_size);
            }
        }
	private void OnTomboyTrayMenuShown (object sender, EventArgs args)
		{
			// Add in the top tasks
			// TODO: Read the number of todo items to show from Preferences
			int max_size = 5;
			int list_size = 0;
			Gtk.MenuItem item;

			// Filter the tasks to the ones that are incomplete
			Gtk.TreeModelFilter store_filter =
			        new Gtk.TreeModelFilter (TasksApplicationAddin.DefaultTaskManager.Tasks, null);
			store_filter.VisibleFunc = FilterTasks;

			// TODO: Sort the tasks to order by due date and priority
			//   store_sort = new Gtk.TreeModelSort (store_filter);
			//   store_sort.DefaultSortFunc =
			//    new Gtk.TreeIterCompareFunc (TaskSortFunc);

			//   tree.Model = store_sort;

			//   int cnt = tree.Model.IterNChildren ();

			//   task_count.Text = string.Format (
			//    Catalog.GetPluralString("Total: {0} task",
			//       "Total: {0} tasks",
			//       cnt),
			//    cnt);


			// List the top "max_size" tasks
			Gtk.TreeIter iter;
			Gtk.SeparatorMenuItem separator;

			// Determine whether the icon is near the top/bottom of the screen
			int position;
			if (!Tomboy.Tray.MenuOpensUpward ())
				position = 2;
			else
				position = tomboy_tray_menu.Children.Length - 7;

			separator = new Gtk.SeparatorMenuItem ();
			tomboy_tray_menu.Insert (separator, position++);
			separator.Show ();
			top_tasks.Add (separator);

			item = new Gtk.MenuItem (Catalog.GetString ("To Do List"));
			tomboy_tray_menu.Insert (item, position++);
			item.ShowAll ();
			top_tasks.Add (item);
			item.Activated += OnOpenTodoList;

			if (store_filter.GetIterFirst (out iter)) {
				do {
					Task task = store_filter.GetValue (iter, 0) as Task;
					item = new TomboyTaskMenuItem (task);
					tomboy_tray_menu.Insert (item, list_size + position);
					item.ShowAll ();
					top_tasks.Add (item);
					list_size++;
				} while (store_filter.IterNext (ref iter) && list_size < max_size);
			}
		}
Ejemplo n.º 3
0
        void OnButtonPressed(object sender, Gtk.ButtonPressEventArgs args)
        {
            switch (args.Event.Button) {
                case 3: // third mouse button (right-click)
                    clickedTask = null;

                    Gtk.TreeView tv = sender as Gtk.TreeView;
                    if (tv == null)
                        return;

                    Gtk.TreeModel model = tv.Model;

                    Gtk.TreeIter iter;
                    Gtk.TreePath path;
                    Gtk.TreeViewColumn column = null;

                    if (!tv.GetPathAtPos ((int) args.Event.X,
                                    (int) args.Event.Y, out path, out column))
                        return;

                    if (!model.GetIter (out iter, path))
                        return;

                    clickedTask = model.GetValue (iter, 0) as ITask;
                    if (clickedTask == null)
                        return;

                    Menu popupMenu = new Menu ();
                    ImageMenuItem item;

                    item = new ImageMenuItem (Catalog.GetString ("_Notes..."));
                    item.Image = new Gtk.Image (noteIcon);
                    item.Activated += OnShowTaskNotes;
                    popupMenu.Add (item);

                    popupMenu.Add (new SeparatorMenuItem ());

                    item = new ImageMenuItem (Catalog.GetString ("_Delete task"));
                    item.Image = new Gtk.Image(Gtk.Stock.Delete, IconSize.Menu);
                    item.Activated += OnDeleteTask;
                    popupMenu.Add (item);

                    item = new ImageMenuItem(Catalog.GetString ("_Edit task"));
                    item.Image = new Gtk.Image(Gtk.Stock.Edit, IconSize.Menu);
                    item.Activated += OnEditTask;
                    popupMenu.Add (item);

                    /*
                     * Depending on the currently selected task's category, we create a context popup
                     * here in order to enable changing categories. The list of available categories
                     * is pre-filtered as to not contain the current category and the AllCategory.
                     */
                    TreeModelFilter filteredCategories = new TreeModelFilter(Application.Backend.Categories, null);
                    filteredCategories.VisibleFunc = delegate(TreeModel t, TreeIter i) {
                        ICategory category = t.GetValue (i, 0) as ICategory;
                        if (category == null || category is AllCategory || category.Equals(clickedTask.Category))
                            return false;
                        return true;
                    };

                    // The categories submenu is only created in case we actually provide at least one category.
                    if (filteredCategories.GetIterFirst(out iter))
                    {
                        Menu categoryMenu = new Menu();
                        CategoryMenuItem categoryItem;

                        filteredCategories.Foreach(delegate(TreeModel t, TreePath p, TreeIter i) {
                            categoryItem = new CategoryMenuItem((ICategory)t.GetValue(i, 0));
                            categoryItem.Activated += OnChangeCategory;
                            categoryMenu.Add(categoryItem);
                            return false;
                        });

                        // TODO Needs translation.
                        item = new ImageMenuItem(Catalog.GetString("_Change category"));
                        item.Image = new Gtk.Image(Gtk.Stock.Convert, IconSize.Menu);
                        item.Submenu = categoryMenu;
                        popupMenu.Add(item);
                    }

                    popupMenu.ShowAll();
                    popupMenu.Popup ();

                    // Logger.Debug ("Right clicked on task: " + task.Name);
                    break;
            }
        }