fortrangoingonforty/sniffly / 24d1435

Browse files

fix some back/forwards state things

Authored by espadonne
SHA
24d1435508230fbb9471c13b9f565f297d1aaa8e
Parents
11d0a00
Tree
f257843

1 changed file

StatusFile+-
M src/gui/gtk_app.f90 46 11
src/gui/gtk_app.f90modified
@@ -68,7 +68,6 @@ module gtk_app
6868
   character(len=512), dimension(MAX_HISTORY), save :: nav_history
6969
   integer, save :: nav_history_count = 0
7070
   integer, save :: nav_history_pos = 0  ! Current position in history (0 = no history)
71
-  logical, save :: suppress_history_add = .false.  ! Flag to prevent adding to history during Back/Forward
7271
 
7372
   ! Button pointers for enabling/disabling
7473
   type(c_ptr), save :: back_btn_ptr = c_null_ptr
@@ -674,17 +673,24 @@ contains
674673
     ! Check if scan is active - disable buttons during scan
675674
     scan_active = is_scan_active()
676675
 
676
+    print *, "=== UPDATE_HISTORY_BUTTONS ==="
677
+    print *, "  pos=", nav_history_pos, " count=", nav_history_count, " scan_active=", scan_active
678
+
677679
     ! Enable Back if we're not at the start of history AND scan is not active
678680
     if (nav_history_pos > 1 .and. .not. scan_active) then
681
+      print *, "  Enabling Back (pos > 1 and scan not active)"
679682
       call gtk_widget_set_sensitive(back_btn_ptr, 1_c_int)
680683
     else
684
+      print *, "  Disabling Back (pos=", nav_history_pos, " or scan active)"
681685
       call gtk_widget_set_sensitive(back_btn_ptr, 0_c_int)
682686
     end if
683687
 
684688
     ! Enable Forward if we're not at the end of history AND scan is not active
685689
     if (nav_history_pos > 0 .and. nav_history_pos < nav_history_count .and. .not. scan_active) then
690
+      print *, "  Enabling Forward (pos < count and scan not active)"
686691
       call gtk_widget_set_sensitive(forward_btn_ptr, 1_c_int)
687692
     else
693
+      print *, "  Disabling Forward (pos=", nav_history_pos, " count=", nav_history_count, " or scan active)"
688694
       call gtk_widget_set_sensitive(forward_btn_ptr, 0_c_int)
689695
     end if
690696
   end subroutine update_history_buttons
@@ -748,15 +754,32 @@ contains
748754
     character(len=*), intent(in) :: path
749755
     integer :: i
750756
 
757
+    print *, "=== ADD_TO_HISTORY CALLED ==="
758
+    print *, "  Path: ", trim(path)
759
+    print *, "  Before: pos=", nav_history_pos, " count=", nav_history_count
760
+    if (nav_history_count > 0) then
761
+      print *, "  Current history:"
762
+      do i = 1, nav_history_count
763
+        if (i == nav_history_pos) then
764
+          print *, "    [", i, "] (CURRENT) ", trim(nav_history(i))
765
+        else
766
+          print *, "    [", i, "] ", trim(nav_history(i))
767
+        end if
768
+      end do
769
+    end if
770
+
751771
     ! Don't add if it's the same as current position
752772
     if (nav_history_pos > 0 .and. nav_history_pos <= nav_history_count) then
753773
       if (trim(nav_history(nav_history_pos)) == trim(path)) then
774
+        print *, "  Path same as current position - not adding"
754775
         return
755776
       end if
756777
     end if
757778
 
758779
     ! If we're in the middle of history, discard forward history
759780
     if (nav_history_pos > 0 .and. nav_history_pos < nav_history_count) then
781
+      print *, "  In middle of history - truncating forward history"
782
+      print *, "  Truncating count from", nav_history_count, "to", nav_history_pos
760783
       nav_history_count = nav_history_pos
761784
     end if
762785
 
@@ -764,8 +787,10 @@ contains
764787
     if (nav_history_count < MAX_HISTORY) then
765788
       nav_history_count = nav_history_count + 1
766789
       nav_history(nav_history_count) = trim(path)
790
+      print *, "  Added to history at position", nav_history_count
767791
     else
768792
       ! Shift history left and add at end
