private void Init() { _dte = GetGlobalService(typeof(DTE)) as DTE2 ?? throw new NullReferenceException($"Unable to get service {nameof(DTE2)}"); //Log context and Serilog enricher VsVersionContext.Current = new VsDteVersionContext(_dte); LoggerContext.Current = new LogentriesSerilogLoggerContext(); LoggerContext.Current.Logger.Info($"{nameof(ReopenPackage)} started to load. Initializing dependencies..."); //DI IDocumentHistoryManager documentHistory = new DocumentHistoryManager(); _documentHistoryCommands = documentHistory; _documentHistoryQueries = documentHistory; //Commands _reopenLastClosedCommand = new RemoveLastCommand(_documentHistoryCommands, new ReopenDocumentCommandFactory(_dte)); _removeLastClosedCommand = new RemoveLastCommand(_documentHistoryCommands, new DoNothingDocumentCommandFactory()); _reopenSomeDocumentsCommandFactory = new HistoryCommandFactory <RemoveSomeCommand>(_documentHistoryCommands, new ReopenDocumentCommandFactory(_dte)); _removeSomeDocumentsCommandFactory = new HistoryCommandFactory <RemoveSomeCommand>(_documentHistoryCommands, new DoNothingDocumentCommandFactory()); _clearHistoryCommand = new ClearHistoryCommand(_documentHistoryCommands); _documentTracker = new DocumentEventsTracker(_dte, documentHistory, new JsonHistoryRepositoryFactory(new ServiceStackJsonSerializer()), new VSMessageBox(this)); }
private void HandleOperatons(IHistoryCommandFactory historyCommandFactory) { var selectedItems = _listView.SelectedItems.Cast <ClosedDocumentHistoryItem>() .Select(s => s.ClosedDocument); var command = historyCommandFactory.CreateCommand(selectedItems.ToArray()); command.Execute(); LoggerContext.Current.Logger.Info($"Command: {command.GetType()} from ToolWindow was executed"); }
public static async Task InitializeAsync(IDocumentHistoryQueries documentHistoryQueries, IHistoryCommand reopenLastClosdCommand, IHistoryCommandFactory reopenSomeDocumentsCommandFactory, IHistoryCommandFactory removeSomeDocumentsCommandFactory, IHistoryCommand clearHistoryCommand, IFileExtensionIconResolver fileExtensionIconResolver, IHistoryToolWindowRepositoryFactory historyToolWindowRepositoryFactory) { ContentWindow = new ClosedDocumentsHistoryControl(documentHistoryQueries, reopenLastClosdCommand, reopenSomeDocumentsCommandFactory, removeSomeDocumentsCommandFactory, clearHistoryCommand, fileExtensionIconResolver, historyToolWindowRepositoryFactory); await Task.CompletedTask; }
private DocumentsHistoryCommand(AsyncPackage package, OleMenuCommandService commandService, IDocumentHistoryQueries documentHistoryQueries, IHistoryCommandFactory reopenSomeDocumentsCommandFactory) { _package = package ?? throw new ArgumentNullException(nameof(package)); commandService = commandService ?? throw new ArgumentNullException(nameof(commandService)); _documentHistoryQueries = documentHistoryQueries ?? throw new ArgumentNullException(nameof(documentHistoryQueries)); _reopenSomeDocumentsCommandFactory = reopenSomeDocumentsCommandFactory ?? throw new ArgumentNullException(nameof(reopenSomeDocumentsCommandFactory)); var menuCommandId = new CommandID(CommandSet, CommandId); var command = new OleMenuCommand(Execute, menuCommandId) { Visible = false, Enabled = false }; command.BeforeQueryStatus += DynamicStartBeforeQueryStatus; commandService.AddCommand(command); }
public static async Task InitializeAsync(AsyncPackage package, IDocumentHistoryQueries documentHistoryQueries, IHistoryCommandFactory reopenSomeDocumentsCommandFactory) { var commandService = package == null ? null : await package.GetServiceAsync(typeof(IMenuCommandService)) as OleMenuCommandService; Instance = new DocumentsHistoryCommand(package, commandService, documentHistoryQueries, reopenSomeDocumentsCommandFactory); }
/// <summary> /// Initializes a new instance of the <see cref="ClosedDocumentsHistoryControl"/> class. /// </summary> public ClosedDocumentsHistoryControl(IDocumentHistoryQueries documentHistoryQueries, IHistoryCommand reopenLastClosdCommand, IHistoryCommandFactory reopenSomeDocumentsCommandFactory, IHistoryCommandFactory removeSomeDocumentsCommandFactory, IHistoryCommand clearHistoryCommand, IFileExtensionIconResolver fileExtensionIconResolver, IHistoryToolWindowRepositoryFactory historyToolWindowRepositoryFactory) { InitializeComponent(); _documentHistoryQueries = documentHistoryQueries; _reopenLastClosdCommand = reopenLastClosdCommand; _reopenSomeDocumentsCommandFactory = reopenSomeDocumentsCommandFactory; _removeSomeDocumentsCommandFactory = removeSomeDocumentsCommandFactory; _clearHistoryCommand = clearHistoryCommand; _fileExtensionIconResolver = fileExtensionIconResolver; _historyToolWindowRepositoryFactory = historyToolWindowRepositoryFactory; var openState = new ButtonDisabledState(_openSelected, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.OpenFile_16x) }, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.OpenFile_16x_Gray) }); openState.Disable(); var removeState = new ButtonDisabledState(_removeSelected, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.RemoveGuide_16x) }, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.RemoveGuide_16x_Gray) }); removeState.Disable(); var removeNonExistingState = new ButtonDisabledState(_removeNonExisting, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.RemoveNonExisting_16x) }, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.RemoveNonExisting_16x_Gray) }); removeNonExistingState.Disable(); var clearState = new ButtonDisabledState(_clearAll, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.ClearWindowContent_16x) }, new Image() { Source = WpfImageSourceConverter.CreateBitmapSource(VSDocumentReopen.Resources.ClearWindowContent_16x_Gray) }); clearState.Disable(); _documentHistoryQueries.HistoryChanged += DocumentHistoryChanged; UpdateHistoryView(GetFullHistory); _listView.Focus(); var customizationSettings = LoadCustomizationSettings(); _columnHeaders = Enumerable.Range(0, _listViewContect.Columns.Count).ToDictionary(i => i++, i => _listViewContect.Columns[i].GetGridViewHeaderText()); AddContextMenu(customizationSettings); HandleColumnsStatus(customizationSettings); }