Skip to content

Commit

Permalink
Initial flow is working again.. needs much more cleanup but we are on…
Browse files Browse the repository at this point in the history
… the right track :)
  • Loading branch information
StefanKert committed Mar 23, 2019
1 parent 46a8a8d commit 0485750
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 45 deletions.
29 changes: 15 additions & 14 deletions src/BuildVision.UI/ViewModels/BuildVisionPaneViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
using BuildVision.Exports.ViewModels;
using BuildVision.Exports.Providers;
using BuildVision.Contracts.Models;
using Microsoft.VisualStudio;

namespace BuildVision.UI.ViewModels
{
Expand Down Expand Up @@ -181,9 +182,9 @@ public DataGridHeadersVisibility GridHeadersVisibility
}

private ProjectItem _selectedProjectItem;
private readonly IBuildService _buildManager;
private readonly IBuildingProjectsProvider _buildingProjectsProvider;
private readonly IBuildInformationProvider _buildInformationProvider;
private readonly IBuildService _buildService;

public ProjectItem SelectedProjectItem
{
Expand All @@ -192,11 +193,11 @@ public ProjectItem SelectedProjectItem
}

[ImportingConstructor]
public BuildVisionPaneViewModel(IBuildService buildManager, IBuildingProjectsProvider buildingProjectsProvider, IBuildInformationProvider buildInformationProvider, IPackageSettingsProvider settingsProvider, ISolutionProvider solutionProvider)
public BuildVisionPaneViewModel(IBuildingProjectsProvider buildingProjectsProvider, IBuildInformationProvider buildInformationProvider, IPackageSettingsProvider settingsProvider, ISolutionProvider solutionProvider, IBuildService buildService)
{
_buildManager = buildManager;
_buildingProjectsProvider = buildingProjectsProvider;
_buildInformationProvider = buildInformationProvider;
_buildService = buildService;
BuildInformationModel = _buildInformationProvider.GetBuildInformationModel();
SolutionModel = solutionProvider.GetSolutionModel();
ControlSettings = settingsProvider.Settings;
Expand Down Expand Up @@ -359,38 +360,38 @@ private void CopyErrorMessageToClipboard(ProjectItem projectItem)

public ICommand SelectedProjectOpenContainingFolderAction => new RelayCommand(obj => OpenContainingFolder(),
canExecute: obj => (SelectedProjectItem != null && !string.IsNullOrEmpty(SelectedProjectItem.FullName)));

//public ICommand SelectedProjectCopyBuildOutputFilesToClipboardAction => new RelayCommand(
// obj => _buildManager.ProjectCopyBuildOutputFilesToClipBoard(SelectedProjectItem),
// obj => _buildService.ProjectCopyBuildOutputFilesToClipBoard(SelectedProjectItem),
// canExecute: obj => (SelectedProjectItem != null && !string.IsNullOrEmpty(SelectedProjectItem.UniqueName) && !ControlSettings.ProjectItemSettings.CopyBuildOutputFileTypesToClipboard.IsEmpty));

//public ICommand SelectedProjectBuildAction => new RelayCommand(
// obj => _buildManager.RaiseCommandForSelectedProject(SelectedProjectItem, (int)VSConstants.VSStd97CmdID.BuildCtx),
// obj => _buildService.RaiseCommandForSelectedProject(SelectedProjectItem, (int)VSConstants.VSStd97CmdID.BuildCtx),
// canExecute: obj => IsProjectItemEnabledForActions());


//public ICommand SelectedProjectRebuildAction => new RelayCommand(
// obj => _buildManager.RaiseCommandForSelectedProject(SelectedProjectItem, (int)VSConstants.VSStd97CmdID.RebuildCtx),
// obj => _buildService.RaiseCommandForSelectedProject(SelectedProjectItem, (int)VSConstants.VSStd97CmdID.RebuildCtx),
// canExecute: obj => IsProjectItemEnabledForActions());

//public ICommand SelectedProjectCleanAction => new RelayCommand(
// obj => _buildManager.RaiseCommandForSelectedProject(SelectedProjectItem, (int)VSConstants.VSStd97CmdID.CleanCtx),
// obj => _buildService.RaiseCommandForSelectedProject(SelectedProjectItem, (int)VSConstants.VSStd97CmdID.CleanCtx),
// canExecute: obj => IsProjectItemEnabledForActions());

public ICommand SelectedProjectCopyErrorMessagesAction => new RelayCommand(obj => CopyErrorMessageToClipboard(SelectedProjectItem),
canExecute: obj => SelectedProjectItem?.ErrorsCount > 0);

public ICommand BuildSolutionAction => new RelayCommand(obj => _buildManager.BuildSolution());
public ICommand BuildSolutionAction => new RelayCommand(obj => _buildService.BuildSolution());

public ICommand RebuildSolutionAction => new RelayCommand(obj => _buildManager.RebuildSolution());
public ICommand RebuildSolutionAction => new RelayCommand(obj => _buildService.RebuildSolution());

public ICommand CleanSolutionAction => new RelayCommand(obj => _buildManager.CleanSolution());
public ICommand CleanSolutionAction => new RelayCommand(obj => _buildService.CleanSolution());

public ICommand CancelBuildSolutionAction => new RelayCommand(obj => _buildManager.CancelBuildSolution());
public ICommand CancelBuildSolutionAction => new RelayCommand(obj => _buildService.CancelBuildSolution());

public ICommand OpenGridColumnsSettingsAction => new RelayCommand(obj => _buildManager.ShowGridColumnsSettingsPage());
public ICommand OpenGridColumnsSettingsAction => new RelayCommand(obj => _buildService.ShowGridColumnsSettingsPage());

public ICommand OpenGeneralSettingsAction => new RelayCommand(obj => _buildManager.ShowGeneralSettingsPage());
public ICommand OpenGeneralSettingsAction => new RelayCommand(obj => _buildService.ShowGeneralSettingsPage());

#endregion
}
Expand Down
5 changes: 5 additions & 0 deletions src/BuildVision/Core/BuildVisionPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using BuildVision.Helpers;
using BuildVision.Services;
using BuildVision.Tool;
using BuildVision.Tool.Building;
using BuildVision.UI;
using BuildVision.UI.Common.Logging;
using BuildVision.UI.Settings.Models;
Expand Down Expand Up @@ -192,6 +193,10 @@ private async void ShowToolWindowAsync(object sender, EventArgs e)
await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync();
var windowFrame = (IVsWindowFrame)window.Frame;
ErrorHandler.ThrowOnFailure(windowFrame.Show());

