Skip to content

Commit

Permalink
Set commandOperations api for commands menu
Browse files Browse the repository at this point in the history
  • Loading branch information
zkovari committed Jun 4, 2024
1 parent cff92f8 commit 58f1641
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions qttextedit/api.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from enum import Enum
from typing import Dict, Optional, Any, Type
from typing import Dict, Optional, Any, Type, List

import qtanim
import qtawesome
Expand Down Expand Up @@ -128,6 +128,13 @@ def __init__(self, parent=None):
self._blockFormatMenu.addAction(
q_action('Delete', qta_icon('fa5s.trash-alt'), lambda: self._deleteBlock(self._blockFormatPosition)))

self._commandActions = [Heading1Operation, Heading2Operation, Heading3Operation, InsertListOperation,
InsertNumberedListOperation, InsertTableOperation, InsertDividerOperation,
InsertGrayBannerOperation,
InsertRedBannerOperation,
InsertBlueBannerOperation, InsertGreenBannerOperation, InsertYellowBannerOperation,
InsertPurpleBannerOperation]

self.document().setDocumentMargin(40)

self._adjustTabDistance()
Expand Down Expand Up @@ -178,6 +185,10 @@ def setCommandsEnabled(self, value: bool):
def setDocumentMargin(self, value: int):
self.document().setDocumentMargin(value)

def setCommandOperations(self, operations: List[Type[TextEditorOperation]]):
self._commandActions.clear()
self._commandActions.extend(operations)

def createEnhancedContextMenu(self, pos: QPoint) -> MenuWidget:
menu = MenuWidget()
menu.addSeparator()
Expand Down Expand Up @@ -758,12 +769,7 @@ def cleanUp():
rect = self.cursorRect()

menu = MenuWidget()
for op_clazz in [Heading1Operation, Heading2Operation, Heading3Operation, InsertListOperation,
InsertNumberedListOperation, InsertTableOperation, InsertDividerOperation,
InsertGrayBannerOperation,
InsertRedBannerOperation,
InsertBlueBannerOperation, InsertGreenBannerOperation, InsertYellowBannerOperation,
InsertPurpleBannerOperation]:
for op_clazz in self._commandActions:
action = op_clazz(menu)
action.activateOperation(self)
menu.addAction(action)
Expand Down

0 comments on commit 58f1641

Please sign in to comment.