Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -248,3 +248,5 @@ test_results/
# Keep docs/*.md and tests fixtures tracked; only ignore root-level files
/AGENTS.md
/*.txt
!CubeMain.txt
!CubeMainWorking.txt
2 changes: 2 additions & 0 deletions CubeMain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
col1 col2
1 2
2 changes: 2 additions & 0 deletions CubeMainWorking.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
col1 col2
1 2
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ Diablo2TextEditor/
- **UI Editor**: Full-featured graphical interface for editing game data
- **Format Validation**: Comprehensive file format verification
- **PDF Extraction**: Tools for extracting data from PDF documentation
- **Drag-and-Drop Loading**: Open any supported `.txt` file by simply dropping it onto the editor window

## Installation

Expand Down
5 changes: 3 additions & 2 deletions file_bindings.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class DataFileBinding:

def __init__(self, json_path: str, txt_path: str = None, metadata: Dict = None):
self.json_path = json_path
self.txt_path = txt_path
# Use an empty string for unbound txt paths so os.path functions don't error.
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment mentions 'os.path functions don't error' but this change affects the logic in load_data() method which checks for falsy values. The comment should clarify that this change enables consistent falsy checking rather than preventing os.path errors.

Suggested change
# Use an empty string for unbound txt paths so os.path functions don't error.
# Use an empty string for unbound txt paths to enable consistent falsy checking (e.g., in load_data()).

Copilot uses AI. Check for mistakes.
self.txt_path = txt_path or ""
self.metadata = metadata or {}
self.base_name = Path(json_path).stem

Expand All @@ -33,7 +34,7 @@ def load_metadata(self) -> Dict:

def load_data(self):
"""Load the actual data from the .txt file."""
if self.txt_path is None:
if not self.txt_path:
raise ValueError("No txt file path set for this binding. Use create_dynamic_binding() first.")
return open_txt_file(self.txt_path)

Expand Down
26 changes: 13 additions & 13 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,25 +662,25 @@ def _load_file_path(self, file_path: str):

# Drag-and-drop support
def dragEnterEvent(self, event):
"""Allow drag if payload contains at least one local .txt file."""
if event.mimeData().hasUrls():
# Accept if any of the URLs is a .txt file
for url in event.mimeData().urls():
if url.isLocalFile() and url.toLocalFile().lower().endswith('.txt'):
event.acceptProposedAction()
return
urls = event.mimeData().urls()
if any(u.isLocalFile() and u.toLocalFile().lower().endswith(".txt") for u in urls):
event.acceptProposedAction()
return
event.ignore()

def dragMoveEvent(self, event):
"""Continuously accept drags containing valid .txt files."""
self.dragEnterEvent(event)
Copy link

Copilot AI Aug 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The dragMoveEvent method calls dragEnterEvent for every mouse movement during a drag operation, which repeatedly validates the same URLs. Consider caching the validation result or implementing a more efficient approach that doesn't re-evaluate the URLs on every move event.

Copilot uses AI. Check for mistakes.

def dropEvent(self, event):
handled = False
"""Open the first dropped .txt file."""
for url in event.mimeData().urls():
local = url.toLocalFile()
if url.isLocalFile() and local.lower().endswith('.txt'):
self._load_file_path(local)
handled = True
# Load only first file for now
if url.isLocalFile() and url.toLocalFile().lower().endswith(".txt"):
self._load_file_path(url.toLocalFile())
event.acceptProposedAction()
break
if handled:
event.acceptProposedAction()
else:
event.ignore()

Expand Down
Loading