var windowStateService = await GetServiceAsync(typeof(IWindowStateService)) as IWindowStateService;
Assumes.Present(windowStateService);
windowStateService.Initialize(window);
}
catch (Exception ex)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BuildVision/Core/BuildVisionPane.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ async Task<BuildVisionPaneViewModel> InitializeAsync(AsyncPackage asyncPackage)
var packageSettingsProvider = await asyncPackage.GetServiceAsync(typeof(IPackageSettingsProvider)) as IPackageSettingsProvider;
Assumes.Present(packageSettingsProvider);

var viewModel = new BuildVisionPaneViewModel(buildService, buildingProjectsProvider, buildInformationProvider, packageSettingsProvider, solutionProvider);
var viewModel = new BuildVisionPaneViewModel(buildingProjectsProvider, buildInformationProvider, packageSettingsProvider, solutionProvider, buildService);

View = CreateControlView();
View.DataContext = viewModel;
Expand Down
1 change: 0 additions & 1 deletion src/BuildVision/Core/ServiceProviderPackage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ protected override async Task InitializeAsync(CancellationToken cancellationToke
AddService(typeof(IWindowStateService), CreateServiceAsync, true);
AddService(typeof(IBuildProgressViewModel), CreateServiceAsync, true);
AddService(typeof(IErrorNavigationService), CreateServiceAsync, true);

}

async Task<object> CreateServiceAsync(IAsyncServiceContainer container, CancellationToken cancellation, Type serviceType)
Expand Down
4 changes: 2 additions & 2 deletions src/BuildVision/Core/Services.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ static TResult GetGlobalService<T, TResult>(IServiceProvider provider = null) wh

public static IComponentModel ComponentModel => GetGlobalService<SComponentModel, IComponentModel>();

