コード例 #1
0
ファイル: PluginMain.cs プロジェクト: zvoronz/flashdevelop
 private void UpdateMenuItems(ResolvedContext resolved)
 {
     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();
         bool     isValid     = langIsValid && resolved != null && resolved.Position >= 0;
         ASResult result      = isValid ? resolved.Result : null;
         if (result != null && !result.IsNull())
         {
             var validator = CommandFactoryProvider.GetFactory(result)?.GetValidator(typeof(Rename))
                             ?? CommandFactoryProvider.DefaultFactory.GetValidator(typeof(Rename));
             var isRenameable = validator(result);
             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.InFile != null && result.InClass != null && (result.InClass.Flags & FlagType.Interface) == 0 && result.Member != null && result.Type != 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 { }
 }