//this method is MIT/X11, 2009, Michael Hutchinson / (c) Novell public static async void OpenFiles(IEnumerable <FileOpenInformation> files) { if (!files.Any()) { return; } if (!IsInitialized) { EventHandler onInit = null; onInit = delegate { Initialized -= onInit; OpenFiles(files); }; Initialized += onInit; return; } var filteredFiles = new List <FileOpenInformation> (); bool closeCurrent = true; foreach (var file in files) { if (Services.ProjectService.IsWorkspaceItemFile(file.FileName) || Services.ProjectService.IsSolutionItemFile(file.FileName)) { try { // Close the current solution, but only for the first solution we open. // If more than one solution is specified in the list we want to open all them together. await Workspace.OpenWorkspaceItem(file.FileName, closeCurrent); closeCurrent = false; } catch (Exception ex) { MessageService.ShowError(GettextCatalog.GetString("Could not load solution: {0}", file.FileName), ex); } } else if (file.FileName.HasExtension("mpack")) { var service = new SetupService(AddinManager.Registry); AddinManagerWindow.RunToInstallFile(Workbench.RootWindow, service, file.FileName.FullPath); } else { filteredFiles.Add(file); } } // Wait for active load operations to be finished (there might be a solution already being loaded // when OpenFiles was called). This will ensure that files opened as part of the solution status // restoration won't steal the focus from the files we are explicitly loading here. await Workspace.CurrentWorkspaceLoadTask; foreach (var file in filteredFiles) { Workbench.OpenDocument(file.FileName, null, file.Line, file.Column, file.Options).ContinueWith(t => { if (t.IsFaulted) { MessageService.ShowError(GettextCatalog.GetString("Could not open file: {0}", file.FileName), t.Exception); } }, TaskScheduler.FromCurrentSynchronizationContext()).Ignore(); } Workbench.Present(); }
//this method is MIT/X11, 2009, Michael Hutchinson / (c) Novell internal static async Task <bool> OpenFilesAsync(IEnumerable <FileOpenInformation> files, OpenWorkspaceItemMetadata metadata) { if (!files.Any()) { return(false); } await initializationTask.Task; Workbench.Present(); var filteredFiles = new List <FileOpenInformation> (); Gdk.ModifierType mtype = Components.GtkWorkarounds.GetCurrentKeyModifiers(); bool closeCurrent = !mtype.HasFlag(Gdk.ModifierType.ControlMask); if (Platform.IsMac && closeCurrent) { closeCurrent = !mtype.HasFlag(Gdk.ModifierType.Mod2Mask); } foreach (var file in files) { if (Services.ProjectService.IsWorkspaceItemFile(file.FileName) || Services.ProjectService.IsSolutionItemFile(file.FileName)) { try { // Close the current solution, but only for the first solution we open. // If more than one solution is specified in the list we want to open all them together. await Workspace.OpenWorkspaceItem(file.FileName, closeCurrent, true, metadata); closeCurrent = false; } catch (Exception ex) { MessageService.ShowError(GettextCatalog.GetString("Could not load solution: {0}", file.FileName), ex); } } else if (file.FileName.HasExtension("mpack")) { var service = new SetupService(AddinManager.Registry); AddinManagerWindow.RunToInstallFile(Workbench.RootWindow.Visible ? Workbench.RootWindow : null, service, file.FileName.FullPath); } else { filteredFiles.Add(file); } } // Wait for active load operations to be finished (there might be a solution already being loaded // when OpenFiles was called). This will ensure that files opened as part of the solution status // restoration won't steal the focus from the files we are explicitly loading here. await Workspace.CurrentWorkspaceLoadTask; for (int n = 0; n < filteredFiles.Count; n++) { var file = filteredFiles [n]; if (n == 0) { file.Options |= OpenDocumentOptions.BringToFront; } else { file.Options &= ~OpenDocumentOptions.BringToFront; } IdeServices.DocumentManager.OpenDocument(file).Ignore(); } return(true); }