feat: Ctrl+S save shortcut + enable/disable-all actions (#55) #59
@@ -23,6 +23,7 @@ from PySide6.QtGui import (
|
||||
QDesktopServices,
|
||||
QGuiApplication,
|
||||
QIcon,
|
||||
QKeySequence,
|
||||
QPainter,
|
||||
QPixmap,
|
||||
)
|
||||
@@ -1686,11 +1687,21 @@ class MainWindow(QMainWindow):
|
||||
head.setObjectName("h1")
|
||||
v.addWidget(head)
|
||||
|
||||
search_row = QHBoxLayout()
|
||||
self.search_box = QLineEdit()
|
||||
self.search_box.setPlaceholderText("Search servers by name, command, or url…")
|
||||
self.search_box.setClearButtonEnabled(True)
|
||||
self.search_box.textChanged.connect(self._on_search_changed)
|
||||
v.addWidget(self.search_box)
|
||||
search_row.addWidget(self.search_box, 1)
|
||||
self.enable_all_btn = QPushButton("All on")
|
||||
self.enable_all_btn.setToolTip("Enable every server")
|
||||
self.enable_all_btn.clicked.connect(lambda: self._set_all_enabled(True))
|
||||
search_row.addWidget(self.enable_all_btn)
|
||||
self.disable_all_btn = QPushButton("All off")
|
||||
self.disable_all_btn.setToolTip("Disable every server")
|
||||
self.disable_all_btn.clicked.connect(lambda: self._set_all_enabled(False))
|
||||
search_row.addWidget(self.disable_all_btn)
|
||||
v.addLayout(search_row)
|
||||
|
||||
# Active and Disabled sections live in a vertical splitter so the user
|
||||
# can drag the divider instead of being stuck with a fixed-height
|
||||
@@ -1774,6 +1785,12 @@ class MainWindow(QMainWindow):
|
||||
undo_action.setShortcut("Ctrl+Z")
|
||||
undo_action.triggered.connect(self._undo)
|
||||
self.addAction(undo_action)
|
||||
# Ctrl+S / Cmd+S shortcut — routed through a guard so it respects
|
||||
# the same dirty/validation gating as the Save button.
|
||||
save_action = QAction(self)
|
||||
save_action.setShortcut(QKeySequence.StandardKey.Save)
|
||||
save_action.triggered.connect(self._save_shortcut)
|
||||
self.addAction(save_action)
|
||||
bar.addStretch()
|
||||
self.validation_lbl = QLabel("")
|
||||
bar.addWidget(self.validation_lbl)
|
||||
@@ -1800,6 +1817,19 @@ class MainWindow(QMainWindow):
|
||||
self._mark_dirty()
|
||||
self.status.setText("Undone.")
|
||||
|
||||
def _set_all_enabled(self, enabled: bool):
|
||||
"""Flip every server's enabled flag in one step (one undo snapshot)."""
|
||||
if not self.servers or all(s.enabled == enabled for s in self.servers):
|
||||
return # nothing to change
|
||||
cur = self._current_index()
|
||||
self._push_undo()
|
||||
for s in self.servers:
|
||||
s.enabled = enabled
|
||||
sel = cur if 0 <= cur < len(self.servers) else None
|
||||
self._refresh_tables(select_index=sel)
|
||||
self._mark_dirty()
|
||||
self.status.setText("All servers enabled." if enabled else "All servers disabled.")
|
||||
|
||||
# --- profiles -------------------------------------------------------- #
|
||||
def reload_profiles(self):
|
||||
discovered = core.discover_profiles()
|
||||
@@ -2314,6 +2344,13 @@ class MainWindow(QMainWindow):
|
||||
self.save_btn.setEnabled(self.dirty)
|
||||
return True
|
||||
|
||||
def _save_shortcut(self):
|
||||
"""Ctrl+S / Cmd+S handler — only fires when the Save button itself
|
||||
would accept a click, so the shortcut can't bypass validation/dirty
|
||||
gating."""
|
||||
if self.save_btn.isEnabled():
|
||||
self.save()
|
||||
|
||||
def save(self):
|
||||
if not self.current_profile:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user