コード例 #1
0
        /// <summary>
        /// Saves the current collection of splits (if valid).
        /// </summary>
        public void SaveSplits(bool updateStatus)
        {
            // This check prevents accidentialy wiping all splits on load.
            if (splitControls.Count == 0)
            {
                return;
            }

            Split[] splits = new Split[splitControls.Count];

            for (int i = 0; i < splits.Length; i++)
            {
                SplitControl control = (SplitControl)splitControls[i];
                splits[i] = new Split(control.SplitType, control.SplitData);
            }

            int invalidIndex;

            if (ValidateSplits(splits, out invalidIndex))
            {
                SplitCollection.Splits = splits;

                if (updateStatus)
                {
                    UpdateStatusLabel("Splits saved.", Color.Green);
                }
            }
            else if (updateStatus)
            {
                UpdateStatusLabel($"Invalid split (line {invalidIndex + 1}).", Color.Red);
            }
        }
コード例 #2
0
        /// <summary>
        /// Moves the given control down.
        /// </summary>
        public void MoveDown(SplitControl control)
        {
            int index = splitControls.IndexOf(control);

            Swap(index, index + 1);
            SaveSplits(false);
        }
コード例 #3
0
        /// <summary>
        /// Removes the given split control from the panel's collection.
        /// </summary>
        public void Remove(SplitControl control)
        {
            int index = splitControls.IndexOf(control);

            splitControls.RemoveAt(index);

            if (splitControls.Count > 0)
            {
                for (int i = index; i < splitControls.Count; i++)
                {
                    SplitControl toMove = (SplitControl)splitControls[i];
                    toMove.Location = toMove.Location.Subtract(spacing);
                    toMove.Index    = i + 1;
                }

                if (index == 0)
                {
                    ((SplitControl)splitControls[index]).ToggleUp(false);
                }

                if (index == splitControls.Count)
                {
                    ((SplitControl)splitControls.Last()).ToggleDown(false);
                }
            }

            UpdateCountLabel();
            SaveSplits(false);
        }
コード例 #4
0
        /// <summary>
        /// Called when the Add Split button is pressed.
        /// </summary>
        private void addSplitButton_Click(object sender, EventArgs e)
        {
            SplitControl newSplit = new SplitControl(this, splitControls.Count + 1);

            if (splitControls.Count > 0)
            {
                SplitControl control = (SplitControl)splitControls.Last();

                newSplit.Location = control.Location.Add(spacing);
                control.ToggleDown(true);
            }

            newSplit.ToggleUp(splitControls.Count > 0);
            newSplit.ToggleDown(false);
            splitControls.Add(newSplit);

            UpdateCountLabel();
        }
コード例 #5
0
        /// <summary>
        /// Swaps the two split controls with the given indices.
        /// </summary>
        private void Swap(int index1, int index2)
        {
            SplitControl control1 = (SplitControl)splitControls[index1];
            SplitControl control2 = (SplitControl)splitControls[index2];

            Point temporaryLocation = control1.Location;

            control1.Location = control2.Location;
            control2.Location = temporaryLocation;

            splitControls.SetChildIndex(control1, index2);
            splitControls.SetChildIndex(control2, index1);

            ToggleButtons(control1, index2);
            ToggleButtons(control2, index1);

            control1.Index = index2 + 1;
            control2.Index = index1 + 1;
        }
コード例 #6
0
 /// <summary>
 /// Toggles up/down buttons on the given split control based on the given index.
 /// </summary>
 private void ToggleButtons(SplitControl control, int index)
 {
     control.ToggleUp(index > 0);
     control.ToggleDown(index < splitControls.Count - 1);
 }