Skip to content

Commit

Permalink
Merge branch 'next' into RecoverSelectionAfterRewrite
Browse files Browse the repository at this point in the history
# Conflicts:
#	Rubberduck.Resources/RubberduckUI.resx
  • Loading branch information
MDoerner committed Feb 13, 2019
2 parents fc36605 + e7079f1 commit b01f450
Show file tree
Hide file tree
Showing 40 changed files with 1,049 additions and 382 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug_report.md
Expand Up @@ -33,7 +33,7 @@ A clear and concise description of what you expected to happen.
If applicable, add screenshots to help explain your problem.

**Logfile**
Rubberduck generates extensive logging in TRACE-Level. If no log was created at `%APP_DATA%\Rubberduck\Logs`, check your settings. Include this Log for bugreports about the behavior of Rubbberduck
Rubberduck generates extensive logging in TRACE-Level. If no log was created at `%APPDATA%\Rubberduck\Logs`, check your settings. Include this Log for bugreports about the behavior of Rubbberduck

**Additional context**
Add any other context about the problem here.
10 changes: 10 additions & 0 deletions Rubberduck.Core/AutoComplete/AutoCompleteHandlerBase.cs
Expand Up @@ -5,6 +5,9 @@

namespace Rubberduck.AutoComplete
{
/// <summary>
/// A base class/interface for AC services / "handlers".
/// </summary>
public abstract class AutoCompleteHandlerBase
{
protected AutoCompleteHandlerBase(ICodePaneHandler pane)
Expand All @@ -14,6 +17,13 @@ protected AutoCompleteHandlerBase(ICodePaneHandler pane)

protected ICodePaneHandler CodePaneHandler { get; }

/// <summary>
/// A method that returns <c>false</c> if the input isn't handled, <c>true</c> if it is.
/// </summary>
/// <param name="e">The autocompletion event info</param>
/// <param name="settings">The current AC settings</param>
/// <param name="result">If handled, the resulting <c>CodeString</c></param>
/// <returns></returns>
public abstract bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settings, out CodeString result);
}
}
Expand Up @@ -5,8 +5,12 @@
using Rubberduck.Settings;
using Rubberduck.VBEditor.Events;

namespace Rubberduck.AutoComplete.Service
namespace Rubberduck.AutoComplete
{
/// <summary>
/// A service responsible for dispatching CodePane work to more specialized autocompletion services.
/// Handles changes in configuration settings.
/// </summary>
public class AutoCompleteService : IDisposable
{
private static readonly ILogger Logger = LogManager.GetCurrentClassLogger();
Expand Down Expand Up @@ -151,6 +155,7 @@ private bool TryHandle(AutoCompleteEventArgs e, AutoCompleteHandlerBase handler)
return false;
}

Logger.Debug($"Keypress was handled by {handler.GetType().Name}.");
e.Handled = true;
return true;

Expand All @@ -169,7 +174,8 @@ public void Dispose()
}

private bool _isDisposed;
protected virtual void Dispose(bool disposing)

