Exemple #1
0
        private void mnuDelete_Click(object sender, EventArgs e)
        {
            if (lstLabels.SelectedIndices.Count > 0)
            {
                int        topIndex          = lstLabels.TopItem.Index;
                int        lastSelectedIndex = lstLabels.SelectedIndices[lstLabels.SelectedIndices.Count - 1];
                List <int> selectedIndexes   = new List <int>(lstLabels.SelectedIndices.Cast <int>().ToList());
                for (int i = selectedIndexes.Count - 1; i >= 0; i--)
                {
                    CodeLabel label = (CodeLabel)_listItems[selectedIndexes[i]].SubItems[1].Tag;
                    LabelManager.DeleteLabel(label, i == 0);
                }

                //Reposition scroll bar and selected/focused item
                if (lstLabels.Items.Count > topIndex)
                {
                    lstLabels.TopItem = lstLabels.Items[topIndex];
                }
                if (lastSelectedIndex < lstLabels.Items.Count)
                {
                    lstLabels.Items[lastSelectedIndex].Selected = true;
                }
                else if (lstLabels.Items.Count > 0)
                {
                    lstLabels.Items[lstLabels.Items.Count - 1].Selected = true;
                }
                if (lstLabels.SelectedIndices.Count > 0)
                {
                    GetSelectedItem().Focused = true;
                }
            }
        }
Exemple #2
0
        private void mnuDelete_Click(object sender, EventArgs e)
        {
            if (lstLabels.SelectedItems.Count > 0)
            {
                int topIndex          = lstLabels.TopItem.Index;
                int lastSelectedIndex = lstLabels.SelectedIndices[lstLabels.SelectedIndices.Count - 1];
                for (int i = lstLabels.SelectedItems.Count - 1; i >= 0; i--)
                {
                    CodeLabel label = (CodeLabel)lstLabels.SelectedItems[i].SubItems[1].Tag;
                    LabelManager.DeleteLabel(label.Address, label.AddressType, i == 0);
                }

                //Reposition scroll bar and selected/focused item
                if (lstLabels.Items.Count > topIndex)
                {
                    lstLabels.TopItem = lstLabels.Items[topIndex];
                }
                if (lastSelectedIndex < lstLabels.Items.Count)
                {
                    lstLabels.Items[lastSelectedIndex].Selected = true;
                }
                else if (lstLabels.Items.Count > 0)
                {
                    lstLabels.Items[lstLabels.Items.Count - 1].Selected = true;
                }
                if (lstLabels.SelectedItems.Count > 0)
                {
                    lstLabels.SelectedItems[0].Focused = true;
                }
            }
        }
Exemple #3
0
        public static void EditLabel(UInt32 address, AddressType type)
        {
            CodeLabel existingLabel = LabelManager.GetLabel(address, type);
            CodeLabel newLabel      = new CodeLabel()
            {
                Address     = existingLabel?.Address ?? address,
                AddressType = existingLabel?.AddressType ?? type,
                Label       = existingLabel?.Label,
                Comment     = existingLabel?.Comment,
                Length      = existingLabel?.Length ?? 1
            };

            frmEditLabel frm = new frmEditLabel(newLabel, existingLabel);

            if (frm.ShowDialog() == DialogResult.OK)
            {
                bool empty = string.IsNullOrWhiteSpace(newLabel.Label) && string.IsNullOrWhiteSpace(newLabel.Comment);
                if (existingLabel != null)
                {
                    LabelManager.DeleteLabel(existingLabel, empty);
                }
                if (!empty)
                {
                    LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length);
                }
            }
        }
Exemple #4
0
        public void DeleteLabel()
        {
            LabelManager label  = new LabelManager();
            var          result = label.DeleteLabel(1);

            Assert.NotNull(result);
        }
Exemple #5
0
        public static void EditComment(UInt32 address, AddressType type)
        {
            string    autoName      = "C" + address.ToString("X4");
            CodeLabel existingLabel = LabelManager.GetLabel(address, type);
            CodeLabel newLabel      = new CodeLabel()
            {
                Address     = existingLabel?.Address ?? address,
                AddressType = existingLabel?.AddressType ?? type,
                Label       = existingLabel?.Label,
                Comment     = existingLabel?.Comment,
                Length      = existingLabel?.Length ?? 1
            };

            if (existingLabel == null)
            {
                newLabel.Label = autoName;
            }
            bool isMultiLine = false;

            if (existingLabel != null && existingLabel.Comment.Contains("\r\n"))
            {
                isMultiLine = true;
            }

            if (isMultiLine)
            {
                frmEditLabel frm = new frmEditLabel(newLabel, existingLabel, true);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName;
                    if (existingLabel != null)
                    {
                        LabelManager.DeleteLabel(existingLabel, empty);
                    }
                    if (!empty)
                    {
                        LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length);
                    }
                }
            }
            else
            {
                frmEditComment frm = new frmEditComment(newLabel, existingLabel);
                if (frm.ShowDialog() == DialogResult.OK)
                {
                    bool empty = string.IsNullOrWhiteSpace(newLabel.Comment) && newLabel.Label == autoName;
                    if (existingLabel != null)
                    {
                        LabelManager.DeleteLabel(existingLabel, empty);
                    }
                    if (!empty)
                    {
                        LabelManager.SetLabel(newLabel.Address, newLabel.AddressType, newLabel.Label, newLabel.Comment, true, CodeLabelFlags.None, newLabel.Length);
                    }
                }
            }
        }