@@ -12,13 +12,6 @@ public class MainWindow : Adw.ApplicationWindow
1212{
1313 private readonly MainWindowController _controller ;
1414 private readonly Gtk . Builder _builder ;
15- private readonly Gtk . DropTarget _dropTarget ;
16- private readonly Gio . SimpleAction _actQuit ;
17- private readonly Gio . SimpleAction _actOpenFolder ;
18- private readonly Gio . SimpleAction _actCloseFolder ;
19- private readonly Gio . SimpleAction _actPreferences ;
20- private readonly Gio . SimpleAction _actKeyboardShortcuts ;
21- private readonly Gio . SimpleAction _actAbout ;
2215
2316 [ Gtk . Connect ( "windowTitle" ) ]
2417 private Adw . WindowTitle ? _windowTitle ;
@@ -42,8 +35,8 @@ public MainWindow(MainWindowController controller, Adw.Application application)
4235
4336 private MainWindow ( MainWindowController controller , Adw . Application application , Gtk . Builder builder ) : base ( new Adw . Internal . ApplicationWindowHandle ( builder . GetPointer ( "root" ) , false ) )
4437 {
45- Application = application ;
4638 _controller = controller ;
39+ _application = application ;
4740 _builder = builder ;
4841 _builder . Connect ( this ) ;
4942 // Window
@@ -57,46 +50,46 @@ private MainWindow(MainWindowController controller, Adw.Application application,
5750 _pageGreeting ! . Title = _controller . Greeting ;
5851 // Events
5952 OnCloseRequest += Window_OnCloseRequest ;
60- _controller . AppNotificationSent += ( sender , args ) => GLib . Functions . IdleAdd ( 200 , ( ) =>
53+ _controller . AppNotificationSent += ( sender , args ) => GLib . Functions . IdleAdd ( 0 , ( ) =>
6154 {
6255 Controller_AppNotificationSent ( sender , args ) ;
6356 return false ;
6457 } ) ;
6558 _controller . FolderChanged += Controller_FolderChanged ;
6659 // Drop target
67- _dropTarget = Gtk . DropTarget . New ( Gio . FileHelper . GetGType ( ) , Gdk . DragAction . Copy ) ;
68- _dropTarget . OnDrop += Window_OnDrop ;
69- AddController ( _dropTarget ) ;
60+ var dropTarget = Gtk . DropTarget . New ( Gio . FileHelper . GetGType ( ) , Gdk . DragAction . Copy ) ;
61+ dropTarget . OnDrop += Window_OnDrop ;
62+ AddController ( dropTarget ) ;
7063 // Quit action
71- _actQuit = Gio . SimpleAction . New ( "quit" , null ) ;
72- _actQuit . OnActivate += Quit ;
73- AddAction ( _actQuit ) ;
74- Application ! . SetAccelsForAction ( "win.quit" , [ "<Ctrl>q" ] ) ;
64+ var actQuit = Gio . SimpleAction . New ( "quit" , null ) ;
65+ actQuit . OnActivate += Quit ;
66+ AddAction ( actQuit ) ;
67+ _application . SetAccelsForAction ( "win.quit" , [ "<Ctrl>q" ] ) ;
7568 // Open folder action
76- _actOpenFolder = Gio . SimpleAction . New ( "openFolder" , null ) ;
77- _actOpenFolder . OnActivate += OpenFolder ;
78- AddAction ( _actOpenFolder ) ;
79- Application ! . SetAccelsForAction ( "win.openFolder" , [ "<Ctrl>o" ] ) ;
69+ var actOpenFolder = Gio . SimpleAction . New ( "openFolder" , null ) ;
70+ actOpenFolder . OnActivate += OpenFolder ;
71+ AddAction ( actOpenFolder ) ;
72+ _application . SetAccelsForAction ( "win.openFolder" , [ "<Ctrl>o" ] ) ;
8073 // Close folder action
81- _actCloseFolder = Gio . SimpleAction . New ( "closeFolder" , null ) ;
82- _actCloseFolder . OnActivate += CloseFolder ;
83- AddAction ( _actCloseFolder ) ;
84- Application ! . SetAccelsForAction ( "win.closeFolder" , [ "<Ctrl>w" ] ) ;
74+ var actCloseFolder = Gio . SimpleAction . New ( "closeFolder" , null ) ;
75+ actCloseFolder . OnActivate += CloseFolder ;
76+ AddAction ( actCloseFolder ) ;
77+ _application . SetAccelsForAction ( "win.closeFolder" , [ "<Ctrl>w" ] ) ;
8578 // Preferences action
86- _actPreferences = Gio . SimpleAction . New ( "preferences" , null ) ;
87- _actPreferences . OnActivate += Preferences ;
88- AddAction ( _actPreferences ) ;
89- Application ! . SetAccelsForAction ( "win.preferences" , [ "<Ctrl>period" ] ) ;
79+ var actPreferences = Gio . SimpleAction . New ( "preferences" , null ) ;
80+ actPreferences . OnActivate += Preferences ;
81+ AddAction ( actPreferences ) ;
82+ _application . SetAccelsForAction ( "win.preferences" , [ "<Ctrl>period" ] ) ;
9083 // Keyboard shortcuts action
91- _actKeyboardShortcuts = Gio . SimpleAction . New ( "keyboardShortcuts" , null ) ;
92- _actKeyboardShortcuts . OnActivate += KeyboardShortcuts ;
93- AddAction ( _actKeyboardShortcuts ) ;
94- Application ! . SetAccelsForAction ( "win.keyboardShortcuts" , [ "<Ctrl>question" ] ) ;
84+ var actKeyboardShortcuts = Gio . SimpleAction . New ( "keyboardShortcuts" , null ) ;
85+ actKeyboardShortcuts . OnActivate += KeyboardShortcuts ;
86+ AddAction ( actKeyboardShortcuts ) ;
87+ _application . SetAccelsForAction ( "win.keyboardShortcuts" , [ "<Ctrl>question" ] ) ;
9588 // About action
96- _actAbout = Gio . SimpleAction . New ( "about" , null ) ;
97- _actAbout . OnActivate += About ;
98- AddAction ( _actAbout ) ;
99- Application ! . SetAccelsForAction ( "win.about" , [ "F1" ] ) ;
89+ var actAbout = Gio . SimpleAction . New ( "about" , null ) ;
90+ actAbout . OnActivate += About ;
91+ AddAction ( actAbout ) ;
92+ _application . SetAccelsForAction ( "win.about" , [ "F1" ] ) ;
10093 }
10194
10295 public new void Present ( )
@@ -154,19 +147,23 @@ private void Quit(Gio.SimpleAction sender, Gio.SimpleAction.ActivateSignalArgs a
154147 {
155148 if ( ! Window_OnCloseRequest ( this , new EventArgs ( ) ) )
156149 {
157- Application ! . Quit ( ) ;
150+ _application . Quit ( ) ;
158151 }
159152 }
160153
161154 private async void OpenFolder ( Gio . SimpleAction sender , Gio . SimpleAction . ActivateSignalArgs args )
162155 {
163156 var folderDialog = Gtk . FileDialog . New ( ) ;
164157 folderDialog . Title = _controller . Translator . _ ( "Open Folder" ) ;
165- var file = await folderDialog . SelectFolderAsync ( this ) ;
166- if ( file is not null )
158+ try
167159 {
168- _controller . OpenFolder ( file . GetPath ( ) ! ) ;
160+ var file = await folderDialog . SelectFolderAsync ( this ) ;
161+ if ( file is not null )
162+ {
163+ _controller . OpenFolder ( file . GetPath ( ) ! ) ;
164+ }
169165 }
166+ catch { }
170167 }
171168
172169 private void CloseFolder ( Gio . SimpleAction sender , Gio . SimpleAction . ActivateSignalArgs args ) => _controller . CloseFolder ( ) ;
0 commit comments