Exemple #1
0
 public void AddRow(int address, Label alias)
 {
     if (locked)
     {
         return;
     }
     RawAdd(address, alias);
     dataGridView1.Invalidate();
 }
Exemple #2
0
        private static void OutputCsvLine(TextWriter sw, int labelSnesAddress, Label label)
        {
            var outputLine = $"{Util.ToHexString6(labelSnesAddress)},{label.Name},{label.Comment}";

            sw.WriteLine(outputLine);
        }
Exemple #3
0
 private void RawAdd(int address, Label alias)
 {
     dataGridView1.Rows.Add(Util.ToHexString6(address), alias.Name, alias.Comment);
 }
Exemple #4
0
        private void dataGridView1_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if (dataGridView1.Rows[e.RowIndex].IsNewRow)
            {
                return;
            }

            var existingSnesAddressStr = (string)dataGridView1.Rows[e.RowIndex].Cells[0].Value;
            var existingName           = (string)dataGridView1.Rows[e.RowIndex].Cells[1].Value;
            var existingComment        = (string)dataGridView1.Rows[e.RowIndex].Cells[2].Value;

            int.TryParse(existingSnesAddressStr, NumberStyles.HexNumber, null, out var existingSnesAddress);

            var newLabel = new Label
            {
                Name    = existingName,
                Comment = existingComment
            };

            toolStripStatusLabel1.Text = "";
            var newSnesAddress = -1;

            switch (e.ColumnIndex)
            {
            case 0:     // label's address
            {
                if (!int.TryParse(e.FormattedValue.ToString(), NumberStyles.HexNumber, null, out newSnesAddress))
                {
                    e.Cancel = true;
                    toolStripStatusLabel1.Text = "Must enter a valid hex address.";
                    break;
                }

                if (existingSnesAddress == -1 && Data.Labels.GetLabel(newSnesAddress) != null)
                {
                    e.Cancel = true;
                    toolStripStatusLabel1.Text = "This address already has a label.";
                    break;
                }

                if (dataGridView1.EditingControl != null)
                {
                    dataGridView1.EditingControl.Text = Util.ToHexString6(newSnesAddress);
                }
                break;
            }

            case 1:     // label name
            {
                newSnesAddress = existingSnesAddress;
                newLabel.Name  = e.FormattedValue.ToString();
                // todo (validate for valid label characters)
                break;
            }

            case 2:     // label comment
            {
                newSnesAddress   = existingSnesAddress;
                newLabel.Comment = e.FormattedValue.ToString();
                // todo (validate for valid comment characters, if any)
                break;
            }
            }

            locked = true;
            if (currentlyEditing >= 0)
            {
                if (newSnesAddress >= 0)
                {
                    Data.Labels.RemoveLabel(existingSnesAddress);
                }

                Data.Labels.AddLabel(newSnesAddress, newLabel, true);
            }
            locked = false;

            currentlyEditing = -1;
        }