Browse Source

Treeview DataBinding,small cleanup

pull/23/head
PeterForstmeier 14 years ago
parent
commit
949c922629
  1. 1
      src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj
  2. 140
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceDialog.xaml
  3. 21
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceDialog.xaml.cs
  4. 118
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceViewModel.cs
  5. 59
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReferenceHelper.cs
  6. 2
      src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/ReferenceFolderNodeCommands.cs

1
src/Main/Base/Project/ICSharpCode.SharpDevelop.csproj

@ -254,6 +254,7 @@
<SubType>Code</SubType> <SubType>Code</SubType>
</Compile> </Compile>
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\AddServiceReferenceViewModel.cs" /> <Compile Include="Src\Gui\Dialogs\ReferenceDialog\AddServiceReferenceViewModel.cs" />
<Compile Include="Src\Gui\Dialogs\ReferenceDialog\ServiceReferenceHelper.cs" />
<Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.cs" /> <Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.cs" />
<Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.Designer.cs"> <Compile Include="Src\Gui\Dialogs\ToolNotFoundDialog.Designer.cs">
<DependentUpon>ToolNotFoundDialog.cs</DependentUpon> <DependentUpon>ToolNotFoundDialog.cs</DependentUpon>

140
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceDialog.xaml

@ -1,77 +1,77 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<Window <Window
x:Class="Gui.Dialogs.ReferenceDialog.AddServiceReferenceDialog" x:Class="ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog.AddServiceReferenceDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets" xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
xmlns:core="http://icsharpcode.net/sharpdevelop/core" xmlns:core="http://icsharpcode.net/sharpdevelop/core"
xmlns:src="clr-namespace:Gui.Dialogs.ReferenceDialog" xmlns:src="clr-namespace:ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog"
xmlns:web="clr-namespace:System.Web.Services.Description;assembly=System.Web.Services" xmlns:web="clr-namespace:System.Web.Services.Description;assembly=System.Web.Services"
WindowStartupLocation="CenterOwner" WindowStartupLocation="CenterOwner"
Style="{x:Static core:GlobalStyles.DialogWindowStyle}" Style="{x:Static core:GlobalStyles.DialogWindowStyle}"
Height="425" Height="425"
Width="500" Width="500"
Title="{Binding Title}"> Title="{Binding Title}">
<!--
<!-- http://blogs.msdn.com/b/chkoenig/archive/2008/05/24/hierarchical-databinding-in-wpf.aspx
http://blogs.msdn.com/b/chkoenig/archive/2008/05/24/hierarchical-databinding-in-wpf.aspx
http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx?msg=3663052 http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx?msg=3663052
--> -->
<Window.Resources> <Window.Resources>
<!--
<DataTemplate x:Key="ServiceTemplate">
<TextBlock Text="{Binding Path=Name}" ></TextBlock>
</DataTemplate>
ItemTemplate="{StaticResource ServiceTemplate}">-->
<HierarchicalDataTemplate x:Key="HeaderTemplate" <HierarchicalDataTemplate x:Key="HeaderTemplate"
ItemsSource="{Binding SubItems}"> ItemsSource="{Binding SubItems}">
<TextBlock Grid.Row="0" Text="{Binding Path=Name}" /> <TextBlock Grid.Row="0" Text="{Binding Path=Name}" />
</HierarchicalDataTemplate> </HierarchicalDataTemplate>
</Window.Resources> </Window.Resources>
<Grid
<Grid Name="grid" ShowGridLines="True"> Name="grid"
ShowGridLines="True">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition <RowDefinition
Height="1*" /> Height="1*" />
<RowDefinition Height="3*"></RowDefinition> <RowDefinition
Height="3*"></RowDefinition>
<RowDefinition <RowDefinition
Height="Auto" /> Height="Auto" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid
<Grid Grid.Row="0"> Grid.Row="0">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition> <RowDefinition
<RowDefinition Height="Auto"></RowDefinition> Height="40"></RowDefinition>
<RowDefinition
Height="Auto"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBox
<TextBox Grid.Row="0" Grid.Row="0"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="To see a list of available services on an specific Server, Text="To see a list of available services on an specific Server,&#xD;&#xA;&#x9;&#x9;&#x9;enter a service URL and click Go.To browse for available services cklick Discover"></TextBox>
enter a service URL and click Go.To browse for available services cklick Discover" <Grid
></TextBox> Grid.Row="1"
ShowGridLines="True">
<Grid Grid.Row="1" ShowGridLines="True">
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition> <RowDefinition
Height="Auto"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="300"></ColumnDefinition> <ColumnDefinition
Width="300"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition> <ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<ComboBox
<ComboBox Grid.Column="0" Margin="0,4,12,12" Grid.Column="0"
IsEditable="True" Margin="0,4,12,12"
ItemsSource="{Binding MruServices}" IsEditable="True"
IsSynchronizedWithCurrentItem="True" ItemsSource="{Binding MruServices}"
LostFocus="Cbo_LostFocus" IsSynchronizedWithCurrentItem="True"
SelectedItem="{Binding SelectedService, UpdateSourceTrigger=PropertyChanged}"> LostFocus="Cbo_LostFocus"
</ComboBox> SelectedItem="{Binding SelectedService, UpdateSourceTrigger=PropertyChanged}"></ComboBox>
<widgets:UniformGridWithSpacing
<widgets:UniformGridWithSpacing Columns="2" Grid.Column="1" Margin="0,4,12,12" HorizontalAlignment="Center"> Columns="2"
Grid.Column="1"
Margin="0,4,12,12"
HorizontalAlignment="Center">
<Button <Button
Content="Go" Content="Go"
Command="{Binding GoCommand}" Command="{Binding GoCommand}"
@ -79,44 +79,38 @@ http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx?msg=3663052
<Button <Button
Content="Discover" Content="Discover"
Command="{Binding DiscoverCommand}" Command="{Binding DiscoverCommand}"
Style="{x:Static core:GlobalStyles.ButtonStyle}"/> Style="{x:Static core:GlobalStyles.ButtonStyle}" />
</widgets:UniformGridWithSpacing> </widgets:UniformGridWithSpacing>
</Grid> </Grid>
</Grid> </Grid>
<!-- Main Area --> <!-- Main Area -->
<Grid Grid.Row="1"> <Grid
Grid.Row="1">
<Grid.ColumnDefinitions> <Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/> <ColumnDefinition
<ColumnDefinition Width="*"/> Width="100" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions> </Grid.ColumnDefinitions>
<!-- <TreeView
<TreeView Name="tree" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Name="tree"
ItemsSource="{Binding Path=ServiceDescriptionCollection}" HorizontalAlignment="Stretch"
ItemTemplate="{StaticResource HeaderTemplate}" VerticalAlignment="Stretch"
PreviewMouseDoubleClick="TreeView_PreviewMouseDoubleClick"> ItemsSource="{Binding Path=Items}"
ItemTemplate="{StaticResource HeaderTemplate}"
</TreeView> SelectedItemChanged="Tree_SelectedItemChanged"></TreeView>
--> <GridSplitter
<TreeView Name="tree" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="0"
ItemsSource="{Binding Path=Items}" Width="2"
ItemTemplate="{StaticResource HeaderTemplate}" Background="Black" />
SelectedItemChanged="Tree_SelectedItemChanged"> <ListView Grid.Column="1"></ListView>
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}" >
<Setter Property="IsSelected" Value="{Binding IsSelected, Mode=TwoWay}" />
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
<GridSplitter Grid.Column="0" Width="2" Background="Black"/>
<Label Grid.Column="1"/>
</Grid> </Grid>
<widgets:UniformGridWithSpacing
Columns="2"
<widgets:UniformGridWithSpacing Columns="2" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Margin="0,4,12,12"> Grid.Column="0"
Grid.Row="2"
HorizontalAlignment="Right"
Margin="0,4,12,12">
<Button <Button
Content="{core:Localize Global.OKButtonText}" Content="{core:Localize Global.OKButtonText}"
IsDefault="True" IsDefault="True"

