Browse Source
git-svn-id: svn://svn.sharpdevelop.net/sharpdevelop/trunk@4989 1ccf3a8d-04fe-1044-b7c0-cef0b8235c61shortcuts
12 changed files with 473 additions and 149 deletions
@ -1,29 +1,52 @@ |
|||||||
<UserControl x:Class="ICSharpCode.StartPage.RecentProjectsControl" |
<?xml version="1.0" encoding="utf-8"?> |
||||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
<UserControl |
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
x:Class="ICSharpCode.StartPage.RecentProjectsControl" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:core="http://icsharpcode.net/sharpdevelop/core"> |
||||||
xmlns:core="http://icsharpcode.net/sharpdevelop/core"> |
<StackPanel |
||||||
<StackPanel Orientation="Vertical"> |
Orientation="Vertical"> |
||||||
<ListView Name="lastProjectsListView" SelectionMode="Single" MouseDoubleClick="lastProjectsDoubleClick" KeyDown="lastProjectsKeyDown"> |
<ListView |
||||||
|
Name="lastProjectsListView" |
||||||
|
SelectionMode="Single" |
||||||
|
core:SortableGridViewColumn.SortMode="Automatic" |
||||||
|
MouseDoubleClick="lastProjectsDoubleClick" |
||||||
|
KeyDown="lastProjectsKeyDown"> |
||||||
<ListView.Resources> |
<ListView.Resources> |
||||||
<DataTemplate x:Key="nameCellTemplate"> |
<DataTemplate |
||||||
|
x:Key="nameCellTemplate"> |
||||||
<TextBlock> |
<TextBlock> |
||||||
<Hyperlink Tag="{Binding}" Click="listViewHyperlinkClick"> |
<Hyperlink |
||||||
<TextBlock Text="{Binding Path=Name}" /> |
Tag="{Binding}" |
||||||
|
Click="listViewHyperlinkClick"> |
||||||
|
<TextBlock |
||||||
|
Text="{Binding Path=Name}" /> |
||||||
</Hyperlink> |
</Hyperlink> |
||||||
</TextBlock> |
</TextBlock> |
||||||
</DataTemplate> |
</DataTemplate> |
||||||
</ListView.Resources> |
</ListView.Resources> |
||||||
<ListView.View> |
<ListView.View> |
||||||
<GridView> |
<GridView> |
||||||
<GridViewColumn CellTemplate="{StaticResource nameCellTemplate}" Header="{core:Localize Global.Name}" /> |
<core:SortableGridViewColumn |
||||||
<GridViewColumn DisplayMemberBinding="{Binding Path=LastModification}" Header="{core:Localize StartPage.StartMenu.ModifiedTable}" /> |
SortBy="Name" |
||||||
<GridViewColumn DisplayMemberBinding="{Binding Path=Path}" Header="{core:Localize StartPage.StartMenu.LocationTable}" /> |
CellTemplate="{StaticResource nameCellTemplate}" |
||||||
|
Header="{core:Localize Global.Name}" /> |
||||||
|
<core:SortableGridViewColumn |
||||||
|
DisplayMemberBinding="{Binding Path=LastModification}" |
||||||
|
Header="{core:Localize StartPage.StartMenu.ModifiedTable}" /> |
||||||
|
<core:SortableGridViewColumn |
||||||
|
DisplayMemberBinding="{Binding Path=Path}" |
||||||
|
Header="{core:Localize StartPage.StartMenu.LocationTable}" /> |
||||||
</GridView> |
</GridView> |
||||||
</ListView.View> |
</ListView.View> |
||||||
</ListView> |
</ListView> |
||||||
<StackPanel Orientation="Horizontal" Margin="0,20,0,0"> |
<StackPanel |
||||||
<Button Content="{core:Localize StartPage.StartMenu.OpenCombineButton}" Click="openSolutionClick" /> |
Orientation="Horizontal" |
||||||
<Button Content="{core:Localize StartPage.StartMenu.NewCombineButton}" Click="newSolutionClick" Margin="8,0,0,0" /> |
Margin="0,20,0,0"> |
||||||
|
<Button |
||||||
|
Content="{core:Localize StartPage.StartMenu.OpenCombineButton}" |
||||||
|
Click="openSolutionClick" /> |
||||||
|
<Button |
||||||
|
Content="{core:Localize StartPage.StartMenu.NewCombineButton}" |
||||||
|
Click="newSolutionClick" |
||||||
|
Margin="8,0,0,0" /> |
||||||
</StackPanel> |
</StackPanel> |
||||||
</StackPanel> |
</StackPanel> |
||||||
</UserControl> |
</UserControl> |
||||||
@ -0,0 +1,65 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Markup; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core.Presentation |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// ExtensionMethods that help with WPF.
|
||||||
|
/// </summary>
|
||||||
|
public static class ExtensionMethods |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Sets the value of a dependency property on <paramref name="targetObject"/> using a markup extension.
|
||||||
|
/// </summary>
|
||||||
|
/// <remarks>This method does not support markup extensions like x:Static that depend on
|
||||||
|
/// having a XAML file as context.</remarks>
|
||||||
|
public static void SetValueToExtension(this DependencyObject targetObject, DependencyProperty property, MarkupExtension markupExtension) |
||||||
|
{ |
||||||
|
if (targetObject == null) |
||||||
|
throw new ArgumentNullException("targetObject"); |
||||||
|
if (property == null) |
||||||
|
throw new ArgumentNullException("property"); |
||||||
|
if (markupExtension == null) |
||||||
|
throw new ArgumentNullException("markupExtension"); |
||||||
|
|
||||||
|
var serviceProvider = new SetValueToExtensionServiceProvider(targetObject, property); |
||||||
|
targetObject.SetValue(property, markupExtension.ProvideValue(serviceProvider)); |
||||||
|
} |
||||||
|
|
||||||
|
sealed class SetValueToExtensionServiceProvider : IServiceProvider, IProvideValueTarget |
||||||
|
{ |
||||||
|
readonly DependencyObject targetObject; |
||||||
|
readonly DependencyProperty targetProperty; |
||||||
|
|
||||||
|
public SetValueToExtensionServiceProvider(DependencyObject targetObject, DependencyProperty property) |
||||||
|
{ |
||||||
|
this.targetObject = targetObject; |
||||||
|
this.targetProperty = property; |
||||||
|
} |
||||||
|
|
||||||
|
public object GetService(Type serviceType) |
||||||
|
{ |
||||||
|
if (serviceType == typeof(IProvideValueTarget)) |
||||||
|
return this; |
||||||
|
else |
||||||
|
return null; |
||||||
|
} |
||||||
|
|
||||||
|
public object TargetObject { |
||||||
|
get { return targetObject; } |
||||||
|
} |
||||||
|
|
||||||
|
public object TargetProperty { |
||||||
|
get { return targetProperty; } |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,212 @@ |
|||||||
|
// <file>
|
||||||
|
// <copyright see="prj:///doc/copyright.txt"/>
|
||||||
|
// <license see="prj:///doc/license.txt"/>
|
||||||
|
// <owner name="Daniel Grunwald"/>
|
||||||
|
// <version>$Revision$</version>
|
||||||
|
// </file>
|
||||||
|
|
||||||
|
using System; |
||||||
|
using System.ComponentModel; |
||||||
|
using System.Windows; |
||||||
|
using System.Windows.Controls; |
||||||
|
using System.Windows.Data; |
||||||
|
|
||||||
|
namespace ICSharpCode.Core.Presentation |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Allows to automatically sort a grid view.
|
||||||
|
/// </summary>
|
||||||
|
public class SortableGridViewColumn : GridViewColumn |
||||||
|
{ |
||||||
|
static readonly ComponentResourceKey headerTemplateKey = new ComponentResourceKey(typeof(SortableGridViewColumn), "ColumnHeaderTemplate"); |
||||||
|
|
||||||
|
public SortableGridViewColumn() |
||||||
|
{ |
||||||
|
this.SetValueToExtension(HeaderTemplateProperty, new DynamicResourceExtension(headerTemplateKey)); |
||||||
|
} |
||||||
|
|
||||||
|
string sortBy; |
||||||
|
|
||||||
|
public string SortBy { |
||||||
|
get { return sortBy; } |
||||||
|
set { |
||||||
|
if (sortBy != value) { |
||||||
|
sortBy = value; |
||||||
|
OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("SortBy")); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
#region SortDirection property
|
||||||
|
public static readonly DependencyProperty SortDirectionProperty = |
||||||
|
DependencyProperty.RegisterAttached("SortDirection", typeof(ColumnSortDirection), typeof(SortableGridViewColumn), |
||||||
|
new FrameworkPropertyMetadata(ColumnSortDirection.None, OnSortDirectionChanged)); |
||||||
|
|
||||||
|
public ColumnSortDirection SortDirection { |
||||||
|
get { return (ColumnSortDirection)GetValue(SortDirectionProperty); } |
||||||
|
set { SetValue(SortDirectionProperty, value); } |
||||||
|
} |
||||||
|
|
||||||
|
public static ColumnSortDirection GetSortDirection(ListView listView) |
||||||
|
{ |
||||||
|
return (ColumnSortDirection)listView.GetValue(SortDirectionProperty); |
||||||
|
} |
||||||
|
|
||||||
|
public static void SetSortDirection(ListView listView, ColumnSortDirection value) |
||||||
|
{ |
||||||
|
listView.SetValue(SortDirectionProperty, value); |
||||||
|
} |
||||||
|
|
||||||
|
static void OnSortDirectionChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) |
||||||
|
{ |
||||||
|
ListView grid = sender as ListView; |
||||||
|
if (grid != null) { |
||||||
|
SortableGridViewColumn col = GetCurrentSortColumn(grid); |
||||||
|
if (col != null) |
||||||
|
col.SortDirection = (ColumnSortDirection)args.NewValue; |
||||||
|
Sort(grid); |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region CurrentSortColumn property
|
||||||
|
public static readonly DependencyProperty CurrentSortColumnProperty = |
||||||
|
DependencyProperty.RegisterAttached("CurrentSortColumn", typeof(SortableGridViewColumn), typeof(SortableGridViewColumn), |
||||||
|
new FrameworkPropertyMetadata(OnCurrentSortColumnChanged)); |
||||||
|
|
||||||
|
public static SortableGridViewColumn GetCurrentSortColumn(ListView listView) |
||||||
|
{ |
||||||
|
return (SortableGridViewColumn)listView.GetValue(CurrentSortColumnProperty); |
||||||
|
} |
||||||
|
|
||||||
|
public static void SetCurrentSortColumn(ListView listView, SortableGridViewColumn value) |
||||||
|
{ |
||||||
|
listView.SetValue(CurrentSortColumnProperty, value); |
||||||
|
} |
||||||
|
|
||||||
|
static void OnCurrentSortColumnChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) |
||||||
|
{ |
||||||
|
ListView grid = sender as ListView; |
||||||
|
if (grid != null) { |
||||||
|
SortableGridViewColumn oldColumn = (SortableGridViewColumn)args.OldValue; |
||||||
|
if (oldColumn != null) |
||||||
|
oldColumn.SortDirection = ColumnSortDirection.None; |
||||||
|
SortableGridViewColumn newColumn = (SortableGridViewColumn)args.NewValue; |
||||||
|
if (newColumn != null) { |
||||||
|
newColumn.SortDirection = GetSortDirection(grid); |
||||||
|
} |
||||||
|
Sort(grid); |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region SortMode property
|
||||||
|
public static readonly DependencyProperty SortModeProperty = |
||||||
|
DependencyProperty.RegisterAttached("SortMode", typeof(ListViewSortMode), typeof(SortableGridViewColumn), |
||||||
|
new FrameworkPropertyMetadata(ListViewSortMode.None, OnSortModeChanged)); |
||||||
|
|
||||||
|
public static ListViewSortMode GetSortMode(ListView listView) |
||||||
|
{ |
||||||
|
return (ListViewSortMode)listView.GetValue(SortModeProperty); |
||||||
|
} |
||||||
|
|
||||||
|
public static void SetSortMode(ListView listView, ListViewSortMode value) |
||||||
|
{ |
||||||
|
listView.SetValue(SortModeProperty, value); |
||||||
|
} |
||||||
|
|
||||||
|
static void OnSortModeChanged(DependencyObject sender, DependencyPropertyChangedEventArgs args) |
||||||
|
{ |
||||||
|
ListView grid = sender as ListView; |
||||||
|
if (grid != null) { |
||||||
|
if ((ListViewSortMode)args.NewValue != ListViewSortMode.None) |
||||||
|
grid.AddHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(GridViewColumnHeaderClickHandler)); |
||||||
|
else |
||||||
|
grid.RemoveHandler(GridViewColumnHeader.ClickEvent, new RoutedEventHandler(GridViewColumnHeaderClickHandler)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
static void GridViewColumnHeaderClickHandler(object sender, RoutedEventArgs e) |
||||||
|
{ |
||||||
|
ListView grid = sender as ListView; |
||||||
|
GridViewColumnHeader headerClicked = e.OriginalSource as GridViewColumnHeader; |
||||||
|
if (grid != null && headerClicked != null && headerClicked.Role != GridViewColumnHeaderRole.Padding) { |
||||||
|
if (headerClicked.Column == GetCurrentSortColumn(grid)) { |
||||||
|
if (GetSortDirection(grid) == ColumnSortDirection.Ascending) |
||||||
|
SetSortDirection(grid, ColumnSortDirection.Descending); |
||||||
|
else |
||||||
|
SetSortDirection(grid, ColumnSortDirection.Ascending); |
||||||
|
} else { |
||||||
|
SetSortDirection(grid, ColumnSortDirection.Ascending); |
||||||
|
SetCurrentSortColumn(grid, headerClicked.Column as SortableGridViewColumn); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
#endregion
|
||||||
|
|
||||||
|
static void Sort(ListView grid) |
||||||
|
{ |
||||||
|
ColumnSortDirection currentDirection = GetSortDirection(grid); |
||||||
|
SortableGridViewColumn column = GetCurrentSortColumn(grid); |
||||||
|
if (column != null && GetSortMode(grid) == ListViewSortMode.Automatic && currentDirection != ColumnSortDirection.None) { |
||||||
|
ICollectionView dataView = CollectionViewSource.GetDefaultView(grid.ItemsSource); |
||||||
|
|
||||||
|
string sortBy = column.SortBy; |
||||||
|
if (sortBy == null) { |
||||||
|
Binding binding = column.DisplayMemberBinding as Binding; |
||||||
|
if (binding != null && binding.Path != null) { |
||||||
|
sortBy = binding.Path.Path; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
dataView.SortDescriptions.Clear(); |
||||||
|
if (sortBy != null) { |
||||||
|
ListSortDirection direction; |
||||||
|
if (currentDirection == ColumnSortDirection.Descending) |
||||||
|
direction = ListSortDirection.Descending; |
||||||
|
else |
||||||
|
direction = ListSortDirection.Ascending; |
||||||
|
dataView.SortDescriptions.Add(new SortDescription(sortBy, direction)); |
||||||
|
} |
||||||
|
dataView.Refresh(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public enum ColumnSortDirection |
||||||
|
{ |
||||||
|
None, |
||||||
|
Ascending, |
||||||
|
Descending |
||||||
|
} |
||||||
|
|
||||||
|
public enum ListViewSortMode |
||||||
|
{ |
||||||
|
/// <summary>
|
||||||
|
/// Disable automatic sorting when sortable columns are clicked.
|
||||||
|
/// </summary>
|
||||||
|
None, |
||||||
|
/// <summary>
|
||||||
|
/// Fully automatic sorting.
|
||||||
|
/// </summary>
|
||||||
|
Automatic, |
||||||
|
/// <summary>
|
||||||
|
/// Automatically update SortDirection and CurrentSortColumn properties,
|
||||||
|
/// but do not actually sort the data.
|
||||||
|
/// </summary>
|
||||||
|
HalfAutomatic |
||||||
|
} |
||||||
|
|
||||||
|
sealed class ColumnSortDirectionToVisibilityConverter : IValueConverter |
||||||
|
{ |
||||||
|
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
||||||
|
{ |
||||||
|
return Equals(value, parameter) ? Visibility.Visible : Visibility.Collapsed; |
||||||
|
} |
||||||
|
|
||||||
|
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) |
||||||
|
{ |
||||||
|
throw new NotSupportedException(); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue