@@ -68,7 +68,6 @@ module gtk_app |
| 68 | 68 | character(len=512), dimension(MAX_HISTORY), save :: nav_history |
| 69 | 69 | integer, save :: nav_history_count = 0 |
| 70 | 70 | 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 |
| 72 | 71 | |
| 73 | 72 | ! Button pointers for enabling/disabling |
| 74 | 73 | type(c_ptr), save :: back_btn_ptr = c_null_ptr |
@@ -674,17 +673,24 @@ contains |
| 674 | 673 | ! Check if scan is active - disable buttons during scan |
| 675 | 674 | scan_active = is_scan_active() |
| 676 | 675 | |
| 676 | + print *, "=== UPDATE_HISTORY_BUTTONS ===" |
| 677 | + print *, " pos=", nav_history_pos, " count=", nav_history_count, " scan_active=", scan_active |
| 678 | + |
| 677 | 679 | ! Enable Back if we're not at the start of history AND scan is not active |
| 678 | 680 | if (nav_history_pos > 1 .and. .not. scan_active) then |
| 681 | + print *, " Enabling Back (pos > 1 and scan not active)" |
| 679 | 682 | call gtk_widget_set_sensitive(back_btn_ptr, 1_c_int) |
| 680 | 683 | else |
| 684 | + print *, " Disabling Back (pos=", nav_history_pos, " or scan active)" |
| 681 | 685 | call gtk_widget_set_sensitive(back_btn_ptr, 0_c_int) |
| 682 | 686 | end if |
| 683 | 687 | |
| 684 | 688 | ! Enable Forward if we're not at the end of history AND scan is not active |
| 685 | 689 | 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)" |
| 686 | 691 | call gtk_widget_set_sensitive(forward_btn_ptr, 1_c_int) |
| 687 | 692 | else |
| 693 | + print *, " Disabling Forward (pos=", nav_history_pos, " count=", nav_history_count, " or scan active)" |
| 688 | 694 | call gtk_widget_set_sensitive(forward_btn_ptr, 0_c_int) |
| 689 | 695 | end if |
| 690 | 696 | end subroutine update_history_buttons |
@@ -748,15 +754,32 @@ contains |
| 748 | 754 | character(len=*), intent(in) :: path |
| 749 | 755 | integer :: i |
| 750 | 756 | |
| 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 | + |
| 751 | 771 | ! Don't add if it's the same as current position |
| 752 | 772 | if (nav_history_pos > 0 .and. nav_history_pos <= nav_history_count) then |
| 753 | 773 | if (trim(nav_history(nav_history_pos)) == trim(path)) then |
| 774 | + print *, " Path same as current position - not adding" |
| 754 | 775 | return |
| 755 | 776 | end if |
| 756 | 777 | end if |
| 757 | 778 | |
| 758 | 779 | ! If we're in the middle of history, discard forward history |
| 759 | 780 | 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 |
| 760 | 783 | nav_history_count = nav_history_pos |
| 761 | 784 | end if |
| 762 | 785 | |
@@ -764,8 +787,10 @@ contains |
| 764 | 787 | if (nav_history_count < MAX_HISTORY) then |
| 765 | 788 | nav_history_count = nav_history_count + 1 |
| 766 | 789 | nav_history(nav_history_count) = trim(path) |
| 790 | + print *, " Added to history at position", nav_history_count |
| 767 | 791 | else |
| 768 | 792 | ! Shift history left and add at end |
| 793 | + print *, " History full - shifting left" |
| 769 | 794 | do i = 1, MAX_HISTORY - 1 |
| 770 | 795 | nav_history(i) = nav_history(i + 1) |
| 771 | 796 | end do |
@@ -773,6 +798,8 @@ contains |
| 773 | 798 | end if |
| 774 | 799 | |
| 775 | 800 | nav_history_pos = nav_history_count |
| 801 | + print *, " After: pos=", nav_history_pos, " count=", nav_history_count |
| 802 | + print *, "=== END ADD_TO_HISTORY ===" |
| 776 | 803 | call update_history_buttons() |
| 777 | 804 | end subroutine add_to_history |
| 778 | 805 | |
@@ -781,6 +808,9 @@ contains |
| 781 | 808 | use progressive_scanner, only: is_scan_active |
| 782 | 809 | type(c_ptr), value :: button, user_data |
| 783 | 810 | |
| 811 | + print *, "=== BACK BUTTON CLICKED ===" |
| 812 | + print *, " Before: pos=", nav_history_pos, " count=", nav_history_count |
| 813 | + |
| 784 | 814 | ! Block navigation if scan is active |
| 785 | 815 | if (is_scan_active()) then |
| 786 | 816 | call sniffly_update_status("Cannot navigate: Scan in progress") |
@@ -790,7 +820,8 @@ contains |
| 790 | 820 | if (nav_history_pos > 1) then |
| 791 | 821 | nav_history_pos = nav_history_pos - 1 |
| 792 | 822 | 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) |
| 794 | 825 | call set_scan_path(trim(global_scan_path)) |
| 795 | 826 | call update_path_entry(trim(global_scan_path)) |
| 796 | 827 | call trigger_rescan(global_scan_path) |
@@ -804,6 +835,9 @@ contains |
| 804 | 835 | use progressive_scanner, only: is_scan_active |
| 805 | 836 | type(c_ptr), value :: button, user_data |
| 806 | 837 | |
| 838 | + print *, "=== FORWARD BUTTON CLICKED ===" |
| 839 | + print *, " Before: pos=", nav_history_pos, " count=", nav_history_count |
| 840 | + |
| 807 | 841 | ! Block navigation if scan is active |
| 808 | 842 | if (is_scan_active()) then |
| 809 | 843 | call sniffly_update_status("Cannot navigate: Scan in progress") |
@@ -813,7 +847,8 @@ contains |
| 813 | 847 | if (nav_history_pos > 0 .and. nav_history_pos < nav_history_count) then |
| 814 | 848 | nav_history_pos = nav_history_pos + 1 |
| 815 | 849 | 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) |
| 817 | 852 | call set_scan_path(trim(global_scan_path)) |
| 818 | 853 | call update_path_entry(trim(global_scan_path)) |
| 819 | 854 | call trigger_rescan(global_scan_path) |
@@ -1352,25 +1387,25 @@ contains |
| 1352 | 1387 | use types, only: file_node |
| 1353 | 1388 | type(file_node), pointer :: current_view |
| 1354 | 1389 | |
| 1390 | + print *, "=== BREADCRUMB_CALLBACK ===" |
| 1391 | + |
| 1355 | 1392 | ! Sync global_scan_path with the current view node's path |
| 1356 | 1393 | current_view => get_current_view_node() |
| 1357 | 1394 | if (associated(current_view) .and. allocated(current_view%path)) then |
| 1358 | 1395 | global_scan_path = trim(current_view%path) |
| 1396 | + print *, " Synced global_scan_path to: ", trim(global_scan_path) |
| 1359 | 1397 | end if |
| 1360 | 1398 | |
| 1361 | 1399 | call sniffly_update_breadcrumbs() |
| 1362 | 1400 | call sniffly_update_status_bar_stats() |
| 1363 | 1401 | |
| 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) |
| 1369 | 1407 | end if |
| 1370 | 1408 | |
| 1371 | | - ! Reset suppression flag for next navigation |
| 1372 | | - suppress_history_add = .false. |
| 1373 | | - |
| 1374 | 1409 | ! Update button states now that history may have changed |
| 1375 | 1410 | call update_history_buttons() |
| 1376 | 1411 | end subroutine breadcrumb_callback |