21
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceDialog.xaml.cs

@ -16,7 +16,7 @@ using System.Windows.Documents;
using System.Windows.Input; using System.Windows.Input;
using System.Windows.Media; using System.Windows.Media;
namespace Gui.Dialogs.ReferenceDialog namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog
{ {
/// <summary> /// <summary>
/// Interaction logic for AddServiceReferenceDialog.xaml /// Interaction logic for AddServiceReferenceDialog.xaml
@ -28,11 +28,9 @@ namespace Gui.Dialogs.ReferenceDialog
InitializeComponent(); InitializeComponent();
} }
void okButtonClick(object sender, RoutedEventArgs e) void okButtonClick(object sender, RoutedEventArgs e)
{ {
// http://stackoverflow.com/questions/3373239/wpf-editable-combobox
// var s = cbo.Text;
// var d = this.DataContext;
this.DialogResult = true; this.DialogResult = true;
Close(); Close();
} }
@ -43,27 +41,24 @@ namespace Gui.Dialogs.ReferenceDialog
Close(); Close();
} }
void Cbo_LostFocus(object sender, RoutedEventArgs e) void Cbo_LostFocus(object sender, RoutedEventArgs e)
{ {
var comboBox = (ComboBox) sender; var comboBox = (ComboBox) sender;
if(comboBox.SelectedItem != null) if(comboBox.SelectedItem != null)
return; return;
var newItem = comboBox.Text; var newItem = comboBox.Text;
// _names.Add(newItem);
comboBox.SelectedItem = newItem; comboBox.SelectedItem = newItem;
} }
void TreeView_PreviewMouseDoubleClick(object sender, MouseButtonEventArgs e)
{
var d = tree.DataContext;
var it = tree.ItemTemplate;
}
void Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e) void Tree_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs<object> e)
{ {
MyItem m = (MyItem)e.NewValue; if (e.NewValue != null) {
ServiceItem myItem = (ServiceItem)e.NewValue;
var dc = (AddServiceReferenceViewModel)tree.DataContext;
dc.ServiceItem = myItem;
}
} }
} }

