Skip to content

Commit

Permalink
Merge branch 'next' into SplitRefactorings
Browse files Browse the repository at this point in the history
# Conflicts:
#	Rubberduck.Refactorings/ExtractInterface/ExtractInterfaceRefactoring.cs
#	RubberduckTests/CodeExplorer/MockedCodeExplorer.cs
#	RubberduckTests/Commands/RefactorCommands/ExtractInterfaceCommandTests.cs
#	RubberduckTests/Refactoring/ExtractInterface/ExtractInterfaceTests.cs
  • Loading branch information
MDoerner committed Feb 22, 2020
2 parents c4ad4c8 + d2d3f1f commit 0abf2d8
Show file tree
Hide file tree
Showing 48 changed files with 808 additions and 429 deletions.
14 changes: 12 additions & 2 deletions Rubberduck.Core/AddRemoveReferences/ReferenceReconciler.cs
Expand Up @@ -8,6 +8,7 @@
using Rubberduck.Settings;
using Rubberduck.SettingsProvider;
using Rubberduck.UI.AddRemoveReferences;
using Rubberduck.VBEditor.ComManagement;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;

namespace Rubberduck.AddRemoveReferences
Expand All @@ -29,15 +30,18 @@ public class ReferenceReconciler : IReferenceReconciler
private readonly IMessageBox _messageBox;
private readonly IConfigurationService<ReferenceSettings> _settings;
private readonly IComLibraryProvider _libraryProvider;
private readonly IProjectsProvider _projectsProvider;

public ReferenceReconciler(
IMessageBox messageBox,
IConfigurationService<ReferenceSettings> settings,
IComLibraryProvider libraryProvider)
IComLibraryProvider libraryProvider,
IProjectsProvider projectsProvider)
{
_messageBox = messageBox;
_settings = settings;
_libraryProvider = libraryProvider;
_projectsProvider = projectsProvider;
}

public List<ReferenceModel> ReconcileReferences(IAddRemoveReferencesModel model)
Expand All @@ -58,12 +62,18 @@ public List<ReferenceModel> ReconcileReferences(IAddRemoveReferencesModel model,
return new List<ReferenceModel>();
}

var project = _projectsProvider.Project(model.Project.ProjectId);

if (project == null)
{
return new List<ReferenceModel>();
}

var selected = allReferences.Where(reference => !reference.IsBuiltIn && reference.Priority.HasValue)
.ToDictionary(reference => reference.FullPath);

var output = selected.Values.Where(reference => reference.IsBuiltIn).ToList();

