1111using Nickvision . Desktop . Notifications ;
1212using System ;
1313using System . Diagnostics . CodeAnalysis ;
14+ using System . IO ;
1415using System . Linq ;
1516
1617namespace Nickvision . Application . GNOME . Views ;
1718
1819public class MainWindow : Adw . ApplicationWindow
1920{
2021 private readonly IServiceProvider _serviceProvider ;
22+ private readonly Adw . Application _application ;
2123 private readonly MainWindowController _controller ;
2224 private readonly AppInfo _appInfo ;
2325 private readonly ITranslationService _translationService ;
@@ -39,16 +41,16 @@ public class MainWindow : Adw.ApplicationWindow
3941 [ Gtk . Connect ( "pageFiles" ) ]
4042 private Adw . StatusPage ? _pageFiles ;
4143
42- public MainWindow ( IServiceProvider serviceProvider , MainWindowController controller , AppInfo appInfo , IEventsService eventsService , ITranslationService translationService , IGtkBuilderFactory builderFactory ) : this ( serviceProvider , controller , appInfo , eventsService , translationService , builderFactory . Create ( "MainWindow" ) )
44+ public MainWindow ( IServiceProvider serviceProvider , Adw . Application application , MainWindowController controller , AppInfo appInfo , IEventsService eventsService , ITranslationService translationService , IGtkBuilderFactory builderFactory ) : this ( serviceProvider , application , controller , appInfo , eventsService , translationService , builderFactory . Create ( "MainWindow" ) )
4345 {
4446
4547 }
4648
4749 [ DynamicDependency ( DynamicallyAccessedMemberTypes . NonPublicFields , typeof ( MainWindow ) ) ]
48- private MainWindow ( IServiceProvider serviceProvider , MainWindowController controller , AppInfo appInfo , IEventsService eventsService , ITranslationService translationService , Gtk . Builder builder ) : base ( new Adw . Internal . ApplicationWindowHandle ( builder . GetPointer ( "root" ) , false ) )
50+ private MainWindow ( IServiceProvider serviceProvider , Adw . Application application , MainWindowController controller , AppInfo appInfo , IEventsService eventsService , ITranslationService translationService , Gtk . Builder builder ) : base ( new Adw . Internal . ApplicationWindowHandle ( builder . GetPointer ( "root" ) , false ) )
4951 {
50- var application = serviceProvider . GetRequiredService < Adw . Application > ( ) ;
5152 _serviceProvider = serviceProvider ;
53+ _application = application ;
5254 _controller = controller ;
5355 _appInfo = appInfo ;
5456 _translationService = translationService ;
@@ -87,32 +89,36 @@ private MainWindow(IServiceProvider serviceProvider, MainWindowController contro
8789 var actQuit = Gio . SimpleAction . New ( "quit" , null ) ;
8890 actQuit . OnActivate += Quit ;
8991 AddAction ( actQuit ) ;
90- application . SetAccelsForAction ( "win.quit" , [ "<Ctrl>q" ] ) ;
92+ _application . SetAccelsForAction ( "win.quit" , [ "<Ctrl>q" ] ) ;
93+ // Open in files action
94+ var actOpenInFiles = Gio . SimpleAction . New ( "openInFiles" , null ) ;
95+ actOpenInFiles . OnActivate += OpenInFiles ;
96+ AddAction ( actOpenInFiles ) ;
9197 // Open folder action
9298 var actOpenFolder = Gio . SimpleAction . New ( "openFolder" , null ) ;
9399 actOpenFolder . OnActivate += OpenFolder ;
94100 AddAction ( actOpenFolder ) ;
95- application . SetAccelsForAction ( "win.openFolder" , [ "<Ctrl>o" ] ) ;
101+ _application . SetAccelsForAction ( "win.openFolder" , [ "<Ctrl>o" ] ) ;
96102 // Close folder action
97103 var actCloseFolder = Gio . SimpleAction . New ( "closeFolder" , null ) ;
98104 actCloseFolder . OnActivate += CloseFolder ;
99105 AddAction ( actCloseFolder ) ;
100- application . SetAccelsForAction ( "win.closeFolder" , [ "<Ctrl>w" ] ) ;
106+ _application . SetAccelsForAction ( "win.closeFolder" , [ "<Ctrl>w" ] ) ;
101107 // Preferences action
102108 var actPreferences = Gio . SimpleAction . New ( "preferences" , null ) ;
103109 actPreferences . OnActivate += Preferences ;
104110 AddAction ( actPreferences ) ;
105- application . SetAccelsForAction ( "win.preferences" , [ "<Ctrl>period" ] ) ;
111+ _application . SetAccelsForAction ( "win.preferences" , [ "<Ctrl>period" ] ) ;
106112 // Keyboard shortcuts action
107113 var actKeyboardShortcuts = Gio . SimpleAction . New ( "keyboardShortcuts" , null ) ;
108114 actKeyboardShortcuts . OnActivate += KeyboardShortcuts ;
109115 AddAction ( actKeyboardShortcuts ) ;
110- application . SetAccelsForAction ( "win.keyboardShortcuts" , [ "<Ctrl>question" ] ) ;
116+ _application . SetAccelsForAction ( "win.keyboardShortcuts" , [ "<Ctrl>question" ] ) ;
111117 // About action
112118 var actAbout = Gio . SimpleAction . New ( "about" , null ) ;
113119 actAbout . OnActivate += About ;
114120 AddAction ( actAbout ) ;
115- application . SetAccelsForAction ( "win.about" , [ "F1" ] ) ;
121+ _application . SetAccelsForAction ( "win.about" , [ "F1" ] ) ;
116122 }
117123
118124 public new void Present ( )
@@ -158,6 +164,16 @@ private bool Window_OnDrop(Gtk.DropTarget sender, Gtk.DropTarget.DropSignalArgs
158164
159165 private void Controller_AppNotificationSent ( object ? sender , AppNotificationSentEventArgs e )
160166 {
167+ if ( e . Notification is ShellNotification shellNotification )
168+ {
169+ var notification = Gio . Notification . New ( shellNotification . Title ) ;
170+ notification . SetBody ( shellNotification . Message ) ;
171+ if ( shellNotification . Action == "open" && ! Directory . Exists ( shellNotification . ActionParam ) )
172+ {
173+ notification . AddButton ( _translationService . _ ( "Open in Files" ) , "win.openInFiles" ) ;
174+ }
175+ _application . SendNotification ( null , notification ) ;
176+ }
161177 var toast = Adw . Toast . New ( e . Notification . Message ) ;
162178 if ( e . Notification . Action == "close" )
163179 {
@@ -187,6 +203,16 @@ private void Controller_FolderChanged(object? sender, FolderChangedEventArgs e)
187203
188204 private void Quit ( Gio . SimpleAction sender , Gio . SimpleAction . ActivateSignalArgs e ) => Window_OnCloseRequest ( this , new EventArgs ( ) ) ;
189205
206+ private async void OpenInFiles ( Gio . SimpleAction sender , Gio . SimpleAction . ActivateSignalArgs e )
207+ {
208+ if ( ! Directory . Exists ( _controller . CurrentFolder ) )
209+ {
210+ return ;
211+ }
212+ var launcher = Gtk . FileLauncher . New ( Gio . FileHelper . NewForPath ( _controller . CurrentFolder ) ) ;
213+ await launcher . LaunchAsync ( this ) ;
214+ }
215+
190216 private async void OpenFolder ( Gio . SimpleAction sender , Gio . SimpleAction . ActivateSignalArgs e )
191217 {
192218 var folderDialog = Gtk . FileDialog . New ( ) ;
0 commit comments