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. 118
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceDialog.xaml
  3. 21
      src/Main/Base/Project/Src/Gui/Dialogs/ReferenceDialog/AddServiceReferenceDialog.xaml.cs
  4. 114
      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 @@ @@ -254,6 +254,7 @@
<SubType>Code</SubType>
</Compile>
<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.Designer.cs">
<DependentUpon>ToolNotFoundDialog.cs</DependentUpon>

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

@ -1,77 +1,77 @@ @@ -1,77 +1,77 @@
<?xml version="1.0" encoding="utf-8"?>
<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:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:widgets="http://icsharpcode.net/sharpdevelop/widgets"
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"
WindowStartupLocation="CenterOwner"
Style="{x:Static core:GlobalStyles.DialogWindowStyle}"
Height="425"
Width="500"
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
-->
<Window.Resources>
<!--
<DataTemplate x:Key="ServiceTemplate">
<TextBlock Text="{Binding Path=Name}" ></TextBlock>
</DataTemplate>
ItemTemplate="{StaticResource ServiceTemplate}">-->
<HierarchicalDataTemplate x:Key="HeaderTemplate"
ItemsSource="{Binding SubItems}">
<TextBlock Grid.Row="0" Text="{Binding Path=Name}" />
</HierarchicalDataTemplate>
</Window.Resources>
<Grid Name="grid" ShowGridLines="True">
<Grid
Name="grid"
ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition
Height="1*" />
<RowDefinition Height="3*"></RowDefinition>
<RowDefinition
Height="3*"></RowDefinition>
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid
Grid.Row="0">
<Grid.RowDefinitions>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition
Height="40"></RowDefinition>
<RowDefinition
Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<TextBox Grid.Row="0"
<TextBox
Grid.Row="0"
TextWrapping="Wrap"
Text="To see a list of available services on an specific Server,
enter a service URL and click Go.To browse for available services cklick Discover"
></TextBox>
<Grid Grid.Row="1" ShowGridLines="True">
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>
<Grid
Grid.Row="1"
ShowGridLines="True">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition
Height="Auto"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"></ColumnDefinition>
<ColumnDefinition
Width="300"></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<ComboBox Grid.Column="0" Margin="0,4,12,12"
<ComboBox
Grid.Column="0"
Margin="0,4,12,12"
IsEditable="True"
ItemsSource="{Binding MruServices}"
IsSynchronizedWithCurrentItem="True"
LostFocus="Cbo_LostFocus"
SelectedItem="{Binding SelectedService, UpdateSourceTrigger=PropertyChanged}">
</ComboBox>
<widgets:UniformGridWithSpacing Columns="2" Grid.Column="1" Margin="0,4,12,12" HorizontalAlignment="Center">
SelectedItem="{Binding SelectedService, UpdateSourceTrigger=PropertyChanged}"></ComboBox>
<widgets:UniformGridWithSpacing
Columns="2"
Grid.Column="1"
Margin="0,4,12,12"
HorizontalAlignment="Center">
<Button
Content="Go"
Command="{Binding GoCommand}"
@ -83,40 +83,34 @@ http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx?msg=3663052 @@ -83,40 +83,34 @@ http://www.codeproject.com/KB/WPF/TreeViewWithViewModel.aspx?msg=3663052
</widgets:UniformGridWithSpacing>
</Grid>
</Grid>
<!-- Main Area -->
<Grid Grid.Row="1">
<Grid
Grid.Row="1">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition
Width="100" />
<ColumnDefinition
Width="*" />
</Grid.ColumnDefinitions>
<!--
<TreeView Name="tree" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
ItemsSource="{Binding Path=ServiceDescriptionCollection}"
ItemTemplate="{StaticResource HeaderTemplate}"
PreviewMouseDoubleClick="TreeView_PreviewMouseDoubleClick">
</TreeView>
-->
<TreeView Name="tree" HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
<TreeView
Name="tree"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
ItemsSource="{Binding Path=Items}"
ItemTemplate="{StaticResource HeaderTemplate}"
SelectedItemChanged="Tree_SelectedItemChanged">
<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"/>
SelectedItemChanged="Tree_SelectedItemChanged"></TreeView>
<GridSplitter
Grid.Column="0"
Width="2"
Background="Black" />
<ListView Grid.Column="1"></ListView>
</Grid>
<widgets:UniformGridWithSpacing Columns="2" Grid.Column="0" Grid.Row="2" HorizontalAlignment="Right" Margin="0,4,12,12">
<widgets:UniformGridWithSpacing
Columns="2"
Grid.Column="0"
Grid.Row="2"
HorizontalAlignment="Right"
Margin="0,4,12,12">
<Button
Content="{core:Localize Global.OKButtonText}"
IsDefault="True"

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

@ -16,7 +16,7 @@ using System.Windows.Documents; @@ -16,7 +16,7 @@ using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
namespace Gui.Dialogs.ReferenceDialog
namespace ICSharpCode.SharpDevelop.Gui.Dialogs.ReferenceDialog
{
/// <summary>
/// Interaction logic for AddServiceReferenceDialog.xaml
@ -28,11 +28,9 @@ namespace Gui.Dialogs.ReferenceDialog @@ -28,11 +28,9 @@ namespace Gui.Dialogs.ReferenceDialog
InitializeComponent();
}
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;
Close();
}
@ -43,27 +41,24 @@ namespace Gui.Dialogs.ReferenceDialog @@ -43,27 +41,24 @@ namespace Gui.Dialogs.ReferenceDialog
Close();
}
void Cbo_LostFocus(object sender, RoutedEventArgs e)
{
var comboBox = (ComboBox) sender;
if(comboBox.SelectedItem != null)
return;
var newItem = comboBox.Text;
// _names.Add(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)
{
MyItem m = (MyItem)e.NewValue;
if (e.NewValue != null) {
ServiceItem myItem = (ServiceItem)e.NewValue;
var dc = (AddServiceReferenceViewModel)tree.DataContext;
dc.ServiceItem = myItem;
}
}
}

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

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

Loading…
Cancel
Save