public static IVsSolution GetSolution(this IServiceProvider provider)
public static Solution GetSolution(this IServiceProvider provider)
{
return GetGlobalService<SVsSolution, IVsSolution>(provider);
return Dte.Solution;
}
}
}
27 changes: 10 additions & 17 deletions src/BuildVision/Services/BuildInformationProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ private int GetProjectsCount()
case BuildScopes.BuildScopeSolution:
try
{
var solution = _dte.Solution;
var solution = _serviceProvider.GetSolution();
if (solution != null)
projectsCount = _solution.GetProjects().Count;
projectsCount = solution.GetProjects().Count;
}
catch (Exception ex)
{
Expand Down Expand Up @@ -170,10 +170,6 @@ public void BuildFinished(IEnumerable<IProjectItem> projects, bool success, bool
{
return;
}
if (_buildInformationModel.CurrentBuildState == BuildState.InProgress)
{
return;
}

if (_buildInformationModel.BuildScope == BuildScopes.BuildScopeSolution)
{
Expand Down Expand Up @@ -240,21 +236,18 @@ public void BuildFinished(IEnumerable<IProjectItem> projects, bool success, bool

public void Run(CancellationToken cancellationToken)
{
lock (_buildProcessLockObject)
while (!cancellationToken.IsCancellationRequested)
{
while (!cancellationToken.IsCancellationRequested)
{
BuildUpdate();
BuildUpdate();

for (int i = 0; i < BuildInProcessQuantumSleep * BuildInProcessCountOfQuantumSleep; i += BuildInProcessQuantumSleep)
for (int i = 0; i < BuildInProcessQuantumSleep * BuildInProcessCountOfQuantumSleep; i += BuildInProcessQuantumSleep)
{
if (cancellationToken.IsCancellationRequested)
{
if (cancellationToken.IsCancellationRequested)
{
break;
}

System.Threading.Thread.Sleep(BuildInProcessQuantumSleep);
break;
}

System.Threading.Thread.Sleep(BuildInProcessQuantumSleep);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/BuildVision/Services/BuildProgressViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ namespace BuildVision.UI.ViewModels
{
public class BuildProgressViewModel : BindableBase, IBuildProgressViewModel
{
private readonly ControlSettings _settings;
private readonly IPackageSettingsProvider _packageSettingsProvider;
private IBuildInformationModel _buildInformationModel;
private CancellationTokenSource _resetTaskBarInfoCts;
Expand Down Expand Up @@ -51,7 +50,7 @@ public BuildProgressViewModel(IPackageSettingsProvider packageSettingsProvider)

private void UpdateTaskBarInfo()
{
if (!_settings.GeneralSettings.BuildProgressSettings.TaskBarProgressEnabled)
if (!_packageSettingsProvider.Settings.GeneralSettings.BuildProgressSettings.TaskBarProgressEnabled)
return;

TaskbarItemProgressState state;
Expand All @@ -74,7 +73,7 @@ private void UpdateTaskBarInfo()
public void ResetTaskBarInfo(bool ifTaskBarProgressEnabled = true)
{
if (_taskbarItemInfo.IsValueCreated
&& _settings.GeneralSettings.BuildProgressSettings.TaskBarProgressEnabled == ifTaskBarProgressEnabled)
&& _packageSettingsProvider.Settings.GeneralSettings.BuildProgressSettings.TaskBarProgressEnabled == ifTaskBarProgressEnabled)
{
TaskbarItemInfo.ProgressState = TaskbarItemProgressState.None;
TaskbarItemInfo.ProgressValue = 0;
Expand Down Expand Up @@ -148,7 +147,7 @@ public void OnBuildDone()

private void ResetTaskBarInfoOnBuildDone()
{
var buildProgressSettings = _settings.GeneralSettings.BuildProgressSettings;
var buildProgressSettings = _packageSettingsProvider.Settings.GeneralSettings.BuildProgressSettings;
if (!buildProgressSettings.TaskBarProgressEnabled)
return;

Expand Down
2 changes: 2 additions & 0 deletions src/BuildVision/Services/IWindowStateService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
using BuildVision.UI.Settings.Models.ToolWindow;
using Microsoft.VisualStudio.Shell;

namespace BuildVision.Tool.Building
{
public interface IWindowStateService
{
void ApplyToolWindowStateAction(WindowStateAction windowStateAction);
void Initialize(ToolWindowPane toolWindowPane);
}
}
2 changes: 1 addition & 1 deletion src/BuildVision/Services/StatusBarNotificationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void ShowText(string str)

public void ShowTextWithFreeze(string str)
{
ThreadHelper.ThrowIfNotOnUIThread();
//ThreadHelper.ThrowIfNotOnUIThread();
var statusBar = _serviceProvider.GetService(typeof(IVsStatusbar)) as IVsStatusbar;
var settings = _serviceProvider.GetService(typeof(IPackageSettingsProvider)) as IPackageSettingsProvider;
if (settings == null || statusBar == null)
Expand Down
13 changes: 8 additions & 5 deletions src/BuildVision/Services/WindowStateService.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.ComponentModel.Composition;
using System.Linq;
using BuildVision.Helpers;
using BuildVision.UI.Settings.Models.ToolWindow;
using BuildVision.Views.Settings;
using EnvDTE;
using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
Expand All @@ -12,6 +9,8 @@

namespace BuildVision.Tool.Building
{
[Export(typeof(IWindowStateService))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class WindowStateService : IWindowStateService
{
private DTE _dte;
Expand Down Expand Up @@ -125,19 +124,23 @@ private void ApplyToolWindowStateAction(WindowState windowState)
}
}

public void ApplyToolWindowStateAction(WindowStateAction windowStateAction)
public void Initialize(ToolWindowPane toolWindowPane)
{
if (_window == null || _windowFrame == null)
{
ThreadHelper.ThrowIfNotOnUIThread();
_dte = _serviceProvider.GetService(typeof(DTE)) as DTE;
if (_dte == null)
throw new InvalidOperationException("Unable to get DTE instance.");
_windowFrame = (IVsWindowFrame)(_package.FindToolWindow(typeof(BuildVisionPane), 0, false) ?? _package.FindToolWindow(typeof(BuildVisionPane), 0, true));
_windowFrame = (IVsWindowFrame)toolWindowPane.Frame;
_window = GetWindowInstance(_dte, typeof(BuildVisionPane).GUID);
if (_window == null)
throw new InvalidOperationException("Unable to get Window instance.");
}
}

public void ApplyToolWindowStateAction(WindowStateAction windowStateAction)
{
ApplyToolWindowStateAction(windowStateAction.State);
}
}
Expand Down

0 comments on commit 0485750

Please sign in to comment.