How to use the @theia/core/lib/browser/diff-uris.DiffUris.encode function in @theia/core

To help you get started, we’ve selected a few @theia/core examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github eclipse-theia / theia / packages / git / src / browser / history / git-history-widget.tsx View on Github external
protected openFile(change: GitFileChange, commitSha: string): void {
        const uri: URI = new URI(change.uri);
        let fromURI = change.oldUri ? new URI(change.oldUri) : uri; // set oldUri on renamed and copied
        fromURI = fromURI.withScheme(GIT_RESOURCE_SCHEME).withQuery(commitSha + '~1');
        const toURI = uri.withScheme(GIT_RESOURCE_SCHEME).withQuery(commitSha);
        let uriToOpen = uri;
        if (change.status === GitFileStatus.Deleted) {
            uriToOpen = fromURI;
        } else if (change.status === GitFileStatus.New) {
            uriToOpen = toURI;
        } else {
            uriToOpen = DiffUris.encode(fromURI, toURI);
        }
        open(this.openerService, uriToOpen, { mode: 'reveal' });
    }
}
github eclipse-theia / theia / packages / workspace / src / browser / workspace-commands.ts View on Github external
execute: async uris => {
                const [left, right] = uris;
                const [leftExists, rightExists] = await Promise.all([
                    this.fileSystem.exists(left.toString()),
                    this.fileSystem.exists(right.toString())
                ]);
                if (leftExists && rightExists) {
                    const [leftStat, rightStat] = await Promise.all([
                        this.fileSystem.getFileStat(left.toString()),
                        this.fileSystem.getFileStat(right.toString()),
                    ]);
                    if (leftStat && rightStat) {
                        if (!leftStat.isDirectory && !rightStat.isDirectory) {
                            const uri = DiffUris.encode(left, right);
                            const opener = await this.openerService.getOpener(uri);
                            opener.open(uri);
                        } else {
                            const details = (() => {
                                if (leftStat.isDirectory && rightStat.isDirectory) {
                                    return 'Both resource were a directory.';
                                } else {
                                    if (leftStat.isDirectory) {
                                        return `'${left.path.base}' was a directory.`;
                                    } else {
                                        return `'${right.path.base}' was a directory.`;
                                    }
                                }
                            });
                            this.messageService.warn(`Directories cannot be compared. ${details()}`);
                        }
github eclipse-theia / theia / packages / git / src / browser / git-scm-provider.ts View on Github external
if (change.staged) {
                return DiffUris.encode(
                    changeUri.withScheme(GIT_RESOURCE_SCHEME).withQuery('HEAD'),
                    changeUri.withScheme(GIT_RESOURCE_SCHEME),
                    changeUri.displayName + ' (Index)');
            }
            if (this.stagedChanges.find(c => c.uri === change.uri)) {
                return DiffUris.encode(
                    changeUri.withScheme(GIT_RESOURCE_SCHEME),
                    changeUri,
                    changeUri.displayName + ' (Working tree)');
            }
            if (this.mergeChanges.find(c => c.uri === change.uri)) {
                return changeUri;
            }
            return DiffUris.encode(
                changeUri.withScheme(GIT_RESOURCE_SCHEME).withQuery('HEAD'),
                changeUri,
                changeUri.displayName + ' (Working tree)');
        }
        if (change.staged) {
            return changeUri.withScheme(GIT_RESOURCE_SCHEME);
        }
        if (this.stagedChanges.find(c => c.uri === change.uri)) {
            return DiffUris.encode(
                changeUri.withScheme(GIT_RESOURCE_SCHEME),
                changeUri,
                changeUri.displayName + ' (Working tree)');
        }
        return changeUri;
    }
github eclipse-theia / theia / packages / navigator / src / browser / navigator-diff.ts View on Github external
async compareFiles(): Promise {
        const uriSelected = await this.getURISelection();

        if (this.firstCompareFile === undefined || uriSelected === undefined) {
            return false;
        }
        const diffUri = DiffUris.encode(this.firstCompareFile, uriSelected);

        open(this.openerService, diffUri).catch(e => {
            this.notifications.error(e.message);
        });
        return true;
    }
}
github eclipse-theia / theia / packages / workspace / src / browser / diff-service.ts View on Github external
public async openDiffEditor(left: URI, right: URI, label?: string, options?: OpenerOptions): Promise {
        if (left.scheme === 'file' && right.scheme === 'file') {
            const [leftExists, rightExists] = await Promise.all([
                this.fileSystem.exists(left.toString()),
                this.fileSystem.exists(right.toString())
            ]);
            if (leftExists && rightExists) {
                const [leftStat, rightStat] = await Promise.all([
                    this.fileSystem.getFileStat(left.toString()),
                    this.fileSystem.getFileStat(right.toString()),
                ]);
                if (leftStat && rightStat) {
                    if (!leftStat.isDirectory && !rightStat.isDirectory) {
                        const uri = DiffUris.encode(left, right, label);
                        await open(this.openerService, uri, options);
                    } else {
                        const details = (() => {
                            if (leftStat.isDirectory && rightStat.isDirectory) {
                                return 'Both resource were a directory.';
                            } else {
                                if (leftStat.isDirectory) {
                                    return `'${left.path.base}' was a directory.`;
                                } else {
                                    return `'${right.path.base}' was a directory.`;
                                }
                            }
                        });
                        this.messageService.warn(`Directories cannot be compared. ${details()}`);
                    }
                }
github eclipse-theia / theia / packages / git / src / browser / git-scm-provider.ts View on Github external
getUriToOpen(change: GitFileChange): URI {
        const changeUri: URI = new URI(change.uri);
        if (change.status !== GitFileStatus.New) {
            if (change.staged) {
                return DiffUris.encode(
                    changeUri.withScheme(GIT_RESOURCE_SCHEME).withQuery('HEAD'),
                    changeUri.withScheme(GIT_RESOURCE_SCHEME),
                    changeUri.displayName + ' (Index)');
            }
            if (this.stagedChanges.find(c => c.uri === change.uri)) {
                return DiffUris.encode(
                    changeUri.withScheme(GIT_RESOURCE_SCHEME),
                    changeUri,
                    changeUri.displayName + ' (Working tree)');
            }
            if (this.mergeChanges.find(c => c.uri === change.uri)) {
                return changeUri;
            }
            return DiffUris.encode(
                changeUri.withScheme(GIT_RESOURCE_SCHEME).withQuery('HEAD'),
                changeUri,
github eclipse-theia / theia / packages / git / src / browser / git-scm-provider.ts View on Github external
changeUri,
                    changeUri.displayName + ' (Working tree)');
            }
            if (this.mergeChanges.find(c => c.uri === change.uri)) {
                return changeUri;
            }
            return DiffUris.encode(
                changeUri.withScheme(GIT_RESOURCE_SCHEME).withQuery('HEAD'),
                changeUri,
                changeUri.displayName + ' (Working tree)');
        }
        if (change.staged) {
            return changeUri.withScheme(GIT_RESOURCE_SCHEME);
        }
        if (this.stagedChanges.find(c => c.uri === change.uri)) {
            return DiffUris.encode(
                changeUri.withScheme(GIT_RESOURCE_SCHEME),
                changeUri,
                changeUri.displayName + ' (Working tree)');
        }
        return changeUri;
    }