Esempio n. 1
0
        internal bool RemoveSlot(SlotConfigWindow scw)
        {
            // Ensure at least 1 active & 1 inactive table stays alive
            if ((scw.CurrentSlot.ActivityUse == Slot.ActivityUses.Active ||
                 scw.CurrentSlot.ActivityUse == Slot.ActivityUses.Inactive) &&
                ActiveProfile.Slots.Count(x => x.ActivityUse == scw.CurrentSlot.ActivityUse) == 1)
            {
                Logger.Log("You must have at least one active and one inactive slot. " +
                           "Press Cancel or Save to close the table setup instead",
                           Logger.Status.Warning, showMessageBox: true);
                return(false); // don't allow close
            }

            Logger.Log("SlotConfigHandler: " +
                       $"RemoveSlot() scw {scw.GetHashCode()}");

            if (ActiveProfile.Slots.Count(s => s.Id == scw.CurrentSlot.Id) == 0)
            {
                Logger.Log("SlotConfigHandler: " +
                           $"RemoveSlot() closing a table {scw.GetHashCode()} that's already removed. Called twice?", Logger.Status.Error);
            }

            ActiveProfile.Slots.RemoveAll(s => s.Id == scw.CurrentSlot.Id);         // remove slot
            slotConfigWindows.RemoveAll(x => x.GetHashCode() == scw.GetHashCode()); // remove window
            // Lower possible max id in other tables
            // todo: Fix the ugly code
            string dirtyIdString = (string)((ComboBoxItem)scw.prioCb.SelectedItem).Content;

            ReduceMaxIdAllWindows(dirtyIdString == "Auto" ? 0 :  int.Parse(dirtyIdString));
            // close happens in window class
            return(true);
        }
Esempio n. 2
0
        internal void AddSlot(Slot slot = null, bool isNew = false)
        {
            // Define slot if null
            if (slot == null)
            {
                slot = new Slot(Slot.ActivityUses.Inactive, 0, 0, 480, 366);
                ActiveProfile.Slots.Add(slot);
            }
            else if (isNew)
            {
                ActiveProfile.Slots.Add(slot);
            }

            Logger.Log("SlotConfigHandler: " +
                       $"AddTable() with slot {slot.Id}");

            // Display new slotconfigwindow
            var scw = new SlotConfigWindow(this, slot);

            scw.Show();

            // Correct amount of windows for prioCb, then add to list
            IncreaseMaxIdAllWindows();
            slotConfigWindows.Add(scw);

            // Set up idCb
            for (int i = 0; i < slotConfigWindows.Count; i++)
            {
                var cbi = new ComboBoxItem();
                cbi.Content = (i + 1).ToString();
                scw.prioCb.Items.Add(cbi);
            }

            // Set correct idCb index
            try
            {
                scw.prioCb.SelectedIndex = scw.CurrentSlot.Priority;
            }
            catch (IndexOutOfRangeException ioorEx)
            {
                Logger.Log($"SlotConfigHandler: {ioorEx.HResult} Failed to set ID combobox. " +
                           "Out of range - corrupt config file? Setting to auto", Logger.Status.Error);
                scw.prioCb.SelectedIndex = 0;
            }

            // Setup ActivityUsesBox
            scw.ActivityUsesBox.ItemsSource   = Enum.GetValues(typeof(Slot.ActivityUses)).Cast <Slot.ActivityUses>();
            scw.ActivityUsesBox.SelectedIndex = (int)slot.ActivityUse;

            // Validate change requests on ActivityUsesBox
            scw.CurrentSlot.ActivityUseChangedEventHandler += Scw_ActivityUseChangedEventHandler;
        }