Skip to content

Commit

Permalink
Fixes eclipse-theia#5110, fixes eclipse-theia#5223: re-implemented "o…
Browse files Browse the repository at this point in the history
…pen source" to work with image/pdf files

Signed-off-by: fangnx <[email protected]>
  • Loading branch information
fangnx committed May 29, 2019
1 parent f39185a commit 6ebe28f
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
7 changes: 7 additions & 0 deletions packages/core/src/browser/widget-open-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ export interface WidgetOpenerOptions extends OpenerOptions {
* By default to the main area.
*/
widgetOptions?: ApplicationShell.WidgetOptions;
/**
* Specify what the widget is opened for
* preview: preview of image/pdf/etc.
* edit: source file
* By default to `edit`
*/
openFor?: 'preview' | 'edit';
}

@injectable()
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/src/browser/editor-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ export class EditorManager extends NavigatableWidgetOpenHandler<EditorWidget> {
}

canHandle(uri: URI, options?: WidgetOpenerOptions): number {
// Set the priority negative if an open handler is called for 'preview' (not for 'edit)
if (options && options.openFor === 'preview') {
return -100;
}
return 100;
}

Expand Down
12 changes: 9 additions & 3 deletions packages/mini-browser/src/browser/mini-browser-open-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,15 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
}))();
}

canHandle(uri: URI): number {
canHandle(uri: URI, options?: WidgetOpenerOptions): number {
// It does not guard against directories. For instance, a folder with this name: `Hahahah.html`.
// We could check with the FS, but then, this method would become async again.
const extension = uri.toString().split('.').pop();
if (extension) {
// Set the priority negative if an open handler is called for 'edit' (not for 'preview')
if (options && options.openFor === 'edit') {
return -100;
}
return this.supportedExtensions.get(extension.toLocaleLowerCase()) || 0;
}
return 0;
Expand Down Expand Up @@ -237,7 +241,8 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
const uri = this.getSourceUri(ref);
if (uri) {
await open(this.openerService, uri, {
widgetOptions: { ref, mode: 'open-to-left' }
widgetOptions: { ref, mode: 'open-to-left' },
openFor: 'edit'
});
}
}
Expand Down Expand Up @@ -275,7 +280,8 @@ export class MiniBrowserOpenHandler extends NavigatableWidgetOpenHandler<MiniBro
area: 'right'
},
resetBackground,
iconClass: 'theia-mini-browser-icon'
iconClass: 'theia-mini-browser-icon',
openFor: 'preview'
};
}

Expand Down

0 comments on commit 6ebe28f

Please sign in to comment.