@@ -5,16 +5,18 @@ import bridge from '../../../services/bridge';
5
5
import { ContextMenuItemType , ContextMenuOptions , ContextMenuItems , resourceInfo , textToDataUri , svgUriToPng , svgDimensions } from './contextMenuUtils' ;
6
6
const Menu = bridge ( ) . Menu ;
7
7
const MenuItem = bridge ( ) . MenuItem ;
8
- import Resource from '@joplin/lib/models/Resource' ;
8
+ import Resource , { resourceOcrStatusToString } from '@joplin/lib/models/Resource' ;
9
9
import BaseItem from '@joplin/lib/models/BaseItem' ;
10
10
import BaseModel , { ModelType } from '@joplin/lib/BaseModel' ;
11
11
import { processPastedHtml } from './resourceHandling' ;
12
- import { NoteEntity , ResourceEntity } from '@joplin/lib/services/database/types' ;
12
+ import { NoteEntity , ResourceEntity , ResourceOcrStatus } from '@joplin/lib/services/database/types' ;
13
13
import { TinyMceEditorEvents } from '../NoteBody/TinyMCE/utils/types' ;
14
14
import { itemIsReadOnlySync , ItemSlice } from '@joplin/lib/models/utils/readOnly' ;
15
15
import Setting from '@joplin/lib/models/Setting' ;
16
16
import ItemChange from '@joplin/lib/models/ItemChange' ;
17
17
import { HtmlToMarkdownHandler , MarkupToHtmlHandler } from './types' ;
18
+ import shim from '@joplin/lib/shim' ;
19
+ import { openFileWithExternalEditor } from '@joplin/lib/services/ExternalEditWatcher/utils' ;
18
20
const fs = require ( 'fs-extra' ) ;
19
21
const { writeFile } = require ( 'fs-extra' ) ;
20
22
const { clipboard } = require ( 'electron' ) ;
@@ -135,6 +137,21 @@ export function menuItems(dispatch: Function, htmlToMd: HtmlToMarkdownHandler, m
135
137
} ,
136
138
isActive : ( itemType : ContextMenuItemType , options : ContextMenuOptions ) => ! options . textToCopy && itemType === ContextMenuItemType . Image || itemType === ContextMenuItemType . Resource ,
137
139
} ,
140
+ copyOcrText : {
141
+ label : _ ( 'View OCR text' ) ,
142
+ onAction : async ( options : ContextMenuOptions ) => {
143
+ const { resource } = await resourceInfo ( options ) ;
144
+
145
+ if ( resource . ocr_status === ResourceOcrStatus . Done ) {
146
+ const tempFilePath = `${ Setting . value ( 'tempDir' ) } /${ resource . id } _ocr.txt` ;
147
+ await shim . fsDriver ( ) . writeFile ( tempFilePath , resource . ocr_text , 'utf8' ) ;
148
+ await openFileWithExternalEditor ( tempFilePath , bridge ( ) ) ;
149
+ } else {
150
+ bridge ( ) . showInfoMessageBox ( _ ( 'This attachment does not have OCR data (Status: %s)' , resourceOcrStatusToString ( resource . ocr_status ) ) ) ;
151
+ }
152
+ } ,
153
+ isActive : ( itemType : ContextMenuItemType , _options : ContextMenuOptions ) => itemType === ContextMenuItemType . Resource ,
154
+ } ,
138
155
copyPathToClipboard : {
139
156
label : _ ( 'Copy path to clipboard' ) ,
140
157
onAction : async ( options : ContextMenuOptions ) => {
0 commit comments