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

Commit d4ca990

Browse files
Merge branch 'master' of github.com:icsharpcode/SharpDevelop
2 parents ca0e99d + fa82ddd commit d4ca990

5 files changed

Lines changed: 108 additions & 34 deletions

File tree

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.Designer/Tests/Designer/ModelTests.cs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,34 @@ public void AddBindingWithStaticResourceWhereResourceOnSameElementAlt()
639639
AddBindingWithStaticResourceWhereResourceOnSameElement(true);
640640
}
641641

642+
[Test]
643+
public void AddStaticResourceWhereResourceOnSameElement()
644+
{
645+
DesignItem button = CreateCanvasContext("<Button/>");
646+
DesignItem canvas = button.Parent;
647+
648+
DesignItemProperty resProp = button.Properties.GetProperty("Resources");
649+
Assert.IsTrue(resProp.IsCollection);
650+
DesignItem exampleClassItem = canvas.Services.Component.RegisterComponentForDesigner(new ExampleClass());
651+
exampleClassItem.Key = "res1";
652+
resProp.CollectionElements.Add(exampleClassItem);
653+
654+
button.Properties["Tag"].SetValue(new StaticResourceExtension());
655+
button.Properties["Tag"].Value.Properties["ResourceKey"].SetValue("res1");
656+
657+
string expectedXaml = "<Button>\n" +
658+
" <Button.Resources>\n" +
659+
" <t:ExampleClass x:Key=\"res1\" />\n" +
660+
" </Button.Resources>\n" +
661+
" <Button.Tag>\n" +
662+
" <StaticResourceExtension ResourceKey=\"res1\" />\n" +
663+
" </Button.Tag>\n" +
664+
"</Button>";
665+
666+
AssertCanvasDesignerOutput(expectedXaml, button.Context);
667+
AssertLog("");
668+
}
669+
642670
[Test]
643671
public void AddBrushAsResource()
644672
{

src/AddIns/DisplayBindings/WpfDesign/WpfDesign.XamlDom/Project/MarkupExtensionPrinter.cs

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -38,36 +38,7 @@ public static bool CanPrint(XamlObject obj)
3838
return false;
3939
}
4040

41-
foreach (var property in obj.Properties.Where((prop) => prop.IsSet))
42-
{
43-
var value = property.PropertyValue;
44-
if (value is XamlTextValue)
45-
continue;
46-
else
47-
{
48-
XamlObject xamlObject = value as XamlObject;
49-
if (xamlObject == null || !xamlObject.IsMarkupExtension)
50-
return false;
51-
else {
52-
var staticResource = xamlObject.Instance as System.Windows.StaticResourceExtension;
53-
if (staticResource != null &&
54-
staticResource.ResourceKey != null) {
55-
XamlObject parent = GetNonMarkupExtensionParent(xamlObject);
56-
57-
if (parent != null) {
58-
var parentLocalResource = parent.ServiceProvider.Resolver.FindLocalResource(staticResource.ResourceKey);
59-
60-
// If resource with the specified key is declared locally on the same object as the StaticResource is being used the markup extension
61-
// must be printed as element to find the resource, otherwise it will search from parent-parent and find none or another resource.
62-
if (parentLocalResource != null)
63-
return false;
64-
}
65-
}
66-
}
67-
}
68-
}
69-
70-
return true;
41+
return CanPrint(obj, false, GetNonMarkupExtensionParent(obj));
7142
}
7243

7344
/// <summary>
@@ -115,6 +86,28 @@ public static string Print(XamlObject obj)
11586
return sb.ToString();
11687
}
11788

89+
private static bool CanPrint(XamlObject obj, bool isNested, XamlObject nonMarkupExtensionParent)
90+
{
91+
if ((isNested || obj.ParentObject == nonMarkupExtensionParent) && IsStaticResourceThatReferencesLocalResource(obj, nonMarkupExtensionParent)) {
92+
return false;
93+
}
94+
95+
foreach (var property in obj.Properties.Where((prop) => prop.IsSet)) {
96+
var value = property.PropertyValue;
97+
if (value is XamlTextValue)
98+
continue;
99+
else {
100+
var xamlObject = value as XamlObject;
101+
if (xamlObject == null || !xamlObject.IsMarkupExtension)
102+
return false;
103+
else
104+
return CanPrint(xamlObject, true, nonMarkupExtensionParent);
105+
}
106+
}
107+
108+
return true;
109+
}
110+
118111
private static XamlObject GetNonMarkupExtensionParent(XamlObject markupExtensionObject)
119112
{
120113
System.Diagnostics.Debug.Assert(markupExtensionObject.IsMarkupExtension);
@@ -125,5 +118,21 @@ private static XamlObject GetNonMarkupExtensionParent(XamlObject markupExtension
125118
}
126119
return obj;
127120
}
121+
122+
private static bool IsStaticResourceThatReferencesLocalResource(XamlObject obj, XamlObject nonMarkupExtensionParent)
123+
{
124+
var staticResource = obj.Instance as System.Windows.StaticResourceExtension;
125+
if (staticResource != null && staticResource.ResourceKey != null && nonMarkupExtensionParent != null) {
126+
127+
var parentLocalResource = nonMarkupExtensionParent.ServiceProvider.Resolver.FindLocalResource(staticResource.ResourceKey);
128+
129+
// If resource with the specified key is declared locally on the same object as the StaticResource is being used the markup extension
130+
// must be printed as element to find the resource, otherwise it will search from parent-parent and find none or another resource.
131+
if (parentLocalResource != null)
132+
return true;
133+
}
134+
135+
return false;
136+
}
128137
}
129138
}

