3f04ba7dd4
Merge pull request !926 from 杨辉庆/master |
||
---|---|---|
.gitee | ||
adapter | ||
etc/init | ||
figures | ||
framework | ||
interfaces | ||
profile | ||
services | ||
test/fuzztest | ||
utils/native/include | ||
.gitattributes | ||
.gitignore | ||
BUILD.gn | ||
bundle.json | ||
CODEOWNERS | ||
LICENSE | ||
OAT.xml | ||
pasteboard.gni | ||
pasteboardEvent.yaml | ||
README_ZH.md | ||
README.md |
pasteBoardService
Introduction
As a functional component of the stray subsystem, the clipboard service provides the ability to manage the system clipboard and supports the system copy and paste functions. The system clipboard supports package text, hypertext, URIs and other content operations.
picture 1 Subsystem Architecture Diagram
The clipboard service provides functions that support application developers to use clipboard-related services conveniently and efficiently. Its main components include clipboard management client and clipboard service. The clipboard management client is responsible for clipboard interface management, providing clipboard northbound JS API to applications; creating clipboard data on the application framework side, requesting clipboard SA to perform clipboard creation, deletion, query, text conversion, configuration, etc. The clipboard service is responsible for clipboard event management, manages the life cycle of clipboard SA (startup, destruction, multi-user, etc.); executes application requests, notifies clipboard data management, and returns the results to the clipboard management client.
Directory Structure
/foundation/distributeddatamgr/pasteboard
├── etc # Configuration files for the processes contained in the component
├── figures # Framework diagram
├── framework # innerKit interface
├── interfaces # The interface code provided by the component externally
│ └── kits # Interface provided to the application
├── profile # Configuration files for system services contained in the component
├── services # clipboard service implementation
│ └── core # Core code implementation
│ └── test # native test code
│ └── zidl # Cross-process communication code implementation
├── utils # Tests or services use mocked data
└──README.md # Instructions for use
illustrate
Interface Description
list 1 PasteBoard open main method
list 2 SystemPasteboard open main method
Callback called when the content of the pasteboard is closed |
|
setPasteData(data: PasteData, callback: AsyncCallback<void>:void; |
|
list 3 PasteData open main method
list 4 PasteDataRecord open main method
list 5 PasteDataProperty Parameter Description
Timestamp indicating when the data was written to the system clipboard. |
||
Instructions for use
Clipboard module usage example:
// import module
import pasteboard from '@ohos.pasteboard'
//text copy
console.log('Get SystemPasteboard')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.clear()
var textData = 'Hello World!'
console.log('createPlainTextData = ' + textData)
var pasteData = pasteboard.createPlainTextData(textData)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
console.log('Checks the pasteboard content')
assert.equal(pasteData.getPrimaryText(), textData)
console.log('Checks there is a MIMETYPE_TEXT_PLAIN MIME type of data')
assert.equal(pasteData.hasMimeType(MIMETYPE_TEXT_PLAIN), true)
assert.equal(pasteData.getPrimaryMimeType(), MIMETYPE_TEXT_PLAIN)
//clipboard change listener
console.log('Off the content changes')
var systemPasteboard = pasteboard.getSystemPasteboard()
systemPasteboard.off(contentChanges)
systemPasteboard.clear()
var textData = 'Hello World!'
console.log('createUriData = ' + textData)
var pasteData = pasteboard.createUriData(textData)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
console.log('On the content changes')
systemPasteboard.on(contentChanges)
console.log('Removes the Record')
assert.equal(pasteData.removeRecordAt(0), true)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 0)
console.log('Checks there is no content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), false)
var textDataNew = 'Hello World!-New'
console.log('createUriData = ' + textDataNew)
var pasteData = pasteboard.createUriData(textDataNew)
console.log('Writes PasteData to the pasteboard')
systemPasteboard.setPasteData(pasteData)
console.log('Checks there is content in the pasteboard')
assert.equal(systemPasteboard.hasPasteData(), true)
console.log('Checks the number of records')
pasteData = systemPasteboard.getPasteData()
assert.equal(pasteData.getRecordCount(), 1)
console.log('Checks the pasteboard content')
assert.equal(pasteData.getRecordAt(0).plainText, textDataNew)
Related warehouse
Distributed Data Management subsystem