// ext may be null, but then parameter completion don't work
        public static bool ShowWindow(CompletionTextEditorExtension ext, char firstChar, ICompletionDataList list, ICompletionWidget completionWidget, CodeCompletionContext completionContext)
        {
            try {
                if (ext != null)
                {
                    int inserted = ext.document.Editor.EnsureCaretIsNotVirtual();
                    if (inserted > 0)
                    {
                        completionContext.TriggerOffset = ext.document.Editor.Caret.Offset;
                    }
                }
                if (wnd == null)
                {
                    wnd = new CompletionListWindow();
                    wnd.WordCompleted += HandleWndWordCompleted;
                }
                if (ext != null)
                {
                    wnd.TransientFor = ext.document.Editor.Parent.Toplevel as Gtk.Window;
                }
                else
                {
                    var widget = completionWidget as Gtk.Widget;
                    if (widget != null)
                    {
                        var window = widget.Toplevel as Gtk.Window;
                        if (window != null)
                        {
                            wnd.TransientFor = window;
                        }
                    }
                }
                wnd.Extension = ext;
                try {
                    if (!wnd.ShowListWindow(firstChar, list, completionWidget, completionContext))
                    {
                        if (list is IDisposable)
                        {
                            ((IDisposable)list).Dispose();
                        }
                        HideWindow();
                        return(false);
                    }

                    if (ForceSuggestionMode)
                    {
                        wnd.AutoSelect = false;
                    }
                    wnd.Show();
                    DesktopService.RemoveWindowShadow(wnd);
                    OnWindowShown(EventArgs.Empty);
                    return(true);
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                    return(false);
                }
            } finally {
                ParameterInformationWindowManager.UpdateWindow(ext, completionWidget);
            }
        }
Beispiel #2
0
        public ParameterInformationWindow()
        {
            TypeHint             = Gdk.WindowTypeHint.Tooltip;
            this.SkipTaskbarHint = true;
            this.SkipPagerHint   = true;
            this.AllowShrink     = false;
            this.AllowGrow       = false;
            this.CanFocus        = false;
            this.CanDefault      = false;
            WindowTransparencyDecorator.Attach(this);

            headlabel        = new MonoDevelop.Components.FixedWidthWrapLabel();
            headlabel.Indent = -20;

            headlabel.FontDescription = FontService.GetFontDescription("Editor").CopyModified(1.1);

            headlabel.Wrap = Pango.WrapMode.WordChar;
            headlabel.BreakOnCamelCasing = false;
            headlabel.BreakOnPunctuation = false;
            descriptionBox.Spacing       = 4;
            VBox vb = new VBox(false, 0);

            vb.PackStart(headlabel, true, true, 0);
            vb.PackStart(descriptionBox, true, true, 0);

            HBox hb = new HBox(false, 0);

            hb.PackStart(vb, true, true, 0);

            vb2.Spacing = 4;
            vb2.PackStart(hb, true, true, 0);
            ContentBox.Add(vb2);
            ShowAll();
            DesktopService.RemoveWindowShadow(this);
        }
Beispiel #3
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();
            }
        }
        public TooltipInformationWindow() : base()
        {
            TypeHint             = Gdk.WindowTypeHint.Tooltip;
            this.SkipTaskbarHint = true;
            this.SkipPagerHint   = true;
            if (IdeApp.Workbench != null)
            {
                this.TransientFor = IdeApp.Workbench.RootWindow;
            }
            this.AllowShrink = false;
            this.AllowGrow   = false;
            this.CanFocus    = false;
            this.CanDefault  = false;
            this.Events     |= Gdk.EventMask.EnterNotifyMask;

            headlabel        = new FixedWidthWrapLabel();
            headlabel.Indent = -20;
            var des = FontService.GetFontDescription("Editor").Copy();

            des.Size = des.Size * 9 / 10;
            headlabel.FontDescription = des;
//			headlabel.MaxWidth = 400;
            headlabel.Wrap = Pango.WrapMode.WordChar;
            headlabel.BreakOnCamelCasing = false;
            headlabel.BreakOnPunctuation = false;
            descriptionBox.Spacing       = 4;
            VBox vb = new VBox(false, 8);

            vb.PackStart(headlabel, true, true, 0);
            vb.PackStart(descriptionBox, true, true, 0);

            HBox hb = new HBox(false, 0);

            hb.PackStart(vb, true, true, 0);
            WindowTransparencyDecorator.Attach(this);

            vb2.Spacing = 4;
            vb2.PackStart(hb, true, true, 0);
            ContentBox.Add(vb2);
            var scheme = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle(IdeApp.Preferences.ColorScheme);

            Theme.SetSchemeColors(scheme);
            foreColor = scheme.PlainText.Foreground;
            headlabel.ModifyFg(StateType.Normal, (HslColor)foreColor);
            ShowAll();
            DesktopService.RemoveWindowShadow(this);
        }
