Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@3141 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
9 changed files with 403 additions and 1 deletions
@ -0,0 +1,110 @@
@@ -0,0 +1,110 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.ComponentModel; |
||||
using System.Windows.Data; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class ChooseClass : INotifyPropertyChanged |
||||
{ |
||||
public ChooseClass(IProjectContent projectContent) |
||||
{ |
||||
this.projectContent = projectContent; |
||||
|
||||
AddClassesRecursive(""); |
||||
|
||||
projectClasses.Sort((c1, c2) => c1.Name.CompareTo(c2.Name)); |
||||
|
||||
classes = new ListCollectionView(projectClasses); |
||||
classes.Filter = FilterPredicate; |
||||
} |
||||
|
||||
IProjectContent projectContent; |
||||
List<IClass> projectClasses = new List<IClass>(); |
||||
|
||||
void AddClassesRecursive(string ns) |
||||
{ |
||||
foreach (var item in projectContent.GetNamespaceContents(ns)) { |
||||
if (item is string) { |
||||
AddClassesRecursive(ns.Length == 0 ? item.ToString() : ns + "." + item); |
||||
} else if (item is IClass) { |
||||
IClass c = item as IClass; |
||||
if (c.IsPartial) { |
||||
if (projectClasses.Contains(c)) continue; |
||||
} |
||||
if (c.ClassType == ClassType.Class && c.IsPublic) { |
||||
projectClasses.Add(c); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
ListCollectionView classes; |
||||
|
||||
public ICollectionView Classes { |
||||
get { return classes; } |
||||
} |
||||
|
||||
string filter; |
||||
|
||||
public string Filter { |
||||
get { |
||||
return filter; |
||||
} |
||||
set { |
||||
filter = value; |
||||
Classes.Refresh(); |
||||
RaisePropertyChanged("Filter"); |
||||
} |
||||
} |
||||
|
||||
bool showSystemClasses; |
||||
|
||||
public bool ShowSystemClasses { |
||||
get { |
||||
return showSystemClasses; |
||||
} |
||||
set { |
||||
showSystemClasses = value; |
||||
Classes.Refresh(); |
||||
RaisePropertyChanged("ShowSystemClasses"); |
||||
} |
||||
} |
||||
|
||||
public IClass CurrentClass { |
||||
get { return Classes.CurrentItem as IClass; } |
||||
} |
||||
|
||||
bool FilterPredicate(object item) |
||||
{ |
||||
IClass c = item as IClass; |
||||
if (!ShowSystemClasses) { |
||||
if (c.Namespace.StartsWith("System") || c.Namespace.StartsWith("Microsoft")) { |
||||
return false; |
||||
} |
||||
} |
||||
return Match(c.Name, Filter); |
||||
} |
||||
|
||||
static bool Match(string className, string filter) |
||||
{ |
||||
if (string.IsNullOrEmpty(filter)) |
||||
return true; |
||||
else |
||||
return className.StartsWith(filter, StringComparison.InvariantCultureIgnoreCase); |
||||
} |
||||
|
||||
#region INotifyPropertyChanged Members
|
||||
public event PropertyChangedEventHandler PropertyChanged; |
||||
|
||||
void RaisePropertyChanged(string name) |
||||
{ |
||||
if (PropertyChanged != null) { |
||||
PropertyChanged(this, new PropertyChangedEventArgs(name)); |
||||
} |
||||
} |
||||
#endregion
|
||||
} |
||||
} |
||||
@ -0,0 +1,69 @@
@@ -0,0 +1,69 @@
|
||||
<Window x:Class="ICSharpCode.WpfDesign.AddIn.ChooseClassDialog" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
xmlns:sd="clr-namespace:ICSharpCode.WpfDesign.AddIn" |
||||
Background="{x:Static SystemColors.ControlBrush}" |
||||
SnapsToDevicePixels="True" |
||||
WindowStartupLocation="CenterScreen" |
||||
ResizeMode="CanResizeWithGrip" |
||||
Title="Choose Class" |
||||
Height="438" |
||||
Width="488"> |
||||
|
||||
<Grid> |
||||
<TextBlock Text="Starts with:" |
||||
HorizontalAlignment="Left" |
||||
Margin="12,12,0,0" |
||||
VerticalAlignment="Top" |
||||
Height="13" |
||||
Width="55" /> |
||||
<TextBox x:Name="uxFilter" |
||||
Text="{Binding Filter, UpdateSourceTrigger=PropertyChanged}" |
||||
Height="23" |
||||
Margin="12,31,12,0" |
||||
VerticalAlignment="Top" /> |
||||
|
||||
<sd:ClassListBox x:Name="uxList" |
||||
Margin="12,60,12,78" |
||||
ItemsSource="{Binding Classes}" |
||||
IsSynchronizedWithCurrentItem="True" |
||||
ScrollViewer.HorizontalScrollBarVisibility="Hidden" |
||||
> |
||||
<ListBox.ItemTemplate> |
||||
<DataTemplate> |
||||
<StackPanel Orientation="Horizontal"> |
||||
<Image Source="{sd:GetBitmap Icons.16x16.Class}" |
||||
Stretch="None" /> |
||||
<TextBlock Margin="5 0 0 0" |
||||
Text="{Binding Converter={x:Static sd:ClassNameConverter.Instance}}" |
||||
VerticalAlignment="Center"/> |
||||
</StackPanel> |
||||
</DataTemplate> |
||||
</ListBox.ItemTemplate> |
||||
</sd:ClassListBox> |
||||
|
||||
<CheckBox Content="Show System Classes" |
||||
IsChecked="{Binding ShowSystemClasses}" |
||||
Height="16" |
||||
HorizontalAlignment="Left" |
||||
Margin="12,0,0,56" |
||||
VerticalAlignment="Bottom" |
||||
Width="120" /> |
||||
<Button x:Name="uxOk" |
||||
Content="OK" |
||||
Height="23" |
||||
Margin="0,0,93,12" |
||||
VerticalAlignment="Bottom" |
||||
HorizontalAlignment="Right" |
||||
Width="75" |
||||
IsDefault="True" |
||||
IsEnabled="{Binding SelectedItem, ElementName=uxList, Converter={x:Static sd:NullToBoolConverter.Instance}}"/> |
||||
<Button Content="Cancel" |
||||
Height="23" |
||||
HorizontalAlignment="Right" |
||||
Margin="0,0,12,12" |
||||
VerticalAlignment="Bottom" |
||||
Width="75" |
||||
IsCancel="True" /> |
||||
</Grid> |
||||
</Window> |
||||
@ -0,0 +1,114 @@
@@ -0,0 +1,114 @@
|
||||
using System; |
||||
using System.Collections.Specialized; |
||||
using System.Globalization; |
||||
using System.Reflection; |
||||
using System.Windows; |
||||
using System.Windows.Controls; |
||||
using System.Windows.Controls.Primitives; |
||||
using System.Windows.Data; |
||||
using System.Windows.Input; |
||||
|
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public partial class ChooseClassDialog |
||||
{ |
||||
public ChooseClassDialog(ChooseClass core) |
||||
{ |
||||
DataContext = core; |
||||
InitializeComponent(); |
||||
|
||||
uxFilter.Focus(); |
||||
uxList.MouseDoubleClick += uxList_MouseDoubleClick; |
||||
uxOk.Click += delegate { Ok(); }; |
||||
|
||||
AddHandler(Keyboard.GotKeyboardFocusEvent, |
||||
new KeyboardFocusChangedEventHandler( |
||||
(sender, e) => uxList.SetValue(IsSelectionActivePropertyKey, true) |
||||
), |
||||
true); |
||||
} |
||||
|
||||
//HACK: listbox is always highlighted
|
||||
public static DependencyPropertyKey IsSelectionActivePropertyKey = |
||||
(DependencyPropertyKey)typeof(Selector).GetField("IsSelectionActivePropertyKey", |
||||
BindingFlags.Static | BindingFlags.NonPublic).GetValue(null); |
||||
|
||||
protected override void OnPreviewKeyDown(KeyEventArgs e) |
||||
{ |
||||
if (e.Key == Key.Enter) { |
||||
Ok(); |
||||
e.Handled = true; |
||||
} else if (e.Key == Key.Up) { |
||||
uxList.SelectedIndex = Math.Max(0, uxList.SelectedIndex - 1); |
||||
e.Handled = true; |
||||
} else if (e.Key == Key.Down) { |
||||
uxList.SelectedIndex++; |
||||
e.Handled = true; |
||||
} |
||||
} |
||||
|
||||
void uxList_MouseDoubleClick(object sender, MouseButtonEventArgs e) |
||||
{ |
||||
var f = e.OriginalSource as FrameworkElement; |
||||
if (f != null && f.DataContext is IClass) { |
||||
Ok(); |
||||
} |
||||
} |
||||
|
||||
void Ok() |
||||
{ |
||||
DialogResult = true; |
||||
Close(); |
||||
} |
||||
} |
||||
|
||||
class ClassListBox : ListBox |
||||
{ |
||||
protected override void OnItemsChanged(NotifyCollectionChangedEventArgs e) |
||||
{ |
||||
base.OnItemsChanged(e); |
||||
SelectedIndex = 0; |
||||
ScrollIntoView(SelectedItem); |
||||
} |
||||
|
||||
protected override void OnSelectionChanged(SelectionChangedEventArgs e) |
||||
{ |
||||
base.OnSelectionChanged(e); |
||||
ScrollIntoView(SelectedItem); |
||||
} |
||||
} |
||||
|
||||
public class ClassNameConverter : IValueConverter |
||||
{ |
||||
public static ClassNameConverter Instance = new ClassNameConverter(); |
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
var c = value as IClass; |
||||
if (c == null) return value; |
||||
return c.Name + " (" + c.Namespace + ")"; |
||||
} |
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
|
||||
public class NullToBoolConverter : IValueConverter |
||||
{ |
||||
public static NullToBoolConverter Instance = new NullToBoolConverter(); |
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
return value == null ? false : true; |
||||
} |
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
||||
{ |
||||
throw new NotImplementedException(); |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,20 @@
@@ -0,0 +1,20 @@
|
||||
using System; |
||||
using ICSharpCode.SharpDevelop; |
||||
using ICSharpCode.SharpDevelop.Dom; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
public class ChooseClassService |
||||
{ |
||||
public IClass ChooseClass() |
||||
{ |
||||
var core = new ChooseClass(ParserService.CurrentProjectContent); |
||||
var window = new ChooseClassDialog(core); |
||||
|
||||
if (window.ShowDialog().Value) { |
||||
return core.CurrentClass; |
||||
} |
||||
return null; |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,44 @@
@@ -0,0 +1,44 @@
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Drawing; |
||||
using System.Windows; |
||||
using System.Windows.Interop; |
||||
using System.Windows.Markup; |
||||
using System.Windows.Media.Imaging; |
||||
|
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
class GetBitmapExtension : MarkupExtension |
||||
{ |
||||
public GetBitmapExtension(string key) |
||||
{ |
||||
this.key = key; |
||||
} |
||||
|
||||
static Dictionary<string, BitmapSource> cache = new Dictionary<string, BitmapSource>(); |
||||
|
||||
protected string key; |
||||
|
||||
public override object ProvideValue(IServiceProvider sp) |
||||
{ |
||||
BitmapSource result; |
||||
if (cache.TryGetValue(key, out result)) { |
||||
return result; |
||||
} |
||||
result = GetBitmapSource(); |
||||
result.Freeze(); |
||||
cache[key] = result; |
||||
return result; |
||||
} |
||||
|
||||
BitmapSource GetBitmapSource() |
||||
{ |
||||
using (Bitmap bitmap = ResourceService.GetBitmap(key)) { |
||||
return Imaging.CreateBitmapSourceFromHBitmap(bitmap.GetHbitmap(), IntPtr.Zero, |
||||
Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
@ -0,0 +1,8 @@
@@ -0,0 +1,8 @@
|
||||
<Button |
||||
x:Class="ICSharpCode.WpfDesign.AddIn.ObjectEditor" |
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
||||
Content="New..." |
||||
HorizontalAlignment="Right" |
||||
> |
||||
</Button> |
||||
@ -0,0 +1,25 @@
@@ -0,0 +1,25 @@
|
||||
using System; |
||||
using System.Windows; |
||||
using ICSharpCode.WpfDesign.PropertyEditor; |
||||
|
||||
namespace ICSharpCode.WpfDesign.AddIn |
||||
{ |
||||
[PropertyEditor(typeof(FrameworkElement), "DataContext")] |
||||
public partial class ObjectEditor |
||||
{ |
||||
public ObjectEditor(IPropertyEditorDataProperty property) |
||||
{ |
||||
InitializeComponent(); |
||||
|
||||
var s = property.OwnerDataSource.Services.GetService<ChooseClassService>(); |
||||
if (s != null) { |
||||
Click += delegate { |
||||
var c = s.ChooseClass(); |
||||
if (c != null) { |
||||
MessageBox.Show(c.Name); |
||||
} |
||||
}; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue