Skip to content
This repository was archived by the owner on Oct 4, 2021. It is now read-only.

Commit f449a46

Browse files
committed
[Refactoring] Initial disabled implementation of IPickMembersService
1 parent dba2459 commit f449a46

3 files changed

Lines changed: 234 additions & 0 deletions

File tree

Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
//
2+
// PickMembersDialog.cs
3+
//
4+
// Author:
5+
// Marius Ungureanu <[email protected]>
6+
//
7+
// Copyright (c) 2018
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using System;
27+
using System.Collections.Generic;
28+
using System.Collections.Immutable;
29+
using System.Linq;
30+
using Microsoft.CodeAnalysis;
31+
using Microsoft.CodeAnalysis.PickMembers;
32+
using MonoDevelop.Components.AtkCocoaHelper;
33+
using MonoDevelop.Core;
34+
using MonoDevelop.Ide;
35+
using Xwt;
36+
using Xwt.Drawing;
37+
38+
namespace MonoDevelop.Refactoring.PickMembers
39+
{
40+
public class PickMembersDialog : Xwt.Dialog
41+
{
42+
DataField<bool> symbolIncludedField = new DataField<bool> ();
43+
DataField<string> symbolTextField = new DataField<string> ();
44+
DataField<Image> symbolIconField = new DataField<Image> ();
45+
DataField<ISymbol> symbolField = new DataField<ISymbol> ();
46+
47+
ListStore treeStore;
48+
49+
public IEnumerable<ISymbol> IncludedMembers {
50+
get {
51+
for (int i = 0; i < treeStore.RowCount; i++) {
52+
if (treeStore.GetValue (i, symbolIncludedField))
53+
yield return treeStore.GetValue (i, symbolField);
54+
}
55+
}
56+
}
57+
58+
ListView listViewPublicMembers = new ListView ();
59+
60+
public PickMembersDialog (string title)
61+
{
62+
this.Build (title);
63+
this.buttonSelectAll.Clicked += delegate {
64+
for (int i = 0; i < treeStore.RowCount; i++) {
65+
treeStore.SetValue (i, symbolIncludedField, true);
66+
}
67+
UpdateOkButton ();
68+
};
69+
70+
this.buttonDeselectAll.Clicked += delegate {
71+
for (int i = 0; i < treeStore.RowCount; i++) {
72+
treeStore.SetValue (i, symbolIncludedField, false);
73+
}
74+
UpdateOkButton ();
75+
};
76+
77+
listViewPublicMembers.HeadersVisible = false;
78+
listViewPublicMembers.DataSource = treeStore;
79+
var checkBoxCellView = new CheckBoxCellView (symbolIncludedField);
80+
checkBoxCellView.Editable = true;
81+
checkBoxCellView.Toggled += delegate { UpdateOkButton (); };
82+
listViewPublicMembers.Columns.Add ("", checkBoxCellView);
83+
listViewPublicMembers.Columns.Add ("", new ImageCellView (symbolIconField), new TextCellView (symbolTextField));
84+
}
85+
86+
void Build (string title)
87+
{
88+
this.TransientFor = MessageDialog.RootWindow;
89+
this.Title = GettextCatalog.GetString ("Pick members");
90+
91+
treeStore = new ListStore (symbolIncludedField, symbolField, symbolTextField, symbolIconField);
92+
var box = new VBox {
93+
Margin = 6,
94+
Spacing = 6
95+
};
96+
97+
box.PackStart (new Label {
98+
Markup = "<b>" + title + "</b>"
99+
});
100+
101+
var hbox = new HBox {
102+
Spacing = 6
103+
};
104+
hbox.PackStart (listViewPublicMembers, true);
105+
listViewPublicMembers.Accessible.Description = title;
106+
107+
var vbox = new VBox {
108+
Spacing = 6
109+
};
110+
buttonSelectAll = new Button (GettextCatalog.GetString ("Select All"));
111+
buttonSelectAll.Clicked += delegate {
112+
UpdateOkButton ();
113+
};
114+
vbox.PackStart (buttonSelectAll);
115+
116+
buttonDeselectAll = new Button (GettextCatalog.GetString ("Clear"));
117+
buttonDeselectAll.Clicked += delegate {
118+
UpdateOkButton ();
119+
};
120+
vbox.PackStart (buttonDeselectAll);
121+
122+
hbox.PackStart (vbox);
123+
124+
box.PackStart (hbox, true);
125+
126+
Content = box;
127+
Buttons.Add (okButton = new DialogButton (Command.Ok));
128+
Buttons.Add (new DialogButton (Command.Cancel));
129+
130+
this.Width = 400;
131+
this.Height = 421;
132+
this.Resizable = false;
133+
134+
Show ();
135+
}
136+
137+
static SymbolDisplayFormat memberDisplayFormat = new SymbolDisplayFormat (
138+
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
139+
memberOptions: SymbolDisplayMemberOptions.IncludeParameters,
140+
parameterOptions: SymbolDisplayParameterOptions.IncludeType | SymbolDisplayParameterOptions.IncludeParamsRefOut | SymbolDisplayParameterOptions.IncludeOptionalBrackets,
141+
miscellaneousOptions: SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers | SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
142+
private Button buttonSelectAll;
143+
private Button buttonDeselectAll;
144+
private DialogButton okButton;
145+
146+
ImmutableArray<PickMembersOption> options;
147+
internal void Init (ImmutableArray<ISymbol> members, ImmutableArray<PickMembersOption> options)
148+
{
149+
// options is unused, not even roslyn uses it
150+
this.options = options;
151+
152+
treeStore.Clear ();
153+
foreach (var member in members) {
154+
var row = treeStore.AddRow ();
155+
treeStore.SetValue (row, symbolIncludedField, true);
156+
treeStore.SetValue (row, symbolField, member);
157+
treeStore.SetValue (row, symbolTextField, member.ToDisplayString (memberDisplayFormat));
158+
treeStore.SetValue (row, symbolIconField, ImageService.GetIcon (MonoDevelop.Ide.TypeSystem.Stock.GetStockIcon (member)));
159+
}
160+
}
161+
162+
void UpdateOkButton ()
163+
{
164+
okButton.Sensitive = TrySubmit ();
165+
}
166+
167+
bool TrySubmit ()
168+
{
169+
if (!IncludedMembers.Any ()) {
170+
return false;
171+
}
172+
return true;
173+
}
174+
}
175+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
//
2+
// PickMembersService.cs
3+
//
4+
// Author:
5+
// Marius Ungureanu <[email protected]>
6+
//
7+
// Copyright (c) 2018
8+
//
9+
// Permission is hereby granted, free of charge, to any person obtaining a copy
10+
// of this software and associated documentation files (the "Software"), to deal
11+
// in the Software without restriction, including without limitation the rights
12+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13+
// copies of the Software, and to permit persons to whom the Software is
14+
// furnished to do so, subject to the following conditions:
15+
//
16+
// The above copyright notice and this permission notice shall be included in
17+
// all copies or substantial portions of the Software.
18+
//
19+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25+
// THE SOFTWARE.
26+
using System;
27+
using System.Collections.Immutable;
28+
using Microsoft.CodeAnalysis;
29+
using Microsoft.CodeAnalysis.Host.Mef;
30+
using Microsoft.CodeAnalysis.PickMembers;
31+
using MonoDevelop.Core;
32+
33+
namespace MonoDevelop.Refactoring.PickMembers
34+
{
35+
//[ExportWorkspaceService(typeof(IPickMembersService), ServiceLayer.Host), System.Composition.Shared]
36+
class PickMembersService : IPickMembersService
37+
{
38+
public PickMembersResult PickMembers (string title, ImmutableArray<ISymbol> members, ImmutableArray<PickMembersOption> options = default (ImmutableArray<PickMembersOption>))
39+
{
40+
var dialog = new PickMembersDialog (title);
41+
try {
42+
dialog.Init (members, options);
43+
bool performChange = dialog.Run () == Xwt.Command.Ok;
44+
if (!performChange)
45+
return PickMembersResult.Canceled;
46+
47+
return new PickMembersResult (dialog.IncludedMembers.ToImmutableArray (), options);
48+
} catch (Exception ex) {
49+
LoggingService.LogError ("Error while signature changing.", ex);
50+
return PickMembersResult.Canceled;
51+
} finally {
52+
dialog.Dispose ();
53+
}
54+
}
55+
}
56+
}

main/src/addins/MonoDevelop.Refactoring/MonoDevelop.Refactoring.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@
198198
<Compile Include="MonoDevelop.AnalysisCore\MonoDevelopWorkspaceDiagnosticAnalyzerProviderService.cs" />
199199
<Compile Include="MonoDevelop.AnalysisCore\MonoDevelopWorkspaceDiagnosticAnalyzerProviderService.AnalyzerAssemblyLoader.cs" />
200200
<Compile Include="MonoDevelop.AnalysisCore\MonoDevelopWorkspaceDiagnosticAnalyzerProviderService.OptionsTable.cs" />
201+
<Compile Include="MonoDevelop.Refactoring.PickMembers\PickMembersService.cs" />
202+
<Compile Include="MonoDevelop.Refactoring.PickMembers\PickMembersDialog.cs" />
201203
</ItemGroup>
202204
<ItemGroup>
203205
<Folder Include="MonoDevelop.Refactoring\" />
@@ -210,6 +212,7 @@
210212
<Folder Include="MonoDevelop.Refactoring.GenerateType\" />
211213
<Folder Include="MonoDevelop.Refactoring.PackageInstaller\" />
212214
<Folder Include="MonoDevelop.Refactoring.ExtractInterface\" />
215+
<Folder Include="MonoDevelop.Refactoring.PickMembers\" />
213216
</ItemGroup>
214217
<ItemGroup>
215218
<EmbeddedResource Include="MonoDevelop.Refactoring.addin.xml">

0 commit comments

Comments
 (0)