Skip to content

Commit

Permalink
Extract/rename methods for custom properties
Browse files Browse the repository at this point in the history
  • Loading branch information
gkarsay committed Dec 6, 2021
1 parent 37ccf4d commit 9610de0
Showing 1 changed file with 31 additions and 18 deletions.
49 changes: 31 additions & 18 deletions extension/python/components/Parlatype.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,28 @@ def disposing(self, source):
pass


def get_link_url(doc):
def removeDocumentLink(doc):
'''Remove custom document property "Parlatype".'''
doc_prop = doc.getDocumentProperties()
doc_uprop = doc_prop.getUserDefinedProperties()
doc_uprop.removeProperty('Parlatype')


def setDocumentLink(doc, link):
'''Create custom document property "Parlatype", if it doesn't exist,
and set its value.'''
doc_prop = doc.getDocumentProperties()
doc_uprop = doc_prop.getUserDefinedProperties()
set = doc_uprop.getPropertySetInfo()
if set.hasPropertyByName('Parlatype') is False:
doc_uprop.addProperty('Parlatype',
MAYBEVOID + BOUND + REMOVEABLE,
"") # default value
doc_uprop.setPropertyValue('Parlatype', link)


def getDocumentLink(doc):
'''Get value of custom document property "Parlatype".'''
doc_prop = doc.getDocumentProperties()
doc_uprop = doc_prop.getUserDefinedProperties()
set = doc_uprop.getPropertySetInfo()
Expand Down Expand Up @@ -198,8 +219,8 @@ def openParlatype(ctx):
desktop = smgr.createInstanceWithContext(
"com.sun.star.frame.Desktop", ctx)
doc = desktop.getCurrentComponent()
url = get_link_url(doc)
if url is not None:
url = getDocumentLink(doc)
if url is not None and len(url) > 0:
cmdline.append(url)

try:
Expand Down Expand Up @@ -308,9 +329,7 @@ def setLinkedStatus(self, status):
def unlinkMedia(self):
try:
doc = self.desktop.getCurrentComponent()
doc_prop = doc.getDocumentProperties()
doc_uprop = doc_prop.getUserDefinedProperties()
doc_uprop.removeProperty('Parlatype')
removeDokumentLink(doc)
self.linked = False
return True
except Exception as e:
Expand All @@ -320,12 +339,9 @@ def unlinkMedia(self):

def linkMedia(self):
doc = self.desktop.getCurrentComponent()
doc_prop = doc.getDocumentProperties()
doc_uprop = doc_prop.getUserDefinedProperties()
set = doc_uprop.getPropertySetInfo()
if set.hasPropertyByName('Parlatype'):
showMessage(self.ctx, "Already linked to {}.".format(
doc_uprop.getPropertyValue()))
previous = getDocumentLink(doc)
if previous is not None and len(previous) > 0:
showMessage(self.ctx, "Already linked to {}.".format(previous))
return

try:
Expand All @@ -344,10 +360,7 @@ def linkMedia(self):
showMessage(self.ctx, _("Please open a media file first."))
return

doc_uprop.addProperty('Parlatype',
MAYBEVOID + BOUND + REMOVEABLE,
"") # default value
doc_uprop.setPropertyValue('Parlatype', media)
setDocumentLink(doc, media)
self.linked = True

def link(self):
Expand Down Expand Up @@ -489,8 +502,8 @@ def updateLinkButton(self):
desktop = smgr.createInstanceWithContext(
"com.sun.star.frame.Desktop", self.ctx)
doc = desktop.getCurrentComponent()
url = get_link_url(doc)
if url is None:
url = getDocumentLink(doc)
if url is None or len(url) == 0:
self.pt.setLinkedStatus(False)
self.pt.deactivateTimestampScanner()
self.status = False
Expand Down

0 comments on commit 9610de0

Please sign in to comment.