feat(context_menu_manager) Rewritten class CustomLineEdit for removing hotkeys from translations
This commit is contained in:
@ -10,7 +10,7 @@ import psutil
|
|||||||
import signal
|
import signal
|
||||||
from PySide6.QtWidgets import QMessageBox, QDialog, QMenu, QLineEdit, QApplication
|
from PySide6.QtWidgets import QMessageBox, QDialog, QMenu, QLineEdit, QApplication
|
||||||
from PySide6.QtCore import QUrl, QPoint, QObject, Signal, Qt
|
from PySide6.QtCore import QUrl, QPoint, QObject, Signal, Qt
|
||||||
from PySide6.QtGui import QDesktopServices, QIcon
|
from PySide6.QtGui import QDesktopServices, QIcon, QKeySequence
|
||||||
from portprotonqt.localization import _
|
from portprotonqt.localization import _
|
||||||
from portprotonqt.config_utils import parse_desktop_entry, read_favorites, save_favorites
|
from portprotonqt.config_utils import parse_desktop_entry, read_favorites, save_favorites
|
||||||
from portprotonqt.steam_api import is_game_in_steam, add_to_steam, remove_from_steam
|
from portprotonqt.steam_api import is_game_in_steam, add_to_steam, remove_from_steam
|
||||||
@ -1097,48 +1097,34 @@ class CustomLineEdit(QLineEdit):
|
|||||||
return QIcon(icon)
|
return QIcon(icon)
|
||||||
return QIcon()
|
return QIcon()
|
||||||
|
|
||||||
|
def add_action(text: str, shortcut: QKeySequence.StandardKey, icon_name: str, slot, enabled=True):
|
||||||
|
icon = get_safe_icon(icon_name)
|
||||||
|
shortcut_str = QKeySequence(shortcut).toString(QKeySequence.SequenceFormat.NativeText)
|
||||||
|
action_text = f"{text}\t{shortcut_str}"
|
||||||
|
action = menu.addAction(icon, action_text)
|
||||||
|
action.triggered.connect(slot)
|
||||||
|
action.setEnabled(enabled)
|
||||||
|
|
||||||
menu = QMenu(self)
|
menu = QMenu(self)
|
||||||
|
|
||||||
if self.theme and hasattr(self.theme, "CONTEXT_MENU_STYLE"):
|
if self.theme and hasattr(self.theme, "CONTEXT_MENU_STYLE"):
|
||||||
menu.setStyleSheet(self.theme.CONTEXT_MENU_STYLE)
|
menu.setStyleSheet(self.theme.CONTEXT_MENU_STYLE)
|
||||||
|
|
||||||
# Undo
|
add_action(_("Undo"), QKeySequence.StandardKey.Undo, "undo", self.undo, self.isUndoAvailable())
|
||||||
undo = menu.addAction(get_safe_icon("undo"), _("Undo\tCtrl+Z"))
|
add_action(_("Redo"), QKeySequence.StandardKey.Redo, "redo", self.redo, self.isRedoAvailable())
|
||||||
undo.triggered.connect(self.undo)
|
|
||||||
undo.setEnabled(self.isUndoAvailable())
|
|
||||||
|
|
||||||
# Redo
|
|
||||||
redo = menu.addAction(get_safe_icon("redo"), _("Redo\tCtrl+Y"))
|
|
||||||
redo.triggered.connect(self.redo)
|
|
||||||
redo.setEnabled(self.isRedoAvailable())
|
|
||||||
|
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
|
|
||||||
# Cut
|
add_action(_("Cut"), QKeySequence.StandardKey.Cut, "cut", self.cut, self.hasSelectedText())
|
||||||
cut = menu.addAction(get_safe_icon("cut"), _("Cut\tCtrl+X"))
|
add_action(_("Copy"), QKeySequence.StandardKey.Copy, "copy", self.copy, self.hasSelectedText())
|
||||||
cut.triggered.connect(self.cut)
|
add_action(_("Paste"), QKeySequence.StandardKey.Paste, "paste", self.paste,
|
||||||
cut.setEnabled(self.hasSelectedText())
|
QApplication.clipboard().mimeData().hasText())
|
||||||
|
add_action(_("Delete"), QKeySequence.StandardKey.Delete, "delete", self._delete_selected_text,
|
||||||
# Copy
|
self.hasSelectedText())
|
||||||
copy = menu.addAction(get_safe_icon("copy"), _("Copy\tCtrl+C"))
|
|
||||||
copy.triggered.connect(self.copy)
|
|
||||||
copy.setEnabled(self.hasSelectedText())
|
|
||||||
|
|
||||||
# Paste
|
|
||||||
paste = menu.addAction(get_safe_icon("paste"), _("Paste\tCtrl+V"))
|
|
||||||
paste.triggered.connect(self.paste)
|
|
||||||
paste.setEnabled(QApplication.clipboard().mimeData().hasText())
|
|
||||||
|
|
||||||
# Delete
|
|
||||||
delete = menu.addAction(get_safe_icon("delete"), _("Delete\tDel"))
|
|
||||||
delete.triggered.connect(self._delete_selected_text)
|
|
||||||
delete.setEnabled(self.hasSelectedText())
|
|
||||||
|
|
||||||
menu.addSeparator()
|
menu.addSeparator()
|
||||||
|
|
||||||
# Select All
|
add_action(_("Select All"), QKeySequence.StandardKey.SelectAll, "select_all", self.selectAll, bool(self.text()))
|
||||||
select_all = menu.addAction(get_safe_icon("select_all"), _("Select All\tCtrl+A"))
|
|
||||||
select_all.triggered.connect(self.selectAll)
|
|
||||||
select_all.setEnabled(bool(self.text()))
|
|
||||||
|
|
||||||
menu.exec(event.globalPos())
|
menu.exec(event.globalPos())
|
||||||
|
|
||||||
|
@ -109,7 +109,7 @@ CONTEXT_MENU_STYLE = f"""
|
|||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
}}
|
}}
|
||||||
QMenu::item {{
|
QMenu::item {{
|
||||||
padding: 8px 20px 8px 10px;
|
padding: 10px 20px 10px 10px;
|
||||||
background: {color_h};
|
background: {color_h};
|
||||||
border-radius: {border_radius_a};
|
border-radius: {border_radius_a};
|
||||||
color: {color_f};
|
color: {color_f};
|
||||||
@ -134,7 +134,7 @@ CONTEXT_MENU_STYLE = f"""
|
|||||||
QMenu::separator {{
|
QMenu::separator {{
|
||||||
height: 1px;
|
height: 1px;
|
||||||
background-color: #7f7f7f;
|
background-color: #7f7f7f;
|
||||||
margin: 4px 8px;
|
margin: 3px 6px;
|
||||||
}}
|
}}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user