@@ -25,10 +25,6 @@ public override void InitializePlugIn()
2525 #region FinalizePlugIn
2626 public override void FinalizePlugIn ( )
2727 {
28- //
29- // TODO: Add your finalization code here.
30- //
31-
3228 base . FinalizePlugIn ( ) ;
3329 }
3430 #endregion
@@ -65,9 +61,16 @@ private void ConvertStringToAppSetting_Execute(Object sender, ApplyContentEventA
6561 string BasePath = System . IO . Path . GetDirectoryName ( ActiveProject . FilePath ) ;
6662 string Filename = BasePath + "\\ App.Config" ;
6763 TextDocument configDoc = CodeRush . Documents . GetTextDocument ( Filename ) ;
64+
65+ if ( configDoc == null )
66+ {
67+ // Open configDoc
68+ configDoc = ( TextDocument ) CodeRush . File . Activate ( Filename ) ;
69+ }
6870
69- if ( configDoc == null )
71+ if ( configDoc == null )
7072 {
73+ // Create configDoc
7174 string DefaultSettings = "<?xml version=\" 1.0\" encoding=\" utf-8\" ?><configuration></configuration>" ;
7275 CodeRush . File . WriteTextFile ( Filename , DefaultSettings ) ;
7376 CodeRush . Project . AddFile ( ActiveProject , Filename ) ;
@@ -104,8 +107,10 @@ private void ConvertStringToAppSetting_Execute(Object sender, ApplyContentEventA
104107 CodeDoc . ParseIfTextChanged ( ) ;
105108 CodeDoc . ParseIfNeeded ( ) ;
106109 var SourceNode = CodeDoc . GetNodeAt ( NewCodeRange . Start ) ;
107-
110+
108111 // Find Newly created Setting
112+ configDoc . ParseIfTextChanged ( ) ;
113+ configDoc . ParseIfNeeded ( ) ;
109114 RootNode = ( SP . HtmlElement ) configDoc . FileNode . Nodes [ 1 ] ;
110115 AppSettings = GetAppSettings ( RootNode ) ;
111116 SettingNode = GetSettingWithKeyAndValue ( AppSettings , SettingName , SettingValue ) ;
@@ -115,7 +120,7 @@ private void ConvertStringToAppSetting_Execute(Object sender, ApplyContentEventA
115120 SourceRange StringRange = ( SourceNode . Parent . Parent . Parent . Parent . DetailNodes [ 0 ] as LanguageElement ) . Range ;
116121 SourceRange CodeSourceRange = new SourceRange ( StringRange . Start . OffsetPoint ( 0 , 1 ) , StringRange . End . OffsetPoint ( 0 , - 1 ) ) ;
117122 LinkSet . Add ( new FileSourceRange ( CodeDoc . FileNode , CodeSourceRange ) ) ;
118- LinkSet . Add ( new FileSourceRange ( configDoc . FileNode , SettingNode . Attributes [ "Key " ] . ValueRange ) ) ;
123+ LinkSet . Add ( new FileSourceRange ( configDoc . FileNode , SettingNode . Attributes [ "key " ] . ValueRange ) ) ;
119124 CodeRush . LinkedIdentifiers . Invalidate ( configDoc ) ;
120125 CodeDoc . Activate ( ) ;
121126 CodeRush . LinkedIdentifiers . Invalidate ( CodeDoc ) ;
0 commit comments