Browse Source

Adding of custom assemblies to ClassBrowser from GAC through OpenFromGacDialog.

newNRILSpyDebugger
Andreas Weizel 12 years ago
parent
commit
33addc9353
  1. 11
      src/Main/SharpDevelop/Dom/ClassBrowser/Commands.cs
  2. 46
      src/Main/SharpDevelop/Dom/ClassBrowser/OpenFromGacDialog.xaml
  3. 188
      src/Main/SharpDevelop/Dom/ClassBrowser/OpenFromGacDialog.xaml.cs
  4. 5
      src/Main/SharpDevelop/SharpDevelop.csproj

11
src/Main/SharpDevelop/Dom/ClassBrowser/Commands.cs

@ -36,7 +36,16 @@ namespace ICSharpCode.SharpDevelop.Dom.ClassBrowser @@ -36,7 +36,16 @@ namespace ICSharpCode.SharpDevelop.Dom.ClassBrowser
{
public override void Execute(object parameter)
{
// throw new NotImplementedException();
var classBrowser = SD.GetService<IClassBrowser>();
if (classBrowser != null) {
OpenFromGacDialog gacDialog = new OpenFromGacDialog();
if (gacDialog.ShowDialog() ?? false)
{
foreach (string assemblyFile in gacDialog.SelectedFileNames) {
classBrowser.AssemblyList.Assemblies.Add(ClassBrowserPad.CreateAssemblyModelFromFile(assemblyFile));
}
}
}
}
}

46
src/Main/SharpDevelop/Dom/ClassBrowser/OpenFromGacDialog.xaml

@ -0,0 +1,46 @@ @@ -0,0 +1,46 @@
<Window
x:Class="ICSharpCode.SharpDevelop.Dom.ClassBrowser.OpenFromGacDialog"
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"
Title="Open From GAC"
Style="{DynamicResource DialogWindow}"
WindowStartupLocation="CenterOwner"
ResizeMode="CanResizeWithGrip"
MinWidth="200"
MinHeight="150"
Height="350"
Width="750"
FocusManager.FocusedElement="{Binding ElementName=filterTextBox}">
<Grid
Margin="12,8">
<Grid.RowDefinitions>
<RowDefinition
Height="Auto" />
<RowDefinition
Height="1*" />
<RowDefinition
Height="Auto" />
</Grid.RowDefinitions>
<DockPanel>
<Label DockPanel.Dock="Left" Target="{Binding ElementName=filterTextBox}">_Search:</Label>
<TextBox Name="filterTextBox" TextChanged="FilterTextBox_TextChanged" />
</DockPanel>
<ListView Name="listView" Grid.Row="1" Margin="0, 8" core:SortableGridViewColumn.SortMode="Automatic" SelectionChanged="ListView_SelectionChanged">
<ListView.View>
<GridView>
<core:SortableGridViewColumn x:Name="nameColumn" Width="300" Header="Reference Name" DisplayMemberBinding="{Binding ShortName}" />
<core:SortableGridViewColumn Width="75" Header="Version" DisplayMemberBinding="{Binding Version}" />
<core:SortableGridViewColumn Width="65" Header="Culture" DisplayMemberBinding="{Binding Culture}" />
<core:SortableGridViewColumn Width="115" Header="Public Key Token" DisplayMemberBinding="{Binding PublicKeyToken}" />
<core:SortableGridViewColumn Width="1000" Header="Location" DisplayMemberBinding="{Binding FileName}" />
</GridView>
</ListView.View>
</ListView>
<StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
<Button IsDefault="True" Margin="2,0" Height="23" MinWidth="75" IsEnabled="False" Name="okButton" Click="OKButton_Click">Open</Button>
<Button IsCancel="True" Margin="2,0" Height="23" MinWidth="75">Cancel</Button>
</StackPanel>
<ProgressBar Grid.Row="1" Height="10" HorizontalAlignment="Stretch" Name="gacReadingProgressBar" VerticalAlignment="Bottom" Visibility="Hidden" />
</Grid>
</Window>

188
src/Main/SharpDevelop/Dom/ClassBrowser/OpenFromGacDialog.xaml.cs

