Skip to content

Commit

Permalink
Remove unrelated methods from MainWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
tom-englert committed Oct 27, 2024
1 parent 530370c commit e38ed25
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 45 deletions.
2 changes: 1 addition & 1 deletion ILSpy/AboutPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ static void ShowAvailableVersion(AvailableVersionInfo availableVersion, StackPan
button.Content = Resources.Download;
button.Cursor = Cursors.Arrow;
button.Click += delegate {
MainWindow.OpenLink(availableVersion.DownloadUrl);
GlobalUtils.OpenLink(availableVersion.DownloadUrl);
};
stackPanel.Children.Add(button);
}
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/AssemblyTree/AssemblyTreeModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ private Task JumpToReferenceAsync(object? reference, bool inNewTabPage = false)
switch (reference)
{
case Decompiler.Disassembler.OpCodeInfo opCode:
MainWindow.OpenLink(opCode.Link);
GlobalUtils.OpenLink(opCode.Link);
break;
case EntityReference unresolvedEntity:
string protocol = unresolvedEntity.Protocol;
Expand Down
2 changes: 1 addition & 1 deletion ILSpy/Commands/SearchMsdnContextMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static void SearchMsdn(ILSpyTreeNode node)

address = address.ToLower();
if (!string.IsNullOrEmpty(address))
MainWindow.OpenLink(address);
GlobalUtils.OpenLink(address);
}
}
}
38 changes: 1 addition & 37 deletions ILSpy/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@
using System;
using System.ComponentModel;
using System.Composition;
using System.Diagnostics;
using System.Drawing;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Threading;

using ICSharpCode.ILSpy.Updates;

using Screen = System.Windows.Forms.Screen;

namespace ICSharpCode.ILSpy
Expand Down Expand Up @@ -70,8 +66,6 @@ void SetWindowBounds(Rect bounds)
this.Height = bounds.Height;
}

#region Message Hook

protected override void OnSourceInitialized(EventArgs e)
{
base.OnSourceInitialized(e);
Expand All @@ -91,8 +85,6 @@ protected override void OnSourceInitialized(EventArgs e)
this.WindowState = sessionSettings.WindowState;
}

#endregion

protected override void OnKeyDown(KeyEventArgs e)
{
base.OnKeyDown(e);
Expand All @@ -116,34 +108,6 @@ protected override void OnKeyDown(KeyEventArgs e)
}
}

public static void OpenLink(string link)
{
try
{
Process.Start(new ProcessStartInfo { FileName = link, UseShellExecute = true });
}
catch (Exception)
{
// Process.Start can throw several errors (not all of them documented),
// just ignore all of them.
}
}

public static void ExecuteCommand(string fileName, string arguments)
{
try
{
Process.Start(fileName, arguments);
#pragma warning disable RECS0022 // A catch clause that catches System.Exception and has an empty body
}
catch (Exception)
{
#pragma warning restore RECS0022 // A catch clause that catches System.Exception and has an empty body
// Process.Start can throw several errors (not all of them documented),
// just ignore all of them.
}
}

protected override void OnStateChanged(EventArgs e)
{
base.OnStateChanged(e);
Expand All @@ -168,4 +132,4 @@ protected override void OnClosing(CancelEventArgs e)
snapshot.Save();
}
}
}
}
4 changes: 2 additions & 2 deletions ILSpy/TreeNodes/AssemblyTreeNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ public void Execute(TextViewContext context)
var path = node.LoadedAssembly.FileName;
if (File.Exists(path))
{
MainWindow.ExecuteCommand("explorer.exe", $"/select,\"{path}\"");
GlobalUtils.ExecuteCommand("explorer.exe", $"/select,\"{path}\"");
}
}
}
Expand Down Expand Up @@ -806,7 +806,7 @@ public void Execute(TextViewContext context)
var path = Path.GetDirectoryName(node.LoadedAssembly.FileName);
if (Directory.Exists(path))
{
MainWindow.ExecuteCommand("cmd.exe", $"/k \"cd {path}\"");
GlobalUtils.ExecuteCommand("cmd.exe", $"/k \"cd {path}\"");
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions ILSpy/Util/GlobalUtils.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using System;
using System.Diagnostics;

namespace ICSharpCode.ILSpy.Util
{
static class GlobalUtils
{
public static void OpenLink(string link)
{
try
{
Process.Start(new ProcessStartInfo { FileName = link, UseShellExecute = true });
}
catch (Exception)
{
// Process.Start can throw several errors (not all of them documented),
// just ignore all of them.
}
}

public static void ExecuteCommand(string fileName, string arguments)
{
try
{
Process.Start(fileName, arguments);
}
catch (Exception)
{
// Process.Start can throw several errors (not all of them documented),
// just ignore all of them.
}
}
}
}
3 changes: 1 addition & 2 deletions ILSpy/ViewModels/PaneModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using System.Windows;
using System.Windows.Input;

using ICSharpCode.Decompiler.IL;
using ICSharpCode.ILSpy.Docking;

using TomsToolbox.Wpf;
Expand All @@ -30,7 +29,7 @@ namespace ICSharpCode.ILSpy.ViewModels
{
public abstract class PaneModel : ObservableObject
{
private Throttle titleChangeThrottle;
private readonly Throttle titleChangeThrottle;

protected static DockWorkspace DockWorkspace => App.ExportProvider.GetExportedValue<DockWorkspace>();

Expand Down
2 changes: 1 addition & 1 deletion ILSpy/ViewModels/UpdatePanelViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ async void DownloadOrCheckUpdate()
{
if (updateAvailableDownloadUrl != null)
{
MainWindow.OpenLink(updateAvailableDownloadUrl);
GlobalUtils.OpenLink(updateAvailableDownloadUrl);
}
else
{
Expand Down

0 comments on commit e38ed25

Please sign in to comment.