|
1 | 1 | import React from 'react'; |
2 | 2 |
|
3 | 3 | import { INJECTOR_TOKEN, Injector } from '@opensumi/di'; |
4 | | -import { AppConfig, localize, useInjectable } from '@opensumi/ide-core-browser'; |
| 4 | +import { AppConfig, IEventBus, localize, useInjectable } from '@opensumi/ide-core-browser'; |
5 | 5 | import { IElectronMainUIService } from '@opensumi/ide-core-common/lib/electron'; |
6 | | -import { ReactEditorComponent } from '@opensumi/ide-editor/lib/browser'; |
| 6 | +import { |
| 7 | + ReactEditorComponent, |
| 8 | + ResourceOpenTypeChangedEvent, |
| 9 | + WorkbenchEditorService, |
| 10 | +} from '@opensumi/ide-editor/lib/browser'; |
7 | 11 |
|
8 | | -import styles from './style.module.less'; |
| 12 | +import { PreventComponent } from './prevent.view'; |
9 | 13 |
|
10 | 14 | export const BinaryEditorComponent: ReactEditorComponent<null> = (props) => { |
11 | 15 | const srcPath = props.resource.uri.codeUri.fsPath; |
12 | 16 | const injector: Injector = useInjectable(INJECTOR_TOKEN); |
13 | 17 | const appConfig: AppConfig = useInjectable(AppConfig); |
| 18 | + const editorService = useInjectable<WorkbenchEditorService>(WorkbenchEditorService); |
| 19 | + const eventBus = useInjectable<IEventBus>(IEventBus); |
14 | 20 |
|
15 | | - return ( |
16 | | - <div className={styles.external}> |
17 | | - {localize('editor.cannotOpenBinary')} |
18 | | - {appConfig.isElectronRenderer ? ( |
19 | | - <a onClick={() => injector.get(IElectronMainUIService).openPath(srcPath)}>{localize('editor.openExternal')}</a> |
20 | | - ) : null} |
21 | | - </div> |
22 | | - ); |
| 21 | + const handleClick = () => { |
| 22 | + const current = editorService.currentResource; |
| 23 | + |
| 24 | + if (!current) { |
| 25 | + return; |
| 26 | + } |
| 27 | + |
| 28 | + current.metadata = { ...current.metadata, skipPreventBinary: true }; |
| 29 | + eventBus.fire(new ResourceOpenTypeChangedEvent(current.uri)); |
| 30 | + }; |
| 31 | + |
| 32 | + const actions = [ |
| 33 | + { |
| 34 | + label: localize('editor.file.prevent.stillOpen'), |
| 35 | + onClick: () => handleClick(), |
| 36 | + }, |
| 37 | + ]; |
| 38 | + |
| 39 | + if (appConfig.isElectronRenderer) { |
| 40 | + actions.push({ |
| 41 | + label: localize('editor.openExternal'), |
| 42 | + onClick: () => injector.get(IElectronMainUIService).openPath(srcPath), |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + return <PreventComponent description={localize('editor.cannotOpenBinary')} actions={actions} />; |
23 | 47 | }; |
0 commit comments