Example #1
0
 /// <summary>
 /// Updates the state of the menu items
 /// </summary>
 private void UpdateMenuItems()
 {
     try
     {
         var document    = PluginBase.MainForm.CurrentDocument;
         var curFileName = document != null ? document.FileName : string.Empty;
         this.refactorMainMenu.DelegateMenuItem.Enabled    = false;
         this.refactorContextMenu.DelegateMenuItem.Enabled = false;
         bool            langIsValid = RefactoringHelper.GetLanguageIsValid();
         ResolvedContext resolved    = ASComplete.CurrentResolvedContext;
         bool            isValid     = langIsValid && resolved != null && resolved.Position >= 0;
         ASResult        result      = isValid ? resolved.Result : null;
         if (result != null && !result.IsNull())
         {
             bool isRenameable = (result.Member != null && RefactoringHelper.ModelFileExists(result.Member.InFile) && !RefactoringHelper.IsUnderSDKPath(result.Member.InFile)) ||
                                 (result.Type != null && RefactoringHelper.ModelFileExists(result.Type.InFile) && !RefactoringHelper.IsUnderSDKPath(result.Type.InFile)) ||
                                 (RefactoringHelper.ModelFileExists(result.InFile) && !RefactoringHelper.IsUnderSDKPath(result.InFile)) ||
                                 result.IsPackage;
             this.refactorContextMenu.RenameMenuItem.Enabled = isRenameable;
             this.refactorMainMenu.RenameMenuItem.Enabled    = isRenameable;
             var enabled = !result.IsPackage && (File.Exists(curFileName) || curFileName.Contains("[model]"));
             this.editorReferencesItem.Enabled = enabled;
             this.viewReferencesItem.Enabled   = enabled;
             if (result.Member != null && result.Type != null && result.InClass != null && result.InFile != null)
             {
                 FlagType flags = result.Member.Flags;
                 if ((flags & FlagType.Variable) > 0 && (flags & FlagType.LocalVar) == 0 && (flags & FlagType.ParameterVar) == 0)
                 {
                     this.refactorContextMenu.DelegateMenuItem.Enabled = true;
                     this.refactorMainMenu.DelegateMenuItem.Enabled    = true;
                 }
             }
         }
         else
         {
             this.refactorMainMenu.RenameMenuItem.Enabled    = false;
             this.refactorContextMenu.RenameMenuItem.Enabled = false;
             this.editorReferencesItem.Enabled = false;
             this.viewReferencesItem.Enabled   = false;
         }
         IASContext context = ASContext.Context;
         if (context != null && context.CurrentModel != null)
         {
             bool enabled = langIsValid && context.CurrentModel.Imports.Count > 0;
             this.refactorContextMenu.OrganizeMenuItem.Enabled = enabled;
             this.refactorContextMenu.TruncateMenuItem.Enabled = enabled;
             this.refactorMainMenu.OrganizeMenuItem.Enabled    = enabled;
             this.refactorMainMenu.TruncateMenuItem.Enabled    = enabled;
         }
         refactorMainMenu.MoveMenuItem.Enabled                         = false;
         refactorContextMenu.MoveMenuItem.Enabled                      = false;
         this.surroundContextMenu.Enabled                              = false;
         this.refactorMainMenu.SurroundMenu.Enabled                    = false;
         this.refactorMainMenu.ExtractMethodMenuItem.Enabled           = false;
         this.refactorContextMenu.ExtractMethodMenuItem.Enabled        = false;
         this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled    = false;
         this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = false;
         if (document != null && document.IsEditable && langIsValid)
         {
             bool isValidFile = IsValidFile(curFileName);
             refactorMainMenu.MoveMenuItem.Enabled    = isValidFile;
             refactorContextMenu.MoveMenuItem.Enabled = isValidFile;
             var sci = document.SciControl;
             if (sci.SelTextSize > 0)
             {
                 if (!sci.PositionIsOnComment(sci.SelectionStart) || !sci.PositionIsOnComment(sci.SelectionEnd))
                 {
                     this.surroundContextMenu.Enabled                       = true;
                     this.refactorMainMenu.SurroundMenu.Enabled             = true;
                     this.refactorMainMenu.ExtractMethodMenuItem.Enabled    = true;
                     this.refactorContextMenu.ExtractMethodMenuItem.Enabled = true;
                 }
                 if (context != null)
                 {
                     var declAtSelStart = context.GetDeclarationAtLine(sci.LineFromPosition(sci.SelectionStart));
                     var declAtSelEnd   = context.GetDeclarationAtLine(sci.LineFromPosition(sci.SelectionEnd));
                     if (declAtSelStart != null && declAtSelStart.Member != null && (declAtSelStart.Member.Flags & FlagType.Function) > 0 &&
                         declAtSelEnd != null && declAtSelStart.Member.Equals(declAtSelEnd.Member))
                     {
                         this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled    = true;
                         this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = true;
                     }
                 }
             }
         }
         this.refactorMainMenu.CodeGeneratorMenuItem.Enabled    = isValid;
         this.refactorContextMenu.CodeGeneratorMenuItem.Enabled = isValid;
     }
     catch {}
 }
