public static void RenameUnit(string FileName, string new_val)
        {
            if (CodeCompletion.CodeCompletionController.CurrentParser == null) return;
            ccp = new CodeCompletionProvider();
            IDocument doc = null;
            CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
            string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;
            PascalABCCompiler.SyntaxTree.compilation_unit cu = controller.ParseOnlySyntaxTree(FileName, text);
            PascalABCCompiler.SyntaxTree.ident unitName = null;
            if (cu is PascalABCCompiler.SyntaxTree.unit_module)
            {
                unitName = (cu as PascalABCCompiler.SyntaxTree.unit_module).unit_name.idunit_name;
            }
            else  if (cu is PascalABCCompiler.SyntaxTree.program_module)
            {
                if ((cu as PascalABCCompiler.SyntaxTree.program_module).program_name == null)
                    return;
                unitName = (cu as PascalABCCompiler.SyntaxTree.program_module).program_name.prog_name;
            }

            List<SymbolsViewerSymbol> refers = ccp.Rename(unitName.name, unitName.name, FileName, unitName.source_context.begin_position.line_num, unitName.source_context.begin_position.column_num);
            if (refers == null || new_val == null) return;
            int addit = 0;
            PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0);
            string file_name = null;
            VisualPABCSingleton.MainForm.StopTimer();
            WorkbenchServiceFactory.CodeCompletionParserController.StopParseThread();
            foreach (IFileInfo fi in ProjectFactory.Instance.CurrentProject.SourceFiles)
            {
                WorkbenchServiceFactory.CodeCompletionParserController.RegisterFileForParsing(fi.Path);
            }
            WorkbenchServiceFactory.CodeCompletionParserController.ParseInThread();
            foreach (SymbolsViewerSymbol svs in refers)
            {
                if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line)
                    addit = 0;
                else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column)
                    addit = 0;
                if (svs.SourceLocation.FileName != file_name)
                {
                    CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName);
                    if (cfdoc == null) continue;
                    doc = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document;
                    file_name = svs.SourceLocation.FileName;
                }
                tmp = svs.SourceLocation;
                TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1, svs.SourceLocation.BeginPosition.Line - 1);
                //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column);
                int offset = doc.PositionToOffset(tl_beg);
                //addit += new_val.Length - unitName.name.Length;
                doc.Replace(offset, unitName.name.Length, new_val);
                doc.CommitUpdate();
            }
            WorkbenchServiceFactory.CodeCompletionParserController.RunParseThread();
            VisualPABCSingleton.MainForm.StartTimer();
        }
예제 #2
0
        public static void Rename(TextArea textArea)
        {
            if (CodeCompletion.CodeCompletionController.CurrentParser == null)
            {
                return;
            }
            IDocument doc         = textArea.Document;
            string    textContent = doc.TextContent;

            ccp = new CodeCompletionProvider();
            string name                       = null;
            string expressionResult           = FindOnlyIdent(textContent, textArea, ref name).Trim(' ', '\n', '\t', '\r');
            string new_val                    = null;
            List <SymbolsViewerSymbol> refers = ccp.Rename(expressionResult, name, textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref new_val);

            if (refers == null || new_val == null)
            {
                return;
            }
            int addit = 0;

            PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0);
            string file_name = null;

            foreach (SymbolsViewerSymbol svs in refers)
            {
                if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line)
                {
                    addit = 0;
                }
                else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column)
                {
                    addit = 0;
                }
                if (svs.SourceLocation.FileName != file_name)
                {
                    CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName);
                    if (cfdoc == null)
                    {
                        continue;
                    }
                    doc       = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document;
                    file_name = svs.SourceLocation.FileName;
                }
                tmp = svs.SourceLocation;
                TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1 + addit, svs.SourceLocation.BeginPosition.Line - 1);
                //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column);
                int offset = doc.PositionToOffset(tl_beg);
                addit += new_val.Length - name.Length;
                doc.Replace(offset, name.Length, new_val);
                doc.CommitUpdate();
            }
        }
 public static void Rename(TextArea textArea)
 {
     if (CodeCompletion.CodeCompletionController.CurrentParser == null) return;
     IDocument doc = textArea.Document;
     string textContent = doc.TextContent;
     ccp = new CodeCompletionProvider();
     string name = null;
     string expressionResult = FindOnlyIdent(textContent, textArea, ref name).Trim(' ', '\n', '\t', '\r');
     string new_val = null;
     List<SymbolsViewerSymbol> refers = ccp.Rename(expressionResult, name, textArea.MotherTextEditorControl.FileName, textArea.Caret.Line, textArea.Caret.Column, ref new_val);
     if (refers == null || new_val == null) return;
     int addit = 0;
     PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0);
     string file_name = null;
     foreach (SymbolsViewerSymbol svs in refers)
     {
         if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line)
             addit = 0;
         else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column)
             addit = 0;
         if (svs.SourceLocation.FileName != file_name)
         {
             CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName);
             if (cfdoc == null) continue;
             doc = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document;
             file_name = svs.SourceLocation.FileName;
         }
         tmp = svs.SourceLocation;
         TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1 + addit, svs.SourceLocation.BeginPosition.Line - 1);
         //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column);
         int offset = doc.PositionToOffset(tl_beg);
         addit += new_val.Length - name.Length;
         doc.Replace(offset, name.Length, new_val);
         doc.CommitUpdate();
     }
 }
