Skip to content

Commit

Permalink
UX improvements, closes #5, #6, #7, #8.
Browse files Browse the repository at this point in the history
  • Loading branch information
artfwo committed Mar 18, 2014
1 parent 9c2f888 commit 25d502f
Show file tree
Hide file tree
Showing 10 changed files with 112 additions and 24 deletions.
27 changes: 27 additions & 0 deletions Accelerators.xcu
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<oor:component-data xmlns:oor="http://openoffice.org/2001/registry" xmlns:xs="http://www.w3.org/2001/XMLSchema" oor:name="Accelerators" oor:package="org.openoffice.Office">
<node oor:name="PrimaryKeys">
<node oor:name="Modules">
<!--
Writer
-->
<node oor:name="com.sun.star.text.TextDocument">
<node oor:name="V_MOD2_MOD1" oor:op="replace">
<prop oor:name="Command">
<value xml:lang="en-US">service:se.commonsmachinery.extensions.paste_with_credit.PasteWithCreditJob?execute</value>
</prop>
</node>
</node>
<!--
Impress
-->
<node oor:name="com.sun.star.presentation.PresentationDocument">
<node oor:name="V_MOD2_MOD1" oor:op="replace">
<prop oor:name="Command">
<value xml:lang="en-US">service:se.commonsmachinery.extensions.paste_with_credit.PasteWithCreditJob?execute</value>
</prop>
</node>
</node>
</node>
</node>
</oor:component-data>
26 changes: 22 additions & 4 deletions Addons.xcu
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<value>service:se.commonsmachinery.extensions.paste_with_credit.PasteWithCreditJob?execute</value>
</prop>
<prop oor:name="Title">
<value xml:lang="en">Paste with credit</value>
<value xml:lang="en">Paste with credits</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.text.TextDocument</value>
Expand Down Expand Up @@ -54,7 +54,7 @@
<value>service:se.commonsmachinery.extensions.paste_with_credit.PasteWithCreditJob?execute</value>
</prop>
<prop oor:name="Title">
<value xml:lang="en">Paste with credit</value>
<value xml:lang="en">Paste with credits</value>
</prop>
<prop oor:name="Context" oor:type="xs:string">
<value>com.sun.star.presentation.PresentationDocument</value>
Expand Down Expand Up @@ -120,7 +120,7 @@
<value>service:se.commonsmachinery.extensions.paste_with_credit.PasteWithCreditJob?execute</value>
</prop>
<prop oor:name="Title">
<value>Paste with credit</value>
<value>Paste with credits</value>
</prop>
</node>
</node>
Expand Down Expand Up @@ -148,12 +148,30 @@
<value>service:se.commonsmachinery.extensions.paste_with_credit.PasteWithCreditJob?execute</value>
</prop>
<prop oor:name="Title">
<value>Paste with credit</value>
<value>Paste with credits</value>
</prop>
</node>
</node>
</node>
</node>
</node>
<!--
Images
-->
<node oor:name="Images">
<node oor:name="se.commonsmachinery.extensions.paste_with_credit.image1" oor:op="replace">
<prop oor:name="URL">
<value>service:se.commonsmachinery.extensions.paste_with_credit.PasteWithCreditJob?execute</value>
</prop>
<node oor:name="UserDefinedImages">
<prop oor:name="ImageSmallURL" oor:type="xs:string">
<value>%origin%/icons/icon_16.png</value>
</prop>
<prop oor:name="ImageBigURL" oor:type="xs:string">
<value>%origin%/icons/icon_24.png</value>
</prop>
</node>
</node>
</node>
</node>
</oor:component-data>
2 changes: 2 additions & 0 deletions META-INF/manifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@
manifest:full-path ="Jobs.xcu"/>
<manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
manifest:full-path ="ProtocolHandler.xcu"/>
<manifest:file-entry manifest:media-type="application/vnd.sun.star.configuration-data"
manifest:full-path ="Accelerators.xcu"/>
</manifest:manifest>
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ SOURCES = \
Addons.xcu \
Jobs.xcu \
ProtocolHandler.xcu \
Accelerators.xcu \
cm-paste.py

ADDITIONAL_PATHS = pythonpath
ADDITIONAL_PATHS = pythonpath icons

EXTENSION = paste_with_credit.oxt

Expand Down
21 changes: 15 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@ Installation
Usage
-----

To paste an image and automatically add credit data:
To paste an image and automatically add credits:

1. Copy an image with metadata from Firefox.
2. Paste via "Edit->Paste with credit".
1. Copy an image with credits from Firefox.
2. Paste via "Edit->Paste with credits" or click "Paste with credits" button
next to the regular Paste button on the toolbar.

To copy image with credit metadata back to clipboard:
Note: Credits won't show in Impress, see below for how to make them visible.

To copy image with credit metadata back to clipboard (Writer-only):

1. Right-click the image.
2. Choose "Copy with metadata"
2. Choose "Copy with credits"

To generate a credits block in Impress:

1. Paste one or more images using "Edit->Paste with credit"
1. Paste one or more images using "Edit->Paste with credits"
2. Choose "Insert->Credits" from the main menu.

License
Expand All @@ -41,6 +44,12 @@ Author(s): Artem Popov <[email protected]>,