var project = model.Project.Project;
using (var references = project.References)
{
foreach (var reference in references)
Expand Down
Expand Up @@ -84,7 +84,7 @@ private void Synchronize(IEnumerable<Declaration> declarations)
foreach (var project in adding)
{
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe, false);
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe, _state.ProjectsProvider,false);
Projects.Add(model);
}
}).Wait();
Expand Down
2 changes: 1 addition & 1 deletion Rubberduck.Core/Formatters/DeclarationFormatter.cs
Expand Up @@ -21,7 +21,7 @@ public object[] ToArray()
public string ToClipboardString()
{
return string.Format(RubberduckUI.CodeExplorer_IExportable_DeclarationFormat,
_declaration.Project.Name,
_declaration.ProjectName,
_declaration.CustomFolder,
_declaration.ComponentName,
_declaration.DeclarationType,
Expand Down
28 changes: 4 additions & 24 deletions Rubberduck.Core/Formatters/InspectionResultFormatter.cs
@@ -1,18 +1,18 @@
using Rubberduck.Common;
using Rubberduck.Parsing.Inspections.Abstract;
using Rubberduck.Inspections.Abstract;
using System.IO;
using Rubberduck.Resources.Inspections;

namespace Rubberduck.Formatters
{
public class InspectionResultFormatter : IExportable
{
private readonly IInspectionResult _inspectionResult;
private readonly string _documentName;

public InspectionResultFormatter(IInspectionResult inspectionResult)
public InspectionResultFormatter(IInspectionResult inspectionResult, string documentName)
{
_inspectionResult = inspectionResult;
_documentName = documentName;
}

public object[] ToArray()
Expand All @@ -29,30 +29,10 @@ public object[] ToArray()
};
}

/// <summary>
/// WARNING: This property can have side effects. It can change the ActiveVBProject if the result has a null Declaration,
/// which causes a flicker in the VBE. This should only be called if it is *absolutely* necessary.
/// </summary>
public string ToClipboardString()
{
var module = _inspectionResult.QualifiedSelection.QualifiedName;
var documentName = _inspectionResult.Target != null
? _inspectionResult.Target.ProjectDisplayName
: string.Empty;

//todo: Find a sane way to reimplement this.
//if (string.IsNullOrEmpty(documentName))
//{
// var component = module.Component;
// documentName = component != null
// ? component.ParentProject.ProjectDisplayName
// : string.Empty;
//}

if (string.IsNullOrEmpty(documentName))
{
documentName = Path.GetFileName(module.ProjectPath);
}
var documentName = _documentName;

return string.Format(
InspectionsUI.QualifiedSelectionInspection,
Expand Down
Expand Up @@ -5,6 +5,7 @@
using Rubberduck.Navigation.Folders;
using Rubberduck.Parsing.Symbols;
using Rubberduck.Parsing.VBA;
using Rubberduck.VBEditor.ComManagement;
using Rubberduck.VBEditor.SafeComWrappers;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;

Expand All @@ -21,11 +22,20 @@ public class CodeExplorerProjectViewModel : CodeExplorerItemViewModel
};

private readonly IVBE _vbe;

public CodeExplorerProjectViewModel(Declaration project, ref List<Declaration> declarations, RubberduckParserState state, IVBE vbe, bool references = true) : base(null, project)
private readonly IProjectsProvider _projectsProvider;

public CodeExplorerProjectViewModel(
Declaration project,
ref List<Declaration> declarations,
RubberduckParserState state,
IVBE vbe,
IProjectsProvider projectsProvider,
bool references = true)
: base(null, project)
{
State = state;
State = state;
_vbe = vbe;
_projectsProvider = projectsProvider;
ShowReferences = references;

SetName();
Expand All @@ -47,15 +57,23 @@ public override FontWeight FontWeight
{
get
{
if (_vbe.Kind == VBEKind.Hosted || Declaration.Project == null)
if (_vbe.Kind == VBEKind.Hosted || Declaration == null)
{
return base.FontWeight;
}

var project = _projectsProvider.Project(Declaration.ProjectId);
if (project == null)
{
return base.FontWeight;
}

using (var vbProjects = _vbe.VBProjects)
using (var startProject = vbProjects?.StartProject)
{
return Declaration.Project.Equals(startProject) ? FontWeights.Bold : base.FontWeight;
return project.Equals(startProject)
? FontWeights.Bold
: base.FontWeight;
}
}
}
Expand Down Expand Up @@ -139,7 +157,12 @@ private void SynchronizeReferences()

private List<ReferenceModel> GetProjectReferenceModels()
{
var project = Declaration?.Project;
if (Declaration == null)
{
return new List<ReferenceModel>();
}

var project = _projectsProvider.Project(Declaration.ProjectId);
if (project == null)
{
return new List<ReferenceModel>();
Expand Down Expand Up @@ -170,11 +193,24 @@ private void SetName()
_name = Declaration?.IdentifierName ?? string.Empty;

// F' the flicker. Digging into the properties has some even more evil side-effects, and is a performance nightmare by comparison.
_displayName = Declaration?.ProjectDisplayName ?? string.Empty;
_displayName = DisplayName(Declaration);

OnNameChanged();
}

private string DisplayName(Declaration declaration)
{
if (declaration == null)
{
return string.Empty;
}

var project = _projectsProvider.Project(declaration.ProjectId);
return project != null
? project.ProjectDisplayName
: string.Empty;
}

private static readonly List<DeclarationType> UntrackedTypes = new List<DeclarationType>
{
DeclarationType.Parameter,
Expand Down
11 changes: 5 additions & 6 deletions Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerViewModel.cs
Expand Up @@ -13,7 +13,6 @@
using Rubberduck.UI.Command;
using Rubberduck.VBEditor.SafeComWrappers;
using System.Windows;
using System.Windows.Forms;
using System.Windows.Input;
using Rubberduck.Parsing.UIContext;
using Rubberduck.Templates;
Expand Down Expand Up @@ -287,7 +286,7 @@ private void Synchronize(IEnumerable<Declaration> declarations)
foreach (var project in adding)
{
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe) { Filter = Search };
var model = new CodeExplorerProjectViewModel(project, ref updates, _state, _vbe, _state.ProjectsProvider) { Filter = Search };
Projects.Add(model);
}
Expand All @@ -305,12 +304,12 @@ private void ParserState_ModuleStateChanged(object sender, ParseProgressEventArg
return;
}

var componentProject = _state.ProjectsProvider.Project(e.Module.ProjectId);
var componentProjectId = e.Module.ProjectId;

var module = Projects.OfType<CodeExplorerProjectViewModel>()
.FirstOrDefault(p => p.Declaration.Project?.Equals(componentProject) ?? false)?.Children
.OfType<CodeExplorerComponentViewModel>().FirstOrDefault(component =>
component.QualifiedSelection?.QualifiedName.Equals(e.Module) ?? false);
.FirstOrDefault(p => p.Declaration?.ProjectId.Equals(componentProjectId) ?? false)?.Children
.OfType<CodeExplorerComponentViewModel>()
.FirstOrDefault(component => component.QualifiedSelection?.QualifiedName.Equals(e.Module) ?? false);

if (module == null)
{
Expand Down
Expand Up @@ -10,14 +10,15 @@
using Rubberduck.Settings;
using Rubberduck.SettingsProvider;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.ComManagement;
using Rubberduck.VBEditor.SafeComWrappers;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;

namespace Rubberduck.UI.AddRemoveReferences
{
public interface IAddRemoveReferencesPresenterFactory
{
AddRemoveReferencesPresenter Create(ProjectDeclaration project);
AddRemoveReferencesPresenter Create(ProjectDeclaration projectDeclaration);
}

public class AddRemoveReferencesPresenterFactory : IAddRemoveReferencesPresenterFactory
Expand All @@ -31,25 +32,35 @@ public class AddRemoveReferencesPresenterFactory : IAddRemoveReferencesPresenter
private readonly IRegisteredLibraryFinderService _finder;
private readonly IReferenceReconciler _reconciler;
private readonly IFileSystemBrowserFactory _browser;
private readonly IProjectsProvider _projectsProvider;

public AddRemoveReferencesPresenterFactory(IVBE vbe,
RubberduckParserState state,
IConfigurationService<ReferenceSettings> settingsProvider,
IRegisteredLibraryFinderService finder,
IReferenceReconciler reconciler,
IFileSystemBrowserFactory browser)
IFileSystemBrowserFactory browser,
IProjectsProvider projectsProvider)
{
_vbe = vbe;
_state = state;
_settings = settingsProvider;
_finder = finder;
_reconciler = reconciler;
_browser = browser;
_projectsProvider = projectsProvider;
}

public AddRemoveReferencesPresenter Create(ProjectDeclaration project)
public AddRemoveReferencesPresenter Create(ProjectDeclaration projectDeclaration)
{
if (project is null)
if (projectDeclaration is null)
{
return null;
}

var project = _projectsProvider.Project(projectDeclaration.ProjectId);

if (project == null)
{
return null;
}
Expand All @@ -75,7 +86,7 @@ public AddRemoveReferencesPresenter Create(ProjectDeclaration project)
}

var models = new Dictionary<RegisteredLibraryKey, ReferenceModel>();
using (var references = project.Project?.References)
using (var references = project.References)
{
if (references is null)
{
Expand All @@ -101,7 +112,7 @@ public AddRemoveReferencesPresenter Create(ProjectDeclaration project)
: new ReferenceModel(reference, priority++);

adding.IsUsed = adding.IsBuiltIn ||
_state.DeclarationFinder.IsReferenceUsedInProject(project,
_state.DeclarationFinder.IsReferenceUsedInProject(projectDeclaration,
adding.ToReferenceInfo());

models.Add(libraryId, adding);
Expand All @@ -117,7 +128,7 @@ public AddRemoveReferencesPresenter Create(ProjectDeclaration project)
}

var settings = _settings.Read();
model = new AddRemoveReferencesModel(_state, project, models.Values, settings);
model = new AddRemoveReferencesModel(_state, projectDeclaration, models.Values, settings);
if (AddRemoveReferencesViewModel.HostHasProjects)
{
model.References.AddRange(GetUserProjectFolderModels(model.Settings).Where(proj =>
Expand All @@ -136,7 +147,7 @@ public AddRemoveReferencesPresenter Create(ProjectDeclaration project)

return (model != null)
? new AddRemoveReferencesPresenter(
new AddRemoveReferencesDialog(new AddRemoveReferencesViewModel(model, _reconciler, _browser)))
new AddRemoveReferencesDialog(new AddRemoveReferencesViewModel(model, _reconciler, _browser, _projectsProvider)))
: null;
}

Expand Down

0 comments on commit 0abf2d8

Please sign in to comment.