118
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceViewModel.cs

@ -27,7 +27,7 @@ using ICSharpCode.SharpDevelop.Project;
using ICSharpCode.SharpDevelop.Widgets; using ICSharpCode.SharpDevelop.Widgets;
using Microsoft.Win32; using Microsoft.Win32;
namespace Gui.Dialogs.ReferenceDialog namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog
{ {
/// <summary> /// <summary>
/// Description of AddServiceReferenceViewModel. /// Description of AddServiceReferenceViewModel.
@ -47,7 +47,7 @@ namespace Gui.Dialogs.ReferenceDialog
discoverButtonContend = "Disvover"; discoverButtonContend = "Disvover";
HeadLine = header1 + header2; HeadLine = header1 + header2;
MruServices = AddMruList(); MruServices = ServiceReferenceHelper.AddMruList();
SelectedService = MruServices[0]; SelectedService = MruServices[0];
GoCommand = new RelayCommand(ExecuteGo,CanExecuteGo); GoCommand = new RelayCommand(ExecuteGo,CanExecuteGo);
@ -97,31 +97,10 @@ namespace Gui.Dialogs.ReferenceDialog
#region Create List of services #region Create List of services
// Modifyed Code from Matt private List<string> mruServices = new List<string>();
List <string> AddMruList()
{
var list = new List<string>();
try {
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\TypedURLs");
if (key != null) {
foreach (string name in key.GetValueNames()) {
list.Add ((string)key.GetValue(name));
}
}
} catch (Exception)
{
};
return list;
}
private List<string> mruServices;
public List<string> MruServices { public List<string> MruServices {
get { get {
if (mruServices == null) {
mruServices = new List<string>();
}
return mruServices; } return mruServices; }
set { mruServices = value; set { mruServices = value;
base.RaisePropertyChanged(() =>MruServices); base.RaisePropertyChanged(() =>MruServices);
@ -136,8 +115,6 @@ namespace Gui.Dialogs.ReferenceDialog
base.RaisePropertyChanged(() =>SelectedService);} base.RaisePropertyChanged(() =>SelectedService);}
} }
#endregion #endregion
#region Go #region Go
@ -182,7 +159,7 @@ namespace Gui.Dialogs.ReferenceDialog
CredentialCache credentialCache = new CredentialCache(); CredentialCache credentialCache = new CredentialCache();
WebServiceDiscoveryClientProtocol discoveryClientProtocol; WebServiceDiscoveryClientProtocol discoveryClientProtocol;
ICSharpCode.SharpDevelop.Gui.WebReference webReference; // ICSharpCode.SharpDevelop.Gui.WebReference webReference;
string namespacePrefix = String.Empty; string namespacePrefix = String.Empty;
delegate DiscoveryDocument DiscoverAnyAsync(string url); delegate DiscoveryDocument DiscoverAnyAsync(string url);
delegate void DiscoveredWebServicesHandler(DiscoveryClientProtocol protocol); delegate void DiscoveredWebServicesHandler(DiscoveryClientProtocol protocol);
@ -295,18 +272,20 @@ namespace Gui.Dialogs.ReferenceDialog
if (protocol != null) { if (protocol != null) {
// webServicesView.Add(GetServiceDescriptions(protocol)); // webServicesView.Add(GetServiceDescriptions(protocol));
ServiceDescriptionCollection = GetServiceDescriptions(protocol); ServiceDescriptionCollection = ServiceReferenceHelper.GetServiceDescriptions(protocol);
FillItems (ServiceDescriptionCollection); FillItems (ServiceDescriptionCollection);
var defaultNameSpace = GetDefaultNamespace(); var defaultNameSpace = GetDefaultNamespace();
var referenceName = GetReferenceName(discoveryUri); var referenceName = GetReferenceName(discoveryUri);
/*
webReference = new ICSharpCode.SharpDevelop.Gui.WebReference(project, webReference = new ICSharpCode.SharpDevelop.Gui.WebReference(project,
discoveryUri.AbsoluteUri, discoveryUri.AbsoluteUri,
defaultNameSpace, defaultNameSpace,
referenceName, protocol); referenceName, protocol);
*/
} }
else else
{ {
webReference = null; // webReference = null;
} }
} }
@ -335,55 +314,33 @@ namespace Gui.Dialogs.ReferenceDialog
if (discoveryUri != null) { if (discoveryUri != null) {
return discoveryUri.Host; return discoveryUri.Host;
} }
return String.Empty;*/ return String.Empty;
} */
ServiceDescriptionCollection GetServiceDescriptions(DiscoveryClientProtocol protocol)
{
ServiceDescriptionCollection services = new ServiceDescriptionCollection();
protocol.ResolveOneLevel();
foreach (DictionaryEntry entry in protocol.References) {
ContractReference contractRef = entry.Value as ContractReference;
if (contractRef != null) {
services.Add(contractRef.Contract);
}
}
return services;
} }
ServiceDescriptionCollection serviceDescriptionCollection;
ServiceDescriptionCollection serviceDescriptionCollection = new ServiceDescriptionCollection();
public ServiceDescriptionCollection ServiceDescriptionCollection public ServiceDescriptionCollection ServiceDescriptionCollection
{ {
get {return serviceDescriptionCollection;} get {
return serviceDescriptionCollection;
set { }
if (serviceDescriptionCollection == null) { set
serviceDescriptionCollection = new ServiceDescriptionCollection(); {
}
serviceDescriptionCollection = value; serviceDescriptionCollection = value;
var s = serviceDescriptionCollection[0];
RaisePropertyChanged(() =>ServiceDescriptionCollection); RaisePropertyChanged(() =>ServiceDescriptionCollection);
} }
} }
#endregion #endregion
#region new binding #region new binding
List<ServiceItem> items = new List <ServiceItem>();
List<MyItem> items = new List <MyItem>();
object isSelected;
public object IsSelected {
get { return isSelected; }
set { isSelected = value; }
}
public List <MyItem> Items { public List <ServiceItem> Items {
get {return items; } get {return items; }
set { set {
@ -392,6 +349,21 @@ namespace Gui.Dialogs.ReferenceDialog
} }
} }
ServiceItem myItem;
public ServiceItem ServiceItem {
get { return myItem; }
set { myItem = value;
UpdateListView();
base.RaisePropertyChanged(() =>ServiceItem);
}
}
void UpdateListView ()
{
}
void FillItems (ServiceDescriptionCollection descriptions) void FillItems (ServiceDescriptionCollection descriptions)
{ {
foreach (ServiceDescription element in descriptions) foreach (ServiceDescription element in descriptions)
@ -401,20 +373,21 @@ namespace Gui.Dialogs.ReferenceDialog
} }
void Add(ServiceDescription description) void Add(ServiceDescription description)
{ {
List<MyItem> l = new List<MyItem>(); List<ServiceItem> l = new List<ServiceItem>();
var rootNode = new MyItem(GetName(description)); var rootNode = new ServiceItem(GetName(description));
rootNode.Tag = description; rootNode.Tag = description;
l.Add(rootNode); l.Add(rootNode);
foreach(Service service in description.Services) { foreach(Service service in description.Services) {
var serviceNode = new MyItem(service.Name); var serviceNode = new ServiceItem(service.Name);
serviceNode.Tag = service; serviceNode.Tag = service;
rootNode.SubItems.Add(serviceNode); rootNode.SubItems.Add(serviceNode);
foreach(Port port in service.Ports) { foreach(Port port in service.Ports) {
var portNode = new MyItem(port.Name); var portNode = new ServiceItem(port.Name);
portNode.Tag = port; portNode.Tag = port;
serviceNode.SubItems.Add(portNode); serviceNode.SubItems.Add(portNode);
@ -424,7 +397,7 @@ namespace Gui.Dialogs.ReferenceDialog
PortType portType = description.PortTypes[binding.Type.Name]; PortType portType = description.PortTypes[binding.Type.Name];
if (portType != null) { if (portType != null) {
foreach(Operation operation in portType.Operations) { foreach(Operation operation in portType.Operations) {
var operationNode = new MyItem(operation.Name); var operationNode = new ServiceItem(operation.Name);
operationNode.Tag = operation; operationNode.Tag = operation;
// operationNode.ImageIndex = OperationImageIndex; // operationNode.ImageIndex = OperationImageIndex;
// operationNode.SelectedImageIndex = OperationImageIndex; // operationNode.SelectedImageIndex = OperationImageIndex;
@ -457,17 +430,16 @@ namespace Gui.Dialogs.ReferenceDialog
} }
public class MyItem public class ServiceItem
{ {
public MyItem (string name) public ServiceItem (string name)
{ {
this.Name = name; this.Name = name;
SubItems = new List<MyItem>(); SubItems = new List<ServiceItem>();
} }
public string Name {get;set;} public string Name {get;set;}
public object Tag {get;set;} public object Tag {get;set;}
public List<MyItem> SubItems {get;set;} public List<ServiceItem> SubItems {get;set;}
} }
} }

59
src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/ServiceReferenceHelper.cs

@ -0,0 +1,59 @@
/*
* Created by SharpDevelop.
* User: Peter Forstmeier
* Date: 24.10.2011
* Time: 20:39
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections;
using System.Collections.Generic;
using System.Web.Services.Description;
using System.Web.Services.Discovery;
using Microsoft.Win32;
namespace ICSharpCode.SharpDevelop.Gui
{
/// <summary>
/// Description of ServiceReferenceHelper.
/// </summary>
internal class ServiceReferenceHelper
{
private ServiceReferenceHelper()
{
}
public static List <string> AddMruList()
{
var list = new List<string>();
try {
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Internet Explorer\TypedURLs");
if (key != null) {
foreach (string name in key.GetValueNames()) {
list.Add ((string)key.GetValue(name));
}
}
} catch (Exception)
{
};
return list;
}
public static ServiceDescriptionCollection GetServiceDescriptions(DiscoveryClientProtocol protocol)
{
ServiceDescriptionCollection services = new ServiceDescriptionCollection();
protocol.ResolveOneLevel();
foreach (DictionaryEntry entry in protocol.References) {
ContractReference contractRef = entry.Value as ContractReference;
if (contractRef != null) {
services.Add(contractRef.Contract);
}
}
return services;
}
}
}

2
src/Main/Base/Project/Src/Gui/Pads/ProjectBrowser/Commands/ReferenceFolderNodeCommands.cs

@ -8,7 +8,7 @@ using System.Web.Services.Discovery;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml; using System.Xml;
using Gui.Dialogs.ReferenceDialog; using ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog;
using ICSharpCode.Core; using ICSharpCode.Core;
using ICSharpCode.SharpDevelop.Gui; using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Gui.OptionPanels; using ICSharpCode.SharpDevelop.Gui.OptionPanels;

Loading…
Cancel
Save