private ActivityCategoryWrapper AddCategoryNode(ActivityCategoryWrapper categoryNode, ActivityCategoryWrapper parent)
        {
            IActivityCategory category = (IActivityCategory)categoryNode.Element;
            ActivityCategoryWrapper selection = null;

            if (parent != null)
            {
                parent.Children.Add(categoryNode);

                if (Options.Instance.LastImportCategory == category)
                {
                    selection = categoryNode;
                }
            }

            foreach (IActivityCategory currentCategory in category.SubCategories)
            {
                if (Options.Instance.GetVisibleInWorkoutList(currentCategory))
                {
                    ActivityCategoryWrapper childSelection = null;
                    ActivityCategoryWrapper newNode = new ActivityCategoryWrapper(categoryNode, currentCategory);

                    childSelection = AddCategoryNode(newNode, categoryNode);

                    if (childSelection != null)
                    {
                        selection = childSelection;
                    }
                }
            }

            return selection;
        }
        public SelectCategoryDialog(string workoutName)
        {
            InitializeComponent();

            this.Text = GarminFitnessView.GetLocalizedString("SelectCategoryDialogText") + workoutName;
            SelectCategoryLabel.Text = this.Text;
            UseCategoryForAllCheckBox.Text = GarminFitnessView.GetLocalizedString("UseCategoryForAllCheckBoxText");
            OkButton.Text = CommonResources.Text.ActionOk;

            // Fill list
            List<TreeList.TreeListNode> categories = new List<TreeList.TreeListNode>();
            List<TreeList.TreeListNode> selection = new List<TreeList.TreeListNode>();

            foreach (IActivityCategory currentCategory in PluginMain.GetApplication().Logbook.ActivityCategories)
            {
                if (Options.Instance.GetVisibleInWorkoutList(currentCategory))
                {
                    ActivityCategoryWrapper childSelection = null;
                    ActivityCategoryWrapper newNode = new ActivityCategoryWrapper(null, currentCategory);

                    categories.Add(newNode);
                    childSelection = AddCategoryNode(newNode, null);

                    if (Options.Instance.LastImportCategory == currentCategory)
                    {
                        selection.Add(newNode);
                    }
                    else if (childSelection != null)
                    {
                        selection.Add(childSelection);
                    }
                }
            }

            if (selection.Count == 0)
            {
                selection.Add(categories[0]);
            }

            ActivityCategoryList.RowData = categories;
            ActivityCategoryList.Columns.Clear();
            ActivityCategoryList.Columns.Add(new TreeList.Column("Name", GarminFitnessView.GetLocalizedString("CategoryText"),
                                                         150, StringAlignment.Near));
            ActivityCategoryList.Selected = selection;
        }
 public ActivityCategoryWrapper(ActivityCategoryWrapper parent, IActivityCategory element)
     : base(parent, element)
 {
 }
Esempio n. 4
0
 public WorkoutWrapper(ActivityCategoryWrapper parent, Workout element)
     : base(parent, element)
 {
 }
        private WorkoutWrapper GetWorkoutWrapper(Workout workout, ActivityCategoryWrapper parent)
        {
            WorkoutWrapper wrapper = null;

            if (GarminWorkoutManager.Instance.Workouts.Contains(workout))
            {
                // If we already have a wrapper for this workout, use it
                if (m_WorkoutWrapperMap.ContainsKey(workout))
                {
                    wrapper = m_WorkoutWrapperMap[workout];
                }
                else
                {
                    // Create a new wrapper
                    wrapper = new WorkoutWrapper(parent, workout);

                    m_WorkoutWrapperMap[workout] = wrapper;
                }
            }

            return wrapper;
        }
        private ActivityCategoryWrapper GetActivityCategoryWrapper(IActivityCategory category, ActivityCategoryWrapper parent)
        {
            ActivityCategoryWrapper wrapper;

            // If we already have a wrapper for this category, use it
            if (m_CategoryWrapperMap.ContainsKey(category))
            {
                wrapper = m_CategoryWrapperMap[category];
            }
            else
            {
                // Create a new wrapper
                wrapper = new ActivityCategoryWrapper(parent, category);

                m_CategoryWrapperMap[category] = wrapper;
            }

            return wrapper;
        }
        private void CreateCategoryNode(ActivityCategoryWrapper categoryNode, ActivityCategoryWrapper parent)
        {
            IActivityCategory category = (IActivityCategory)categoryNode.Element;

            if (parent != null)
            {
                parent.Children.Add(categoryNode);
            }
            categoryNode.Parent = parent;

            foreach (IActivityCategory subCategory in category.SubCategories)
            {
                if(Options.Instance.GetVisibleInWorkoutList(subCategory))
                {
                    ActivityCategoryWrapper wrapper = GetActivityCategoryWrapper(subCategory, categoryNode);
                    wrapper.Children.Clear();

                    CreateCategoryNode(wrapper, categoryNode);
                }
            }
        }