Skip to content

Commit 4176185

Browse files
authored
Merge pull request #4233 from comintern/next
Pimp the toolbar (for some values of "pimp")
2 parents 0dae613 + e5aecba commit 4176185

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+850
-203
lines changed

Rubberduck.Core/Navigation/CodeExplorer/CodeExplorerMemberViewModel.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,12 @@ private static string DetermineMemberName(Declaration declaration)
154154
return declaration.IdentifierName + "()";
155155
}
156156
return declaration.IdentifierName;
157+
case DeclarationType.EnumerationMember:
157158
case DeclarationType.Constant:
158-
var valuedDeclaration = (ConstantDeclaration)declaration;
159-
return valuedDeclaration.IdentifierName + " = " + valuedDeclaration.Expression;
160-
159+
var valuedDeclaration = (ValuedDeclaration)declaration;
160+
return (!string.IsNullOrEmpty(valuedDeclaration.Expression))
161+
? valuedDeclaration.IdentifierName + " = " + valuedDeclaration.Expression
162+
: valuedDeclaration.IdentifierName;
161163
default:
162164
return declaration.IdentifierName;
163165
}

Rubberduck.Core/UI/Command/MenuItems/CommandBars/IContextFormatter.cs

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,27 @@ private string FormatDeclaration(Declaration declaration, bool multipleControls
5353
: declaration.AsTypeName;
5454
var declarationType = RubberduckUI.ResourceManager.GetString("DeclarationType_" + declaration.DeclarationType, Settings.Settings.Culture);
5555

56-
typeName = multipleControls
57-
? RubberduckUI.ContextMultipleControlsSelection
58-
: "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) + ")";
56+
if (multipleControls)
57+
{
58+
typeName = RubberduckUI.ContextMultipleControlsSelection;
59+
}
60+
else if (declaration is ValuedDeclaration)
61+
{
62+
var valued = (ValuedDeclaration)declaration;
63+
typeName = "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) +
64+
(string.IsNullOrEmpty(valued.Expression) ? string.Empty : $" = {valued.Expression}") + ")";
65+
66+
}
67+
else if (declaration is ParameterDeclaration)
68+
{
69+
var parameter = (ParameterDeclaration)declaration;
70+
typeName = "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) +
71+
(string.IsNullOrEmpty(parameter.DefaultValue) ? string.Empty : $" = {parameter.DefaultValue}") + ")";
72+
}
73+
else
74+
{
75+
typeName = "(" + declarationType + (string.IsNullOrEmpty(typeName) ? string.Empty : ":" + typeName) + ")";
76+
}
5977

6078
if (declaration.DeclarationType.HasFlag(DeclarationType.Project) || declaration.DeclarationType == DeclarationType.BracketedExpression)
6179
{

Rubberduck.Core/UI/Command/MenuItems/CommandBars/RubberduckCommandBar.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ private void OnSelectionChange(object sender, DeclarationChangedEventArgs e)
6969

7070
var refCount = e.Declaration?.References.Count() ?? 0;
7171
var description = e.Declaration?.DescriptionString ?? string.Empty;
72-
SetContextSelectionCaption(caption, refCount, description);
72+
//& renders the next character as if it was an accelerator.
73+
SetContextSelectionCaption(caption?.Replace("&", "&&"), refCount, description);
7374
EvaluateCanExecute(_parser.State, e.Declaration);
7475
}
7576

Rubberduck.Parsing/ComReflection/ComDocumentation.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ namespace Rubberduck.Parsing.ComReflection
44
{
55
public class ComDocumentation
66
{
7+
public const int LibraryIndex = -1;
8+
79
public string Name { get; }
810
public string DocString { get; }
911
public string HelpFile { get; }

Rubberduck.Parsing/ComReflection/ComEnumeration.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ namespace Rubberduck.Parsing.ComReflection
1111
{
1212
public class ComEnumeration : ComType
1313
{
14-
public List<ComEnumerationMember> Members { get; }
14+
public List<ComEnumerationMember> Members { get; }
1515

1616
public ComEnumeration(IComBase parent, ITypeLib typeLib, ITypeInfo info, TYPEATTR attrib, int index) : base(parent, typeLib, attrib, index)
17-
{
17+
{
1818
Members = new List<ComEnumerationMember>();
19-
Type = DeclarationType.Enumeration;
19+
Type = DeclarationType.Enumeration;
2020
GetEnumerationMembers(info, attrib);
2121
ComProject.KnownEnumerations.TryAdd(Guid, this);
2222
}
@@ -32,7 +32,7 @@ private void GetEnumerationMembers(ITypeInfo info, TYPEATTR attrib)
3232
var desc = Marshal.PtrToStructure<VARDESC>(varPtr);
3333
Members.Add(new ComEnumerationMember(this, info, desc));
3434
}
35-
}
35+
}
3636
}
3737
}
3838
}

Rubberduck.Parsing/ComReflection/ComField.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Runtime.InteropServices;
66
using System.Runtime.InteropServices.ComTypes;
7+
using Rubberduck.Parsing.Grammar;
78
using Rubberduck.Parsing.Symbols;
89
using Rubberduck.VBEditor.Utility;
910
using TYPEATTR = System.Runtime.InteropServices.ComTypes.TYPEATTR;
@@ -23,7 +24,7 @@ public class ComField
2324
public object DefaultValue { get; }
2425
public bool IsReferenceType { get; private set; }
2526

26-
private string _valueType = "Object";
27+
private string _valueType = Tokens.Object;
2728
public string ValueType => IsArray ? $"{_valueType}()" : _valueType;
2829

