116
public void PopulateFixes (Gtk.Menu menu)
117
public void PopulateFixes (Gtk.Menu menu, ref int items)
118
119
int mnemonic = 1;
119
120
foreach (var fix_ in fixes.OrderByDescending (i => GetUsage (i.IdString))) {
121
122
var escapedLabel = fix.Title.Replace ("_", "__");
122
123
var label = (mnemonic <= 10)
123
? "_" + (mnemonic++ % 10).ToString () + " " + escapedLabel
124
? "_" + (mnemonic++ % 10).ToString () + " " + escapedLabel
124
125
: " " + escapedLabel;
125
126
var menuItem = new Gtk.MenuItem (label);
126
127
menuItem.Activated += new ContextActionRunner (fix, document, loc).Run;
155
157
menu.Add (menuItem);
161
foreach (var fix_ in fixes.Where (f => f.BoundToIssue != null)) {
163
foreach (var inspector_ in RefactoringService.GetInspectors (document.Editor.MimeType).Where (i => i.GetSeverity () != ICSharpCode.NRefactory.CSharp.Severity.None)) {
164
var inspector = inspector_;
166
if (inspector.IdString.IndexOf (fix.BoundToIssue.FullName, StringComparison.Ordinal) < 0)
169
menu.Add (new Gtk.SeparatorMenuItem ());
172
if (alreadyInserted.Contains (inspector))
174
alreadyInserted.Add (inspector);
176
var label = GettextCatalog.GetString ("_Inspection options for \"{0}\"", inspector.Title);
177
var menuItem = new Gtk.MenuItem (label);
178
menuItem.Activated += delegate {
179
MessageService.RunCustomDialog (new CodeIssueOptionsDialog (inspector), MessageService.RootWindow);
160
void PopupQuickFixMenu (Gdk.EventButton evt)
190
void PopupQuickFixMenu (Gdk.EventButton evt, Action<Gtk.Menu> menuAction)
162
192
var menu = new Gtk.Menu ();
193
menu.Events |= Gdk.EventMask.AllEventsMask;
164
194
Gtk.Menu fixMenu = menu;
165
195
ResolveResult resolveResult;
166
196
ICSharpCode.NRefactory.CSharp.AstNode node;
167
198
if (ResolveCommandHandler.ResolveAt (document, out resolveResult, out node)) {
168
199
var possibleNamespaces = MonoDevelop.Refactoring.ResolveCommandHandler.GetPossibleNamespaces (
174
205
bool addUsing = !(resolveResult is AmbiguousTypeResolveResult);
176
foreach (string ns_ in possibleNamespaces) {
207
foreach (var t in possibleNamespaces.Where (tp => tp.IsAccessibleWithGlobalUsing)) {
208
string ns = t.Namespace;
209
var reference = t.Reference;
178
210
var menuItem = new Gtk.MenuItem (string.Format ("using {0};", ns));
179
211
menuItem.Activated += delegate {
180
new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, true).Run ();
212
new ResolveCommandHandler.AddImport (document, resolveResult, ns, reference, true, node).Run ();
213
if (reference != null)
214
document.Project.Items.Add (reference);
183
217
menu.Add (menuItem);
187
222
bool resolveDirect = !(resolveResult is UnknownMemberResolveResult);
188
223
if (resolveDirect) {
189
foreach (string ns in possibleNamespaces) {
224
foreach (var t in possibleNamespaces) {
225
string ns = t.Namespace;
226
var reference = t.Reference;
190
227
var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("{0}", ns + "." + document.Editor.GetTextBetween (node.StartLocation, node.EndLocation)));
191
228
menuItem.Activated += delegate {
192
new MonoDevelop.Refactoring.ResolveCommandHandler.AddImport (document, resolveResult, ns, false).Run ();
229
new ResolveCommandHandler.AddImport (document, resolveResult, ns, reference, false, node).Run ();
195
232
menu.Add (menuItem);
198
236
if (menu.Children.Any () && fixes.Any ()) {
200
238
var menuItem = new Gtk.MenuItem (GettextCatalog.GetString ("Quick Fixes"));
201
239
menuItem.Submenu = fixMenu;
202
240
menu.Add (menuItem);
206
PopulateFixes (fixMenu);
245
PopulateFixes (fixMenu, ref items);
250
document.Editor.SuppressTooltips = true;
251
document.Editor.Parent.HideTooltip ();
252
if (menuAction != null)
209
255
menu.SelectFirst (true);
210
256
menuPushed = true;
257
menu.Hidden += delegate {
258
document.Editor.SuppressTooltips = false;
211
260
menu.Destroyed += delegate {
212
261
menuPushed = false;
215
var container = (TextEditorContainer)document.Editor.Parent.Parent;
216
var child = (TextEditorContainer.EditorContainerChild)container [this];
217
GtkWorkarounds.ShowContextMenu (menu, document.Editor.Parent, null, new Gdk.Rectangle (child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0));
264
var container = document.Editor.Parent;
265
var child = (TextEditor.EditorContainerChild)container [this];
268
/* if (child != null) {
269
rect = new Gdk.Rectangle (child.X, child.Y + Allocation.Height - (int)document.Editor.VAdjustment.Value, 0, 0);
271
var p = container.LocationToPoint (loc);
272
rect = new Gdk.Rectangle (p.X + container.Allocation.X , p.Y + (int)document.Editor.LineHeight + container.Allocation.Y, 0, 0);
274
GtkWorkarounds.ShowContextMenu (menu, document.Editor.Parent, null, rect);
220
277
class ContextActionRunner
269
326
using (var cr = Gdk.CairoHelper.Create (evnt.Window)) {
270
327
cr.LineWidth = border;
271
328
cr.Rectangle (0, 0, Allocation.Width, Allocation.Height);
272
cr.Color = document.Editor.ColorStyle.Default.CairoBackgroundColor;
329
cr.Color = document.Editor.ColorStyle.PlainText.Background;
275
332
FoldingScreenbackgroundRenderer.DrawRoundRectangle (cr,
277
334
0, 0, Allocation.Width / 2,
278
335
Allocation.Width, Allocation.Height);
279
cr.Color = isMouseInside || menuPushed ? document.Editor.ColorStyle.Default.CairoColor : document.Editor.ColorStyle.FoldLine.CairoColor;
336
cr.Color = isMouseInside || menuPushed ? document.Editor.ColorStyle.PlainText.Foreground : document.Editor.ColorStyle.FoldLineColor.Color;
282
evnt.Window.DrawPixbuf (Style.BaseGC (State), icon,
284
(Allocation.Width - icon.Width) / 2, (Allocation.Height - icon.Height) / 2,
285
icon.Width, icon.Height,
286
Gdk.RgbDither.None, 0, 0);
339
Gdk.CairoHelper.SetSourcePixbuf (cr, icon, (Allocation.Width - icon.Width) / 2, (Allocation.Height - icon.Height) / 2);