Esempio n. 1
0
        public MainWindow(Builder builder)
            : base(builder.GetObject ("mainWindow").Handle)
        {
            builder.Autoconnect (this);

            taskEditor = new TaskEditor (builder);
            taskTree = new TaskTree (builder);

            taskTree.SelectedTaskChanged += (sender, e) => {
                taskEditor.SetCurrentTask (e);
                taskEditor.LoadTask ();
            };

            Destroyed += (sender, e) => Application.Quit ();

            DeleteEvent += (o, args) => {
                if (TaskManager.Instance.ModelModified) {
                    switch (UiUtils.ShowYesNoCancelDialog (this, "Save changes?")) {
                    case ResponseType.Yes:
                        TaskManager.Instance.SaveModel ();
                        break;
                    case ResponseType.Cancel:
                        args.RetVal = true;
                        break;
                    }
                }
            };

            removeDoneButton.Clicked += (sender, e) => TaskManager.Instance.RemoveTasks (task => task.IsDone);

            addNewTaskButton.Clicked += AddNewTaskButton_Clicked;

            saveToFileButton.Clicked += (sender, e) => TaskManager.Instance.SaveModel ();

            TaskManager.Instance.ModelStateModified += TaskManager_Instance_ModelStateModified;

            taskEditor.SetCurrentTask (null);

            RadioToolButton[] filterButtons = {
                allTasksToolButton,
                todaysTasksToolButton,
                thisWeekToolButton,
                expiredToolButton,
                noDeadlineToolButton
            };

            ProcessTaskFunc[] filterFuncs = {
                task => true,
                task => task.Deadline.HasValue && task.Deadline.Value.Date == DateTime.Now.Date,
                task => task.Deadline.HasValue && task.Deadline.Value.Date >= DateTime.Now.Date && task.Deadline.Value.Date < DateTime.Now.Date.AddDays (7),
                task => task.Deadline.HasValue && task.Deadline.Value.Date < DateTime.Now.Date,
                task => !task.Deadline.HasValue
            };

            foreach (var btn in filterButtons) {
                btn.Toggled += (sender, e) => {
                    if ((sender as RadioToolButton).Active) {
                        int index = Array.IndexOf (filterButtons, sender);
                        taskTree.SetFilterFunc (filterFuncs [index]);
                    }
                };
            }

            TaskManager.Instance.LoadModel ();
        }
Esempio n. 2
0
        public MainWindow(Builder builder) : base(builder.GetObject("mainWindow").Handle)
        {
            builder.Autoconnect(this);

            taskEditor = new TaskEditor(builder);
            taskTree   = new TaskTree(builder);

            taskTree.SelectedTaskChanged += (sender, e) => {
                taskEditor.SetCurrentTask(e);
                taskEditor.LoadTask();
            };

            Destroyed += (sender, e) => Application.Quit();

            DeleteEvent += (o, args) => {
                if (TaskManager.Instance.ModelModified)
                {
                    switch (UiUtils.ShowYesNoCancelDialog(this, "Save changes?"))
                    {
                    case ResponseType.Yes:
                        TaskManager.Instance.SaveModel();
                        break;

                    case ResponseType.Cancel:
                        args.RetVal = true;
                        break;
                    }
                }
            };

            removeDoneButton.Clicked += (sender, e) => TaskManager.Instance.RemoveTasks(task => task.IsDone);

            addNewTaskButton.Clicked += AddNewTaskButton_Clicked;

            saveToFileButton.Clicked += (sender, e) => TaskManager.Instance.SaveModel();

            TaskManager.Instance.ModelStateModified += TaskManager_Instance_ModelStateModified;

            taskEditor.SetCurrentTask(null);

            RadioToolButton[] filterButtons =
            {
                allTasksToolButton,
                todaysTasksToolButton,
                thisWeekToolButton,
                expiredToolButton,
                noDeadlineToolButton
            };

            ProcessTaskFunc[] filterFuncs =
            {
                task => true,
                task => task.Deadline.HasValue && task.Deadline.Value.Date == DateTime.Now.Date,
                task => task.Deadline.HasValue && task.Deadline.Value.Date >= DateTime.Now.Date && task.Deadline.Value.Date < DateTime.Now.Date.AddDays(7),
                task => task.Deadline.HasValue && task.Deadline.Value.Date < DateTime.Now.Date,
                task => !task.Deadline.HasValue
            };

            foreach (var btn in filterButtons)
            {
                btn.Toggled += (sender, e) => {
                    if ((sender as RadioToolButton).Active)
                    {
                        int index = Array.IndexOf(filterButtons, sender);
                        taskTree.SetFilterFunc(filterFuncs [index]);
                    }
                };
            }

            TaskManager.Instance.LoadModel();
        }