src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ProjectReferencePanel.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ namespace ICSharpCode.SharpDevelop.Gui
2727
public class ProjectReferencePanel : ListView, IReferencePanel
2828
{
2929
ISelectReferenceDialog selectDialog;
30+
TextBox filterTextBox;
3031

3132
public ProjectReferencePanel(ISelectReferenceDialog selectDialog)
3233
{
@@ -48,6 +49,15 @@ public ProjectReferencePanel(ISelectReferenceDialog selectDialog)
4849

4950
ItemActivate += delegate { AddReference(); };
5051
PopulateListView();
52+
53+
54+
Panel upperPanel = new Panel { Dock = DockStyle.Top, Height = 20 };
55+
filterTextBox = new TextBox { Width = 150, Dock = DockStyle.Right };
56+
filterTextBox.TextChanged += delegate { Search(); };
57+
58+
upperPanel.Controls.Add(filterTextBox);
59+
60+
this.Controls.Add(upperPanel);
5161
}
5262

5363
public void AddReference()
@@ -60,6 +70,7 @@ public void AddReference()
6070
new ProjectReferenceProjectItem(selectDialog.ConfigureProject, project)
6171
);
6272
}
73+
filterTextBox.Text = "";
6374
}
6475

6576
void PopulateListView()
@@ -74,5 +85,32 @@ void PopulateListView()
7485
Items.Add(newItem);
7586
}
7687
}
88+
89+
static bool ContainsAnyOfTokens(string bigText, string[] tokens)
90+
{
91+
if(tokens.Length==0)
92+
return true;
93+
foreach(var token in tokens)
94+
{
95+
if(bigText.IndexOf(token, StringComparison.OrdinalIgnoreCase)<0)
96+
return false;
97+
}
98+
return true;
99+
}
100+
101+
void Search()
102+
{
103+
Items.Clear();
104+
var tokens = filterTextBox.Text.Split(new []{' '}, StringSplitOptions.RemoveEmptyEntries);
105+
106+
foreach (IProject project in ProjectService.OpenSolution.Projects.
107+
Where(pr=>ContainsAnyOfTokens(pr.Name, tokens))
108+
.OrderBy(p => p.Name, StringComparer.OrdinalIgnoreCase)
109+
) {
110+
ListViewItem newItem = new ListViewItem(new string[] { project.Name, project.Directory });
111+
newItem.Tag = project;
112+
Items.Add(newItem);
113+
}
114+
}
77115
}
78116
}

src/Main/Base/Project/Util/SharpDevelopServiceContainer.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,8 @@ public Task<T> GetFutureService<T>()
161161
{
162162
Type serviceType = typeof(T);
163163
lock (services) {
164-
object instance;
165-
if (services.TryGetValue(serviceType, out instance)) {
166-
return Task.FromResult((T)instance);
164+
if (services.ContainsKey(serviceType)) {
165+
return Task.FromResult((T)GetService(serviceType));
167166
} else {
168167
object taskCompletionSource;
169168
if (taskCompletionSources.TryGetValue(serviceType, out taskCompletionSource)) {

src/Main/GlobalAssemblyInfo.cs.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ internal static class RevisionClass
4646
public const string Minor = "0";
4747
public const string Build = "0";
4848
public const string Revision = "$INSERTREVISION$";
49-
public const string VersionName = "Beta 4"; // "" is not valid for no version name, you have to use null if you don't want a version name (eg "Beta 1")
49+
public const string VersionName = "Beta 5"; // "" is not valid for no version name, you have to use null if you don't want a version name (eg "Beta 1")
5050

5151
public const string FullVersion = Major + "." + Minor + "." + Build + ".$INSERTREVISION$$INSERTBRANCHPOSTFIX$$INSERTVERSIONNAMEPOSTFIX$";
5252
}

0 commit comments

Comments
 (0)