예제 #4
0
        public static void RenameUnit(string FileName, string new_val)
        {
            if (CodeCompletion.CodeCompletionController.CurrentParser == null)
            {
                return;
            }
            ccp = new CodeCompletionProvider();
            IDocument doc = null;

            CodeCompletion.CodeCompletionController controller = new CodeCompletion.CodeCompletionController();
            string text = WorkbenchServiceFactory.Workbench.VisualEnvironmentCompiler.SourceFilesProvider(FileName, PascalABCCompiler.SourceFileOperation.GetText) as string;

            PascalABCCompiler.SyntaxTree.compilation_unit cu       = controller.ParseOnlySyntaxTree(FileName, text);
            PascalABCCompiler.SyntaxTree.ident            unitName = null;
            if (cu is PascalABCCompiler.SyntaxTree.unit_module)
            {
                unitName = (cu as PascalABCCompiler.SyntaxTree.unit_module).unit_name.idunit_name;
            }
            else if (cu is PascalABCCompiler.SyntaxTree.program_module)
            {
                if ((cu as PascalABCCompiler.SyntaxTree.program_module).program_name == null)
                {
                    return;
                }
                unitName = (cu as PascalABCCompiler.SyntaxTree.program_module).program_name.prog_name;
            }

            List <SymbolsViewerSymbol> refers = ccp.Rename(unitName.name, unitName.name, FileName, unitName.source_context.begin_position.line_num, unitName.source_context.begin_position.column_num);

            if (refers == null || new_val == null)
            {
                return;
            }
            int addit = 0;

            PascalABCCompiler.SourceLocation tmp = new PascalABCCompiler.SourceLocation(null, 0, 0, 0, 0);
            string file_name = null;

            VisualPABCSingleton.MainForm.StopTimer();
            WorkbenchServiceFactory.CodeCompletionParserController.StopParseThread();
            foreach (IFileInfo fi in ProjectFactory.Instance.CurrentProject.SourceFiles)
            {
                WorkbenchServiceFactory.CodeCompletionParserController.RegisterFileForParsing(fi.Path);
            }
            WorkbenchServiceFactory.CodeCompletionParserController.ParseInThread();
            foreach (SymbolsViewerSymbol svs in refers)
            {
                if (svs.SourceLocation.BeginPosition.Line != tmp.BeginPosition.Line)
                {
                    addit = 0;
                }
                else if (svs.SourceLocation.BeginPosition.Column < tmp.BeginPosition.Column)
                {
                    addit = 0;
                }
                if (svs.SourceLocation.FileName != file_name)
                {
                    CodeFileDocumentControl cfdoc = VisualPABCSingleton.MainForm.FindTab(svs.SourceLocation.FileName);
                    if (cfdoc == null)
                    {
                        continue;
                    }
                    doc       = cfdoc.TextEditor.ActiveTextAreaControl.TextArea.Document;
                    file_name = svs.SourceLocation.FileName;
                }
                tmp = svs.SourceLocation;
                TextLocation tl_beg = new TextLocation(svs.SourceLocation.BeginPosition.Column - 1, svs.SourceLocation.BeginPosition.Line - 1);
                //TextLocation tl_end = new TextLocation(svs.SourceLocation.EndPosition.Line,svs.SourceLocation.EndPosition.Column);
                int offset = doc.PositionToOffset(tl_beg);
                //addit += new_val.Length - unitName.name.Length;
                doc.Replace(offset, unitName.name.Length, new_val);
                doc.CommitUpdate();
            }
            WorkbenchServiceFactory.CodeCompletionParserController.RunParseThread();
            VisualPABCSingleton.MainForm.StartTimer();
        }