Fix history pane, some small cleanups
This commit is contained in:
parent
f023224074
commit
ab1af80d10
12 changed files with 47 additions and 114 deletions
|
|
@ -427,29 +427,6 @@ class DBManager:
|
|||
cur.execute("SELECT sqlcipher_export('backup')")
|
||||
cur.execute("DETACH DATABASE backup")
|
||||
|
||||
def export_by_extension(self, file_path: str) -> None:
|
||||
"""
|
||||
Fallback catch-all that runs one of the above functions based on
|
||||
the extension of the file name that was chosen by the user.
|
||||
"""
|
||||
entries = self.get_all_entries()
|
||||
ext = os.path.splitext(file_path)[1].lower()
|
||||
|
||||
if ext == ".json":
|
||||
self.export_json(entries, file_path)
|
||||
elif ext == ".csv":
|
||||
self.export_csv(entries, file_path)
|
||||
elif ext == ".txt":
|
||||
self.export_txt(entries, file_path)
|
||||
elif ext in {".html", ".htm"}:
|
||||
self.export_html(entries, file_path)
|
||||
elif ext in {".sql", ".sqlite"}:
|
||||
self.export_sql(file_path)
|
||||
elif ext == ".md":
|
||||
self.export_markdown(entries, file_path)
|
||||
else:
|
||||
raise ValueError(f"Unsupported extension: {ext}")
|
||||
|
||||
def compact(self) -> None:
|
||||
"""
|
||||
Runs VACUUM on the db.
|
||||
|
|
|
|||
|
|
@ -21,9 +21,8 @@ from PySide6.QtWidgets import (
|
|||
class FindBar(QWidget):
|
||||
"""Widget for finding text in the Editor"""
|
||||
|
||||
closed = (
|
||||
Signal()
|
||||
) # emitted when the bar is hidden (Esc/✕), so caller can refocus editor
|
||||
# emitted when the bar is hidden (Esc/✕), so caller can refocus editor
|
||||
closed = Signal()
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
|
|
@ -45,7 +44,7 @@ class FindBar(QWidget):
|
|||
layout.addWidget(QLabel("Find:"))
|
||||
|
||||
self.edit = QLineEdit(self)
|
||||
self.edit.setPlaceholderText("Type to search…")
|
||||
self.edit.setPlaceholderText("Type to search")
|
||||
layout.addWidget(self.edit)
|
||||
|
||||
self.case = QCheckBox("Match case", self)
|
||||
|
|
@ -79,7 +78,7 @@ class FindBar(QWidget):
|
|||
|
||||
@property
|
||||
def editor(self) -> QTextEdit | None:
|
||||
"""Get the current editor (no side effects)."""
|
||||
"""Get the current editor"""
|
||||
return self._editor_getter()
|
||||
|
||||
# ----- Public API -----
|
||||
|
|
|
|||
|
|
@ -118,9 +118,9 @@ class HistoryDialog(QDialog):
|
|||
return local.strftime("%Y-%m-%d %H:%M:%S %Z")
|
||||
|
||||
def _load_versions(self):
|
||||
self._versions = self._db.list_versions(
|
||||
self._date
|
||||
) # [{id,version_no,created_at,note,is_current}]
|
||||
# [{id,version_no,created_at,note,is_current}]
|
||||
self._versions = self._db.list_versions(self._date)
|
||||
|
||||
self._current_id = next(
|
||||
(v["id"] for v in self._versions if v["is_current"]), None
|
||||
)
|
||||
|
|
@ -152,13 +152,8 @@ class HistoryDialog(QDialog):
|
|||
self.btn_revert.setEnabled(False)
|
||||
return
|
||||
sel_id = item.data(Qt.UserRole)
|
||||
# Preview selected as plain text (markdown)
|
||||
sel = self._db.get_version(version_id=sel_id)
|
||||
# Show markdown as plain text with monospace font for better readability
|
||||
self.preview.setPlainText(sel["content"])
|
||||
self.preview.setStyleSheet(
|
||||
"font-family: Consolas, Menlo, Monaco, monospace; font-size: 13px;"
|
||||
)
|
||||
self.preview.setMarkdown(sel["content"])
|
||||
# Diff vs current (textual diff)
|
||||
cur = self._db.get_version(version_id=self._current_id)
|
||||
self.diff.setHtml(_colored_unified_diff_html(cur["content"], sel["content"]))
|
||||
|
|
|
|||
|
|
@ -808,7 +808,7 @@ class MainWindow(QMainWindow):
|
|||
def _adjust_today(self):
|
||||
"""Jump to today."""
|
||||
today = QDate.currentDate()
|
||||
self.calendar.setSelectedDate(today)
|
||||
self._create_new_tab(today)
|
||||
|
||||
def _load_yesterday_todos(self):
|
||||
try:
|
||||
|
|
@ -1090,7 +1090,7 @@ If you want an encrypted backup, choose Backup instead of Export.
|
|||
elif selected_filter.startswith("SQL"):
|
||||
self.db.export_sql(filename)
|
||||
else:
|
||||
self.db.export_by_extension(filename)
|
||||
raise ValueError("Unrecognised extension!")
|
||||
|
||||
QMessageBox.information(self, "Export complete", f"Saved to:\n{filename}")
|
||||
except Exception as e:
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ class MarkdownHighlighter(QSyntaxHighlighter):
|
|||
self.setCurrentBlockState(1 if in_code_block else 0)
|
||||
# Format the fence markers - but keep them somewhat visible for editing
|
||||
# Use code format instead of syntax format so cursor is visible
|
||||
self.setFormat(0, len(text), self.code_block_format)
|
||||
self.setFormat(0, len(text), self.code_format)
|
||||
return
|
||||
|
||||
if in_code_block:
|
||||
|
|
@ -258,13 +258,13 @@ class MarkdownEditor(QTextEdit):
|
|||
|
||||
# Transform only this line:
|
||||
# - "TODO " at start (with optional indent) -> "- ☐ "
|
||||
# - "- [ ] " -> "- ☐ " and "- [x] " -> "- ☑ "
|
||||
# - "- [ ] " -> " ☐ " and "- [x] " -> " ☑ "
|
||||
def transform_line(s: str) -> str:
|
||||
s = s.replace("- [x] ", f"- {self._CHECK_CHECKED_DISPLAY} ")
|
||||
s = s.replace("- [ ] ", f"- {self._CHECK_UNCHECKED_DISPLAY} ")
|
||||
s = s.replace("- [x] ", f"{self._CHECK_CHECKED_DISPLAY} ")
|
||||
s = s.replace("- [ ] ", f"{self._CHECK_UNCHECKED_DISPLAY} ")
|
||||
s = re.sub(
|
||||
r"^([ \t]*)TODO\b[:\-]?\s+",
|
||||
lambda m: f"{m.group(1)}- {self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
lambda m: f"{m.group(1)}\n{self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
s,
|
||||
)
|
||||
return s
|
||||
|
|
@ -293,8 +293,8 @@ class MarkdownEditor(QTextEdit):
|
|||
text = self._extract_images_to_markdown()
|
||||
|
||||
# Convert Unicode checkboxes back to markdown syntax
|
||||
text = text.replace(f"- {self._CHECK_CHECKED_DISPLAY} ", "- [x] ")
|
||||
text = text.replace(f"- {self._CHECK_UNCHECKED_DISPLAY} ", "- [ ] ")
|
||||
text = text.replace(f"{self._CHECK_CHECKED_DISPLAY} ", "- [x] ")
|
||||
text = text.replace(f"{self._CHECK_UNCHECKED_DISPLAY} ", "- [ ] ")
|
||||
|
||||
return text
|
||||
|
||||
|
|
@ -336,15 +336,15 @@ class MarkdownEditor(QTextEdit):
|
|||
"""Load markdown text into the editor (convert markdown checkboxes to Unicode)."""
|
||||
# Convert markdown checkboxes to Unicode for display
|
||||
display_text = markdown_text.replace(
|
||||
"- [x] ", f"- {self._CHECK_CHECKED_DISPLAY} "
|
||||
"- [x] ", f"{self._CHECK_CHECKED_DISPLAY} "
|
||||
)
|
||||
display_text = display_text.replace(
|
||||
"- [ ] ", f"- {self._CHECK_UNCHECKED_DISPLAY} "
|
||||
"- [ ] ", f"{self._CHECK_UNCHECKED_DISPLAY} "
|
||||
)
|
||||
# Also convert any plain 'TODO ' at the start of a line to an unchecked checkbox
|
||||
display_text = re.sub(
|
||||
r"(?m)^([ \t]*)TODO\s",
|
||||
lambda m: f"{m.group(1)}- {self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
lambda m: f"{m.group(1)}\n{self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
display_text,
|
||||
)
|
||||
|
||||
|
|
@ -425,10 +425,10 @@ class MarkdownEditor(QTextEdit):
|
|||
line = line.lstrip()
|
||||
|
||||
# Checkbox list (Unicode display format)
|
||||
if line.startswith(f"- {self._CHECK_UNCHECKED_DISPLAY} ") or line.startswith(
|
||||
f"- {self._CHECK_CHECKED_DISPLAY} "
|
||||
if line.startswith(f"{self._CHECK_UNCHECKED_DISPLAY} ") or line.startswith(
|
||||
f"{self._CHECK_CHECKED_DISPLAY} "
|
||||
):
|
||||
return ("checkbox", f"- {self._CHECK_UNCHECKED_DISPLAY} ")
|
||||
return ("checkbox", f"{self._CHECK_UNCHECKED_DISPLAY} ")
|
||||
|
||||
# Bullet list
|
||||
if re.match(r"^[-*+]\s", line):
|
||||
|
|
@ -533,19 +533,19 @@ class MarkdownEditor(QTextEdit):
|
|||
|
||||
# Check if clicking on a checkbox line
|
||||
if (
|
||||
f"- {self._CHECK_UNCHECKED_DISPLAY} " in line
|
||||
or f"- {self._CHECK_CHECKED_DISPLAY} " in line
|
||||
f"{self._CHECK_UNCHECKED_DISPLAY} " in line
|
||||
or f"{self._CHECK_CHECKED_DISPLAY} " in line
|
||||
):
|
||||
# Toggle the checkbox
|
||||
if f"- {self._CHECK_UNCHECKED_DISPLAY} " in line:
|
||||
if f"{self._CHECK_UNCHECKED_DISPLAY} " in line:
|
||||
new_line = line.replace(
|
||||
f"- {self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
f"- {self._CHECK_CHECKED_DISPLAY} ",
|
||||
f"{self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
f"{self._CHECK_CHECKED_DISPLAY} ",
|
||||
)
|
||||
else:
|
||||
new_line = line.replace(
|
||||
f"- {self._CHECK_CHECKED_DISPLAY} ",
|
||||
f"- {self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
f"{self._CHECK_CHECKED_DISPLAY} ",
|
||||
f"{self._CHECK_UNCHECKED_DISPLAY} ",
|
||||
)
|
||||
|
||||
cursor.insertText(new_line)
|
||||
|
|
@ -745,18 +745,18 @@ class MarkdownEditor(QTextEdit):
|
|||
|
||||
# Check if already has checkbox (Unicode display format)
|
||||
if (
|
||||
f"- {self._CHECK_UNCHECKED_DISPLAY} " in line
|
||||
or f"- {self._CHECK_CHECKED_DISPLAY} " in line
|
||||
f"{self._CHECK_UNCHECKED_DISPLAY} " in line
|
||||
or f"{self._CHECK_CHECKED_DISPLAY} " in line
|
||||
):
|
||||
# Remove checkbox - use raw string to avoid escape sequence warning
|
||||
new_line = re.sub(
|
||||
rf"^\s*-\s*[{self._CHECK_UNCHECKED_DISPLAY}{self._CHECK_CHECKED_DISPLAY}]\s+",
|
||||
rf"^\s*[{self._CHECK_UNCHECKED_DISPLAY}{self._CHECK_CHECKED_DISPLAY}]\s+",
|
||||
"",
|
||||
line,
|
||||
)
|
||||
else:
|
||||
# Add checkbox (Unicode display format)
|
||||
new_line = f"- {self._CHECK_UNCHECKED_DISPLAY} " + line.lstrip()
|
||||
new_line = f"{self._CHECK_UNCHECKED_DISPLAY} " + line.lstrip()
|
||||
|
||||
cursor.insertText(new_line)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue