fortrangoingonforty/sniffly / ee85585

Browse files

Improve Properties button: auto-display selection info, open macOS Get Info

Changes to Properties/Info button:
- Icon changed from document-properties to dialog-information (more intuitive)
- Tooltip updated to "Show in Finder Info"
- Button now opens native macOS Get Info window via AppleScript
- Extracted build_selection_info() helper function for reusability

Auto-display selection info in status bar:
- Selection info (name, size, item count) now auto-displays when items are selected
- Info updates automatically when selection changes
- Info clears when selection is removed
- Other messages (errors, navigation) can still interrupt and auto-dismiss after 5s
- Selection info remains persistent until selection changes
Authored by espadonne
SHA
ee8558515e161b9d4e445cedd9b4107b4fa3544e
Parents
4f55caa
Tree
cb72efa

1 changed file

StatusFile+-
M src/gui/gtk_app.f90 62 22
src/gui/gtk_app.f90modified
@@ -310,10 +310,10 @@ contains
310310
     call gtk_box_append(toolbar, copy_path_btn)
311311
     copy_path_btn_ptr = copy_path_btn  ! Store for enabling/disabling
312312
 
313
-    ! Create Properties/Info button
313
+    ! Create Properties/Info button (opens macOS Get Info window)
314314
     info_btn = gtk_button_new()
