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

Commit ea71545

Browse files
Merge branch 'master' of github.com:icsharpcode/SharpDevelop
2 parents c7c4344 + e063402 commit ea71545

50 files changed

Lines changed: 2481 additions & 88 deletions

Some content is hidden

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

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
root = true
2+
[*]
3+
indent_style = tab

samples/XamlDesigner/Toolbox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public void LoadSettings()
7070
{
7171
AddAssembly(Environment.ExpandEnvironmentVariables(path), false);
7272
}
73-
catch (Exception ex)
73+
catch (Exception)
7474
{ }
7575
}
7676
}

src/AddIns/BackendBindings/XamlBinding/XamlBinding/XamlConst.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,16 @@ public static IEnumerable<string> GetAllowedItems(XamlCompletionContext context)
9494

9595
switch (context.Description) {
9696
case XamlContextDescription.AtTag:
97-
if (context.ParentElement != null && string.Equals(context.ParentElement.Name, xKey + "Members", StringComparison.OrdinalIgnoreCase)) {
97+
if (context.ParentElement == null || context.RootElement == null)
98+
yield break;
99+
if (string.Equals(context.ParentElement.Name, xKey + "Members", StringComparison.OrdinalIgnoreCase)) {
98100
yield return xKey + "Member";
99101
yield return xKey + "Property";
100102
} else if (context.ParentElement == context.RootElement && context.RootElement.Attributes.Any(attr => string.Equals(attr.Name, xKey + "Class", StringComparison.OrdinalIgnoreCase))) {
101103
yield return xKey + "Code";
102104
yield return xKey + "Members";
103105
} else {
104-
if (context.ParentElement != null && string.Equals(context.ParentElement.Name, xKey + "Code", StringComparison.OrdinalIgnoreCase))
106+
if (string.Equals(context.ParentElement.Name, xKey + "Code", StringComparison.OrdinalIgnoreCase))
105107
yield break;
106108
yield return xKey + "Array";
107109
yield return xKey + "Boolean";
Lines changed: 198 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,198 @@
1+
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using System.Windows;
21+
using System.Windows.Controls;
22+
using System.Windows.Data;
23+
using System.Windows.Input;
24+
using System.Windows.Media.Animation;
25+
26+
namespace ICSharpCode.WpfDesign.Designer.Controls
27+
{
28+
/// <summary>
29+
/// Allows animated collapsing of the content of this panel.
30+
/// </summary>
31+
public class CollapsiblePanel : ContentControl
32+
{
33+
static CollapsiblePanel()
34+
{
35+
DefaultStyleKeyProperty.OverrideMetadata(typeof(CollapsiblePanel),
36+
new FrameworkPropertyMetadata(typeof(CollapsiblePanel)));
37+
FocusableProperty.OverrideMetadata(typeof(CollapsiblePanel),
38+
new FrameworkPropertyMetadata(false));
39+
}
40+
41+
public static readonly DependencyProperty IsCollapsedProperty = DependencyProperty.Register(
42+
"IsCollapsed", typeof(bool), typeof(CollapsiblePanel),
43+
new UIPropertyMetadata(false, new PropertyChangedCallback(OnIsCollapsedChanged)));
44+
45+
public bool IsCollapsed {
46+
get { return (bool)GetValue(IsCollapsedProperty); }
47+
set { SetValue(IsCollapsedProperty, value); }
48+
}
49+
50+
public static readonly DependencyProperty CollapseOrientationProperty =
51+
DependencyProperty.Register("CollapseOrientation", typeof(Orientation), typeof(CollapsiblePanel),
52+
new FrameworkPropertyMetadata(Orientation.Vertical));
53+
54+
public Orientation CollapseOrientation {
55+
get { return (Orientation)GetValue(CollapseOrientationProperty); }
56+
set { SetValue(CollapseOrientationProperty, value); }
57+
}
58+
59+
public static readonly DependencyProperty DurationProperty = DependencyProperty.Register(
60+
"Duration", typeof(TimeSpan), typeof(CollapsiblePanel),
61+
new UIPropertyMetadata(TimeSpan.FromMilliseconds(250)));
62+
63+
/// <summary>
64+
/// The duration in milliseconds of the animation.
65+
/// </summary>
66+
public TimeSpan Duration {
67+
get { return (TimeSpan)GetValue(DurationProperty); }
68+
set { SetValue(DurationProperty, value); }
69+
}
70+
71+
protected internal static readonly DependencyProperty AnimationProgressProperty = DependencyProperty.Register(
72+
"AnimationProgress", typeof(double), typeof(CollapsiblePanel),
73+
new FrameworkPropertyMetadata(1.0));
74+
75+
/// <summary>
76+
/// Value between 0 and 1 specifying how far the animation currently is.
77+
/// </summary>
78+
protected internal double AnimationProgress {
79+
get { return (double)GetValue(AnimationProgressProperty); }
80+
set { SetValue(AnimationProgressProperty, value); }
81+
}
82+
83+
protected internal static readonly DependencyProperty AnimationProgressXProperty = DependencyProperty.Register(
84+
"AnimationProgressX", typeof(double), typeof(CollapsiblePanel),
85+
new FrameworkPropertyMetadata(1.0));
86+
87+
/// <summary>
88+
/// Value between 0 and 1 specifying how far the animation currently is.
89+
/// </summary>
90+
protected internal double AnimationProgressX {
91+
get { return (double)GetValue(AnimationProgressXProperty); }
92+
set { SetValue(AnimationProgressXProperty, value); }
93+
}
94+
95+
protected internal static readonly DependencyProperty AnimationProgressYProperty = DependencyProperty.Register(
96+
"AnimationProgressY", typeof(double), typeof(CollapsiblePanel),
97+
new FrameworkPropertyMetadata(1.0));
98+
99+
/// <summary>
100+
/// Value between 0 and 1 specifying how far the animation currently is.
101+
/// </summary>
102+
protected internal double AnimationProgressY {
103+
get { return (double)GetValue(AnimationProgressYProperty); }
104+
set { SetValue(AnimationProgressYProperty, value); }
105+
}
106+
107+
static void OnIsCollapsedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
108+
{
109+
((CollapsiblePanel)d).SetupAnimation((bool)e.NewValue);
110+
}
111+
112+
void SetupAnimation(bool isCollapsed)
113+
{
114+
if (this.IsLoaded) {
115+
// If the animation is already running, calculate remaining portion of the time
116+
double currentProgress = AnimationProgress;
117+
if (!isCollapsed) {
118+
currentProgress = 1.0 - currentProgress;
119+
}
120+
121+
DoubleAnimation animation = new DoubleAnimation();
122+
animation.To = isCollapsed ? 0.0 : 1.0;
123+
animation.Duration = TimeSpan.FromSeconds(Duration.TotalSeconds * currentProgress);
124+
animation.FillBehavior = FillBehavior.HoldEnd;
125+
126+
this.BeginAnimation(AnimationProgressProperty, animation);
127+
if (CollapseOrientation == Orientation.Horizontal) {
128+
this.BeginAnimation(AnimationProgressXProperty, animation);
129+
this.AnimationProgressY = 1.0;
130+
} else {
131+
this.AnimationProgressX = 1.0;
132+
this.BeginAnimation(AnimationProgressYProperty, animation);
133+
}
134+
} else {
135+
this.AnimationProgress = isCollapsed ? 0.0 : 1.0;
136+
this.AnimationProgressX = (CollapseOrientation == Orientation.Horizontal) ? this.AnimationProgress : 1.0;
137+
this.AnimationProgressY = (CollapseOrientation == Orientation.Vertical) ? this.AnimationProgress : 1.0;
138+
}
139+
}
140+
}
141+
142+
sealed class CollapsiblePanelProgressToVisibilityConverter : IValueConverter
143+
{
144+
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
145+
{
146+
if (value is double)
147+
return (double)value > 0 ? Visibility.Visible : Visibility.Collapsed;
148+
else
149+
return Visibility.Visible;
150+
}
151+
152+
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
153+
{
154+
throw new NotImplementedException();
155+
}
156+
}
157+
158+
public class SelfCollapsingPanel : CollapsiblePanel
159+
{
160+
public static readonly DependencyProperty CanCollapseProperty =
161+
DependencyProperty.Register("CanCollapse", typeof(bool), typeof(SelfCollapsingPanel),
162+
new FrameworkPropertyMetadata(false, new PropertyChangedCallback(OnCanCollapseChanged)));
163+
164+
public bool CanCollapse {
165+
get { return (bool)GetValue(CanCollapseProperty); }
166+
set { SetValue(CanCollapseProperty, value); }
167+
}
168+
169+
static void OnCanCollapseChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
170+
{
171+
SelfCollapsingPanel panel = (SelfCollapsingPanel)d;
172+
if ((bool)e.NewValue) {
173+
if (!panel.HeldOpenByMouse)
174+
panel.IsCollapsed = true;
175+
} else {
176+
panel.IsCollapsed = false;
177+
}
178+
}
179+
180+
bool HeldOpenByMouse {
181+
get { return IsMouseOver || IsMouseCaptureWithin; }
182+
}
183+
184+
protected override void OnMouseLeave(MouseEventArgs e)
185+
{
186+
base.OnMouseLeave(e);
187+
if (CanCollapse && !HeldOpenByMouse)
188+
IsCollapsed = true;
189+
}
190+
191+
protected override void OnLostMouseCapture(MouseEventArgs e)
192+
{
193+
base.OnLostMouseCapture(e);
194+
if (CanCollapse && !HeldOpenByMouse)
195+
IsCollapsed = true;
196+
}
197+
}
198+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
// Copyright (c) 2014 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using System.Windows.Media;
21+
22+
namespace ICSharpCode.WpfDesign.Designer.Controls
23+
{
24+
public static class ColorHelper
25+
{
26+
public static Color ColorFromString(string s)
27+
{
28+
if (string.IsNullOrEmpty(s)) {
29+
return Colors.White;
30+
}
31+
if (s[0] != '#') s = "#" + s;
32+
try {
33+
return (Color)ColorConverter.ConvertFromString(s);
34+
}
35+
catch {
36+
return Colors.White;
37+
}
38+
}
39+
40+
public static string StringFromColor(Color c)
41+
{
42+
return c.ToString().Substring(1);
43+
}
44+
45+
public static Color ColorFromHsv(double h, double s, double v)
46+
{
47+
double r, g, b;
48+
RgbFromHsv(h, s, v, out r, out g, out b);
49+
return Color.FromRgb((byte)(r * 255), (byte)(g * 255), (byte)(b * 255));
50+
51+
}
52+
53+
public static void HsvFromColor(Color c, out double h, out double s, out double v)
54+
{
55+
HsvFromRgb(c.R / 255.0, c.G / 255.0, c.B / 255.0, out h, out s, out v);
56+
}
57+
58+
// http://en.wikipedia.org/wiki/HSV_color_space
59+
public static void HsvFromRgb(double r, double g, double b, out double h, out double s, out double v)
60+
{
61+
var max = Math.Max(r, Math.Max(g, b));
62+
var min = Math.Min(r, Math.Min(g, b));
63+
64+
if (max == min) {
65+
h = 0;
66+
}
67+
else if (max == r) {
68+
h = (60 * (g - b) / (max - min)) % 360;
69+
}
70+
else if (max == g) {
71+
h = 60 * (b - r) / (max - min) + 120;
72+
}
73+
else {
74+
h = 60 * (r - g) / (max - min) + 240;
75+
}
76+
77+
if (h < 0) h += 360; // C# '%' can return negative values, use real modulus instead
78+
79+
if (max == 0) {
80+
s = 0;
81+
}
82+
else {
83+
s = 1 - min / max;
84+
}
85+
86+
v = max;
87+
}
88+
89+
// http://en.wikipedia.org/wiki/HSV_color_space
90+
public static void RgbFromHsv(double h, double s, double v, out double r, out double g, out double b)
91+
{
92+
h = h % 360;
93+
if (h < 0) h += 360; // C# '%' can return negative values, use real modulus instead
94+
int hi = (int)(h / 60) % 6;
95+
var f = h / 60 - (int)(h / 60);
96+
var p = v * (1 - s);
97+
var q = v * (1 - f * s);
98+
var t = v * (1 - (1 - f) * s);
99+
100+
switch (hi) {
101+
case 0: r = v; g = t; b = p; break;
102+
case 1: r = q; g = v; b = p; break;
103+
case 2: r = p; g = v; b = t; break;
104+
case 3: r = p; g = q; b = v; break;
105+
case 4: r = t; g = p; b = v; break;
106+
default: r = v; g = p; b = q; break;
107+
}
108+
}
109+
}
110+
}

0 commit comments

Comments
 (0)