Ejemplo n.º 1
0
        /// <summary>
        /// Initializes
        /// </summary>
        public void Initialize()
        {
            Builder.AddFromFile("MainWin.glade");
            TaskPropertyDialogMaker.Initialize();

            MainWindow            = Builder.GetObject("MainWindow") as Window;
            MainWindow.Destroyed += app_quit;

            TaskStore = Builder.GetObject("TaskStore") as TreeStore;
            TaskList  = (TreeView)Builder.GetObject("TaskView");

            TaskSelection = (TreeSelection)Builder.GetObject("TaskSelection");

            //TaskStore = new TreeStore (GType.Int, GType.String, GType.String);
            TaskStore = (TreeStore)Builder.GetObject("TaskStore");
            CatStore  = (ListStore)Builder.GetObject("CatStore");
            buildCats();
            TaskList.Model = TaskStore;

            IdColumn    = (TreeViewColumn)Builder.GetObject("TaskIdColumn");
            NameColumn  = (TreeViewColumn)Builder.GetObject("TaskNameColumn");
            StateColumn = (TreeViewColumn)Builder.GetObject("TaskStatusColumn");

            var idCellRendererText    = new CellRendererText();
            var nameCellRendererText  = new CellRendererText();
            var stateCellRendererText = new CellRendererText();

            IdColumn.PackStart(idCellRendererText, true);
            NameColumn.PackStart(nameCellRendererText, true);
            StateColumn.PackStart(stateCellRendererText, true);

            IdColumn.AddAttribute(idCellRendererText, "text", (int)ColAssign.Id);
            NameColumn.AddAttribute(nameCellRendererText, "text", (int)ColAssign.Name);
            StateColumn.AddAttribute(stateCellRendererText, "text", (int)ColAssign.State);

            nameCellRendererText.Editable = true;
            nameCellRendererText.Edited  += nameChanged;

            var catNameCellRender = (CellRendererText)Builder.GetObject("CatStatusNameRender");

            catNameCellRender.Editable = true;
            catNameCellRender.Edited  +=
                delegate(object o, EditedArgs args)
            {
                TreeIter iter;
                CatStore.GetIterFromString(out iter, args.Path);
                CatStore.SetValue(iter, 1, args.NewText);
                var catId = (int)CatStore.GetValue(iter, 0);
                Tasks.GetById <Category> (catId).Name = args.NewText;
            };


            StatusBar = Builder.GetObject("Status bar") as Statusbar;

            NewTaskAction = Builder.GetObject("actNewTask") as Gtk.Action;
            NewChildTask  = Builder.GetObject("actNewChild") as Gtk.Action;
            RemoveTask    = Builder.GetObject("actRemove") as Gtk.Action;
            StartTask     = Builder.GetObject("actStart") as Gtk.Action;
            StopTask      = Builder.GetObject("actStop") as Gtk.Action;
            FinishTask    = Builder.GetObject("actFinish") as Gtk.Action;
            EditTask      = Builder.GetObject("actEditTask") as Gtk.Action;

            ((Gtk.Action)Builder.GetObject("actSave")).Activated    += save;
            ((Gtk.Action)Builder.GetObject("actSaveAs")).Activated  += saveAs;
            ((Gtk.Action)Builder.GetObject("actLoad")).Activated    += load;
            ((Gtk.Action)Builder.GetObject("actExit")).Activated    += app_quit;
            ((Gtk.Action)Builder.GetObject("cat.AddCat")).Activated += delegate
            {
                var newCat = Tasks.AddCategory();
                newCat.Name = "Cat";

                CatStore.AppendValues(newCat.Id, newCat.Name, true, true);
            };

            var toggleCatRender = ((CellRendererToggle)Builder.GetObject("CatStatusCellRender"));

            toggleCatRender.Toggled += delegate(object o, ToggledArgs args)
            {
                TreeIter iter;
                if (!CatStore.GetIterFromString(out iter, args.Path))
                {
                    return;
                }

                var state = (bool)CatStore.GetValue(iter, 3);
                var indet = (bool)CatStore.GetValue(iter, 2);

                if (indet)
                {
                    indet = false;
                    state = false;
                }
                else
                {
                    if (state)
                    {
                        indet = true;
                    }
                    else
                    {
                        state = true;
                    }
                }

                CatStore.SetValue(iter, 3, state);
                CatStore.SetValue(iter, 2, indet);

                CurrentFilter.Refilter();
            };

            ((Gtk.Action)Builder.GetObject("actContractAll")).Activated += delegate
            {
                TaskList.CollapseAll();
            };

            ((Gtk.Action)Builder.GetObject("actExpandAll")).Activated += expandTasks;

            ((Gtk.Action)Builder.GetObject("actFilterAll")).Activated += delegate
            {
                var togActive = (ToggleToolButton)Builder.GetObject("togFilterActive");
                var togComplt = (ToggleToolButton)Builder.GetObject("togFilterComplete");
                togActive.Active            = false;
                togComplt.Active            = false;
                FilterOptions.ShowCompleted = true;
                FilterOptions.ShowInactive  = true;
                CurrentFilter.Refilter();
            };
            ((Gtk.Action)Builder.GetObject("actFilterActive")).Activated += delegate
            {
                FilterOptions.ShowInactive = !FilterOptions.ShowInactive;
                CurrentFilter.Refilter();
            };
            ((Gtk.Action)Builder.GetObject("actFilterUnfinished")).Activated += delegate
            {
                FilterOptions.ShowCompleted = !FilterOptions.ShowCompleted;
                CurrentFilter.Refilter();
            };

            NewTaskAction.Activated += newTask;
            NewChildTask.Activated  += newChild;
            RemoveTask.Activated    += removeTask;
            EditTask.Activated      += delegate
            {
                TaskPropertyDialogMaker.Task = GetSelectedTask();
                TaskPropertyDialogMaker.BuildWindow();
                TaskPropertyDialogMaker.AfterResponse = delegate
                {
                    // iter.HasValue is asserted
                    var iter = GetSelectedIter().Value;
                    reloadIter(iter);
                };

                TaskPropertyDialogMaker.Dialog.Run();
            };
            StartTask.Activated += delegate
            {
                setTaskStatus(GetSelectedIter().Value, TaskStatus.Active);
            };

            StopTask.Activated += delegate
            {
                setTaskStatus(GetSelectedIter().Value, TaskStatus.Inactive);
            };

            FinishTask.Activated += delegate
            {
                setTaskStatus(GetSelectedIter().Value, TaskStatus.Completed);
            };

            FilterOptions             = new TaskFilter(Tasks);
            FilterOptions.CatRules    = getCurrentCatFilter;
            CurrentFilter             = new TreeModelFilter(TaskStore, null);
            CurrentFilter.VisibleFunc = FilterOptions.ApplyFilter;
            TaskList.Model            = CurrentFilter;

            TaskSelection.Changed += updateSensibility;
            updateSensibility(this, null);
        }