@ -0,0 +1,188 @@ @@ -0,0 +1,188 @@
// Copyright (c) 2011 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Threading;
using ICSharpCode.Core.Presentation;
using ICSharpCode.SharpDevelop.Gui;
using ICSharpCode.SharpDevelop.Parser;
namespace ICSharpCode.SharpDevelop.Dom.ClassBrowser
{
/// <summary>
/// Interaction logic for OpenFromGacDialog.xaml
/// </summary>
public partial class OpenFromGacDialog : Window
{
ObservableCollection<GacEntry> gacEntries = new ObservableCollection<GacEntry>();
ObservableCollection<GacEntry> filteredEntries = new ObservableCollection<GacEntry>();
Predicate<GacEntry> filterMethod = _ => true;
volatile bool cancelFetchThread;
public OpenFromGacDialog()
{
InitializeComponent();
FormLocationHelper.ApplyWindow(this, "ICSharpCode.SharpDevelop.Dom.OpenFromGacDialog.Bounds", true);
listView.ItemsSource = filteredEntries;
SortableGridViewColumn.SetCurrentSortColumn(listView, nameColumn);
SortableGridViewColumn.SetSortDirection(listView, ColumnSortDirection.Ascending);
new Thread(new ThreadStart(FetchGacContents)).Start();
}
protected override void OnClosing(CancelEventArgs e)
{
base.OnClosing(e);
cancelFetchThread = true;
}
#region Fetch Gac Contents
sealed class GacEntry
{
readonly DomAssemblyName r;
readonly string fileName;
string formattedVersion;
public GacEntry(DomAssemblyName r, string fileName)
{
this.r = r;
this.fileName = fileName;
}
public string FullName {
get { return r.FullName; }
}
public string ShortName {
get { return r.ShortName; }
}
public string FileName {
get { return fileName; }
}
public Version Version {
get { return r.Version; }
}
public string FormattedVersion {
get {
if (formattedVersion == null)
formattedVersion = Version.ToString();
return formattedVersion;
}
}
public string Culture {
get { return r.Culture; }
}
public string PublicKeyToken {
get {
StringBuilder s = new StringBuilder();
foreach (byte b in r.PublicKeyToken)
s.Append(b.ToString("x2"));
return s.ToString();
}
}
public override string ToString()
{
return r.FullName;
}
}
void FetchGacContents()
{
IGlobalAssemblyCacheService gacService = SD.GetService<IGlobalAssemblyCacheService>();
HashSet<string> fullNames = new HashSet<string>();
UpdateProgressBar(pg => { pg.Visibility = System.Windows.Visibility.Visible; pg.IsIndeterminate = true; });
var list = gacService.Assemblies.TakeWhile(_ => !cancelFetchThread).ToList();
UpdateProgressBar(pg => { pg.IsIndeterminate = false; pg.Maximum = list.Count; });
foreach (var r in list) {
if (cancelFetchThread)
break;
if (fullNames.Add(r.FullName)) { // filter duplicates
var file = gacService.FindAssemblyInNetGac(r);
if (file != null) {
var entry = new GacEntry(r, file);
UpdateProgressBar(pg => { pg.Value = pg.Value + 1; AddNewEntry(entry); });
}
}
}
UpdateProgressBar(pg => { pg.Visibility = System.Windows.Visibility.Hidden; });
}
void UpdateProgressBar(Action<ProgressBar> updateAction)
{
Dispatcher.BeginInvoke(DispatcherPriority.Normal, (Action)(() => updateAction(gacReadingProgressBar)));
}
void AddNewEntry(GacEntry entry)
{
gacEntries.Add(entry);
if (filterMethod(entry))
filteredEntries.Add(entry);
}
#endregion
void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e)
{
string filterString = filterTextBox.Text.Trim();
if (filterString.Length == 0)
filterMethod = _ => true;
else {
var elements = filterString.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
filterMethod = entry => elements.All(el => Contains(entry.FullName, el) || Contains(entry.FormattedVersion, el));
}
filteredEntries.Clear();
filteredEntries.AddRange(gacEntries.Where(entry => filterMethod(entry)));
}
static bool Contains(string s, string subString)
{
return s.IndexOf(subString, StringComparison.OrdinalIgnoreCase) >= 0;
}
void ListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
okButton.IsEnabled = listView.SelectedItems.Count > 0;
}
void OKButton_Click(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
Close();
}
public string[] SelectedFileNames {
get {
return listView.SelectedItems.OfType<GacEntry>().Select(e => e.FileName).ToArray();
}
}
}
}

5
src/Main/SharpDevelop/SharpDevelop.csproj

@ -109,6 +109,10 @@ @@ -109,6 +109,10 @@
<Compile Include="Dom\ClassBrowser\ClassBrowserPad.cs" />
<Compile Include="Dom\ClassBrowser\ClassBrowserTreeNodesFactory.cs" />
<Compile Include="Dom\ClassBrowser\Commands.cs" />
<Compile Include="Dom\ClassBrowser\OpenFromGacDialog.xaml.cs">
<DependentUpon>OpenFromGacDialog.xaml</DependentUpon>
<SubType>Code</SubType>
</Compile>
<Compile Include="Dom\ModelFactory.cs" />
<Compile Include="Dom\MemberModel.cs" />
<Compile Include="Dom\NamespaceModel.cs" />
@ -331,6 +335,7 @@ @@ -331,6 +335,7 @@
<Folder Include="Workbench\DisplayBinding" />
</ItemGroup>
<ItemGroup>
<Page Include="Dom\ClassBrowser\OpenFromGacDialog.xaml" />
<Page Include="OptionPanels\LoadSaveOptions.xaml" />
<Page Include="Startup\App.xaml" />
<Page Include="Workbench\WpfWorkbench.xaml" />

Loading…
Cancel
Save