/// <summary>
        /// Sets the category of a task for a given ID
        /// </summary>
        /// <param name="id">
        /// A <see cref="System.String"/> for the ID of the task
        /// </param>
        /// <param name="category">
        /// A <see cref="System.String"/> the category of the task
        /// </param>
        /// <returns>
        /// A <see cref="System.Boolean"/>, true for success, false
        /// for failure.
        /// </returns>
        public bool SetCategoryForTaskById(string id,
                                           string categoryName)
        {
            ITask task = GetTaskById(id);

            if (task == null)
            {
                return(false);
            }
            Gtk.TreeIter  iter;
            Gtk.TreeModel model = Application.Backend.Categories;

            if (!model.GetIterFirst(out iter))
            {
                return(false);
            }

            do
            {
                ICategory category = model.GetValue(iter, 0) as ICategory;
                if (string.Compare(category.Name, categoryName) == 0)
                {
                    task.Category = category;
                    return(true);
                }
            } while (model.IterNext(ref iter));
            return(false);
        }
        /// <summary>
        /// Return an array of Category names.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/>
        /// </returns>
        public string[] GetCategoryNames()
        {
            List <string> categories = new List <string> ();

            string[] emptyArray = categories.ToArray();

            Gtk.TreeIter  iter;
            Gtk.TreeModel model = Application.Backend.Categories;

            if (!model.GetIterFirst(out iter))
            {
                return(emptyArray);
            }

            do
            {
                ICategory category = model.GetValue(iter, 0) as ICategory;
                if (category is AllCategory)
                {
                    continue;                     // Prevent the AllCategory from being returned
                }
                categories.Add(category.Name);
            } while (model.IterNext(ref iter));

            return(categories.ToArray());
        }
Пример #3
0
 public bool MoveNext()
 {
     if (changed == false)
     {
         if (reset == true)
         {
             reset = false;
             return(model.GetIterFirst(out iter));
         }
         else
         {
             return(model.IterNext(ref iter));
         }
     }
     else
     {
         throw new InvalidOperationException("List has changed.");
     }
 }
Пример #4
0
        List <NotebookMenuItem> GetNotebookMenuItems()
        {
            List <NotebookMenuItem> items = new List <NotebookMenuItem> ();

            Gtk.TreeModel model = NotebookManager.Notebooks;
            Gtk.TreeIter  iter;

            if (model.GetIterFirst(out iter) == true)
            {
                do
                {
                    Notebook         notebook = model.GetValue(iter, 0) as Notebook;
                    NotebookMenuItem item     = new NotebookMenuItem(Note, notebook);
                    items.Add(item);
                } while (model.IterNext(ref iter) == true);
            }

            items.Sort();

            return(items);
        }
Пример #5
0
        private void AddMenuItems(Gtk.Menu menu)
        {
            RemoveMenuItems(menu);

            NotebookNewNoteMenuItem item;

            Gtk.TreeModel model = NotebookManager.Notebooks;
            Gtk.TreeIter  iter;

            // Add in the "New Notebook..." menu item
            Gtk.ImageMenuItem newNotebookMenuItem =
                new Gtk.ImageMenuItem(Catalog.GetString("New Note_book..."));
            newNotebookMenuItem.Image      = new Gtk.Image(NewNotebookIcon);
            newNotebookMenuItem.Activated += OnNewNotebookMenuItem;
            newNotebookMenuItem.ShowAll();
            menu.Append(newNotebookMenuItem);

            if (model.IterNChildren() > 0)
            {
                Gtk.SeparatorMenuItem separator = new Gtk.SeparatorMenuItem();
                separator.ShowAll();
                menu.Append(separator);

                if (model.GetIterFirst(out iter) == true)
                {
                    do
                    {
                        Notebook notebook = model.GetValue(iter, 0) as Notebook;
                        item = new NotebookNewNoteMenuItem(notebook);
                        item.ShowAll();
                        menu.Append(item);
                    } while (model.IterNext(ref iter) == true);
                }
            }
#if MAC
            menu.ShowAll();
#endif
        }
        /// <summary>
        /// Create a new task in Tasque using the given categoryName and name.
        /// </summary>
        /// <param name="categoryName">
        /// A <see cref="System.String"/>.  The name of an existing category.
        /// Matches are not case-sensitive.
        /// </param>
        /// <param name="taskName">
        /// A <see cref="System.String"/>.  The name of the task to be created.
        /// </param>
        /// <param name="enterEditMode">
        /// A <see cref="System.Boolean"/>.  Specify true if the TaskWindow
        /// should be shown, the new task scrolled to, and have it be put into
        /// edit mode immediately.
        /// </param>
        /// <param name="parseDate">
        /// A <see cref="System.Boolean"/>.  Specify true if the
        /// date should be parsed out of the taskName (in case
        /// Preferences.ParseDateEnabledKey is true as well).
        /// </param>
        /// <returns>
        /// A unique <see cref="System.String"/> which can be used to reference
        /// the task later.
        /// </returns>
        public string CreateTask(string categoryName, string taskName,
                                 bool enterEditMode, bool parseDate)
        {
            Gtk.TreeIter  iter;
            Gtk.TreeModel model = Application.Backend.Categories;

            //
            // Validate the input parameters.  Don't allow null or empty strings
            // be passed-in.
            //
            if (categoryName == null || categoryName.Trim() == string.Empty ||
                taskName == null || taskName.Trim() == string.Empty)
            {
                return(string.Empty);
            }

            //
            // Look for the specified category
            //
            if (!model.GetIterFirst(out iter))
            {
                return(string.Empty);
            }

            ICategory category = null;

            do
            {
                ICategory tempCategory = model.GetValue(iter, 0) as ICategory;
                if (tempCategory.Name.ToLower().CompareTo(categoryName.ToLower()) == 0)
                {
                    // Found a match
                    category = tempCategory;
                }
            } while (model.IterNext(ref iter));

            if (category == null)
            {
                return(string.Empty);
            }

            // If enabled, attempt to parse due date information
            // out of the taskName.
            DateTime taskDueDate = DateTime.MinValue;

            if (parseDate && Application.Preferences.GetBool(Preferences.ParseDateEnabledKey))
            {
                TaskParser.Instance.TryParse(
                    taskName,
                    out taskName,
                    out taskDueDate);
            }
            ITask task = null;

            try {
                task = Application.Backend.CreateTask(taskName, category);
                if (taskDueDate != DateTime.MinValue)
                {
                    task.DueDate = taskDueDate;
                }
            } catch (Exception e) {
                Logger.Error("Exception calling Application.Backend.CreateTask from RemoteControl: {0}", e.Message);
                return(string.Empty);
            }

            if (task == null)
            {
                return(string.Empty);
            }

            if (enterEditMode)
            {
                TaskWindow.SelectAndEdit(task);
            }

                        #if ENABLE_NOTIFY_SHARP
            // Use notify-sharp to alert the user that a new task has been
            // created successfully.
            Notification notify =
                new Notification(
                    Catalog.GetString("New task created."),           // summary
                    Catalog.GetString(taskName),                      // body
                    tasqueIcon);
            Application.ShowAppNotification(notify);
                        #endif


            return(task.Id);
        }