Beispiel #1
0
        void OnOKClicked(object sender, EventArgs e)
        {
            try {
                StringBuilder code          = new StringBuilder();
                CodeGenerator generator     = CodeGenerator.CreateGenerator(editor.Editor.Document.MimeType, editor.Editor.TabsToSpaces, editor.Editor.Options.TabSize, editor.Editor.EolMarker);
                IType         declaringType = editor.GetType(cls.Location.Line, cls.Location.Column) ?? cls;

                foreach (KeyValuePair <IType, IEnumerable <TreeIter> > kvp in GetAllClasses())
                {
                    if (code.Length > 0)
                    {
                        code.AppendLine();
                        code.AppendLine();
                    }

                    //update the target class so that new members don't get inserted in weird locations
                    StringBuilder curImpl = new StringBuilder();
                    foreach (var pair in YieldImpls(kvp))
                    {
                        if (curImpl.Length > 0)
                        {
                            curImpl.AppendLine();
                            curImpl.AppendLine();
                        }
                        curImpl.Append(generator.CreateMemberImplementation(declaringType, pair.Key, pair.Value != null).Code);
                    }
                    if (kvp.Key.ClassType == ClassType.Interface)
                    {
                        code.Append(generator.WrapInRegions(kvp.Key.Name + " implementation", curImpl.ToString()));
                    }
                    else
                    {
                        code.Append(curImpl.ToString());
                    }
                }

                var mode       = new InsertionCursorEditMode(editor.Editor.Parent, CodeGenerationService.GetInsertionPoints(editor, this.cls));
                var helpWindow = new ModeHelpWindow();
                helpWindow.Shown       += (s, a) => DesktopService.RemoveWindowShadow(helpWindow);
                helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
                helpWindow.TitleText    = GettextCatalog.GetString("<b>Override -- Targeting</b>");
                helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Key</b>"), GettextCatalog.GetString("<b>Behavior</b>")));
                helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Up</b>"), GettextCatalog.GetString("Move to <b>previous</b> target point.")));
                helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Down</b>"), GettextCatalog.GetString("Move to <b>next</b> target point.")));
                helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Enter</b>"), GettextCatalog.GetString("<b>Declare overrides</b> at target point.")));
                helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Esc</b>"), GettextCatalog.GetString("<b>Cancel</b> this refactoring.")));
                mode.HelpWindow = helpWindow;
                mode.CurIndex   = mode.InsertionPoints.Count - 1;
                mode.StartMode();
                mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
                    if (args.Success)
                    {
                        args.InsertionPoint.Insert(editor.Editor, code.ToString());
                    }
                };
            } finally {
                ((Widget)this).Destroy();
            }
        }
Beispiel #2
0
        void OnOKClicked(object sender, EventArgs e)
        {
            TreeIter iter;

            if (!store.GetIterFirst(out iter))
            {
                return;
            }

            List <FieldData> data = new List <FieldData> ();

            do
            {
                bool selected = (bool)store.GetValue(iter, colCheckedIndex);
                if (!selected)
                {
                    continue;
                }

                string    propertyName = (string)store.GetValue(iter, colPropertyNameIndex);
                string    visibility   = (string)store.GetValue(iter, colVisibilityIndex);
                bool      read_only    = (bool)store.GetValue(iter, colReadOnlyIndex);
                IField    field        = (IField)store.GetValue(iter, colFieldIndex);
                Modifiers mod          = Modifiers.None;
                if (visibility.ToUpper() == "PUBLIC")
                {
                    mod = Modifiers.Public;
                }
                if (visibility.ToUpper() == "PRIVATE")
                {
                    mod = Modifiers.Private;
                }
                if (visibility.ToUpper() == "PROTECTED")
                {
                    mod = Modifiers.Protected;
                }
                if (visibility.ToUpper() == "INTERNAL")
                {
                    mod = Modifiers.Internal;
                }
                data.Add(new FieldData(field, propertyName, read_only, mod));
            } while (store.IterNext(ref iter));

            InsertionCursorEditMode mode       = new InsertionCursorEditMode(editor.Editor.Parent, CodeGenerationService.GetInsertionPoints(editor, declaringType));
            ModeHelpWindow          helpWindow = new ModeHelpWindow();

            helpWindow.TransientFor = IdeApp.Workbench.RootWindow;
            helpWindow.TitleText    = GettextCatalog.GetString("<b>Encapsulate Field -- Targeting</b>");
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Key</b>"), GettextCatalog.GetString("<b>Behavior</b>")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Up</b>"), GettextCatalog.GetString("Move to <b>previous</b> target point.")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Down</b>"), GettextCatalog.GetString("Move to <b>next</b> target point.")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Enter</b>"), GettextCatalog.GetString("<b>Declare new property</b> at target point.")));
            helpWindow.Items.Add(new KeyValuePair <string, string> (GettextCatalog.GetString("<b>Esc</b>"), GettextCatalog.GetString("<b>Cancel</b> this refactoring.")));
            mode.HelpWindow = helpWindow;
            mode.CurIndex   = mode.InsertionPoints.Count - 1;
            int          idx = -1, i = 0;
            TextLocation lTextLocation = TextLocation.Empty;

            foreach (IMember member in declaringType.Members)
            {
                if (lTextLocation != member.Location && data.Any(d => d.Field.Location == member.Location))
                {
                    idx = i;
                }
                lTextLocation = member.Location;
                i++;
            }
            if (idx >= 0)
            {
                mode.CurIndex = idx + 1;
            }
            mode.StartMode();
            mode.Exited += delegate(object s, InsertionCursorEventArgs args) {
                if (args.Success)
                {
                    CodeGenerator generator = CodeGenerator.CreateGenerator(editor.Editor.Document.MimeType, editor.Editor.TabsToSpaces, editor.Editor.Options.TabSize, editor.Editor.EolMarker);
                    StringBuilder code      = new StringBuilder();
                    for (int j = 0; j < data.Count; j++)
                    {
                        if (j > 0)
                        {
                            code.AppendLine();
                            code.AppendLine();
                        }
                        var f = data[j];
                        code.Append(generator.CreateFieldEncapsulation(declaringType, f.Field, f.PropertyName, f.Modifiers, f.ReadOnly));
                    }
                    args.InsertionPoint.Insert(editor.Editor, code.ToString());
                }
            };
            ((Widget)this).Destroy();
        }