private string DoGetNamespace(Boss windowBoss, string type) { if (type.Length == 0) throw new InvalidOperationException("Expected a selection with a type name."); // Get the namespaces the type is within. string[] candidates = DoFindFullNames(windowBoss, type, 12); var names = new List<string>(); foreach (string candidate in candidates) { string temp = candidate; int i = temp.IndexOf('/'); // strip off the nested type if (i > 0) temp = temp.Substring(0, i); i = temp.LastIndexOf('.'); // strip off the type name if (i > 0) names.Add(temp.Substring(0, i)); } // Figure out which namespace we want to add. string name = null; if (names.Count == 0) { throw new InvalidOperationException("Couldn't find a type named '" + type + "'."); } else if (names.Count == 1) { name = names[0]; } else { var picker = new GetItem<string>{ Title = "Select Namespace", Items = names.ToArray(), AllowsMultiple = false}; string[] result = picker.Run(s => s); if (result.Length == 1) name = result[0]; } return name; }
private bool DoOpenPath(List<string> candidates, int line, int col) { Contract.Requires(candidates.Count > 0); var paths = new List<string>(candidates); if (paths.Count > 2) { paths.Sort(); var getter = new GetItem<string>{Title = "Choose Files", Items = paths.ToArray(), AllowsMultiple = true}; paths = new List<string>(getter.Run(i => i)); // If the user canceled then we don't want to proceed so we'll say we opened it. if (paths.Count == 0) return true; } bool opened = false; if (paths.Count > 0) { Boss boss = ObjectModel.Create("Application"); var launcher = boss.Get<ILaunch>(); var bad = new List<string>(); foreach (string p in paths) { try { launcher.Launch(p, line, col, 1); opened = true; } catch { bad.Add(p); } } if (bad.Count > 0) { NSString title = NSString.Create("Couldn't open."); NSString message = NSString.Create(string.Join("\n", bad.ToArray())); Unused.Value = Functions.NSRunAlertPanel(title, message); } } return opened; }