internal void AddTimerMenuItemToMainMenu(ClockMenuItem tmi)
 {
     if (!AlreadyExistsInMenus((ClockVM)tmi.DataContext))
     {
         Items.Insert(Items.Count - 1, tmi);
     }
 }
        private void Model_ClockRemoved(object sender, ClockEventArgs e)
        {
            var td = e.Clock as TimerData;

            if (td == null)
            {
                return;
            }

            ClockVM vm = MyDataFile.ClockVMCollection.VMForM(td);

            bool          active = true;
            ClockMenuItem tmi    = ExistingClockMenuItemInActiveMenu(vm);

            if (tmi == null)
            {
                active = false;
                //tmi = ExistingClockMenuItemInInactiveMenu(vm);
            }
            if (tmi != null)
            {
                if (active)
                {
                    Items.Remove(tmi);
                }
                else
                {
                    //MyInactiveMenuItem.Items.Remove(tmi);
                }
            }

            UpdateSeparatorsVisibility();
        }
        private void Model_ClockMoved(object sender, ClockMovedEventArgs e)
        {
            var td = e.Clock as TimerData;

            if (td == null)
            {
                return;
            }

            ClockVM vm = MyDataFile.ClockVMCollection.VMForM(td);

            bool          active = true;
            ClockMenuItem tmi    = ExistingClockMenuItemInActiveMenu(vm);

            //if (tmi == null)
            //{
            //    active = false;
            //    tmi = ExistingClockMenuItemInInactiveMenu(vm);
            //}
            if (tmi != null)
            {
                // TODO: What if e.NewIndex does not care about FilteredOut property of ClockData?

                //if (active)
                //{
                Items.Remove(tmi);

                int idx = Math.Min(e.NewIndex, Items.Count);

                Items.Insert(idx, tmi);
                //}
                //else
                //{
                //    MyInactiveMenuItem.Items.Remove(tmi);

                //    int idx = Math.Min(e.NewIndex, MyInactiveMenuItem.Items.Count);

                //    MyInactiveMenuItem.Items.Insert(idx, tmi);
                //}
            }
        }
        private void Model_ClockAdded(object sender, ClockEventArgs e)
        {
            if (e.Clock is TimerData tdd)
            {
                ClockVM vm = MyDataFile.ClockVMCollection.VMForM(tdd);

                var tmi = new ClockMenuItem();
                tmi.DataContext = vm;
                if (tdd.Running)
                {
                    AddTimerMenuItemToMainMenu(tmi);
                }
                else
                {
                    AddTimerMenuItemToMainMenu(tmi);
                    //MyInactiveMenuItem.Items.Insert(0, tmi);
                }
            }

            UpdateSeparatorsVisibility();
        }
        internal void HandleClockRemoval(ClockM c)
        {
            var td = c as TimerData;

            if (td == null)
            {
                return;
            }

            ClockVM vm = MyDataFile.ClockVMCollection.VMForM(td);

            ClockMenuItem tmi = ExistingClockMenuItemInActiveMenu(vm);

            if (tmi != null)
            {
                //tmi.UpdateImage();
                //ToolStrip p = tmi.Owner;
                //Items.Remove(tmi);
                //MyInactiveMenuItem.Items.Insert(0, tmi);
            }

            UpdateSeparatorsVisibility();
        }
        private void Model_ClocksAdded(object sender, ClocksEventArgs e)
        {
            foreach (ClockM m in e.Clocks)
            {
                ClockVM vm = MyDataFile.ClockVMCollection.VMForM(m);

                if (m is TimerData tdd)
                {
                    var tmi = new ClockMenuItem();
                    tmi.DataContext = vm;
                    //if (tdd.Running)
                    //{
                    AddTimerMenuItemToMainMenu(tmi);
                    //}
                    //else
                    //{
                    //    MyInactiveMenuItem.Items.Insert(0, tmi);
                    //}
                }
            }

            UpdateSeparatorsVisibility();
        }