Esempio n. 1
0
 static bool FileServiceErrorHandler(string message, Exception ex)
 {
     MessageService.ShowError(message, ex);
     return(true);
 }
Esempio n. 2
0
        //this method is MIT/X11, 2009, Michael Hutchinson / (c) Novell
        public static 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> ();

            //open the firsts sln/workspace file, and remove the others from the list
            //FIXME: can we handle multiple slns?
            bool            foundSln = false;
            IAsyncOperation openSolutionOperation = null;

            foreach (var file in files)
            {
                if (Services.ProjectService.IsWorkspaceItemFile(file.FileName) ||
                    Services.ProjectService.IsSolutionItemFile(file.FileName))
                {
                    if (!foundSln)
                    {
                        try {
                            var op = Workspace.OpenWorkspaceItem(file.FileName);
                            foundSln = true;
                            openSolutionOperation = op;
                        } catch (Exception ex) {
                            MessageService.ShowError(GettextCatalog.GetString("Could not load solution: {0}", file.FileName), ex);
                        }
                    }
                }
                else
                {
                    filteredFiles.Add(file);
                }
            }

            // Wait for solution and it's open files to load, so we are sure
            // that the files we open afterwards are actually opened in tabs
            // after the solution's saved open files and that the last file
            // in the filteredFiles gets focus, if specified as an option.
            if (filteredFiles.Count > 0 && openSolutionOperation != null)
            {
                openSolutionOperation.WaitForCompleted();
            }

            foreach (var file in filteredFiles)
            {
                try {
                    Workbench.OpenDocument(file.FileName, file.Line, file.Column, file.Options);
                } catch (Exception ex) {
                    MessageService.ShowError(GettextCatalog.GetString("Could not open file: {0}", file.FileName), ex);
                }
            }

            Workbench.Present();
        }
Esempio n. 3
0
        //this method is MIT/X11, 2009, Michael Hutchinson / (c) Novell
        internal static async void OpenFiles(IEnumerable <FileOpenInformation> files, IDictionary <string, string> metadata)
        {
            if (!files.Any())
            {
                return;
            }

            if (!IsInitialized)
            {
                EventHandler onInit = null;
                onInit = delegate {
                    Initialized -= onInit;
                    OpenFiles(files, metadata);
                };
                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, 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,
                                                        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();
        }
Esempio n. 4
0
        //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);
        }