For add files, have it remember last location after closing
This commit is contained in:
parent
7ef200c13a
commit
6a799a4be5
2 changed files with 47 additions and 5 deletions
|
|
@ -8,7 +8,7 @@ from PyQt5.QtWidgets import (
|
||||||
QPushButton, QLabel, QFileDialog, QMessageBox, QGroupBox,
|
QPushButton, QLabel, QFileDialog, QMessageBox, QGroupBox,
|
||||||
QSplitter, QTextEdit, QProgressBar, QCheckBox
|
QSplitter, QTextEdit, QProgressBar, QCheckBox
|
||||||
)
|
)
|
||||||
from PyQt5.QtCore import Qt, QThread, pyqtSignal
|
from PyQt5.QtCore import Qt, QThread, pyqtSignal, QSettings
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -19,6 +19,11 @@ class FileManager(QWidget):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
# Persistent settings for remembering last-open directory
|
||||||
|
try:
|
||||||
|
self.settings = QSettings("DazedTranslations", "DazedMTLTool")
|
||||||
|
except Exception:
|
||||||
|
self.settings = None
|
||||||
self.input_files = []
|
self.input_files = []
|
||||||
self.output_directory = Path("translated")
|
self.output_directory = Path("translated")
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
|
@ -168,16 +173,32 @@ class FileManager(QWidget):
|
||||||
|
|
||||||
def add_input_files(self):
|
def add_input_files(self):
|
||||||
"""Add input files via dialog."""
|
"""Add input files via dialog."""
|
||||||
|
# Try to restore last used directory
|
||||||
|
start_dir = ""
|
||||||
|
try:
|
||||||
|
if self.settings:
|
||||||
|
start_dir = self.settings.value("last_open_dir", "") or ""
|
||||||
|
except Exception:
|
||||||
|
start_dir = ""
|
||||||
|
|
||||||
files, _ = QFileDialog.getOpenFileNames(
|
files, _ = QFileDialog.getOpenFileNames(
|
||||||
self,
|
self,
|
||||||
"Select Input Files",
|
"Select Input Files",
|
||||||
"",
|
start_dir,
|
||||||
"JSON Files (*.json);;All Files (*)"
|
"JSON Files (*.json);;All Files (*)"
|
||||||
)
|
)
|
||||||
|
|
||||||
for file_path in files:
|
for file_path in files:
|
||||||
if file_path not in self.input_files:
|
if file_path not in self.input_files:
|
||||||
self.input_files.append(file_path)
|
self.input_files.append(file_path)
|
||||||
|
|
||||||
|
# Persist directory used
|
||||||
|
try:
|
||||||
|
if self.settings and len(files) > 0:
|
||||||
|
import os
|
||||||
|
self.settings.setValue("last_open_dir", os.path.dirname(files[0]))
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
self.refresh_input_files()
|
self.refresh_input_files()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ from PyQt5.QtWidgets import (
|
||||||
QSplitter, QFileDialog, QComboBox, QCheckBox, QProgressBar, QFrame, QFormLayout, QStackedWidget
|
QSplitter, QFileDialog, QComboBox, QCheckBox, QProgressBar, QFrame, QFormLayout, QStackedWidget
|
||||||
)
|
)
|
||||||
from PyQt5.QtWidgets import QSizePolicy
|
from PyQt5.QtWidgets import QSizePolicy
|
||||||
from PyQt5.QtCore import Qt, QTimer, pyqtSignal, QThread, QMutex, QProcess, QEvent, QRect
|
from PyQt5.QtCore import Qt, QTimer, pyqtSignal, QThread, QMutex, QProcess, QEvent, QRect, QSettings
|
||||||
from PyQt5.QtGui import QFont
|
from PyQt5.QtGui import QFont
|
||||||
from gui.log_viewer import LogViewer
|
from gui.log_viewer import LogViewer
|
||||||
|
|
||||||
|
|
@ -495,6 +495,11 @@ class TranslationTab(QWidget):
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
super().__init__(parent)
|
super().__init__(parent)
|
||||||
self.parent_window = parent
|
self.parent_window = parent
|
||||||
|
# Persistent settings (remember last directory used in file dialogs)
|
||||||
|
try:
|
||||||
|
self.settings = QSettings("DazedTranslations", "DazedMTLTool")
|
||||||
|
except Exception:
|
||||||
|
self.settings = None
|
||||||
self.translation_process = None
|
self.translation_process = None
|
||||||
self.log_buffer = [] # Buffer for batching log messages
|
self.log_buffer = [] # Buffer for batching log messages
|
||||||
self.log_timer = QTimer() # Timer for flushing log buffer
|
self.log_timer = QTimer() # Timer for flushing log buffer
|
||||||
|
|
@ -1193,15 +1198,31 @@ class TranslationTab(QWidget):
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
def add_input_files(self):
|
def add_input_files(self):
|
||||||
"""Add files to the input directory."""
|
"""Add files to the input directory, remembering last used directory."""
|
||||||
|
# Restore last used directory from settings if available
|
||||||
|
start_dir = ""
|
||||||
|
try:
|
||||||
|
if self.settings:
|
||||||
|
start_dir = self.settings.value("last_open_dir", "") or ""
|
||||||
|
except Exception:
|
||||||
|
start_dir = ""
|
||||||
|
|
||||||
file_paths, _ = QFileDialog.getOpenFileNames(
|
file_paths, _ = QFileDialog.getOpenFileNames(
|
||||||
self,
|
self,
|
||||||
"Select files to add",
|
"Select files to add",
|
||||||
"",
|
start_dir,
|
||||||
"All Files (*)"
|
"All Files (*)"
|
||||||
)
|
)
|
||||||
|
|
||||||
if file_paths:
|
if file_paths:
|
||||||
|
# Save the directory used so next time we open the same place
|
||||||
|
try:
|
||||||
|
if self.settings and len(file_paths) > 0:
|
||||||
|
import os
|
||||||
|
dir_used = os.path.dirname(file_paths[0])
|
||||||
|
self.settings.setValue("last_open_dir", dir_used)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
try:
|
try:
|
||||||
import shutil
|
import shutil
|
||||||
copied_count = 0
|
copied_count = 0
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue