AGS.Editor.Components.FontsComponent.CommandClick C# (CSharp) Method

CommandClick() public method

public CommandClick ( string controlID ) : void
controlID string
return void
        public override void CommandClick(string controlID)
        {
            if (controlID == COMMAND_NEW_ITEM)
            {
                if (_agsEditor.CurrentGame.Fonts.Count == Game.MAX_FONTS)
                {
                    Factory.GUIController.ShowMessage("You already have the maximum number of fonts in your game, and cannot add any more.", MessageBoxIcon.Warning);
                    return;
                }
                IList<AGS.Types.Font> items = _agsEditor.CurrentGame.Fonts;
                AGS.Types.Font newItem = new AGS.Types.Font();
                newItem.ID = items.Count;
                newItem.Name = "Font " + newItem.ID;
                newItem.OutlineStyle = FontOutlineStyle.None;
                newItem.PointSize = items[0].PointSize;
                newItem.SourceFilename = Utilities.GetRelativeToProjectPath(items[0].SourceFilename);
                items.Add(newItem);
                Utilities.CopyFont(0, newItem.ID);
                Factory.NativeProxy.GameSettingsChanged(_agsEditor.CurrentGame);
                _guiController.ProjectTree.StartFromNode(this, TOP_LEVEL_COMMAND_ID);
                _guiController.ProjectTree.AddTreeLeaf(this, GetNodeID(newItem), newItem.ID.ToString() + ": " + newItem.Name, "FontIcon");
                _guiController.ProjectTree.SelectNode(this, GetNodeID(newItem));
                ShowOrAddPane(newItem);
                FontTypeConverter.SetFontList(_agsEditor.CurrentGame.Fonts);
            }
            else if (controlID == COMMAND_DELETE_ITEM)
            {
                if (MessageBox.Show("Are you sure you want to delete this font? Doing so could break any scripts that refer to fonts by number.", "Confirm delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    int removingID = _itemRightClicked.ID;
                    _agsEditor.DeleteFileOnDiskAndSourceControl(_itemRightClicked.WFNFileName);
                    _agsEditor.DeleteFileOnDiskAndSourceControl(_itemRightClicked.TTFFileName);

                    foreach (AGS.Types.Font item in _agsEditor.CurrentGame.Fonts)
                    {
                        if (item.ID > removingID)
                        {
                            if (File.Exists(item.WFNFileName))
                            {
                                _agsEditor.SourceControlProvider.RenameFileOnDiskAndInSourceControl(item.WFNFileName, "agsfnt" + (item.ID - 1) + ".wfn");
                            }
                            if (File.Exists(item.TTFFileName))
                            {
                                _agsEditor.SourceControlProvider.RenameFileOnDiskAndInSourceControl(item.TTFFileName, "agsfnt" + (item.ID - 1) + ".ttf");
                            }
                            item.ID--;
                        }
                    }
                    if (_documents.ContainsKey(_itemRightClicked))
                    {
                        _guiController.RemovePaneIfExists(_documents[_itemRightClicked]);
                        _documents.Remove(_itemRightClicked);
                    }
                    _agsEditor.CurrentGame.Fonts.Remove(_itemRightClicked);
                    _agsEditor.CurrentGame.FilesAddedOrRemoved = true;
                    Factory.NativeProxy.GameSettingsChanged(_agsEditor.CurrentGame);
                    RePopulateTreeView();
                    FontTypeConverter.SetFontList(_agsEditor.CurrentGame.Fonts);
                }
            }
            else
            {
                if (controlID != TOP_LEVEL_COMMAND_ID)
                {
                    AGS.Types.Font chosenFont = _agsEditor.CurrentGame.Fonts[Convert.ToInt32(controlID.Substring(3))];
                    ShowOrAddPane(chosenFont);
                }
            }
        }