public void Initialize(EditorContext context)
        {
            // class at caret (either declaration of usage)
            this.Class = GetClass(context.CurrentSymbol);
            if (this.Class == null)
            {
                return;
            }
            var c = this.Class;

            var classDecls = context.GetClassDeclarationsOnCurrentLine().ToList();

            this.IsCaretAtClassDeclaration = classDecls.Count == 1 && (classDecls[0].FullyQualifiedName == c.FullyQualifiedName);

            this.IsClassFileNameCorrect = (c.IsInnerClass() || (!c.IsUserCode()) ||
                                           c.Name.Equals(Path.GetFileNameWithoutExtension(c.CompilationUnit.FileName), StringComparison.OrdinalIgnoreCase));

            if (string.IsNullOrEmpty(c.Name) || c.CompilationUnit == null || string.IsNullOrEmpty(c.CompilationUnit.FileName))
            {
                // Cannot get path
                this.CorrectClassFileName            = null;
                this.IsCorrectClassFileNameAvailable = false;
                return;
            }
            this.CorrectClassFileName = Path.Combine(Path.GetDirectoryName(c.CompilationUnit.FileName),
                                                     c.Name + Path.GetExtension(c.CompilationUnit.FileName));

            this.IsCorrectClassFileNameAvailable = (FileUtility.IsValidPath(CorrectClassFileName) &&
                                                    Path.IsPathRooted(CorrectClassFileName) &&
                                                    !File.Exists(CorrectClassFileName));

            this.IsClassReadOnly = FindReferencesAndRenameHelper.IsReadOnly(this.Class);
        }
        public System.Windows.Forms.ToolStripItem[] BuildSubmenu(Codon codon, object owner)
        {
            List <ToolStripItem> resultItems = new List <ToolStripItem>();

            IClass c = ClassBookmarkSubmenuBuilder.GetClass(owner);

            if (c == null)
            {
                return(new ToolStripMenuItem[0]);
            }
            LanguageProperties language = c.ProjectContent.Language;

            if (!FindReferencesAndRenameHelper.IsReadOnly(c))
            {
                AddRenameCommand(c, resultItems);

                if (language.RefactoringProvider.SupportsExtractInterface)
                {
                    AddExtractInterfaceCommand(c, resultItems);
                }
            }

            return(resultItems.ToArray());
        }
        public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
        {
            MenuCommand cmd;
            IMember     member;
            MemberNode  memberNode = owner as MemberNode;

            if (memberNode != null)
            {
                member = memberNode.Member;
            }
            else
            {
                ClassMemberBookmark bookmark = (ClassMemberBookmark)owner;
                member = bookmark.Member;
            }
            IMethod method            = member as IMethod;
            List <ToolStripItem> list = new List <ToolStripItem>();

            bool canGenerateCode =
                member.DeclaringType.ProjectContent.Language.CodeGenerator != null &&
                !FindReferencesAndRenameHelper.IsReadOnly(member.DeclaringType);

            if (method == null || !method.IsConstructor)
            {
                if (!FindReferencesAndRenameHelper.IsReadOnly(member.DeclaringType) &&
                    !(member is IProperty && ((IProperty)member).IsIndexer))
                {
                    cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.RenameCommand}", Rename);
                    cmd.Tag = member;
                    list.Add(cmd);
                }
            }
            if (member.IsOverride)
            {
                cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.GoToBaseClassCommand}", GoToBase);
                cmd.Tag = member;
                list.Add(cmd);
            }
            if (member.IsVirtual || member.IsAbstract || (member.IsOverride && !member.DeclaringType.IsSealed))
            {
                cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.FindOverridesCommand}", FindOverrides);
                cmd.Tag = member;
                list.Add(cmd);
            }

            cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.FindReferencesCommand}", FindReferences);
            cmd.Tag = member;
            list.Add(cmd);

            if (member is IField && member.DeclaringType.ClassType != ClassType.Enum)
            {
                IProperty foundProperty = FindReferencesAndRenameHelper.FindProperty(member as IField);
                if (foundProperty != null)
                {
                    cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.GoToProperty}", GotoTagMember);
                    cmd.Tag = foundProperty;
                    list.Add(cmd);
                }
                else
                {
                    if (canGenerateCode)
                    {
                        if (member.IsReadonly)
                        {
                            cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.CreateProperty}", CreateGetter);
                            cmd.Tag = member;
                            list.Add(cmd);
                        }
                        else
                        {
                            cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.CreateGetter}", CreateGetter);
                            cmd.Tag = member;
                            list.Add(cmd);
                            cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.CreateProperty}", CreateProperty);
                            cmd.Tag = member;
                            list.Add(cmd);
                        }
                    }
                }
            }
            if (member is IProperty)
            {
                if (((IProperty)member).CanSet && canGenerateCode)
                {
                    cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.CreateChangedEvent}", CreateChangedEvent);
                    cmd.Tag = member;
                    list.Add(cmd);
                }
            }
            if (member is IEvent)
            {
                if (canGenerateCode)
                {
                    cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.CreateOnEventMethod}", CreateOnEventMethod);
                    cmd.Tag = member;
                    list.Add(cmd);
                }
            }

            return(list.ToArray());
        }
        public ToolStripItem[] BuildSubmenu(Codon codon, object owner)
        {
            MenuCommand cmd;
            IClass      c;
            ClassNode   classNode = owner as ClassNode;

            if (classNode != null)
            {
                c = classNode.Class;
            }
            else
            {
                ClassBookmark bookmark = (ClassBookmark)owner;
                c = bookmark.Class;
            }

            ParserService.ParseCurrentViewContent();
            c = c.ProjectContent.GetClass(c.FullyQualifiedName, c.TypeParameters.Count);
            if (c == null)
            {
                return(new ToolStripMenuItem[0]);
            }

            LanguageProperties language = c.ProjectContent.Language;

            List <ToolStripItem> list = new List <ToolStripItem>();

            if (!FindReferencesAndRenameHelper.IsReadOnly(c))
            {
                if (c.DeclaringType == null &&
                    !c.BodyRegion.IsEmpty &&
                    !c.Name.Equals(Path.GetFileNameWithoutExtension(c.CompilationUnit.FileName),
                                   StringComparison.InvariantCultureIgnoreCase))
                {
                    // File name does not match class name
                    string correctFileName = Path.Combine(Path.GetDirectoryName(c.CompilationUnit.FileName),
                                                          c.Name + Path.GetExtension(c.CompilationUnit.FileName));
                    if (FileUtility.IsValidFileName(correctFileName) &&
                        Path.IsPathRooted(correctFileName) &&
                        !File.Exists(correctFileName))
                    {
                        if (c.CompilationUnit.Classes.Count == 1)
                        {
                            // Rename file to ##
                            cmd = new MenuCommand(StringParser.Parse("${res:SharpDevelop.Refactoring.RenameFileTo}", new string[, ] {
                                { "FileName", Path.GetFileName(correctFileName) }
                            }),
                                                  delegate {
                                FileService.RenameFile(c.CompilationUnit.FileName, correctFileName, false);
                                if (c.ProjectContent.Project != null)
                                {
                                    ((IProject)c.ProjectContent.Project).Save();
                                }
                            });
                            list.Add(cmd);
                        }
                        else if (language.RefactoringProvider.SupportsCreateNewFileLikeExisting && language.RefactoringProvider.SupportsGetFullCodeRangeForType)
                        {
                            // Move class to file ##
                            cmd = new MenuCommand(StringParser.Parse("${res:SharpDevelop.Refactoring.MoveClassToFile}", new string[, ] {
                                { "FileName", Path.GetFileName(correctFileName) }
                            }),
                                                  delegate {
                                MoveClassToFile(c, correctFileName);
                            });
                            list.Add(cmd);
                        }
                    }
                }

                cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.RenameCommand}", Rename);
                cmd.Tag = c;
                list.Add(cmd);
            }

            if (c.BaseTypes.Count > 0)
            {
                cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.GoToBaseCommand}", GoToBase);
                cmd.Tag = c;
                list.Add(cmd);
                if (c.ClassType != ClassType.Interface && !FindReferencesAndRenameHelper.IsReadOnly(c))
                {
                    AddImplementInterfaceCommands(c, list);
                }
            }
            if (!c.IsSealed && !c.IsStatic)
            {
                cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.FindDerivedClassesCommand}", FindDerivedClasses);
                cmd.Tag = c;
                list.Add(cmd);
            }

            cmd     = new MenuCommand("${res:SharpDevelop.Refactoring.FindReferencesCommand}", FindReferences);
            cmd.Tag = c;
            list.Add(cmd);

            return(list.ToArray());
        }