private void Dispose(bool disposing)
{
if (_isDisposed || !disposing)
{
Expand Down
@@ -1,7 +1,7 @@
using Rubberduck.VBEditor;
using System;
using System;
using Rubberduck.VBEditor;

namespace Rubberduck.AutoComplete.Service
namespace Rubberduck.AutoComplete.SelfClosingPairs
{
public class SelfClosingPair : IEquatable<SelfClosingPair>
{
Expand Down
Expand Up @@ -8,7 +8,7 @@
using Rubberduck.Parsing.VBA.Parsing;
using Rubberduck.VBEditor;

namespace Rubberduck.AutoComplete.Service
namespace Rubberduck.AutoComplete.SelfClosingPairs
{
public class SelfClosingPairCompletionService
{
Expand Down
@@ -1,13 +1,16 @@
using System.Collections.Generic;
using System.Diagnostics;
using System;
using System.Collections.Generic;
using System.Linq;
using Rubberduck.Settings;
using Rubberduck.VBEditor;
using Rubberduck.VBEditor.Events;
using Rubberduck.VBEditor.SourceCodeHandling;

namespace Rubberduck.AutoComplete.Service
namespace Rubberduck.AutoComplete.SelfClosingPairs
{
/// <summary>
/// An AC handler that automatically closes certain specific "pairs" of characters, e.g. double quotes, or parentheses.
/// </summary>
public class SelfClosingPairHandler : AutoCompleteHandlerBase
{
private const int MaximumLines = 25;
Expand Down Expand Up @@ -39,6 +42,7 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
result = null;
if (!_scpInputLookup.TryGetValue(e.Character, out var pair) && e.Character != '\b')
{
// not an interesting keypress.
return false;
}

Expand All @@ -50,15 +54,25 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin
return false;
}

if (!original.CaretPosition.IsSingleCharacter)
{
// here would be an opportunity to "wrap selection" with a SCP.
// todo: WrapSelectionWith(pair)?
result = null;
return false;
}

if (pair != null)
{
// found a SCP for the input key; see if we should handle it:
if (!HandleInternal(e, original, pair, out result))
{
return false;
}
}
else if (e.Character == '\b')
{
// backspace - see if SCP logic needs to intervene:
foreach (var scp in _selfClosingPairs)
{
if (HandleInternal(e, original, scp, out result))
Expand All @@ -70,9 +84,11 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin

if (result == null)
{
// no meaningful output; let the input be handled by another handler, maybe.
return false;
}

// 1-based selection span in the code pane starts at column 1 but really encompasses the entire line.
var snippetPosition = new Selection(result.SnippetPosition.StartLine, 1, result.SnippetPosition.EndLine, 1);
result = new CodeString(result.Code, result.CaretPosition, snippetPosition);

Expand All @@ -82,13 +98,6 @@ public override bool Handle(AutoCompleteEventArgs e, AutoCompleteSettings settin

private bool HandleInternal(AutoCompleteEventArgs e, CodeString original, SelfClosingPair pair, out CodeString result)
{
if (!original.CaretPosition.IsSingleCharacter)
{
// todo: WrapSelectionWith(pair)?
result = null;
return false;
}

// if executing the SCP against the original code yields no result, we need to bail out.
if (!_scpService.Execute(pair, original, e.Character, out result))
{
Expand All @@ -115,21 +124,34 @@ private bool HandleInternal(AutoCompleteEventArgs e, CodeString original, SelfCl
);
}

if (original.CaretLine.EndsWith(" ") &&
string.Equals(original.CaretLine, prettified.CaretLine + " ", StringComparison.InvariantCultureIgnoreCase))
{
prettified = original;
}

// if executing the SCP against the prettified code yields no result, we need to bail out.
if (!_scpService.Execute(pair, prettified, e.Character, out result))
{
return false;
}

var reprettified = CodePaneHandler.Prettify(e.Module, result);
if (pair.OpeningChar == '(' && e.Character == pair.OpeningChar && !reprettified.Equals(result))
if (pair.OpeningChar == '(' && e.Character == pair.OpeningChar)
{
if (string.Equals(reprettified.Code, result.Code, StringComparison.InvariantCultureIgnoreCase))
{
e.Handled = true;
result = reprettified;
return true;
}

// VBE eats it. bail out but don't swallow the keypress.
e.Handled = false;
result = null;
return false;
}

var currentLine = reprettified.Lines[reprettified.CaretPosition.StartLine];
if (!string.IsNullOrWhiteSpace(currentLine) &&
currentLine.EndsWith(" ") &&
Expand Down
Expand Up @@ -3,7 +3,7 @@
using Rubberduck.UI.Command;
using Rubberduck.VBEditor.SafeComWrappers.Abstract;

namespace Rubberduck.AutoComplete.Service
namespace Rubberduck.AutoComplete
{
public interface IShowIntelliSenseCommand
{
Expand Down
Expand Up @@ -4,7 +4,7 @@
using Rubberduck.VBEditor.Events;
using Rubberduck.VBEditor.SourceCodeHandling;

namespace Rubberduck.AutoComplete.Service
namespace Rubberduck.AutoComplete.SmartConcat
{
/// <summary>
/// Adds a line continuation when {ENTER} is pressed when inside a string literal.
Expand Down
1 change: 0 additions & 1 deletion Rubberduck.Core/Common/RubberduckHooks.cs
Expand Up @@ -8,7 +8,6 @@
using Rubberduck.VBEditor.SafeComWrappers.Abstract;
using Rubberduck.VBEditor.WindowsApi;
using Rubberduck.AutoComplete;
using Rubberduck.AutoComplete.Service;

namespace Rubberduck.Common
{
Expand Down
14 changes: 14 additions & 0 deletions Rubberduck.Core/UI/Command/ReparseCommand.cs
Expand Up @@ -15,6 +15,12 @@

namespace Rubberduck.UI.Command
{
[ComVisible(false)]
public class ReparseCancellationFlag
{
public bool Canceled { get; set; }
}

[ComVisible(false)]
public class ReparseCommand : CommandBase
{
Expand Down Expand Up @@ -58,13 +64,21 @@ protected override void OnExecute(object parameter)
{
if (!VerifyCompileOnDemand())
{
if (parameter is ReparseCancellationFlag cancellation)
{
cancellation.Canceled = true;
}
return;
}

if (AreAllProjectsCompiled(out var failedNames))
{
if (!PromptUserToContinue(failedNames))
{
if (parameter is ReparseCancellationFlag cancellation)
{
cancellation.Canceled = true;
}
return;
}
}
Expand Down
35 changes: 35 additions & 0 deletions Rubberduck.Core/UI/Controls/GroupItemExpandedBehavior.cs
@@ -0,0 +1,35 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interactivity;
using GongSolutions.Wpf.DragDrop.Utilities;

namespace Rubberduck.UI.Controls
{
public class GroupItemExpandedBehavior : Behavior<DataGrid>
{
public object ExpandedState
{
get => GetValue(ExpandedStateProperty);
set => SetValue(ExpandedStateProperty, value);
}

public static readonly DependencyProperty ExpandedStateProperty =
DependencyProperty.Register("ExpandedState", typeof(object), typeof(GroupItemExpandedBehavior), new UIPropertyMetadata(null, OnExpandedStateChanged));

private static void OnExpandedStateChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
{
if (!(sender is GroupItemExpandedBehavior data) ||
!(data.AssociatedObject is DataGrid grid) ||
!grid.IsGrouping ||
!(e.NewValue is bool))
{
return;
}

foreach (var expander in grid.GetVisualDescendents<Expander>())
{
expander.IsExpanded = (bool)e.NewValue;
}
}
}
}
14 changes: 11 additions & 3 deletions Rubberduck.Core/UI/Controls/GroupingGrid.xaml
Expand Up @@ -60,7 +60,7 @@
<Setter Property="Template">
<Setter.Value>
<ControlTemplate>
<Expander Background="WhiteSmoke" Foreground="Black" FontWeight="SemiBold" IsExpanded="True">
<Expander Background="WhiteSmoke" Foreground="Black" FontWeight="SemiBold">
<Expander.Header>
<StackPanel Orientation="Horizontal">
<TextBlock Margin="4"
Expand Down Expand Up @@ -107,7 +107,6 @@
<Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ItemContainerStyle" Value="{StaticResource PrettifyRow}" />
<Setter Property="ColumnHeaderHeight" Value="22" />
<Setter Property="SelectionMode" Value="Single" />
</Style>
</DataGrid.Style>
<DataGrid.CellStyle>
Expand All @@ -116,7 +115,16 @@
<Setter Property="Background" Value="Transparent" />
<Setter Property="Padding" Value="0" />
<Setter Property="VerticalContentAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Grid Background="{TemplateBinding Background}">
<ContentPresenter VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.CellStyle>
</DataGrid>
2 changes: 1 addition & 1 deletion Rubberduck.Core/UI/Controls/GroupingGrid.xaml.cs
Expand Up @@ -7,7 +7,7 @@ namespace Rubberduck.UI.Controls
public partial class GroupingGrid
{
public static readonly DependencyProperty ShowGroupingItemCountProperty =
DependencyProperty.Register("ShowGroupingItemCount", typeof (bool), typeof (GroupingGrid));
DependencyProperty.Register("ShowGroupingItemCount", typeof (bool), typeof(GroupingGrid));

public bool ShowGroupingItemCount
{
Expand Down
@@ -0,0 +1,35 @@
using System;
using System.Globalization;
using System.Windows.Data;

namespace Rubberduck.UI.Inspections
{
internal class InspectionFilterToBooleanConverter : IValueConverter
{
private InspectionResultsFilter _state;

public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(parameter is InspectionResultsFilter flag) ||
!(value is InspectionResultsFilter bound))
{
return _state;
}

_state = bound;
return _state.HasFlag(flag);
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
if (!(parameter is InspectionResultsFilter flag) ||
!(value is bool isSet))
{
return _state;
}

_state ^= flag;
return _state;
}
}
}

0 comments on commit b01f450

Please sign in to comment.