예제 #1
0
        public override bool Rename(string newName)
        {
            //Add .galaxy++ if not present
            if (!newName.EndsWith(".Dialog"))
            {
                newName = newName + ".Dialog";
            }

            //Dont reneme if there is a clash
            foreach (FileSystemInfo dir in Parent.Dir.GetFileSystemInfos())
            {
                if (dir.Name == newName + ".Dialog")
                {
                    return(false);
                }
            }

            File.Move(Parent.Dir.FullName + "\\" + Name,
                      Parent.Dir.FullName + "\\" + newName);
            string oldName = Name;

            Name = newName;
            InvokeRenamed(this, oldName, newName);

            //Change other stuff
            string shortName = Name.Substring(0, Name.LastIndexOf(".Dialog"));

            CodeGUINode.Text     = shortName + (CodeGUINode.Text.EndsWith("*") ? ".galaxy++*" : ".galaxy++");
            DesignerGUINode.Text = shortName + (DesignerGUINode.Text.EndsWith("*") ? ".Designer.galaxy++*" : ".Designer.galaxy++");
            if (OpenFileData != null)
            {
                if (OpenFileData.TabPage != null)
                {
                    OpenFileData.TabPage.Title = Name + (OpenFileData.TabPage.Title.EndsWith("*") ? "*" : "");
                }
                if (OpenFileData.CodeTabPage != null)
                {
                    OpenFileData.CodeTabPage.Title = shortName + (OpenFileData.CodeTabPage.Title.EndsWith("*") ? ".galaxy++*" : ".galaxy++");
                }
                if (OpenFileData.DesignerTabPage != null)
                {
                    OpenFileData.DesignerTabPage.Title = shortName + ".Designer.galaxy++";
                }
            }
            //Fix refferences to dialog
            try
            {
                DialogData data;
                if (OpenFileData != null)
                {
                    data = OpenFileData;
                }
                else
                {
                    data            = DialogData.Load(FullName);
                    data.DialogItem = this;
                }
                string code = data.ActualCode;
                Name = oldName;
                string oldIdentifier = data.DialogIdentiferName;
                Name = newName;
                string       newIdentifier = data.DialogIdentiferName;
                Parser       parser        = new Parser(new Lexer(new StringReader(code)));
                AASourceFile start         = (AASourceFile)parser.Parse().GetPSourceFile();
                Renamer      ren           = new Renamer(oldIdentifier);
                start.Apply(ren);
                ren.types.Reverse();//To avoid changeing the position of stuff we must change
                string[] lines = code.Split('\n');
                foreach (TIdentifier identifier in ren.types)
                {
                    lines[identifier.Line - 1] = lines[identifier.Line - 1].Substring(0, identifier.Pos - 1) +
                                                 newIdentifier +
                                                 lines[identifier.Line - 1].Substring(identifier.Pos +
                                                                                      oldIdentifier.Length - 1);
                }
                string newCode = "";
                foreach (string line in lines)
                {
                    newCode += line + "\n";
                }
                newCode = newCode.Remove(code.Length);
                if (code != newCode)
                {
                    if (OpenFileData == null)
                    {
                        Form1.Form.OpenFile(this, CodeGUINode);
                    }
                    OpenFileData.ActualCode = newCode;
                }
            }
            catch (Exception err)
            {
                //Or not..
            }
            Form1.Form.compiler.DialogItemChanged(this, null, true);
            return(true);
        }