793
+      print *, "  History full - shifting left"
769794
       do i = 1, MAX_HISTORY - 1
770795
         nav_history(i) = nav_history(i + 1)
771796
       end do
@@ -773,6 +798,8 @@ contains
773798
     end if
774799
 
775800
     nav_history_pos = nav_history_count
801
+    print *, "  After: pos=", nav_history_pos, " count=", nav_history_count
802
+    print *, "=== END ADD_TO_HISTORY ==="
776803
     call update_history_buttons()
777804
   end subroutine add_to_history
778805
 
@@ -781,6 +808,9 @@ contains
781808
     use progressive_scanner, only: is_scan_active
782809
     type(c_ptr), value :: button, user_data
783810
 
811
+    print *, "=== BACK BUTTON CLICKED ==="
812
+    print *, "  Before: pos=", nav_history_pos, " count=", nav_history_count
813
+
784814
     ! Block navigation if scan is active
785815
     if (is_scan_active()) then
786816
       call sniffly_update_status("Cannot navigate: Scan in progress")
@@ -790,7 +820,8 @@ contains
790820
     if (nav_history_pos > 1) then
791821
       nav_history_pos = nav_history_pos - 1
792822
       global_scan_path = trim(nav_history(nav_history_pos))
793
-      suppress_history_add = .true.  ! Prevent adding to history during Back navigation
823
+      print *, "  Moving back to pos=", nav_history_pos
824
+      print *, "  Path: ", trim(global_scan_path)
794825
       call set_scan_path(trim(global_scan_path))
795826
       call update_path_entry(trim(global_scan_path))
796827
       call trigger_rescan(global_scan_path)
@@ -804,6 +835,9 @@ contains
804835
     use progressive_scanner, only: is_scan_active
805836
     type(c_ptr), value :: button, user_data
806837
 
838
+    print *, "=== FORWARD BUTTON CLICKED ==="
839
+    print *, "  Before: pos=", nav_history_pos, " count=", nav_history_count
840
+
807841
     ! Block navigation if scan is active
808842
     if (is_scan_active()) then
809843
       call sniffly_update_status("Cannot navigate: Scan in progress")
@@ -813,7 +847,8 @@ contains
813847
     if (nav_history_pos > 0 .and. nav_history_pos < nav_history_count) then
814848
       nav_history_pos = nav_history_pos + 1
815849
       global_scan_path = trim(nav_history(nav_history_pos))
816
-      suppress_history_add = .true.  ! Prevent adding to history during Forward navigation
850
+      print *, "  Moving forward to pos=", nav_history_pos
851
+      print *, "  Path: ", trim(global_scan_path)
817852
       call set_scan_path(trim(global_scan_path))
818853
       call update_path_entry(trim(global_scan_path))
819854
       call trigger_rescan(global_scan_path)
@@ -1352,25 +1387,25 @@ contains
13521387
     use types, only: file_node
13531388
     type(file_node), pointer :: current_view
13541389
 
1390
+    print *, "=== BREADCRUMB_CALLBACK ==="
1391
+
13551392
     ! Sync global_scan_path with the current view node's path
13561393
     current_view => get_current_view_node()
13571394
     if (associated(current_view) .and. allocated(current_view%path)) then
13581395
       global_scan_path = trim(current_view%path)
1396
+      print *, "  Synced global_scan_path to: ", trim(global_scan_path)
13591397
     end if
13601398
 
13611399
     call sniffly_update_breadcrumbs()
13621400
     call sniffly_update_status_bar_stats()
13631401
 
1364
-    ! Add current path to navigation history (unless suppressed by Back/Forward)
1365
-    if (.not. suppress_history_add) then
1366
-      if (len_trim(global_scan_path) > 0) then
1367
-        call add_to_history(global_scan_path)
1368
-      end if
1402
+    ! Always add current path to navigation history
1403
+    ! (add_to_history has duplicate detection built-in)
1404
+    if (len_trim(global_scan_path) > 0) then
1405
+      print *, "  Calling add_to_history..."
1406
+      call add_to_history(global_scan_path)
13691407
     end if
13701408
 
1371
-    ! Reset suppression flag for next navigation
1372
-    suppress_history_add = .false.
1373
-
13741409
     ! Update button states now that history may have changed
13751410
     call update_history_buttons()
13761411
   end subroutine breadcrumb_callback