|
17 | 17 | import sys
|
18 | 18 | import time
|
19 | 19 | from pathlib import Path
|
| 20 | +from platform import system |
20 | 21 | from queue import Queue
|
21 | 22 | from warnings import catch_warnings
|
22 | 23 |
|
|
97 | 98 | from tagstudio.qt.widgets.panel import PanelModal
|
98 | 99 | from tagstudio.qt.widgets.preview_panel import PreviewPanel
|
99 | 100 | from tagstudio.qt.widgets.progress import ProgressWidget
|
| 101 | +from tagstudio.qt.widgets.thumb_button import ThumbButton |
100 | 102 | from tagstudio.qt.widgets.thumb_renderer import ThumbRenderer
|
101 | 103 |
|
102 | 104 | BADGE_TAGS = {
|
@@ -406,6 +408,21 @@ def start(self) -> None:
|
406 | 408 | file_menu.addAction(self.refresh_dir_action)
|
407 | 409 | file_menu.addSeparator()
|
408 | 410 |
|
| 411 | + self.open_selected_action = QAction(Translations["file.open_files.title.plural"], self) |
| 412 | + self.open_selected_action.triggered.connect(self.open_selected_files) |
| 413 | + if system() == "Darwin": |
| 414 | + shortcut: QtCore.QKeyCombination | Qt.Key = QtCore.QKeyCombination( |
| 415 | + QtCore.Qt.KeyboardModifier(QtCore.Qt.KeyboardModifier.ControlModifier), |
| 416 | + QtCore.Qt.Key.Key_Down, |
| 417 | + ) |
| 418 | + else: |
| 419 | + shortcut = Qt.Key.Key_Return |
| 420 | + |
| 421 | + self.open_selected_action.setShortcut(shortcut) |
| 422 | + self.open_selected_action.setEnabled(False) |
| 423 | + file_menu.addAction(self.open_selected_action) |
| 424 | + file_menu.addSeparator() |
| 425 | + |
409 | 426 | self.close_library_action = QAction(Translations["menu.file.close_library"], menu_bar)
|
410 | 427 | self.close_library_action.triggered.connect(self.close_library)
|
411 | 428 | self.close_library_action.setEnabled(False)
|
@@ -1426,6 +1443,40 @@ def toggle_item_selection(self, item_id: int, append: bool, bridge: bool):
|
1426 | 1443 |
|
1427 | 1444 | self.preview_panel.update_widgets()
|
1428 | 1445 |
|
| 1446 | + def open_selected_files(self): |
| 1447 | + if not ( |
| 1448 | + QApplication.focusWidget() == self.main_window.scrollArea |
| 1449 | + or isinstance(QApplication.focusWidget(), ThumbButton) |
| 1450 | + ): |
| 1451 | + return |
| 1452 | + count = len(self.selected) |
| 1453 | + result = QMessageBox.ButtonRole.ActionRole |
| 1454 | + |
| 1455 | + if count >= 5: # Only confirm if we have lots of files |
| 1456 | + confirm_open = QMessageBox() |
| 1457 | + confirm_open.setText(Translations.format("file.open_files.warning", count=count)) |
| 1458 | + confirm_open.setWindowTitle(Translations["file.open_files.title"]) |
| 1459 | + confirm_open.setIcon(QMessageBox.Icon.Question) |
| 1460 | + |
| 1461 | + cancel_button = confirm_open.addButton( |
| 1462 | + Translations["generic.cancel_alt"], QMessageBox.ButtonRole.RejectRole |
| 1463 | + ) |
| 1464 | + confirm_open.setEscapeButton(cancel_button) |
| 1465 | + |
| 1466 | + open_button = confirm_open.addButton( |
| 1467 | + Translations["generic.open"], QMessageBox.ButtonRole.ActionRole |
| 1468 | + ) |
| 1469 | + confirm_open.setDefaultButton(open_button) |
| 1470 | + |
| 1471 | + result = QMessageBox.ButtonRole(confirm_open.exec()) |
| 1472 | + |
| 1473 | + if result == QMessageBox.ButtonRole.ActionRole: |
| 1474 | + opened = [] |
| 1475 | + for it in self.item_thumbs: |
| 1476 | + if it.item_id in self.selected and it.item_id not in opened: |
| 1477 | + it.opener.open_file() |
| 1478 | + opened.append(it.item_id) |
| 1479 | + |
1429 | 1480 | def set_macro_menu_viability(self):
|
1430 | 1481 | # self.autofill_action.setDisabled(not self.selected)
|
1431 | 1482 | pass
|
@@ -1453,11 +1504,20 @@ def set_select_actions_visibility(self):
|
1453 | 1504 | self.add_tag_to_selected_action.setEnabled(True)
|
1454 | 1505 | self.clear_select_action.setEnabled(True)
|
1455 | 1506 | self.delete_file_action.setEnabled(True)
|
| 1507 | + |
| 1508 | + self.open_selected_action.setEnabled(True) |
| 1509 | + if len(self.selected) == 1: |
| 1510 | + self.open_selected_action.setText(Translations["file.open_files.title.singular"]) |
| 1511 | + else: |
| 1512 | + self.open_selected_action.setText(Translations["file.open_files.title.plural"]) |
1456 | 1513 | else:
|
1457 | 1514 | self.add_tag_to_selected_action.setEnabled(False)
|
1458 | 1515 | self.clear_select_action.setEnabled(False)
|
1459 | 1516 | self.delete_file_action.setEnabled(False)
|
1460 | 1517 |
|
| 1518 | + self.open_selected_action.setEnabled(False) |
| 1519 | + self.open_selected_action.setText(Translations["file.open_files.title.plural"]) |
| 1520 | + |
1461 | 1521 | def update_completions_list(self, text: str) -> None:
|
1462 | 1522 | matches = re.search(
|
1463 | 1523 | r"((?:.* )?)(mediatype|filetype|path|tag|tag_id):(\"?[A-Za-z0-9\ \t]+\"?)?", text
|
|
0 commit comments