Beispiel #5
0
        public TooltipInformationWindow() : base()
        {
            TypeHint             = Gdk.WindowTypeHint.Tooltip;
            this.SkipTaskbarHint = true;
            this.SkipPagerHint   = true;
            if (IdeApp.Workbench != null)
            {
                this.TransientFor = IdeApp.Workbench.RootWindow;
            }
            this.AllowShrink = false;
            this.AllowGrow   = false;
            this.CanFocus    = false;
            this.CanDefault  = false;
            this.Events     |= Gdk.EventMask.EnterNotifyMask;

            headLabel                    = new FixedWidthWrapLabel();
            headLabel.Indent             = -20;
            headLabel.FontDescription    = FontService.GetFontDescription("Editor(TooltipSource)");;
            headLabel.Wrap               = Pango.WrapMode.WordChar;
            headLabel.BreakOnCamelCasing = false;
            headLabel.BreakOnPunctuation = false;

            descriptionBox.Spacing = 4;

            VBox vb = new VBox(false, 8);

            vb.PackStart(headLabel, true, true, 4);
            vb.PackStart(descriptionBox, true, true, 4);

            HBox hb = new HBox(false, 4);

            hb.PackStart(vb, true, true, 6);

            WindowTransparencyDecorator.Attach(this);

            vb2.Spacing = 4;
            vb2.PackStart(hb, true, true, 0);
            ContentBox.Add(vb2);

            SetDefaultScheme();

            ShowAll();
            DesktopService.RemoveWindowShadow(this);
        }
        public ParameterInformationWindow()
        {
            TypeHint             = Gdk.WindowTypeHint.Tooltip;
            this.SkipTaskbarHint = true;
            this.SkipPagerHint   = true;
            this.AllowShrink     = false;
            this.AllowGrow       = false;
            this.CanFocus        = false;
            this.CanDefault      = false;
            Mono.TextEditor.PopupWindow.WindowTransparencyDecorator.Attach(this);

            headlabel        = new MonoDevelop.Components.FixedWidthWrapLabel();
            headlabel.Indent = -20;

            headlabel.FontDescription = FontService.GetFontDescription("Editor").CopyModified(1.1);

            headlabel.Wrap = Pango.WrapMode.WordChar;
            headlabel.BreakOnCamelCasing = false;
            headlabel.BreakOnPunctuation = false;
            descriptionBox.Spacing       = 4;
            VBox vb = new VBox(false, 0);

            vb.PackStart(headlabel, true, true, 0);
            vb.PackStart(descriptionBox, true, true, 0);

            HBox hb = new HBox(false, 0);

            hb.PackStart(vb, true, true, 0);


            vb2.Spacing = 4;
            vb2.PackStart(hb, true, true, 0);
            ContentBox.Add(vb2);
            var scheme = Mono.TextEditor.Highlighting.SyntaxModeService.GetColorStyle(IdeApp.Preferences.ColorScheme);

            Theme.SetSchemeColors(scheme);

            foreColor = scheme.PlainText.Foreground;
            headlabel.ModifyFg(StateType.Normal, foreColor.ToGdkColor());
            ShowAll();
            DesktopService.RemoveWindowShadow(this);
        }
        internal static bool ShowWindow(ICompletionDataList list, CodeCompletionContext completionContext)
        {
            if (wnd == null || !isShowing)
            {
                return(false);
            }

            var completionWidget = wnd.CompletionWidget;
            var ext = wnd.Extension;

            try {
                try {
                    isShowing = false;
                    if (!wnd.ShowListWindow(list, completionContext))
                    {
                        if (list is IDisposable)
                        {
                            ((IDisposable)list).Dispose();
                        }
                        HideWindow();
                        return(false);
                    }

                    if (IdeApp.Preferences.ForceSuggestionMode)
                    {
                        wnd.AutoSelect = false;
                    }
                    wnd.Show();
                    DesktopService.RemoveWindowShadow(wnd);
                    OnWindowShown(EventArgs.Empty);
                    return(true);
                } catch (Exception ex) {
                    LoggingService.LogError(ex.ToString());
                    return(false);
                }
            } finally {
                ParameterInformationWindowManager.UpdateWindow(ext, completionWidget);
            }
        }
        public virtual void RepositionWindow(Gdk.Rectangle?newCaret = null)
        {
            if (parent == null)
            {
                return;
            }

            int x, y;

            if (newCaret.HasValue)              //Update caret if parameter is given
            {
                currentCaret = newCaret.Value;
            }
            Gdk.Rectangle caret  = currentCaret;
            Gdk.Window    window = targetWindow;
            if (targetWindow == null)
            {
                return;
            }
            PopupPosition position = Theme.TargetPosition;

            this.position = Theme.TargetPosition;
            UpdatePadding();

            window.GetOrigin(out x, out y);
            var alloc = parent.Allocation;

            if (eventProvided)
            {
                caret.X     = x;
                caret.Y     = y;
                caret.Width = caret.Height = 1;
            }
            else
            {
                if (caret.Equals(Gdk.Rectangle.Zero))
                {
                    caret = new Gdk.Rectangle(0, 0, alloc.Width, alloc.Height);
                }
                caret = GtkUtil.ToScreenCoordinates(parent, parent.GdkWindow, caret);
            }

            Gtk.Requisition request = SizeRequest();
            var             screen  = parent.Screen;

            Gdk.Rectangle geometry = GtkWorkarounds.GetUsableMonitorGeometry(screen, screen.GetMonitorAtPoint(caret.X, caret.Y));

            // Add some spacing between the screen border and the popover window
            geometry.Inflate(-5, -5);

            // Flip the orientation if the window doesn't fit the screen.

            int intPos = (int)position;

            switch ((PopupPosition)(intPos & 0x0f))
            {
            case PopupPosition.Top:
                if (caret.Bottom + request.Height > geometry.Bottom)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Bottom;
                }
                break;

            case PopupPosition.Bottom:
                if (caret.Top - request.Height < geometry.X)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Top;
                }
                break;

            case PopupPosition.Right:
                if (caret.X - request.Width < geometry.X)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Left;
                }
                break;

            case PopupPosition.Left:
                if (caret.Right + request.Width > geometry.Right)
                {
                    intPos = (intPos & 0xf0) | (int)PopupPosition.Right;
                }
                break;
            }

            position = (PopupPosition)intPos;
            UpdatePadding();

            // Calculate base coordinate

            switch ((PopupPosition)((int)position & 0x0f))
            {
            case PopupPosition.Top:
                y = caret.Bottom;
                break;

            case PopupPosition.Bottom:
                y = caret.Y - request.Height; break;

            case PopupPosition.Right:
                x = caret.X - request.Width; break;

            case PopupPosition.Left:
                x = caret.Right; break;
            }
            int offset;

            if ((position & PopupPosition.Top) != 0 || (position & PopupPosition.Bottom) != 0)
            {
                if (((int)position & 0x10) != 0)
                {
                    x = caret.X - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
                else if (((int)position & 0x20) != 0)
                {
                    x = caret.Right - request.Width + MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                else
                {
                    x = caret.X + (caret.Width - request.Width) / 2;
                }

                if (x < geometry.Left)
                {
                    x = geometry.Left;
                }
                else if (x + request.Width > geometry.Right)
                {
                    x = geometry.Right - request.Width;
                }

                offset = caret.X + caret.Width / 2 - x;
                if (offset - Theme.ArrowWidth / 2 < MinArrowSpacing)
                {
                    offset = MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                if (offset > request.Width - MinArrowSpacing - Theme.ArrowWidth / 2)
                {
                    offset = request.Width - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
            }
            else
            {
                if (((int)position & 0x10) != 0)
                {
                    y = caret.Y - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
                else if (((int)position & 0x20) != 0)
                {
                    y = caret.Bottom - request.Height + MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                else
                {
                    y = caret.Y + (caret.Height - request.Height) / 2;
                }

                if (y < geometry.Top)
                {
                    y = geometry.Top;
                }
                else if (y + request.Height > geometry.Bottom)
                {
                    y = geometry.Bottom - request.Height;
                }
                if (MaximumYTopBound > 0)
                {
                    y = Math.Max(MaximumYTopBound, y);
                }

                offset = caret.Y + caret.Height / 2 - y;
                if (offset - Theme.ArrowWidth / 2 < MinArrowSpacing)
                {
                    offset = MinArrowSpacing + Theme.ArrowWidth / 2;
                }
                if (offset > request.Height - MinArrowSpacing - Theme.ArrowWidth / 2)
                {
                    offset = request.Height - MinArrowSpacing - Theme.ArrowWidth / 2;
                }
            }
            Theme.ArrowOffset = offset;
            this.position     = position;
            UpdatePadding();

            Move(x, y);
            Show();
            if (!ShowWindowShadow)
            {
                DesktopService.RemoveWindowShadow(this);
            }
        }
 public void Show()
 {
     window.Show();
     DesktopService.RemoveWindowShadow(window);
 }
Beispiel #10
0
        public override Task InsertWithCursor(string operation, InsertPosition defaultPosition, IEnumerable <AstNode> nodes)
        {
            var tcs              = new TaskCompletionSource <object> ();
            var editor           = context.TextEditor;
            DocumentLocation loc = context.TextEditor.Caret.Location;
            var declaringType    = context.ParsedDocument.GetInnermostTypeDefinition(loc);
            var mode             = new InsertionCursorEditMode(
                editor.Parent,
                CodeGenerationService.GetInsertionPoints(context.TextEditor, context.ParsedDocument, declaringType));

            if (mode.InsertionPoints.Count == 0)
            {
                MessageService.ShowError(
                    GettextCatalog.GetString("No valid insertion point can be found in type '{0}'.", declaringType.Name)
                    );
                return(tcs.Task);
            }
            var helpWindow = new Mono.TextEditor.PopupWindow.InsertionCursorLayoutModeHelpWindow();

            helpWindow.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
            helpWindow.TitleText    = operation;
            helpWindow.Shown       += (s, a) => DesktopService.RemoveWindowShadow(helpWindow);
            mode.HelpWindow         = helpWindow;

            switch (defaultPosition)
            {
            case InsertPosition.Start:
                mode.CurIndex = 0;
                break;

            case InsertPosition.End:
                mode.CurIndex = mode.InsertionPoints.Count - 1;
                break;

            case InsertPosition.Before:
                for (int i = 0; i < mode.InsertionPoints.Count; i++)
                {
                    if (mode.InsertionPoints [i].Location < loc)
                    {
                        mode.CurIndex = i;
                    }
                }
                break;

            case InsertPosition.After:
                for (int i = 0; i < mode.InsertionPoints.Count; i++)
                {
                    if (mode.InsertionPoints [i].Location > loc)
                    {
                        mode.CurIndex = i;
                        break;
                    }
                }
                break;
            }
            operationsRunning++;
            mode.StartMode();
            DesktopService.RemoveWindowShadow(helpWindow);
            mode.Exited += delegate(object s, InsertionCursorEventArgs iCArgs) {
                if (iCArgs.Success)
                {
                    if (iCArgs.InsertionPoint.LineAfter == NewLineInsertion.None &&
                        iCArgs.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count() > 1)
                    {
                        iCArgs.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
                    }
                    foreach (var node in nodes.Reverse())
                    {
                        var output = OutputNode(CodeGenerationService.CalculateBodyIndentLevel(declaringType), node);
                        var offset = context.TextEditor.LocationToOffset(iCArgs.InsertionPoint.Location);
                        var delta  = iCArgs.InsertionPoint.Insert(editor, output.Text);
                        output.RegisterTrackedSegments(this, delta + offset);
                    }
                    tcs.SetResult(null);
                }
                else
                {
                    Rollback();
                }
                DisposeOnClose();
            };
            return(tcs.Task);
        }
Beispiel #11
0
        public override Task InsertWithCursor(string operation, ITypeDefinition parentType, IEnumerable <AstNode> nodes)
        {
            var tcs = new TaskCompletionSource <object>();

            if (parentType == null)
            {
                return(tcs.Task);
            }
            var part = parentType.Parts.FirstOrDefault();

            if (part == null)
            {
                return(tcs.Task);
            }

            var loadedDocument = Ide.IdeApp.Workbench.OpenDocument(part.Region.FileName);

            loadedDocument.RunWhenLoaded(delegate {
                var editor         = loadedDocument.Editor;
                var loc            = part.Region.Begin;
                var parsedDocument = loadedDocument.UpdateParseDocument();
                var declaringType  = parsedDocument.GetInnermostTypeDefinition(loc);
                var mode           = new InsertionCursorEditMode(
                    editor.Parent,
                    CodeGenerationService.GetInsertionPoints(loadedDocument, declaringType));
                if (mode.InsertionPoints.Count == 0)
                {
                    MessageService.ShowError(
                        GettextCatalog.GetString("No valid insertion point can be found in type '{0}'.", declaringType.Name)
                        );
                    return;
                }
                if (declaringType.Kind == TypeKind.Enum)
                {
                    foreach (var node in nodes.Reverse())
                    {
                        var output = OutputNode(CodeGenerationService.CalculateBodyIndentLevel(declaringType), node);
                        var point  = mode.InsertionPoints.First();
                        var offset = loadedDocument.Editor.LocationToOffset(point.Location);
                        var text   = output.Text + ",";
                        var delta  = point.Insert(editor, text);
                        output.RegisterTrackedSegments(this, delta + offset);
                    }
                    tcs.SetResult(null);
                    return;
                }


                var helpWindow          = new Mono.TextEditor.PopupWindow.InsertionCursorLayoutModeHelpWindow();
                helpWindow.TransientFor = MonoDevelop.Ide.IdeApp.Workbench.RootWindow;
                helpWindow.TitleText    = operation;
                helpWindow.Shown       += (s, a) => DesktopService.RemoveWindowShadow(helpWindow);
                mode.HelpWindow         = helpWindow;

                mode.CurIndex = 0;
                operationsRunning++;
                mode.StartMode();
                mode.Exited += delegate(object s, InsertionCursorEventArgs iCArgs) {
                    if (iCArgs.Success)
                    {
                        if (iCArgs.InsertionPoint.LineAfter == NewLineInsertion.None &&
                            iCArgs.InsertionPoint.LineBefore == NewLineInsertion.None && nodes.Count() > 1)
                        {
                            iCArgs.InsertionPoint.LineAfter = NewLineInsertion.BlankLine;
                        }
                        foreach (var node in nodes.Reverse())
                        {
                            var output = OutputNode(CodeGenerationService.CalculateBodyIndentLevel(declaringType), node);
                            var offset = loadedDocument.Editor.LocationToOffset(iCArgs.InsertionPoint.Location);
                            var text   = output.Text;
                            var delta  = iCArgs.InsertionPoint.Insert(editor, text);
                            output.RegisterTrackedSegments(this, delta + offset);
                        }
                        tcs.SetResult(null);
                    }
                    else
                    {
                        Rollback();
                    }
                    DisposeOnClose();
                };
            });

            return(tcs.Task);
        }
        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();
            DesktopService.RemoveWindowShadow(helpWindow);
            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();
        }