315
-    call gtk_button_set_icon_name(info_btn, "document-properties"//c_null_char)
316
-    call gtk_widget_set_tooltip_text(info_btn, "Show Properties/Info"//c_null_char)
315
+    call gtk_button_set_icon_name(info_btn, "dialog-information"//c_null_char)
316
+    call gtk_widget_set_tooltip_text(info_btn, "Show in Finder Info"//c_null_char)
317317
     call g_signal_connect(info_btn, "clicked"//c_null_char, &
318318
                            c_funloc(on_info_clicked), c_null_ptr)
319319
     call gtk_box_append(toolbar, info_btn)
@@ -590,15 +590,13 @@ contains
590590
     print *, "Path copied successfully!"
591591
   end subroutine on_copy_path_clicked
592592
 
593
-  ! Callback when Properties/Info button is clicked
594
-  subroutine on_info_clicked(button, user_data) bind(c)
593
+  ! Helper: Build selection info string for status bar
594
+  function build_selection_info() result(info_text)
595595
     use iso_fortran_env, only: int64
596596
     use treemap_renderer, only: get_current_view_node
597597
     use treemap_widget, only: get_selected_index
598598
     use types, only: file_node
599599
     use file_system, only: list_directory
600
-    type(c_ptr), value :: button, user_data
601
-    character(len=:), allocatable :: info_msg
602600
     character(len=1024) :: info_text
603601
     character(len=20) :: size_str
604602
     type(file_node), pointer :: view_node
@@ -606,11 +604,7 @@ contains
606604
     integer :: item_count, selected_idx
607605
     character(len=256), dimension(10000) :: entries
608606
 
609
-    ! Check if there's a selection
610
-    if (.not. has_selection()) then
611
-      call sniffly_show_error("No selection to show properties for")
612
-      return
613
-    end if
607
+    info_text = ""
614608
 
615609
     ! Get the selected node
616610
     view_node => get_current_view_node()
@@ -618,23 +612,21 @@ contains
618612
       return
619613
     end if
620614
 
621
-    ! Get the selected child index (1-based: 1 = first child, 2 = second child, etc.)
615
+    ! Get the selected child index (1-based)
622616
     selected_idx = get_selected_index()
623617
     if (selected_idx < 1 .or. selected_idx > view_node%num_children) then
624
-      call sniffly_show_error("Invalid selection")
625618
       return
626619
     end if
627620
 
628
-    ! Get details from selected child (selected_idx is already 1-based)
621
+    ! Get details from selected child
629622
     size_bytes = view_node%children(selected_idx)%size
630623
 
631624
     ! Check if this is a grouped "[N small files]" node
632625
     if (index(view_node%children(selected_idx)%name, '[') == 1 .and. &
633626
         index(view_node%children(selected_idx)%name, 'small files]') > 0) then
634
-      ! This is a grouped small files node - don't count items (name already has the count)
635627
       item_count = -1  ! Special marker for grouped nodes
636628
     else if (view_node%children(selected_idx)%is_directory) then
637
-      ! For regular directories, count entries on-demand to get accurate item count
629
+      ! For regular directories, count entries on-demand
638630
       item_count = list_directory(view_node%children(selected_idx)%path, entries, 10000)
639631
     else
640632
       item_count = 0  ! Files don't have children
@@ -651,7 +643,7 @@ contains
651643
       write(size_str, '(F0.2,A)') real(size_bytes)/(1024.0**3), ' GB'
652644
     end if
653645
 
654
-    ! Build info text for status bar
646
+    ! Build info text
655647
     if (item_count == -1) then
656648
       ! Grouped small files - name already contains the count
657649
       write(info_text, '(A,A,A)') &
@@ -665,10 +657,48 @@ contains
665657
       write(info_text, '(A,A,A,A)') &
666658
         trim(view_node%children(selected_idx)%name), ' | ', trim(size_str), ' | File'
667659
     end if
660
+  end function build_selection_info
661
+
662
+  ! Callback when Properties/Info button is clicked - opens macOS Get Info window
663
+  subroutine on_info_clicked(button, user_data) bind(c)
664
+    type(c_ptr), value :: button, user_data
665
+    character(len=512) :: selected_path
666
+    character(len=1024) :: applescript_cmd
667
+    integer :: exit_status
668
+
669
+    print *, "Info button clicked - opening macOS Get Info window"
670
+
671
+    ! Check if there's a selection
672
+    if (.not. has_selection()) then
673
+      call sniffly_show_error("No selection to show info for")
674
+      return
675
+    end if
668676
 
669
-    ! Show properties in status bar
670
-    info_msg = trim(info_text)
671
-    call sniffly_update_status(info_msg)
677
+    ! Get the selected node path
678
+    selected_path = get_selected_node_path()
679
+    if (len_trim(selected_path) == 0) then
680
+      print *, "Invalid selection path"
681
+      call sniffly_show_error("Invalid selection")
682
+      return
683
+    end if
684
+
685
+    print *, "Opening Get Info for: ", trim(selected_path)
686
+
687
+    ! Build AppleScript command to open Get Info window
688
+    ! We escape single quotes in the path by replacing ' with '\''
689
+    write(applescript_cmd, '(A,A,A)') &
690
+      'osascript -e ''tell application "Finder" to open information window of (POSIX file "', &
691
+      trim(selected_path), '" as alias)'''
692
+
693
+    ! Execute the command
694
+    call execute_command_line(trim(applescript_cmd), exitstat=exit_status)
695
+
696
+    if (exit_status /= 0) then
697
+      print *, "ERROR: Failed to open Get Info window (exit status:", exit_status, ")"
698
+      call sniffly_show_error("Failed to open Get Info window")
699
+    else
700
+      print *, "Successfully opened Get Info window"
701
+    end if
672702
   end subroutine on_info_clicked
673703
 
674704
   ! Helper: Update Back/Forward button states
@@ -730,10 +760,11 @@ contains
730760
     end if
731761
   end subroutine update_cancel_scan_button_state
732762
 
733
-  ! Helper: Update selection-dependent button states
763
+  ! Helper: Update selection-dependent button states and display selection info
734764
   subroutine update_selection_buttons()
735765
     use gtk, only: gtk_widget_set_sensitive
736766
     logical :: has_sel
767
+    character(len=1024) :: sel_info
737768
 
738769
     ! Guard against accessing widgets during shutdown
739770
     if (app_is_shutting_down) return
@@ -750,11 +781,20 @@ contains
750781
       call gtk_widget_set_sensitive(info_btn_ptr, 1_c_int)
751782
       call gtk_widget_set_sensitive(copy_path_btn_ptr, 1_c_int)
752783
       call gtk_widget_set_sensitive(delete_btn_ptr, 1_c_int)
784
+
785
+      ! Auto-display selection info in status bar
786
+      sel_info = build_selection_info()
787
+      if (len_trim(sel_info) > 0) then
788
+        call sniffly_update_status(trim(sel_info))
789
+      end if
753790
     else
754791
       print *, "DEBUG:   Disabling selection-dependent buttons"
755792
       call gtk_widget_set_sensitive(info_btn_ptr, 0_c_int)
756793
       call gtk_widget_set_sensitive(copy_path_btn_ptr, 0_c_int)
757794
       call gtk_widget_set_sensitive(delete_btn_ptr, 0_c_int)
795
+
796
+      ! Clear selection info from status bar when deselected
797
+      call sniffly_update_status("")
758798
     end if
759799
 
760800
     ! Open in Finder button is always enabled (defaults to current directory)