Skip to content

Commit

Permalink
Refactor SearchPane so only the view model is exposed.
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert authored and siegfriedpammer committed Aug 25, 2024
1 parent 82d6975 commit dde581a
Show file tree
Hide file tree
Showing 20 changed files with 328 additions and 320 deletions.
4 changes: 2 additions & 2 deletions ICSharpCode.ILSpyX/Search/AbstractSearchStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public struct SearchRequest
public AssemblySearchKind AssemblySearchKind;
public MemberSearchKind MemberSearchKind;
public string[] Keywords;
public Regex RegEx;
public Regex? RegEx;
public bool FullNameSearch;
public bool OmitGenerics;
public string InNamespace;
Expand All @@ -62,7 +62,7 @@ public struct SearchRequest
public abstract class AbstractSearchStrategy
{
protected readonly string[] searchTerm;
protected readonly Regex regex;
protected readonly Regex? regex;
protected readonly bool fullNameSearch;
protected readonly bool omitGenerics;
protected readonly SearchRequest searchRequest;
Expand Down
13 changes: 11 additions & 2 deletions ILSpy/Commands/ScopeSearchToAssembly.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.AppEnv;
using ICSharpCode.ILSpy.Properties;
using ICSharpCode.ILSpy.Search;
using ICSharpCode.ILSpy.TreeNodes;

namespace ICSharpCode.ILSpy
Expand All @@ -31,11 +32,19 @@ namespace ICSharpCode.ILSpy
[PartCreationPolicy(CreationPolicy.Shared)]
public class ScopeSearchToAssembly : IContextMenuEntry
{
private readonly SearchPaneModel searchPane;

[ImportingConstructor]
public ScopeSearchToAssembly(SearchPaneModel searchPane)
{
this.searchPane = searchPane;
}

public void Execute(TextViewContext context)
{
// asmName cannot be null here, because Execute is only called if IsEnabled/IsVisible return true.
string asmName = GetAssembly(context)!;
string searchTerm = MainWindow.Instance.SearchPane.SearchTerm;
string searchTerm = searchPane.SearchTerm;
string[] args = CommandLineTools.CommandLineToArgumentArray(searchTerm);
bool replaced = false;
for (int i = 0; i < args.Length; i++)
Expand All @@ -55,7 +64,7 @@ public void Execute(TextViewContext context)
{
searchTerm = CommandLineTools.ArgumentArrayToCommandLine(args);
}
MainWindow.Instance.SearchPane.SearchTerm = searchTerm;
searchPane.SearchTerm = searchTerm;
}

public bool IsEnabled(TextViewContext context)
Expand Down
14 changes: 12 additions & 2 deletions ILSpy/Commands/ScopeSearchToNamespace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using ICSharpCode.Decompiler.TypeSystem;
using ICSharpCode.ILSpy.AppEnv;
using ICSharpCode.ILSpy.Properties;
using ICSharpCode.ILSpy.Search;
using ICSharpCode.ILSpy.TreeNodes;

namespace ICSharpCode.ILSpy
Expand All @@ -29,10 +30,18 @@ namespace ICSharpCode.ILSpy
[PartCreationPolicy(CreationPolicy.Shared)]
public class ScopeSearchToNamespace : IContextMenuEntry
{
private readonly SearchPaneModel searchPane;

[ImportingConstructor]
public ScopeSearchToNamespace(SearchPaneModel searchPane)
{
this.searchPane = searchPane;
}

public void Execute(TextViewContext context)
{
string ns = GetNamespace(context);
string searchTerm = MainWindow.Instance.SearchPane.SearchTerm;
string searchTerm = searchPane.SearchTerm;
string[] args = CommandLineTools.CommandLineToArgumentArray(searchTerm);
bool replaced = false;
for (int i = 0; i < args.Length; i++)
Expand All @@ -52,7 +61,8 @@ public void Execute(TextViewContext context)
{
searchTerm = CommandLineTools.ArgumentArrayToCommandLine(args);
}
MainWindow.Instance.SearchPane.SearchTerm = searchTerm;

searchPane.SearchTerm = searchTerm;
}

public bool IsEnabled(TextViewContext context)
Expand Down
8 changes: 7 additions & 1 deletion ILSpy/Controls/CultureSelectionConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,11 @@
using System;
using System.Globalization;
using System.Windows.Data;
using System.Windows.Markup;

namespace ICSharpCode.ILSpy.Controls
{
public class CultureSelectionConverter : IValueConverter
public class CultureSelectionConverter : MarkupExtension, IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
Expand All @@ -37,5 +38,10 @@ public object ConvertBack(object value, Type targetType, object parameter, Cultu
return parameter;
return Binding.DoNothing;
}

public override object ProvideValue(IServiceProvider serviceProvider)
{
return this;
}
}
}
46 changes: 0 additions & 46 deletions ILSpy/Controls/TreeView/Converters.cs

This file was deleted.

5 changes: 3 additions & 2 deletions ILSpy/Controls/TreeView/SharpTreeView.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:Default="clr-namespace:ICSharpCode.ILSpy.Controls.TreeView"
xmlns:styles="urn:TomsToolbox.Wpf.Styles">
xmlns:styles="urn:TomsToolbox.Wpf.Styles"
xmlns:toms="urn:TomsToolbox">

<Style x:Key="ExpandCollapseToggleStyle"
TargetType="{x:Type ToggleButton}" BasedOn="{StaticResource {x:Type ToggleButton}}">
Expand Down Expand Up @@ -227,7 +228,7 @@
<Grid>
<Default:LinesRenderer x:Name="linesRenderer"
ClipToBounds="True"
Visibility="{Binding ShowLines, RelativeSource={RelativeSource AncestorType={x:Type Default:SharpTreeView}}, Converter={Default:CollapsedWhenFalse}}" />
Visibility="{Binding ShowLines, RelativeSource={RelativeSource AncestorType={x:Type Default:SharpTreeView}}, Converter={toms:BooleanToVisibilityConverter}}" />
<StackPanel Orientation="Horizontal">
<FrameworkElement Name="spacer" />
<ToggleButton Name="expander"
Expand Down
6 changes: 3 additions & 3 deletions ILSpy/DecompilationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public class DecompilationOptions
/// <summary>
/// Gets the settings for the decompiler.
/// </summary>
public Decompiler.DecompilerSettings DecompilerSettings { get; private set; }
public DecompilerSettings DecompilerSettings { get; private set; }

/// <summary>
/// Gets/sets an optional state of a decompiler text view.
Expand All @@ -83,7 +83,7 @@ public class DecompilationOptions
internal int StepLimit = int.MaxValue;
internal bool IsDebug = false;

public DecompilationOptions(LanguageVersion version, Decompiler.DecompilerSettings settings, DisplaySettingsViewModel displaySettings)
public DecompilationOptions(LanguageVersion version, DecompilerSettings settings, DisplaySettings displaySettings)
{
if (!Enum.TryParse(version?.Version, out Decompiler.CSharp.LanguageVersion languageVersion))
languageVersion = Decompiler.CSharp.LanguageVersion.Latest;
Expand All @@ -96,7 +96,7 @@ public DecompilationOptions(LanguageVersion version, Decompiler.DecompilerSettin
newSettings.CSharpFormattingOptions.IndentationString = GetIndentationString(displaySettings);
}

private string GetIndentationString(DisplaySettingsViewModel displaySettings)
private string GetIndentationString(DisplaySettings displaySettings)
{
if (displaySettings.IndentationUseTabs)
{
Expand Down
11 changes: 5 additions & 6 deletions ILSpy/Docking/DockWorkspace.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,12 @@
// DEALINGS IN THE SOFTWARE.

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Navigation;
using System.Windows.Threading;

using AvalonDock;
Expand All @@ -36,6 +31,7 @@

using ICSharpCode.AvalonEdit.Highlighting;
using ICSharpCode.ILSpy.Analyzers;
using ICSharpCode.ILSpy.Search;
using ICSharpCode.ILSpy.TextView;
using ICSharpCode.ILSpy.Util;
using ICSharpCode.ILSpy.ViewModels;
Expand Down Expand Up @@ -219,7 +215,7 @@ internal void ResetLayout()
}
CloseAllTabs();
SessionSettings.DockLayout.Reset();
InitializeLayout(MainWindow.Instance.DockManager);
InitializeLayout(MainWindow.Instance.dockManager);
MainWindow.Instance.Dispatcher.BeginInvoke(DispatcherPriority.Background, (Action)MainWindow.Instance.RefreshDecompiledView);
}

Expand Down Expand Up @@ -268,5 +264,8 @@ public bool BeforeInsertDocument(LayoutRoot layout, LayoutDocument anchorableToS
public void AfterInsertDocument(LayoutRoot layout, LayoutDocument anchorableShown)
{
}

// Dummy property to make the XAML designer happy, the model is provided by the AvalonDock PaneStyleSelectors, not by the DockWorkspace, but the designer assumes the data context in the PaneStyleSelectors is the DockWorkspace.
public PaneModel Model { get; } = null;
}
}
Loading

0 comments on commit dde581a

Please sign in to comment.