Go to file
openharmony_ci 6102fdd1b2
!957 add bool judgement
Merge pull request !957 from 杨英华/OpenHarmony-5.0.1-Release
2024-11-18 12:37:05 +00:00
.gitee [fix]:sync md file 2024-10-15 01:41:57 +00:00
adapter Description:change dfx errcode print 2024-10-24 09:38:46 +08:00
etc/init fix: Code discrepancy modifications 4 2024-11-11 07:32:21 +00:00
figures Signed-off-by: LVB8189 <lvbai1@huawei.com> 2022-08-09 15:43:07 +08:00
framework Fix: Correct TASK_PROCESSING Report Condition 2024-11-13 15:01:29 +08:00
interfaces fix:change NAPI_CALL to ASSERT_CALL to delete obj 2024-11-12 10:15:41 +08:00
profile 剪切板动态启停优化 2023-04-28 10:21:05 +08:00
services fix: Code discrepancy modifications 6 2024-11-13 01:57:02 +00:00
test/fuzztest fix: Code discrepancy modifications 4 2024-11-11 07:32:21 +00:00
utils/native/include fix:code sync 2024-11-06 10:22:22 +08:00
.gitattributes fix: Code discrepancy modifications 5 2024-11-12 02:36:48 +00:00
.gitignore 补充测试TDD用例 2023-08-09 17:40:56 +08:00
BUILD.gn Add pasteboard ndk api. 2024-10-11 15:41:45 +08:00
bundle.json !898 Supplementing unit test cases 2024-10-17 02:51:44 +00:00
CODEOWNERS Description:处理告警 2023-07-06 14:30:39 +08:00
LICENSE 提交剪贴板代码 2022-03-09 13:23:51 +08:00
OAT.xml update resources 2024-06-18 11:11:32 +08:00
pasteboard.gni Add pasteboard ndk api. 2024-10-11 15:41:45 +08:00
pasteboardEvent.yaml cde检测问题修改以及Copyright时间调整 2023-03-30 10:21:43 +08:00
publicity.xml fix: Code discrepancy modifications 5 2024-11-12 02:36:48 +00:00
README_ZH.md alert modification 2024-01-18 06:38:19 +00:00
README.md alert modification 2024-01-18 06:38:19 +00:00

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

interface name

describe

createHtmlData(htmlText: string): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_HTML for HTML type data

createWantData(want: Want): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_WANT for data of type want

createPlainTextData(text: string): PasteData

Create a PasteData object of type MIMETYPE_TEXT_PLAIN for plain text data

createUriData(uri: string): PasteData;

Create a PasteData object of type MIMETYPE_TEXT_URI for data of type URI

createHtmlTextRecord(htmlText: string): PasteDataRecord;

Create a PasteDataRecord object of type RecordMIMETYPE_TEXT_HTML for hypertext type data

createWantRecord(want: Want): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_WANT for data of type want

createPlainTextRecord(text: string): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_PLAIN for plain text data

createUriRecord(uri: string): PasteDataRecord;

Create a PasteDataRecord object of type MIMETYPE_TEXT_URI for data of type URI

getSystemPasteboard(): SystemPasteboard

Get system clipboard

list 2 SystemPasteboard open main method

interface name

describe

on(type:'update', callback: () => void): void;

Callback called when the open pasteboard content changes

off(type: 'update', callback?: () => void): void

Callback called when the content of the pasteboard is closed

clear(callback: AsyncCallback): void

clear clipboard

clear(): Promise;

clear clipboard

getPasteData(callback: AsyncCallback<PasteData>): void

Get system clipboard data object

getPasteData():Promise<PasteData>

Get system clipboard data object

hasPasteData(callback: AsyncCallback<boolean>:void;

Check if there is content in the pasteboard

hasPasteData(): Promise<boolean>

Check if there is content in the pasteboard

setPasteData(data: PasteData, callback: AsyncCallback<void>:void;

Write PasteData to the pasteboard

setPasteData(data: PasteData): Promise<void>

Write PasteData to the pasteboard

list 3 PasteData open main method

interface name

describe

addHtmlRecord(htmlText: string): void;

Add the HTML text record to the PasteData object and update the MIME type to PasteData#MIMETYPE_TEXT_HTML in the DataProperty.

addWantRecord(want: Want): void;

Add want record to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_WANT in DataProperty

addRecord(record: PasteDataRecord): void;

Add PasteRecord to paste data object and update MIME type in data attribute

addTextRecord(text: string): void;;

Add plain text records to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_PLAIN in DataProperty

addUriRecord(uri: string): void;

Add URI record to PasteData object and update MIME type to PasteData#MIMETYPE_TEXT_URI in DataProperty

getMimeTypes(): Array<string>

MIME type of everything on the pasteboard

getPrimaryHtml(): string;

HTML text of the main record in the PasteData object

getPrimaryWant(): Want;

The want of the main record in the PasteData object

getPrimaryMimeType(): string;

The MIME type of the main record in the PasteData object

getPrimaryUri(): string;

URI of the main record in the PasteData object

getProperty(): PasteDataProperty;

Get the properties of the clipboard data object

getRecordAt(index: number): PasteDataRecord;

records based on the specified index

getRecordCount(): number;

Number of records in PasteData object

hasMimeType(mimeType: string): boolean;

Checks if data of the specified MIME type exists in the DataProperty

removeRecordAt(index: number): boolean;

Delete records based on specified index

replaceRecordAt(index: number, record: PasteDataRecord): boolean;

Replace the specified record with a new record

list 4 PasteDataRecord open main method

interface name

describe

convertToText(callback: AsyncCallback<string>): void;

Convert PasteData to text content

convertToText(): Promise<void>

Convert PasteData to text content

list 5 PasteDataProperty Parameter Description

name

type

illustrate

additions{[key:string]}

object

Additional property data key-value pair

mimeTypes

Array

Distinct MIME types for all records in PasteData

tag

string

User-defined labels for PasteData objects

timestamp

number

Timestamp indicating when the data was written to the system clipboard.

localOnly

boolean

Check if PasteData is set for local access only.

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)

Distributed Data Management subsystem

distributeddatamgr_pasteboard