Example #2
0
 /// <summary>
 /// Updates the state of the menu items
 /// </summary>
 private void UpdateMenuItems()
 {
     try
     {
         this.refactorMainMenu.DelegateMenuItem.Enabled    = false;
         this.refactorContextMenu.DelegateMenuItem.Enabled = false;
         bool            langIsValid = RefactoringHelper.GetLanguageIsValid();
         ResolvedContext resolved    = ASComplete.CurrentResolvedContext;
         bool            isValid     = langIsValid && resolved != null && resolved.Position >= 0;
         ASResult        result      = isValid ? resolved.Result : null;
         if (result != null && !result.IsNull())
         {
             bool isRenameable = (result.Member != null && RefactoringHelper.ModelFileExists(result.Member.InFile) && !RefactoringHelper.IsUnderSDKPath(result.Member.InFile)) ||
                                 (result.Type != null && RefactoringHelper.ModelFileExists(result.Type.InFile) && !RefactoringHelper.IsUnderSDKPath(result.Type.InFile)) ||
                                 (RefactoringHelper.ModelFileExists(result.InFile) && !RefactoringHelper.IsUnderSDKPath(result.InFile)) ||
                                 result.IsPackage;
             this.refactorContextMenu.RenameMenuItem.Enabled = isRenameable;
             this.refactorMainMenu.RenameMenuItem.Enabled    = isRenameable;
             bool isNotPackage = !result.IsPackage;
             this.editorReferencesItem.Enabled = isNotPackage;
             this.viewReferencesItem.Enabled   = isNotPackage;
             if (result.Member != null && result.Type != null && result.InClass != null && result.InFile != null)
             {
                 FlagType flags = result.Member.Flags;
                 if ((flags & FlagType.Variable) > 0 && (flags & FlagType.LocalVar) == 0 && (flags & FlagType.ParameterVar) == 0)
                 {
                     this.refactorContextMenu.DelegateMenuItem.Enabled = true;
                     this.refactorMainMenu.DelegateMenuItem.Enabled    = true;
                 }
             }
         }
         else
         {
             this.refactorMainMenu.RenameMenuItem.Enabled    = false;
             this.refactorContextMenu.RenameMenuItem.Enabled = false;
             this.editorReferencesItem.Enabled = false;
             this.viewReferencesItem.Enabled   = false;
         }
         IASContext context = ASContext.Context;
         if (context != null && context.CurrentModel != null)
         {
             bool truncate = langIsValid && context.CurrentModel.Imports.Count > 0;
             bool organize = (langIsValid && context.CurrentModel.Imports.Count > 1);
             this.refactorContextMenu.OrganizeMenuItem.Enabled = organize;
             this.refactorContextMenu.TruncateMenuItem.Enabled = truncate;
             this.refactorMainMenu.OrganizeMenuItem.Enabled    = organize;
             this.refactorMainMenu.TruncateMenuItem.Enabled    = truncate;
         }
         this.surroundContextMenu.Enabled                              = false;
         this.refactorMainMenu.SurroundMenu.Enabled                    = false;
         this.refactorContextMenu.ExtractMethodMenuItem.Enabled        = false;
         this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = false;
         this.refactorMainMenu.ExtractMethodMenuItem.Enabled           = false;
         this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled    = false;
         ITabbedDocument document = PluginBase.MainForm.CurrentDocument;
         if (document != null && document.IsEditable && langIsValid && document.SciControl.SelTextSize > 1)
         {
             Int32 selEnd   = document.SciControl.SelectionEnd;
             Int32 selStart = document.SciControl.SelectionStart;
             if (!document.SciControl.PositionIsOnComment(selEnd) || !document.SciControl.PositionIsOnComment(selStart))
             {
                 this.surroundContextMenu.Enabled                              = true;
                 this.refactorMainMenu.SurroundMenu.Enabled                    = true;
                 this.refactorContextMenu.ExtractMethodMenuItem.Enabled        = true;
                 this.refactorMainMenu.ExtractMethodMenuItem.Enabled           = true;
                 this.refactorContextMenu.ExtractLocalVariableMenuItem.Enabled = true;
                 this.refactorMainMenu.ExtractLocalVariableMenuItem.Enabled    = true;
             }
         }
         this.refactorContextMenu.CodeGeneratorMenuItem.Enabled = isValid;
         this.refactorMainMenu.CodeGeneratorMenuItem.Enabled    = isValid;
     }
     catch {}
 }