The ask for name.
Inheritance: System.Windows.Forms.Form
Example #1
0
        /// <summary>
        /// Renames a TAG without rebuilding the map.
        /// Allows names to be expanded by however many characters are available in the padding.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The e.</param>
        /// <remarks></remarks>
        private void renameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int extraSpace = map.FileNames.Offset[map.FileNames.Offset.Length - 1];
            extraSpace = map.MapHeader.offsetTofileIndex - map.MapHeader.offsetTofileNames - extraSpace - 1;

            newName = treeView1.SelectedNode.Text;
            do
            {
                // Create a form for renaming a new tag
                askForName a = new askForName("Rename Tag", "Enter new tag name", "&Rename Tag", newName, newName.Substring(newName.LastIndexOf('\\') + 1), true);
                if (a.ShowDialog() != DialogResult.OK)
                {
                    return;
                }

                newName = a.getTextBoxValue();
                a.Dispose();

                // Check if there is enough space for new name
                if (extraSpace - (newName.Length - treeView1.SelectedNode.Text.Length) < 0)
                {
                    MessageBox.Show(
                        "Name is " + (-(extraSpace - (newName.Length - treeView1.SelectedNode.Text.Length))) +
                        " characters too long!");
                }
            }
            while (extraSpace - (newName.Length - treeView1.SelectedNode.Text.Length) < 0);

            if (newName == treeView1.SelectedNode.Text)
            {
                return;
            }

            if (newName != string.Empty)
            {
                int id = map.Functions.ForMeta.FindByNameAndTagType(
                    treeView1.SelectedNode.Parent.Text, treeView1.SelectedNode.Text);
                if (id == -1)
                {
                    MessageBox.Show("Tag name cannot be found in Meta!");
                    return;
                }

                int offset = map.FileNames.Offset[id];
                int diff = newName.Length - treeView1.SelectedNode.Text.Length;
                map.FileNames.Name[id] = newName;
                map.OpenMap(MapTypes.Internal);
                BinaryReader br = map.BR;
                BinaryWriter bw = map.BW;

                // If we are removing characters, null out data at end
                if (diff < 0)
                {
                    bw.BaseStream.Position = map.MapHeader.offsetTofileNames +
                                             map.FileNames.Offset[map.FileNames.Offset.Length - 1] +
                                             map.FileNames.Length[map.FileNames.Name.Length - 1];
                    bw.Write(new byte[-diff]);
                }

                // reposition filename within file and update the filename index
                for (int x = map.FileNames.Offset.Length - 1; x >= 0; x--)
                {
                    if (map.FileNames.Offset[x] >= offset)
                    {
                        br.BaseStream.Position = map.MapHeader.offsetTofileIndex + x * 4;
                        int o = br.ReadInt32();

                        map.FileNames.Offset[x] += diff;
                        bw.BaseStream.Position = map.MapHeader.offsetTofileIndex + x * 4;
                        bw.Write(map.FileNames.Offset[x]);
                        bw.BaseStream.Position = map.MapHeader.offsetTofileNames + map.FileNames.Offset[x];
                        bw.Write(map.FileNames.Name[x].ToCharArray());
                        bw.Write((byte)0);
                    }
                    else
                    {
                        break;
                    }
                }

                map.CloseMap();
                toolStripHistoryList.DropDownItems[0].Name = "[" + map.MetaInfo.TagType[id] + "] " + newName;
                toolStripHistoryList.DropDownItems[0].Text = toolStripHistoryList.DropDownItems[0].Name;
                toolStripHistoryList.DropDownItems[0].Tag = new[]
                    {
                       id.ToString(), map.MetaInfo.TagType[id], map.FileNames.Name[id]
                    };
                addToQuickList(map.MetaInfo.TagType[id], map.FileNames.Name[id]);
                RefreshTreeView();
                tsItem_Click(toolStripHistoryList.DropDownItems[0], null);
            }
        }
Example #2
0
 /// <summary>
 /// The rename map button_ click.
 /// </summary>
 /// <param name="sender">The sender.</param>
 /// <param name="e">The e.</param>
 /// <remarks></remarks>
 private void renameMapButton_Click(object sender, EventArgs e)
 {
     string newName = map.MapHeader.mapName;
     askForName a = new askForName( "Rename Map Internally", "Enter new map name", "&Rename Map",
                                    map.MapHeader.scenarioPath, newName, true);
     if (a.ShowDialog() == DialogResult.OK)
     {
         this.setMapName(a.getTextBoxValue());
         a.Dispose();
     }
 }