Allow to compare untitled documents (fixes #14501)
This commit is contained in:
parent
4816c4a317
commit
4496c87db5
2 changed files with 24 additions and 19 deletions
|
@ -1119,11 +1119,11 @@ export class GlobalCompareResourcesAction extends Action {
|
|||
}
|
||||
|
||||
public run(): TPromise<any> {
|
||||
const fileResource = toResource(this.editorService.getActiveEditorInput(), { filter: 'file' });
|
||||
if (fileResource) {
|
||||
const activeResource = toResource(this.editorService.getActiveEditorInput(), { filter: ['file', 'untitled'] });
|
||||
if (activeResource) {
|
||||
|
||||
// Keep as resource to compare
|
||||
globalResourceToCompare = fileResource;
|
||||
globalResourceToCompare = activeResource;
|
||||
|
||||
// Pick another entry from history
|
||||
interface IHistoryPickEntry extends IFilePickOpenEntry {
|
||||
|
@ -1137,18 +1137,22 @@ export class GlobalCompareResourcesAction extends Action {
|
|||
let description: string;
|
||||
|
||||
if (input instanceof EditorInput) {
|
||||
return void 0; // only files supported
|
||||
resource = toResource(input, { filter: ['file', 'untitled'] });
|
||||
} else {
|
||||
resource = (input as IResourceInput).resource;
|
||||
}
|
||||
|
||||
const resourceInput = input as IResourceInput;
|
||||
resource = resourceInput.resource;
|
||||
label = paths.basename(resourceInput.resource.fsPath);
|
||||
description = labels.getPathLabel(paths.dirname(resource.fsPath), this.contextService);
|
||||
if (!resource) {
|
||||
return void 0; // only support to compare with files and untitled
|
||||
}
|
||||
|
||||
label = paths.basename(resource.fsPath);
|
||||
description = resource.scheme === 'file' ? labels.getPathLabel(paths.dirname(resource.fsPath), this.contextService) : void 0;
|
||||
|
||||
return <IHistoryPickEntry>{ input, resource, label, description };
|
||||
}).filter(p => !!p);
|
||||
|
||||
return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select an editor history entry to compare with"), autoFocus: { autoFocusFirstEntry: true }, matchOnDescription: true }).then(pick => {
|
||||
return this.quickOpenService.pick(picks, { placeHolder: nls.localize('pickHistory', "Select a previously opened file to compare with"), autoFocus: { autoFocusFirstEntry: true }, matchOnDescription: true }).then(pick => {
|
||||
if (pick) {
|
||||
const compareAction = this.instantiationService.createInstance(CompareResourcesAction, pick.resource, null);
|
||||
if (compareAction._isEnabled()) {
|
||||
|
|
|
@ -413,6 +413,7 @@ export class ActionProvider extends ContributableActionProvider {
|
|||
result.unshift(this.instantiationService.createInstance(OpenToSideAction, tree, resource, false));
|
||||
|
||||
if (!openEditor.isUntitled()) {
|
||||
|
||||
// Files: Save / Revert
|
||||
if (!autoSaveEnabled) {
|
||||
result.push(new Separator());
|
||||
|
@ -427,18 +428,10 @@ export class ActionProvider extends ContributableActionProvider {
|
|||
revertAction.enabled = openEditor.isDirty();
|
||||
result.push(revertAction);
|
||||
}
|
||||
|
||||
result.push(new Separator());
|
||||
|
||||
// Compare Actions
|
||||
const runCompareAction = this.instantiationService.createInstance(CompareResourcesAction, resource, tree);
|
||||
if (runCompareAction._isEnabled()) {
|
||||
result.push(runCompareAction);
|
||||
}
|
||||
result.push(this.instantiationService.createInstance(SelectResourceForCompareAction, resource, tree));
|
||||
}
|
||||
|
||||
// Untitled: Save / Save As
|
||||
else {
|
||||
if (openEditor.isUntitled()) {
|
||||
result.push(new Separator());
|
||||
|
||||
if (this.untitledEditorService.hasAssociatedFilePath(resource)) {
|
||||
|
@ -452,6 +445,14 @@ export class ActionProvider extends ContributableActionProvider {
|
|||
result.push(saveAsAction);
|
||||
}
|
||||
|
||||
// Compare Actions
|
||||
result.push(new Separator());
|
||||
const runCompareAction = this.instantiationService.createInstance(CompareResourcesAction, resource, tree);
|
||||
if (runCompareAction._isEnabled()) {
|
||||
result.push(runCompareAction);
|
||||
}
|
||||
result.push(this.instantiationService.createInstance(SelectResourceForCompareAction, resource, tree));
|
||||
|
||||
result.push(new Separator());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue