79 lines
3.7 KiB
Python
79 lines
3.7 KiB
Python
import os
|
|
import tkinter as tk
|
|
from cfd_app_config import LocaleStrings, _
|
|
|
|
class NavigationManager:
|
|
def __init__(self, dialog):
|
|
self.dialog = dialog
|
|
|
|
def handle_path_entry_return(self, event):
|
|
path_text = self.dialog.widget_manager.path_entry.get().strip()
|
|
potential_path = os.path.realpath(os.path.expanduser(path_text))
|
|
|
|
if os.path.isdir(potential_path):
|
|
self.navigate_to(potential_path)
|
|
elif os.path.isfile(potential_path):
|
|
directory = os.path.dirname(potential_path)
|
|
filename = os.path.basename(potential_path)
|
|
self.navigate_to(directory, file_to_select=filename)
|
|
else:
|
|
self.dialog.widget_manager.search_status_label.config(
|
|
text=f"{LocaleStrings.CFD['path_not_found']}: {self.dialog.shorten_text(path_text, 50)}")
|
|
|
|
def navigate_to(self, path, file_to_select=None):
|
|
try:
|
|
real_path = os.path.realpath(
|
|
os.path.abspath(os.path.expanduser(path)))
|
|
if not os.path.isdir(real_path):
|
|
self.dialog.widget_manager.search_status_label.config(
|
|
text=f"{LocaleStrings.CFD['error_title']}: {LocaleStrings.CFD['directory']} '{os.path.basename(path)}' {LocaleStrings.CFD['not_found']}")
|
|
return
|
|
if not os.access(real_path, os.R_OK):
|
|
self.dialog.widget_manager.search_status_label.config(
|
|
text=f"{LocaleStrings.CFD['access_to']} '{os.path.basename(path)}' {LocaleStrings.CFD['denied']}")
|
|
return
|
|
self.dialog.current_dir = real_path
|
|
if self.dialog.history_pos < len(self.dialog.history) - 1:
|
|
self.dialog.history = self.dialog.history[:self.dialog.history_pos + 1]
|
|
if not self.dialog.history or self.dialog.history[-1] != self.dialog.current_dir:
|
|
self.dialog.history.append(self.dialog.current_dir)
|
|
self.dialog.history_pos = len(self.dialog.history) - 1
|
|
|
|
self.dialog.widget_manager.search_animation.stop()
|
|
|
|
self.dialog.view_manager.populate_files(item_to_select=file_to_select)
|
|
self.update_nav_buttons()
|
|
self.dialog.update_status_bar()
|
|
self.dialog.update_action_buttons_state()
|
|
except Exception as e:
|
|
self.dialog.widget_manager.search_status_label.config(text=f"{LocaleStrings.CFD['error_title']}: {e}")
|
|
|
|
def go_back(self):
|
|
if self.dialog.history_pos > 0:
|
|
self.dialog.history_pos -= 1
|
|
self.dialog.current_dir = self.dialog.history[self.dialog.history_pos]
|
|
self.dialog.view_manager.populate_files()
|
|
self.update_nav_buttons()
|
|
self.dialog.update_status_bar()
|
|
self.dialog.update_action_buttons_state()
|
|
|
|
def go_forward(self):
|
|
if self.dialog.history_pos < len(self.dialog.history) - 1:
|
|
self.dialog.history_pos += 1
|
|
self.dialog.current_dir = self.dialog.history[self.dialog.history_pos]
|
|
self.dialog.view_manager.populate_files()
|
|
self.update_nav_buttons()
|
|
self.dialog.update_status_bar()
|
|
self.dialog.update_action_buttons_state()
|
|
|
|
def go_up_level(self):
|
|
new_path = os.path.dirname(self.dialog.current_dir)
|
|
if new_path != self.dialog.current_dir:
|
|
self.navigate_to(new_path)
|
|
|
|
def update_nav_buttons(self):
|
|
self.dialog.widget_manager.back_button.config(
|
|
state=tk.NORMAL if self.dialog.history_pos > 0 else tk.DISABLED)
|
|
self.dialog.widget_manager.forward_button.config(state=tk.NORMAL if self.dialog.history_pos < len(
|
|
self.dialog.history) - 1 else tk.DISABLED)
|