2930
private Guid _enumGuid = Guid.Empty;
@@ -93,6 +94,7 @@ private void GetFieldType(TYPEDESC desc, ITypeInfo info)
9394
int href;
9495
unchecked
9596
{
97+
//The href is a long, but the size of lpValue depends on the platform, so truncate it after the lword.
9698
href = (int)(desc.lpValue.ToInt64() & 0xFFFFFFFF);
9799
}
98100
try

Rubberduck.Parsing/ComReflection/ComInterface.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,18 +49,18 @@ public ComInterface(IComBase parent, ITypeInfo info, TYPEATTR attrib) : base(par
4949
{
5050
Parent = null;
5151
}
52-
52+
5353
GetImplementedInterfaces(info, attrib);
5454
GetComProperties(info, attrib);
55-
GetComMembers(info, attrib);
55+
GetComMembers(info, attrib);
5656
}
5757

5858
public ComInterface(IComBase parent, ITypeLib typeLib, ITypeInfo info, TYPEATTR attrib, int index) : base(parent, typeLib, attrib, index)
5959
{
6060
Type = DeclarationType.ClassModule;
6161
GetImplementedInterfaces(info, attrib);
6262
GetComProperties(info, attrib);
63-
GetComMembers(info, attrib);
63+
GetComMembers(info, attrib);
6464
}
6565

6666
private void GetImplementedInterfaces(ITypeInfo info, TYPEATTR typeAttr)

Rubberduck.Parsing/ComReflection/ComMember.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private void LoadParameters(FUNCDESC funcDesc, ITypeInfo info)
105105
var paramPtr = new IntPtr(funcDesc.lprgelemdescParam.ToInt64() + Marshal.SizeOf(typeof(ELEMDESC)) * index);
106106
var elemDesc = Marshal.PtrToStructure<ELEMDESC>(paramPtr);
107107
var param = new ComParameter(this, elemDesc, info, names[index + 1] ?? $"{index}unnamedParameter");
108-
_parameters.Add(param);
108+
_parameters.Add(param);
109109
}
110110
if (Parameters.Any() && funcDesc.cParamsOpt == -1)
111111
{

Rubberduck.Parsing/ComReflection/ComParameter.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System.Linq;
44
using System.Runtime.InteropServices;
55
using System.Runtime.InteropServices.ComTypes;
6+
using Rubberduck.Parsing.Grammar;
67
using Rubberduck.VBEditor.Utility;
78
using ELEMDESC = System.Runtime.InteropServices.ComTypes.ELEMDESC;
89
using PARAMFLAG = System.Runtime.InteropServices.ComTypes.PARAMFLAG;
@@ -39,12 +40,13 @@ public class ComParameter
3940
public bool IsReturnValue { get; }
4041
public bool IsParamArray { get; set; }
4142
public object DefaultValue { get; }
43+
public bool HasDefaultValue => DefaultValue != null;
4244

4345
public string DefaultAsEnum
4446
{
4547
get
4648
{
47-
if (!_typeName.IsEnumMember || !ComProject.KnownEnumerations.TryGetValue(_typeName.EnumGuid, out ComEnumeration enumType))
49+
if (!_typeName.IsEnumMember || !HasDefaultValue || !ComProject.KnownEnumerations.TryGetValue(_typeName.EnumGuid, out ComEnumeration enumType))
4850
{
4951
return string.Empty;
5052
}
@@ -114,7 +116,7 @@ private void GetParameterType(TYPEDESC desc, ITypeInfo info)
114116
using (DisposalActionContainer.Create(attribPtr, refTypeInfo.ReleaseTypeAttr))
115117
{
116118
var attribs = Marshal.PtrToStructure<TYPEATTR>(attribPtr);
117-
var type = new ComDocumentation(refTypeInfo, -1).Name;
119+
var type = new ComDocumentation(refTypeInfo, ComDocumentation.LibraryIndex).Name;
118120
if (attribs.typekind == TYPEKIND.TKIND_ENUM)
119121
{
120122
_typeName = new ComTypeName(Project, type, attribs.guid, Guid.Empty);
@@ -131,7 +133,7 @@ private void GetParameterType(TYPEDESC desc, ITypeInfo info)
131133
}
132134
catch (COMException)
133135
{
134-
_typeName = new ComTypeName(Project, "Object");
136+
_typeName = new ComTypeName(Project, Tokens.Object);
135137
}
136138
}
137139
else if (vt == VarEnum.VT_SAFEARRAY || vt == VarEnum.VT_CARRAY || vt.HasFlag(VarEnum.VT_ARRAY))
@@ -142,11 +144,11 @@ private void GetParameterType(TYPEDESC desc, ITypeInfo info)
142144
}
143145
else if (vt == VarEnum.VT_HRESULT)
144146
{
145-
_typeName = new ComTypeName(Project, "Long");
147+
_typeName = new ComTypeName(Project, Tokens.Long);
146148
}
147149
else
148150
{
149-
_typeName = new ComTypeName(Project, (ComVariant.TypeNames.TryGetValue(vt, out string result)) ? result : "Object");
151+
_typeName = new ComTypeName(Project, (ComVariant.TypeNames.TryGetValue(vt, out string result)) ? result : Tokens.Object);
150152
}
151153
}
152154
}

Rubberduck.Parsing/ComReflection/ComProject.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ private void LoadModules(ITypeLib typeLibrary)
7777
{
7878
var typeCount = typeLibrary.GetTypeInfoCount();
7979
for (var index = 0; index < typeCount; index++)
80-
{
80+
{
8181
try
8282
{
8383
typeLibrary.GetTypeInfo(index, out ITypeInfo info);

0 commit comments

Comments
 (0)