@ -31,7 +31,6 @@ using System.Windows;
@@ -31,7 +31,6 @@ using System.Windows;
using System.Windows.Controls ;
using System.Windows.Data ;
using System.Windows.Input ;
using System.Windows.Interop ;
using System.Windows.Media ;
using System.Windows.Navigation ;
using System.Windows.Threading ;
@ -43,7 +42,6 @@ using ICSharpCode.Decompiler.Documentation;
@@ -43,7 +42,6 @@ using ICSharpCode.Decompiler.Documentation;
using ICSharpCode.Decompiler.Metadata ;
using ICSharpCode.Decompiler.TypeSystem ;
using ICSharpCode.Decompiler.TypeSystem.Implementation ;
using ICSharpCode.ILSpy.Analyzers ;
using ICSharpCode.ILSpy.AppEnv ;
using ICSharpCode.ILSpy.Commands ;
using ICSharpCode.ILSpy.Docking ;
@ -58,10 +56,14 @@ using ICSharpCode.ILSpyX;
@@ -58,10 +56,14 @@ using ICSharpCode.ILSpyX;
using ICSharpCode.ILSpyX.FileLoaders ;
using ICSharpCode.ILSpyX.Settings ;
using ICSharpCode.ILSpy.Controls.TreeView ;
using ICSharpCode.ILSpy.Util ;
using ICSharpCode.ILSpyX.Extensions ;
using Microsoft.Win32 ;
using ICSharpCode.ILSpyX.TreeView ;
using TomsToolbox.Composition ;
namespace ICSharpCode.ILSpy
{
/// <summary>
@ -71,9 +73,7 @@ namespace ICSharpCode.ILSpy
@@ -71,9 +73,7 @@ namespace ICSharpCode.ILSpy
{
bool refreshInProgress , changingActiveTab ;
readonly NavigationHistory < NavigationState > history = new NavigationHistory < NavigationState > ( ) ;
ILSpySettings spySettingsForMainWindow_Loaded ;
SessionSettings sessionSettings ;
FilterSettings filterSettings ;
AssemblyList assemblyList ;
AssemblyListTreeNode assemblyListTreeNode ;
@ -83,10 +83,6 @@ namespace ICSharpCode.ILSpy
@@ -83,10 +83,6 @@ namespace ICSharpCode.ILSpy
get { return instance ; }
}
public SessionSettings SessionSettings {
get { return sessionSettings ; }
}
internal AssemblyListManager AssemblyListManager { get ; }
public SharpTreeView AssemblyTreeView {
@ -95,15 +91,9 @@ namespace ICSharpCode.ILSpy
@@ -95,15 +91,9 @@ namespace ICSharpCode.ILSpy
}
}
public AnalyzerTreeView AnalyzerTreeView {
get {
return ! IsLoaded ? null : FindResource ( "AnalyzerTreeView" ) as AnalyzerTreeView ;
}
}
public SearchPane SearchPane {
get {
return FindResource ( "SearchPane" ) as SearchPane ;
return App . ExportProvider . GetExportedValue < SearchPane > ( ) ;
}
}
@ -120,9 +110,10 @@ namespace ICSharpCode.ILSpy
@@ -120,9 +110,10 @@ namespace ICSharpCode.ILSpy
public MainWindow ( )
{
instance = this ;
var spySettings = ILSpySettings . Load ( ) ;
this . spySettingsForMainWindow_Loaded = spySettings ;
this . sessionSettings = new SessionSettings ( spySettings ) ;
var spySettings = SettingsService . Instance . SpySettings ;
var sessionSettings = SettingsService . Instance . SessionSettings ;
this . CurrentDecompilerSettings = DecompilerSettingsPanel . LoadDecompilerSettings ( spySettings ) ;
this . CurrentDisplaySettings = DisplaySettingsPanel . LoadDisplaySettings ( spySettings ) ;
this . AssemblyListManager = new AssemblyListManager ( spySettings ) {
@ -134,7 +125,7 @@ namespace ICSharpCode.ILSpy
@@ -134,7 +125,7 @@ namespace ICSharpCode.ILSpy
this . Icon = Images . ILSpyIcon ;
this . DataContext = new MainWindowViewModel {
Workspace = new DockWorkspace ( this ) ,
Workspace = DockWorkspace . Instance ,
SessionSettings = sessionSettings ,
AssemblyListManager = AssemblyListManager
} ;
@ -144,14 +135,14 @@ namespace ICSharpCode.ILSpy
@@ -144,14 +135,14 @@ namespace ICSharpCode.ILSpy
{
System . Threading . Thread . CurrentThread . CurrentUICulture = new System . Globalization . CultureInfo ( sessionSettings . CurrentCulture ) ;
}
DockWorkspace . Instance . LoadSettings ( sessionSettings ) ;
InitializeComponent ( ) ;
InitToolPanes ( ) ;
DockWorkspace . Instance . InitializeLayout ( DockManager ) ;
sessionSettings . PropertyChanged + = SessionSettings_PropertyChanged ;
filterSettings = sessionSettings . FilterSettings ;
filterSettings . PropertyChanged + = filterSettings_PropertyChanged ;
DockWorkspace . Instance . PropertyChanged + = DockWorkspace_PropertyChanged ;
MessageBus < SessionSettingsChangedEventArgs > . Subscribers + = ( sender , e ) = > SessionSettings_PropertyChanged ( sender , e ) ;
MessageBus < LanguageSettingsChangedEventArgs > . Subscribers + = ( sender , e ) = > filterSettings_PropertyChanged ( sender , e ) ;
MessageBus < DockWorkspaceActiveTabPageChangedEventArgs > . Subscribers + = DockWorkspace_ActiveTabPageChanged ;
InitMainMenu ( ) ;
InitWindowMenu ( ) ;
InitToolbar ( ) ;
@ -161,30 +152,24 @@ namespace ICSharpCode.ILSpy
@@ -161,30 +152,24 @@ namespace ICSharpCode.ILSpy
this . Loaded + = MainWindow_Loaded ;
}
private void DockWorkspace_Property Changed ( object sender , PropertyChanged EventArgs e )
private void DockWorkspace_ActiveTabPage Changed ( object sender , EventArgs e )
{
switch ( e . PropertyName )
{
case nameof ( DockWorkspace . Instance . ActiveTabPage ) :
DockWorkspace dock = DockWorkspace . Instance ;
filterSettings . PropertyChanged - = filterSettings_PropertyChanged ;
filterSettings = dock . ActiveTabPage . FilterSettings ;
filterSettings . PropertyChanged + = filterSettings_PropertyChanged ;
DockWorkspace dock = DockWorkspace . Instance ;
var windowMenuItem = mainMenu . Items . OfType < MenuItem > ( ) . First ( m = > ( string ) m . Tag = = nameof ( Properties . Resources . _ Window ) ) ;
foreach ( MenuItem menuItem in windowMenuItem . Items . OfType < MenuItem > ( ) )
{
if ( menuItem . IsCheckable & & menuItem . Tag is TabPageModel )
{
menuItem . IsChecked = menuItem . Tag = = dock . ActiveTabPage ;
}
}
break ;
var windowMenuItem = mainMenu . Items . OfType < MenuItem > ( ) . First ( m = > ( string ) m . Tag = = nameof ( Properties . Resources . _ Window ) ) ;
foreach ( MenuItem menuItem in windowMenuItem . Items . OfType < MenuItem > ( ) )
{
if ( menuItem . IsCheckable & & menuItem . Tag is TabPageModel )
{
menuItem . IsChecked = menuItem . Tag = = dock . ActiveTabPage ;
}
}
}
private void SessionSettings_PropertyChanged ( object sender , PropertyChangedEventArgs e )
{
var sessionSettings = SettingsService . Instance . SessionSettings ;
switch ( e . PropertyName )
{
case nameof ( SessionSettings . ActiveAssemblyList ) :
@ -245,7 +230,7 @@ namespace ICSharpCode.ILSpy
@@ -245,7 +230,7 @@ namespace ICSharpCode.ILSpy
}
Button MakeToolbarItem ( Lazy < ICommand , IToolbarCommandMetadata > command )
Button MakeToolbarItem ( IExport < ICommand , IToolbarCommandMetadata > command )
{
return new Button {
Style = ThemeManager . Current . CreateToolBarButtonStyle ( ) ,
@ -363,25 +348,12 @@ namespace ICSharpCode.ILSpy
@@ -363,25 +348,12 @@ namespace ICSharpCode.ILSpy
#endregion
#region Tool Pane extensibility
private void InitToolPanes ( )
{
var toolPanes = App . ExportProvider . GetExports < ToolPaneModel , IToolPaneMetadata > ( "ToolPane" ) ;
var templateSelector = new PaneTemplateSelector ( ) ;
templateSelector . Mappings . Add ( new TemplateMapping {
Type = typeof ( TabPageModel ) ,
Template = ( DataTemplate ) FindResource ( "DefaultContentTemplate" )
} ) ;
templateSelector . Mappings . Add ( new TemplateMapping {
Type = typeof ( LegacyToolPaneModel ) ,
Template = ( DataTemplate ) FindResource ( "DefaultContentTemplate" )
} ) ;
foreach ( var toolPane in toolPanes )
{
ToolPaneModel model = toolPane . Value ;
templateSelector . Mappings . Add ( new TemplateMapping { Type = model . GetType ( ) , Template = model . Template } ) ;
DockWorkspace . Instance . ToolPanes . Add ( model ) ;
}
DockManager . LayoutItemTemplateSelector = templateSelector ;
var toolPanes = App . ExportProvider . GetExportedValues < ToolPaneModel > ( "ToolPane" ) . OrderBy ( item = > item . Title ) ;
DockWorkspace . Instance . ToolPanes . AddRange ( toolPanes ) ;
}
private void InitWindowMenu ( )
@ -602,6 +574,8 @@ namespace ICSharpCode.ILSpy
@@ -602,6 +574,8 @@ namespace ICSharpCode.ILSpy
base . OnSourceInitialized ( e ) ;
PresentationSource source = PresentationSource . FromVisual ( this ) ;
var sessionSettings = SettingsService . Instance . SessionSettings ;
// Validate and Set Window Bounds
Rect bounds = Rect . Transform ( sessionSettings . WindowBounds , source . CompositionTarget . TransformToDevice ) ;
var boundsRect = new System . Drawing . Rectangle ( ( int ) bounds . Left , ( int ) bounds . Top , ( int ) bounds . Width , ( int ) bounds . Height ) ;
@ -649,8 +623,6 @@ namespace ICSharpCode.ILSpy
@@ -649,8 +623,6 @@ namespace ICSharpCode.ILSpy
get { return assemblyList ; }
}
public event NotifyCollectionChangedEventHandler CurrentAssemblyListChanged ;
List < LoadedAssembly > commandLineLoadedAssemblies = new List < LoadedAssembly > ( ) ;
internal async Task HandleSingleInstanceCommandLineArguments ( string [ ] args )
@ -672,7 +644,7 @@ namespace ICSharpCode.ILSpy
@@ -672,7 +644,7 @@ namespace ICSharpCode.ILSpy
{
LoadAssemblies ( args . AssembliesToLoad , commandLineLoadedAssemblies , focusNode : false ) ;
if ( args . Language ! = null )
filter Settings. Language = Languages . GetLanguage ( args . Language ) ;
SettingsService . Instance . SessionSettings . Language Settings. Language = Languages . GetLanguage ( args . Language ) ;
return true ;
}
@ -682,6 +654,8 @@ namespace ICSharpCode.ILSpy
@@ -682,6 +654,8 @@ namespace ICSharpCode.ILSpy
/// </summary>
void HandleCommandLineArgumentsAfterShowList ( CommandLineArguments args , ILSpySettings spySettings = null )
{
var sessionSettings = SettingsService . Instance . SessionSettings ;
var relevantAssemblies = commandLineLoadedAssemblies . ToList ( ) ;
commandLineLoadedAssemblies . Clear ( ) ; // clear references once we don't need them anymore
NavigateOnLaunch ( args . NavigateTo , sessionSettings . ActiveTreeViewPath , spySettings , relevantAssemblies ) ;
@ -856,15 +830,12 @@ namespace ICSharpCode.ILSpy
@@ -856,15 +830,12 @@ namespace ICSharpCode.ILSpy
void MainWindow_Loaded ( object sender , RoutedEventArgs e )
{
DockWorkspace . Instance . TabPages . Add ( new TabPageModel ( ) {
FilterSettings = filterSettings . Clone ( )
} ) ;
DockWorkspace . Instance . ActiveTabPage = DockWorkspace . Instance . TabPages . First ( ) ;
DockWorkspace . Instance . TabPages . Add ( ) ;
ILSpySettings spySettings = this . spySettingsForMainWindow_Loaded ;
this . spySettingsForMainWindow_Loaded = null ;
var loadPreviousAssemblies = Options . MiscSettingsPanel . CurrentMiscSettings . LoadPreviousAssemblies ;
var sessionSettings = SettingsService . Instance . SessionSettings ;
if ( loadPreviousAssemblies )
{
// Load AssemblyList only in Loaded event so that WPF is initialized before we start the CPU-heavy stuff.
@ -894,7 +865,7 @@ namespace ICSharpCode.ILSpy
@@ -894,7 +865,7 @@ namespace ICSharpCode.ILSpy
this . assemblyList . Open ( sessionSettings . ActiveAutoLoadedAssembly , true ) ;
}
Dispatcher . BeginInvoke ( DispatcherPriority . Loaded , new Action ( ( ) = > OpenAssemblies ( spySettings ) ) ) ;
Dispatcher . BeginInvoke ( DispatcherPriority . Loaded , new Action ( ( ) = > OpenAssemblies ( Setting sService . Instance . S pySettings) ) ) ;
}
void OpenAssemblies ( ILSpySettings spySettings )
@ -1024,7 +995,6 @@ namespace ICSharpCode.ILSpy
@@ -1024,7 +995,6 @@ namespace ICSharpCode.ILSpy
assemblyList . CollectionChanged + = assemblyList_Assemblies_CollectionChanged ;
assemblyListTreeNode = new AssemblyListTreeNode ( assemblyList ) ;
assemblyListTreeNode . FilterSettings = filterSettings . Clone ( ) ;
assemblyListTreeNode . Select = x = > SelectNode ( x , inNewTabPage : false ) ;
AssemblyTreeView . Root = assemblyListTreeNode ;
@ -1055,7 +1025,8 @@ namespace ICSharpCode.ILSpy
@@ -1055,7 +1025,8 @@ namespace ICSharpCode.ILSpy
nd = > nd . AncestorsAndSelf ( ) . OfType < AssemblyTreeNode > ( ) . Any (
a = > oldAssemblies . Contains ( a . LoadedAssembly ) ) ) ) ;
}
CurrentAssemblyListChanged ? . Invoke ( this , e ) ;
MessageBus . Send ( this , new CurrentAssemblyListChangedEventArgs ( e ) ) ;
}
void LoadInitialAssemblies ( )
@ -1087,13 +1058,7 @@ namespace ICSharpCode.ILSpy
@@ -1087,13 +1058,7 @@ namespace ICSharpCode.ILSpy
public void RefreshTreeViewFilter ( )
{
// filterSettings is mutable; but the ILSpyTreeNode filtering assumes that filter settings are immutable.
// Thus, the main window will use one mutable instance (for data-binding), and assign a new clone to the ILSpyTreeNodes whenever the main
// mutable instance changes.
FilterSettings filterSettings = DockWorkspace . Instance . ActiveTabPage . FilterSettings . Clone ( ) ;
if ( assemblyListTreeNode ! = null )
assemblyListTreeNode . FilterSettings = filterSettings ;
SearchPane . UpdateFilter ( filterSettings ) ;
SearchPane . UpdateFilter ( ) ;
}
internal AssemblyListTreeNode AssemblyListTreeNode {
@ -1120,11 +1085,7 @@ namespace ICSharpCode.ILSpy
@@ -1120,11 +1085,7 @@ namespace ICSharpCode.ILSpy
{
if ( inNewTabPage )
{
DockWorkspace . Instance . TabPages . Add (
new TabPageModel ( ) {
FilterSettings = filterSettings . Clone ( )
} ) ;
DockWorkspace . Instance . ActiveTabPage = DockWorkspace . Instance . TabPages . Last ( ) ;
DockWorkspace . Instance . TabPages . Add ( ) ;
AssemblyTreeView . SelectedItem = null ;
}
@ -1166,11 +1127,7 @@ namespace ICSharpCode.ILSpy
@@ -1166,11 +1127,7 @@ namespace ICSharpCode.ILSpy
{
if ( inNewTabPage )
{
DockWorkspace . Instance . TabPages . Add (
new TabPageModel ( ) {
FilterSettings = filterSettings . Clone ( )
} ) ;
DockWorkspace . Instance . ActiveTabPage = DockWorkspace . Instance . TabPages . Last ( ) ;
DockWorkspace . Instance . TabPages . Add ( ) ;
}
// Ensure nodes exist
@ -1542,10 +1499,9 @@ namespace ICSharpCode.ILSpy
@@ -1542,10 +1499,9 @@ namespace ICSharpCode.ILSpy
}
}
public Language CurrentLanguage = > DockWorkspace . Instance . ActiveTabPage . FilterSettings . Language ;
public LanguageVersion CurrentLanguageVersion = > DockWorkspace . Instance . ActiveTabPage . FilterSettings . LanguageVersion ;
public Language CurrentLanguage = > SettingsService . Instance . SessionSettings . LanguageSettings . Language ;
public bool SupportsLanguageSwitching = > DockWorkspa ce. Instance . ActiveTabPage . SupportsLanguageSwitching ;
public LanguageVersion CurrentLanguageVersion = > SettingsServi ce. Instance . SessionSettings . LanguageSettings . LanguageVersion ;
public event SelectionChangedEventHandler SelectionChanged ;
@ -1615,11 +1571,7 @@ namespace ICSharpCode.ILSpy
@@ -1615,11 +1571,7 @@ namespace ICSharpCode.ILSpy
{
if ( inNewTabPage )
{
DockWorkspace . Instance . TabPages . Add (
new TabPageModel ( ) {
FilterSettings = filterSettings . Clone ( )
} ) ;
DockWorkspace . Instance . ActiveTabPage = DockWorkspace . Instance . TabPages . Last ( ) ;
DockWorkspace . Instance . TabPages . Add ( ) ;
}
if ( e . Uri . Host = = "aboutpage" )
@ -1671,18 +1623,19 @@ namespace ICSharpCode.ILSpy
@@ -1671,18 +1623,19 @@ namespace ICSharpCode.ILSpy
base . OnStateChanged ( e ) ;
// store window state in settings only if it's not minimized
if ( this . WindowState ! = System . Windows . WindowState . Minimized )
sessionSettings . WindowState = this . WindowState ;
Setting sService . Instance . S essionSettings. WindowState = this . WindowState ;
}
protected override void OnClosing ( CancelEventArgs e )
{
base . OnClosing ( e ) ;
var sessionSettings = SettingsService . Instance . SessionSettings ;
sessionSettings . ActiveAssemblyList = assemblyList . ListName ;
sessionSettings . ActiveTreeViewPath = GetPathForNode ( AssemblyTreeView . SelectedItem as SharpTreeNode ) ;
sessionSettings . ActiveAutoLoadedAssembly = GetAutoLoadedAssemblyNode ( AssemblyTreeView . SelectedItem as SharpTreeNode ) ;
sessionSettings . WindowBounds = this . RestoreBounds ;
sessionSettings . DockLayout . Serialize ( new XmlLayoutSerializer ( DockManager ) ) ;
sessionSettings . FilterSettings = DockWorkspace . Instance . ActiveTabPage . FilterSettings . Clone ( ) ;
sessionSettings . Save ( ) ;
}