-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow drag'n'drop of .gcdump on the main window and launching without…
… parameter
- Loading branch information
1 parent
be57156
commit e7f3f74
Showing
5 changed files
with
62 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,53 @@ | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Avalonia.Platform.Storage; | ||
using OneHub.Diagnostics.HeapView; | ||
using System.Linq; | ||
using System; | ||
|
||
namespace OneHub.Tools.HeapView; | ||
|
||
public partial class MainWindow : Window | ||
{ | ||
HeapSnapshot heapSnapshot; | ||
|
||
public MainWindow(string fileName) | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
var heapDump = new GCHeapDump(fileName); | ||
heapSnapshot = new HeapSnapshot(heapDump); | ||
AddHandler(DragDrop.DragOverEvent, DragOver); | ||
AddHandler(DragDrop.DropEvent, Drop); | ||
} | ||
|
||
public void Open(string fileName) | ||
{ | ||
try | ||
{ | ||
var heapDump = new GCHeapDump(fileName); | ||
var heapSnapshot = new HeapSnapshot(heapDump); | ||
heapView.Snapshot = heapSnapshot; | ||
} | ||
catch (Exception ex) | ||
Check warning on line 28 in src/OneHub.Tools.HeapView/MainWindow.axaml.cs GitHub Actions / build
|
||
{ | ||
// TODO: Show error | ||
} | ||
} | ||
|
||
private void DragOver(object? sender, DragEventArgs e) | ||
{ | ||
if (!e.Data.Contains(DataFormats.Files) || e.Data.GetFiles()?.FirstOrDefault() is not IStorageFile) | ||
e.DragEffects = DragDropEffects.None; | ||
else | ||
e.DragEffects = DragDropEffects.Move; | ||
} | ||
|
||
heapView.Snapshot = heapSnapshot; | ||
private void Drop(object? sender, DragEventArgs e) | ||
{ | ||
if (e.Data.Contains(DataFormats.Files)) | ||
{ | ||
var files = e.Data.GetFiles()?.OfType<IStorageFile>().ToArray(); | ||
if (files?.FirstOrDefault()?.TryGetLocalPath() is string path) | ||
{ | ||
Open(path); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"profiles": { | ||
"dotnet-heapview": { | ||
"commandName": "Project" | ||
} | ||
} | ||
} |