@@ -437,50 +437,8 @@ impl LogViewerApp {
437
437
}
438
438
}
439
439
440
- fn check_shortcuts ( & mut self , ui : & mut egui:: Ui ) {
441
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . prev ) ) {
442
- self . move_selected_prev ( ) ;
443
- }
444
-
445
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . next ) ) {
446
- self . move_selected_next ( ) ;
447
- }
448
-
449
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . first ) ) {
450
- self . move_selected_first ( ) ;
451
- }
452
-
453
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . last ) ) {
454
- self . move_selected_last ( ) ;
455
- }
456
-
457
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . unfilter ) ) {
458
- if let Some ( data) = self . data . as_mut ( ) {
459
- data. unfilter ( ) ;
460
- }
461
- }
462
-
463
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . open ) ) {
464
- self . loading_status = self . initiate_loading ( ui. ctx ( ) . clone ( ) ) ;
465
- }
466
-
467
- #[ cfg( not( target_arch = "wasm32" ) ) ]
468
- {
469
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . reload ) ) {
470
- self . loading_status = self . reload_file ( ) ;
471
- }
472
-
473
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . load_latest ) ) {
474
- self . loading_status = self . load_most_recent_file ( ) ;
475
- }
476
- }
477
-
478
- if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . apply_filter ) ) {
479
- if let Some ( data) = self . data . as_mut ( ) {
480
- data. apply_filter ( self . data_display_options . common_fields ( ) ) ;
481
- }
482
- }
483
-
440
+ /// These shortcuts are always enabled
441
+ fn check_global_shortcuts ( & mut self , ui : & mut egui:: Ui ) {
484
442
if ui. input_mut ( |i| i. consume_shortcut ( & self . shortcuts . search ) ) {
485
443
self . focus_search_text_edit ( ) ;
486
444
}
@@ -509,12 +467,11 @@ impl LogViewerApp {
509
467
}
510
468
let mut should_apply_filter = false ;
511
469
if is_filter_enabled {
512
- if shortcut_button ( ui, "Apply" , "" , & self . shortcuts . apply_filter ) . clicked ( ) {
470
+ if shortcut_button ( ui, "Apply" , "" , & self . shortcuts . apply_filter ) {
513
471
should_apply_filter = true ;
514
472
}
515
473
if data. is_filtered ( )
516
474
&& shortcut_button ( ui, "Unfilter" , "Clears Filter " , & self . shortcuts . unfilter )
517
- . clicked ( )
518
475
{
519
476
data. unfilter ( ) ;
520
477
}
@@ -598,32 +555,30 @@ impl LogViewerApp {
598
555
599
556
fn navigation_ui ( & mut self , ui : & mut egui:: Ui ) {
600
557
ui. label ( "Nav:" ) ;
601
- if shortcut_button ( ui, "⏪" , "First " , & self . shortcuts . first ) . clicked ( ) {
558
+ if shortcut_button ( ui, "⏪" , "First " , & self . shortcuts . first ) {
602
559
self . move_selected_first ( ) ;
603
560
}
604
- if shortcut_button ( ui, "⬆" , "Previous " , & self . shortcuts . prev ) . clicked ( ) {
561
+ if shortcut_button ( ui, "⬆" , "Previous " , & self . shortcuts . prev ) {
605
562
self . move_selected_prev ( ) ;
606
563
}
607
- if shortcut_button ( ui, "⬇" , "Next " , & self . shortcuts . next ) . clicked ( ) {
564
+ if shortcut_button ( ui, "⬇" , "Next " , & self . shortcuts . next ) {
608
565
self . move_selected_next ( ) ;
609
566
}
610
- if shortcut_button ( ui, "⏩" , "Last " , & self . shortcuts . last ) . clicked ( ) {
567
+ if shortcut_button ( ui, "⏩" , "Last " , & self . shortcuts . last ) {
611
568
self . move_selected_last ( ) ;
612
569
}
613
570
}
614
571
fn data_load_ui ( & mut self , ui : & mut egui:: Ui ) {
615
572
ui. horizontal ( |ui| {
616
- if shortcut_button ( ui, "📂 Open log file..." , "" , & self . shortcuts . open ) . clicked ( ) {
573
+ if shortcut_button ( ui, "📂 Open log file..." , "" , & self . shortcuts . open ) {
617
574
self . loading_status = self . initiate_loading ( ui. ctx ( ) . clone ( ) ) ;
618
575
}
619
576
#[ cfg( not( target_arch = "wasm32" ) ) ]
620
577
{
621
- if shortcut_button ( ui, "Reload" , "" , & self . shortcuts . reload ) . clicked ( ) {
578
+ if shortcut_button ( ui, "Reload" , "" , & self . shortcuts . reload ) {
622
579
self . loading_status = self . reload_file ( ) ;
623
580
}
624
- if shortcut_button ( ui, "Load Most Recent File" , "" , & self . shortcuts . load_latest )
625
- . clicked ( )
626
- {
581
+ if shortcut_button ( ui, "Load Most Recent File" , "" , & self . shortcuts . load_latest ) {
627
582
self . loading_status = self . load_most_recent_file ( ) ;
628
583
}
629
584
}
@@ -701,7 +656,7 @@ impl eframe::App for LogViewerApp {
701
656
egui:: TopBottomPanel :: top ( "top_panel" ) . show ( ctx, |ui| {
702
657
// The top panel is often a good place for a menu bar:
703
658
704
- self . check_shortcuts ( ui) ;
659
+ self . check_global_shortcuts ( ui) ;
705
660
706
661
egui:: menu:: bar ( ui, |ui| {
707
662
// NOTE: no File->Quit on web pages!
@@ -769,14 +724,20 @@ pub fn calculate_hash<T: Hash + ?Sized>(t: &T) -> u64 {
769
724
s. finish ( )
770
725
}
771
726
727
+ /// Returns true if the button is clicked or the shortcut is pressed
728
+ ///
729
+ /// Note: This makes it the case that the code for both the button and the shortcut press will do the same thing and you cannot use the shortcut to bypass the button not showing
772
730
fn shortcut_button (
773
731
ui : & mut egui:: Ui ,
774
732
caption : impl Into < egui:: WidgetText > ,
775
733
hint_msg : & str ,
776
734
shortcut : & KeyboardShortcut ,
777
- ) -> egui:: Response {
778
- ui. button ( caption) . on_hover_text ( format ! (
779
- "{hint_msg}({})" ,
780
- ui. ctx( ) . format_shortcut( shortcut)
781
- ) )
735
+ ) -> bool {
736
+ ui. button ( caption)
737
+ . on_hover_text ( format ! (
738
+ "{hint_msg}({})" ,
739
+ ui. ctx( ) . format_shortcut( shortcut)
740
+ ) )
741
+ . clicked ( )
742
+ || ui. input_mut ( |i| i. consume_shortcut ( shortcut) )
782
743
}
0 commit comments