/// <summary> /// Initializes a new instance of the <see cref="ShortcutEditorFactory"/> class. /// </summary> internal ShortcutEditorFactory(IServiceProvider provider, IShortcutPersistenceHandler fileHandler) : this(provider) { Guard.NotNull(() => fileHandler, fileHandler); this.PersistenceHandler = fileHandler; }
/// <summary> /// Initializes a new instance of the <see cref="ShortcutEditorFactory"/> class. /// </summary> internal ShortcutEditorFactory(IServiceProvider provider, IShortcutPersistenceHandler fileHandler) : this(provider) { Guard.NotNull(() => fileHandler, fileHandler); this.PersistenceHandler = fileHandler; }
/// <summary> /// Used by the editor factory architecture to create editors that support data/view separation. /// </summary> public int CreateEditorInstance(uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW) { ppunkDocView = IntPtr.Zero; ppunkDocData = IntPtr.Zero; pbstrEditorCaption = string.Empty; pguidCmdUI = this.GetType().GUID; pgrfCDW = 0; // Ensure that the file exists if (File.Exists(pszMkDocument)) { // Ensure we have a file handler. if (this.PersistenceHandler == null) { this.PersistenceHandler = new ShortcutFileHandler(pszMkDocument); } // Launch the shortcut var result = ShortcutLaunchCoordinator.LaunchShortcut(this.serviceProvider, this.PersistenceHandler); return result ? VSConstants.S_OK : VSConstants.S_FALSE; } return VSConstants.S_FALSE; }
/// <summary> /// Used by the editor factory architecture to create editors that support data/view separation. /// </summary> public int CreateEditorInstance(uint grfCreateDoc, string pszMkDocument, string pszPhysicalView, IVsHierarchy pvHier, uint itemid, IntPtr punkDocDataExisting, out IntPtr ppunkDocView, out IntPtr ppunkDocData, out string pbstrEditorCaption, out Guid pguidCmdUI, out int pgrfCDW) { ppunkDocView = IntPtr.Zero; ppunkDocData = IntPtr.Zero; pbstrEditorCaption = string.Empty; pguidCmdUI = this.GetType().GUID; pgrfCDW = 0; // Ensure that the file exists if (File.Exists(pszMkDocument)) { // Ensure we have a file handler. if (this.PersistenceHandler == null) { this.PersistenceHandler = new ShortcutFileHandler(pszMkDocument); } // Launch the shortcut var result = ShortcutLaunchCoordinator.LaunchShortcut(this.serviceProvider, this.PersistenceHandler); return(result ? VSConstants.S_OK : VSConstants.S_FALSE); } return(VSConstants.S_FALSE); }
/// <summary> /// Launches a shortcut from file. /// </summary> public static bool LaunchShortcut(IServiceProvider serviceProvider, IShortcutPersistenceHandler fileHandler) { Guard.NotNull(() => serviceProvider, serviceProvider); Guard.NotNull(() => fileHandler, fileHandler); var messageService = serviceProvider.GetService <IUserMessageService>(); var launchService = serviceProvider.GetService <IShortcutLaunchService>(); try { // Read the file content var shortcut = fileHandler.ReadShortcut(); if (shortcut != null) { // Check if type is registered if (!launchService.IsTypeRegistered(shortcut.Type)) { throw new ShortcutProviderNotExistException(); } // Get an actual instance of the provided shortcut var specificShortcut = launchService.ResolveShortcut(shortcut); if (specificShortcut == null) { throw new ShortcutProviderNotExistException(); } // Execute the shortcut var newShortcut = launchService.Execute(specificShortcut); // Update the shortcut (if updated at all) if (newShortcut != null) { fileHandler.WriteShortcut(newShortcut); } return(true); } } catch (ShortcutProviderNotExistException) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorShortcutProviderNotExist); } } catch (ShortcutFileFormatException) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorShortcutFormat); } } catch (ShortcutFileAccessException) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorShortcutIO); } } catch (Exception) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorUnknown); } } return(false); }
/// <summary> /// Launches a shortcut from file. /// </summary> public static bool LaunchShortcut(IServiceProvider serviceProvider, IShortcutPersistenceHandler fileHandler) { Guard.NotNull(() => serviceProvider, serviceProvider); Guard.NotNull(() => fileHandler, fileHandler); var messageService = serviceProvider.GetService<IUserMessageService>(); var launchService = serviceProvider.GetService<IShortcutLaunchService>(); try { // Read the file content var shortcut = fileHandler.ReadShortcut(); if (shortcut != null) { // Check if type is registered if (!launchService.IsTypeRegistered(shortcut.Type)) { throw new ShortcutProviderNotExistException(); } // Get an actual instance of the provided shortcut var specificShortcut = launchService.ResolveShortcut(shortcut); if (specificShortcut == null) { throw new ShortcutProviderNotExistException(); } // Execute the shortcut var newShortcut = launchService.Execute(specificShortcut); // Update the shortcut (if updated at all) if (newShortcut != null) { fileHandler.WriteShortcut(newShortcut); } return true; } } catch (ShortcutProviderNotExistException) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorShortcutProviderNotExist); } } catch (ShortcutFileFormatException) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorShortcutFormat); } } catch (ShortcutFileAccessException) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorShortcutIO); } } catch (Exception) { if (messageService != null) { messageService.ShowError(Resources.ShortcutEditorFactory_ErrorUnknown); } } return false; }