/// <summary>
        /// Copies the file header from the source interface to the contract file.
        /// </summary>
        /// <param name="filePath">The file path.</param>
        private void CopyFileHeader(string filePath)
        {
            this.CodeRushProxy.File.Activate(filePath);

            // Do not dispose, belongs to CodeRush
            TextDocument contractClassDocument = this.CodeRushProxy.Documents.GetTextDocument(filePath);

            if (contractClassDocument == null)
            {
                return;
            }

            var commentInsertionPoint = contractClassDocument.Range.Top;

            foreach (var headerComment in this.InterfaceUpdater.InterfaceFileComments)
            {
                if (headerComment == null)
                {
                    continue;
                }

                string commentText           = headerComment.Name ?? string.Empty;
                var    contractHeaderComment = new Comment()
                {
                    CommentType = headerComment.CommentType,
                    Name        = commentText.Replace(this.InterfaceName, this.ContractClassName)
                };
                contractClassDocument.InsertText(commentInsertionPoint, this.CodeRushProxy.Language.GenerateElement(contractHeaderComment, this.Language));
                commentInsertionPoint.Line++;
            }

            contractClassDocument.Format();
        }
        public void Organize(
            TextDocument txtDoc, LanguageElement activeType, bool addRegions)
        {
            typeDeclaration = activeType as TypeDeclaration;
            if (typeDeclaration == null)
            {
                return;
            }

            if (txtDoc == null)
            {
                return;
            }

            textDocument = txtDoc;

            SourcePoint cursorPosition = CodeRush.Caret.SourcePoint;

            try
            {
                Class currentClass = typeDeclaration.GetClass();
                if (currentClass == null || currentClass.Document == null)
                {
                    return;
                }

                textDocument.Lock();
                InitializeDictionary();
                //Clear out list of regions that have been deleted
                deletedRegions.Clear();
                //clean out the string builder
                codeToInsert.Remove(0, codeToInsert.Length);

                ReadCodeElements(currentClass);
                BuildCode(addRegions);

                ApplyEdits();
            }
            catch (Exception ex)
            {
                Utilities.HandleException(ex);
            }
            finally
            {
                if (cursorPosition != SourcePoint.Empty)
                {
                    CodeRush.Caret.MoveTo(cursorPosition);
                }

                textDocument.Unlock();
                textDocument.Format();
            }
        }
        private void ConvertProperty(TextDocument textDocument, Property property)
        {
            if (textDocument == null || property == null)
                return;

            Property propertyClone = (Property)property.Clone();
            string newPropertyCode = ChangeProperty(propertyClone);

            SourceRange propertyRange = property.Range.Clone();
            textDocument.DeleteText(propertyRange);
            SourceRange newPropertyRange = textDocument.InsertText(propertyRange.Start, newPropertyCode);
            textDocument.Format(newPropertyRange);

        }
        private void ConvertProperty(TextDocument textDocument, Property property, bool baseClassVersion, LanguageElement classExpression)
        {
            if (textDocument == null || property == null)
                return;

            Property propertyClone = (Property)property.Clone();
            string newPropertyCode = ChangeProperty(propertyClone, baseClassVersion, classExpression);

            SourceRange propertyRange = property.Range.Clone();
            textDocument.DeleteText(propertyRange);
            SourceRange newPropertyRange = textDocument.InsertText(propertyRange.Start, newPropertyCode);
            textDocument.Format(newPropertyRange);

        }
Example #5
0
        private void ConvertProperty(TextDocument textDocument, Property property, bool baseClassVersion, LanguageElement classExpression)
        {
            if (textDocument == null || property == null)
            {
                return;
            }

            Property propertyClone   = (Property)property.Clone();
            string   newPropertyCode = ChangeProperty(propertyClone, baseClassVersion, classExpression);

            SourceRange propertyRange = property.Range.Clone();

            textDocument.DeleteText(propertyRange);
            SourceRange newPropertyRange = textDocument.InsertText(propertyRange.Start, newPropertyCode);

            textDocument.Format(newPropertyRange);
        }
Example #6
0
        private void ConvertProperty(TextDocument textDocument, Property property)
        {
            if (textDocument == null || property == null)
            {
                return;
            }

            Property propertyClone   = (Property)property.Clone();
            string   newPropertyCode = ChangeProperty(propertyClone);

            SourceRange propertyRange = property.Range.Clone();

            textDocument.DeleteText(propertyRange);
            SourceRange newPropertyRange = textDocument.InsertText(propertyRange.Start, newPropertyCode);

            textDocument.Format(newPropertyRange);
        }
		public void Organize(
			 TextDocument txtDoc, LanguageElement activeType, bool addRegions)
		{
			typeDeclaration = activeType as TypeDeclaration;
			if (typeDeclaration == null)
				return;

			if (txtDoc == null)
				return;

			textDocument = txtDoc;

			SourcePoint cursorPosition = CodeRush.Caret.SourcePoint;

			try
			{
				Class currentClass = typeDeclaration.GetClass();
				if (currentClass == null || currentClass.Document == null)
					return;

				textDocument.Lock();
				InitializeDictionary();
				//Clear out list of regions that have been deleted
				deletedRegions.Clear();
				//clean out the string builder
				codeToInsert.Remove(0, codeToInsert.Length);

				ReadCodeElements(currentClass);
				BuildCode(addRegions);

				ApplyEdits();
			}
			catch (Exception ex)
			{
				Utilities.HandleException(ex);
			}
			finally
			{
				if (cursorPosition != SourcePoint.Empty)
					CodeRush.Caret.MoveTo(cursorPosition);

				textDocument.Unlock();
				textDocument.Format();
			}
		}
Example #8
0
        private void AddPropertyChangedMember(TextDocument classFile, LanguageElement classExpression)
        {
            Statement statement;

            if (CodeRush.Language.IsCSharp)
            {
                statement = new Statement("public event PropertyChangedEventHandler PropertyChanged = delegate {}");
            }
            else if (CodeRush.Language.IsBasic)
            {
                statement = new SnippetCodeStatement("Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged", false);
            }
            else
            {
                statement = new Statement(string.Empty);
            }
            SourceRange newEventRange = classFile.InsertText(new SourcePoint(classExpression.EndLine, 1), "\n" + CodeRush.Language.GenerateElement(statement));

            classFile.Format(newEventRange);
        }
 private void AddPropertyChangedMember(TextDocument classFile, LanguageElement classExpression)
 {
     Statement statement;
     if (CodeRush.Language.IsCSharp)
     {
         statement = new Statement("public event PropertyChangedEventHandler PropertyChanged = delegate {}");
     }
     else if (CodeRush.Language.IsBasic)
     {
         statement = new SnippetCodeStatement("Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged",false);
     }
     else
     {
         statement = new Statement(string.Empty);
     }
     SourceRange newEventRange = classFile.InsertText(new SourcePoint(classExpression.EndLine - 1,1), "\n"+CodeRush.Language.GenerateElement(statement));
     classFile.Format(newEventRange);
 }