-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(Not yet working) Implement opening new lumper instance
- Loading branch information
1 parent
359ae2c
commit ebf1a4c
Showing
2 changed files
with
108 additions
and
78 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Markup.Xaml; | ||
using Lumper.UI.ViewModels; | ||
using Lumper.UI.Views; | ||
|
||
namespace Lumper.UI; | ||
|
||
public class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime | ||
desktop) | ||
desktop.MainWindow = new MainWindow | ||
{ | ||
DataContext = new MainWindowViewModel() | ||
}; | ||
|
||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} | ||
using Avalonia; | ||
using Avalonia.Controls.ApplicationLifetimes; | ||
using Avalonia.Markup.Xaml; | ||
using Lumper.UI.ViewModels; | ||
using Lumper.UI.Views; | ||
|
||
namespace Lumper.UI; | ||
|
||
public class App : Application | ||
{ | ||
public override void Initialize() | ||
{ | ||
AvaloniaXamlLoader.Load(this); | ||
} | ||
|
||
public override void OnFrameworkInitializationCompleted() | ||
{ | ||
if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime | ||
desktop) | ||
{ | ||
desktop.MainWindow = new MainWindow | ||
{ | ||
DataContext = new MainWindowViewModel() | ||
}; | ||
|
||
if (desktop.Args?.Length > 0) | ||
{ | ||
((MainWindowViewModel)desktop.MainWindow.DataContext!).LoadBsp(desktop.Args[0]); | ||
} | ||
} | ||
|
||
base.OnFrameworkInitializationCompleted(); | ||
} | ||
} |
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,51 +1,74 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Linq; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Lumper.UI.ViewModels; | ||
|
||
namespace Lumper.UI.Views; | ||
|
||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
AddHandler(DragDrop.DragOverEvent, DragOver); | ||
AddHandler(DragDrop.DropEvent, Drop); | ||
} | ||
|
||
private async void Window_OnClosing(object? sender, CancelEventArgs e) | ||
{ | ||
if (DataContext is not MainWindowViewModel model) | ||
throw new ArgumentOutOfRangeException(); | ||
await model.OnClose(e); | ||
} | ||
|
||
private void DragOver(object? sender, DragEventArgs e) | ||
{ | ||
e.DragEffects = DragDropEffects.Link; | ||
|
||
var names = e.Data.GetFileNames() ?? new List<String>(); | ||
|
||
if (!e.Data.Contains(DataFormats.FileNames) || !names.FirstOrDefault("").ToLower().EndsWith(".bsp")) | ||
e.DragEffects = DragDropEffects.None; | ||
} | ||
|
||
private void Drop(object? sender, DragEventArgs e) | ||
{ | ||
if (e.Data.Contains(DataFormats.FileNames)) | ||
{ | ||
var names = e.Data.GetFileNames() ?? new List<String>(); | ||
var target = names.FirstOrDefault(""); | ||
|
||
if (!target.ToLower().EndsWith(".bsp")) | ||
return; | ||
|
||
((MainWindowViewModel)DataContext!).LoadBsp(target); | ||
} | ||
} | ||
} | ||
using System; | ||
using System.Collections.Generic; | ||
using System.ComponentModel; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
using Avalonia; | ||
using Avalonia.Controls; | ||
using Avalonia.Input; | ||
using Lumper.UI.ViewModels; | ||
|
||
namespace Lumper.UI.Views; | ||
|
||
public partial class MainWindow : Window | ||
{ | ||
public MainWindow() | ||
{ | ||
InitializeComponent(); | ||
|
||
AddHandler(DragDrop.DragOverEvent, DragOver); | ||
AddHandler(DragDrop.DropEvent, Drop); | ||
} | ||
|
||
private async void Window_OnClosing(object? sender, CancelEventArgs e) | ||
{ | ||
if (DataContext is not MainWindowViewModel model) | ||
throw new ArgumentOutOfRangeException(); | ||
await model.OnClose(e); | ||
} | ||
|
||
private void DragOver(object? sender, DragEventArgs e) | ||
{ | ||
e.DragEffects = DragDropEffects.Link; | ||
|
||
var names = e.Data.GetFileNames() ?? new List<String>(); | ||
|
||
if (!e.Data.Contains(DataFormats.FileNames) || !names.FirstOrDefault("").ToLower().EndsWith(".bsp")) | ||
e.DragEffects = DragDropEffects.None; | ||
} | ||
|
||
private void Drop(object? sender, DragEventArgs e) | ||
{ | ||
if (e.Data.Contains(DataFormats.FileNames)) | ||
{ | ||
var names = e.Data.GetFileNames() ?? new List<String>(); | ||
foreach (string target in names) | ||
{ | ||
if (!target.ToLower().EndsWith(".bsp")) | ||
continue; | ||
|
||
if (((MainWindowViewModel)DataContext!).BspModel == null) | ||
{ | ||
// if nothing is open, open it. | ||
((MainWindowViewModel)DataContext!).LoadBsp(target); | ||
} | ||
else | ||
{ | ||
// Otherwise, open a brand new Lumper instance with it. | ||
string? mainModuleFileName = Process.GetCurrentProcess().MainModule?.FileName; | ||
if (mainModuleFileName == null) | ||
return; | ||
|
||
string? executablePath = mainModuleFileName; | ||
ProcessStartInfo startInfo = new ProcessStartInfo() | ||
{ | ||
ArgumentList = { $"\"{target}\"" }, | ||
FileName = executablePath, | ||
}; | ||
|
||
Process.Start(startInfo); | ||
} | ||
} | ||
} | ||
} | ||
} |