Distributed under an GPLv2 license, please see the LICENSE file for details.

Icon by Ilsur Aptukov from The Noun Project
Published at http://www.thenounproject.com/term/clipboard/28307/
Licensed under Creative Commons Attribution 3.0 license
for more information see http://creativecommons.org/licenses/by/3.0/us/


Bundled libraries
-----------------

Expand Down
53 changes: 42 additions & 11 deletions cm-paste.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from com.sun.star.ui import XContextMenuInterceptor
from com.sun.star.ui.ContextMenuInterceptorAction import IGNORED
from com.sun.star.ui.ContextMenuInterceptorAction import EXECUTE_MODIFIED
from com.sun.star.ui.ContextMenuInterceptorAction import CONTINUE_MODIFIED

from com.sun.star.text.ControlCharacter import PARAGRAPH_BREAK
from com.sun.star.text.TextContentAnchorType import AS_CHARACTER
Expand Down Expand Up @@ -565,30 +566,57 @@ class ContextInterceptor(unohelper.Base, XContextMenuInterceptor):
def __init__ (self, ctx):
self.ctx = ctx

def notifyContextMenuExecute (self, event):
def notifyContextMenuExecute(self, event):
menu = event.ActionTriggerContainer
selection = event.Selection.getSelection()
controller = event.Selection
selection = controller.getSelection()
model = controller.getModel()
menu_items = []

# Impress document controller shows up as com.sun.star.drawing.DrawingDocumentDrawView,
# so we rely on the model to get the idea of current document type
canPasteText = model.supportsService("com.sun.star.text.TextDocument") and \
selection.supportsService("com.sun.star.text.TextRanges")
canPastePresentation = model.supportsService("com.sun.star.presentation.PresentationDocument")

if canPasteText or canPastePresentation:
clip = self.ctx.ServiceManager.createInstanceWithContext(
"com.sun.star.datatransfer.clipboard.SystemClipboard", self.ctx)
mimeTypes = [d.MimeType for d in clip.getContents().getTransferDataFlavors()]

if "image/png" in mimeTypes and "application/rdf+xml" in mimeTypes:
item = menu.createInstance("com.sun.star.ui.ActionTrigger")
item.setPropertyValue("Text", "Paste with credits")
item.setPropertyValue("CommandURL", u"se.commonsmachinery.extensions.paste_with_credit.Menu:PasteWithCredit")
menu_items.append(item)

if selection.supportsService("com.sun.star.text.TextGraphicObject"):
# selection can be None in Draw and Impress sometimes
if selection is not None and \
selection.supportsService("com.sun.star.text.TextGraphicObject"):
# TextGraphicObject implicitly supports XNamed
# (not shown in the supported service names)
img_name = selection.getName()

if img_name.startswith("$metadata-tag-do-not-edit$"):
num_items = menu.Count
item = menu.createInstance("com.sun.star.ui.ActionTrigger")
item.setPropertyValue("Text", "Copy with credits")
item.setPropertyValue("CommandURL", u"se.commonsmachinery.extensions.paste_with_credit.Menu:CopyWithMetadata")
menu_items.append(item)

if len(menu_items) > 0:
item_count = menu.Count

if len(menu_items) > 1:
separator = menu.createInstance("com.sun.star.ui.ActionTriggerSeparator")
separator.SeparatorType = LINE
menu_items.insert(1, separator)
#menu.insertByIndex(item_count + 0, separator)

menu.insertByIndex(num_items + 0, separator)
for i, item in enumerate(menu_items, start=item_count):
menu.insertByIndex(i, item)

menu_item = menu.createInstance("com.sun.star.ui.ActionTrigger")
menu_item.setPropertyValue("Text", "Copy with metadata")
menu_item.setPropertyValue("CommandURL", u"se.commonsmachinery.extensions.paste_with_credit.Menu:CopyWithMetadata")
menu.insertByIndex(num_items + 1, menu_item)
return CONTINUE_MODIFIED

return EXECUTE_MODIFIED
# otherwise
return IGNORED


Expand Down Expand Up @@ -627,6 +655,9 @@ def dispatch(self, url, args):
if url.Path == "CopyWithMetadata":
job = CopyWithMetadataJob(self.ctx)
job.trigger(None)
elif url.Path == "PasteWithCredit":
job = PasteWithCreditJob(self.ctx)
job.trigger(None)

def addStatusListener(self, control, url):
pass
Expand Down
4 changes: 2 additions & 2 deletions description.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
xmlns:d="http://openoffice.org/extensions/description/2006"
xmlns:l="http://libreoffice.org/extensions/description/2011"
xmlns:xlink="http://www.w3.org/1999/xlink">
<version value="0.3"/>
<version value="0.3.5"/>
<identifier value="se.commonsmachinery.extensions.paste_with_credit"/>
<platform value="all"/>
<dependencies>
<OpenOffice.org-minimal-version value="3.3" d:name="OpenOffice.org 3.3"/>
</dependencies>
<display-name>
<name lang="en">Paste with credit</name>
<name lang="en">Paste with credits</name>
</display-name>
</description>
Binary file added icons/icon_16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added icons/icon_24.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified paste_with_credit.oxt
Binary file not shown.

0 comments on commit 25d502f

Please sign in to comment.