Skip to content

Commit c39b393

Browse files
Merge pull request #265 from gjsjohnmurray/fix-254
fix #254 detect doubleclick on ObjectScript Explorer items
2 parents 02808e8 + c4296d1 commit c39b393

File tree

6 files changed

+44
-12
lines changed

6 files changed

+44
-12
lines changed

package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@
5555
"onCommand:vscode-objectscript.viewOthers",
5656
"onCommand:vscode-objectscript.previewXml",
5757
"onCommand:vscode-objectscript.explorer.refresh",
58-
"onCommand:vscode-objectscript.explorer.openClass",
59-
"onCommand:vscode-objectscript.explorer.openRoutine",
60-
"onCommand:vscode-objectscript.explorer.openCSPFile",
58+
"onCommand:vscode-objectscript.explorer.open",
6159
"onCommand:vscode-objectscript.compileFolder",
6260
"onCommand:vscode-objectscript.importFolder",
6361
"onLanguage:objectscript",

src/explorer/explorer.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,44 @@ import { AtelierAPI } from "../api";
55
import { config } from "../extension";
66
import { WorkspaceNode } from "./models/workspaceNode";
77

8+
// The vscode-objectscript.explorer.open command is not listed in settings.json as a contribution because it only gets invoked
9+
// from the user's click on an item in the ObjectScriptExplorerProvider tree.
10+
// It serves as a proxy for the vscode.open command, detecting two opens of the same item in quick succession
11+
// and treating the second of these as a non-preview open.
12+
export function registerExplorerOpen(explorerProvider: ObjectScriptExplorerProvider): vscode.Disposable {
13+
return vscode.commands.registerCommand("vscode-objectscript.explorer.open", async function (uri: vscode.Uri) {
14+
let usePreview = <boolean>vscode.workspace.getConfiguration("workbench.editor").get("enablePreview");
15+
16+
if (usePreview) {
17+
usePreview = !wasDoubleClick(uri, explorerProvider);
18+
}
19+
20+
await vscode.commands.executeCommand("vscode.open", uri, { preview: usePreview });
21+
});
22+
}
23+
24+
// Return true if previously called with the same arguments within the past 0.5 seconds
25+
function wasDoubleClick(uri: vscode.Uri, explorerProvider: ObjectScriptExplorerProvider): boolean {
26+
let result = false;
27+
if (explorerProvider.lastOpened) {
28+
const isTheSameUri = explorerProvider.lastOpened.uri === uri;
29+
const dateDiff = <number>(<any>new Date() - <any>explorerProvider.lastOpened.date);
30+
result = isTheSameUri && dateDiff < 500;
31+
}
32+
33+
explorerProvider.lastOpened = {
34+
uri: uri,
35+
date: new Date(),
36+
};
37+
return result;
38+
}
839
export class ObjectScriptExplorerProvider implements vscode.TreeDataProvider<NodeBase> {
940
public onDidChange?: vscode.Event<vscode.Uri>;
1041
public onDidChangeTreeData: vscode.Event<NodeBase>;
42+
43+
// Use for detecting doubleclick
44+
public lastOpened: { uri: vscode.Uri; date: Date };
45+
1146
private _onDidChangeTreeData: vscode.EventEmitter<NodeBase>;
1247
private _showExtra4Workspace: { [key: string]: string[] }[] = [];
1348

src/explorer/models/classNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export class ClassNode extends NodeBase {
1717
collapsibleState: vscode.TreeItemCollapsibleState.None,
1818
command: {
1919
arguments: [itemUri],
20-
command: "vscode-objectscript.explorer.openClass",
21-
title: "Open class",
20+
command: "vscode-objectscript.explorer.open",
21+
title: "Open Class",
2222
},
2323
resourceUri: isLocalFile ? itemUri : undefined,
2424
contextValue: "dataNode:classNode",

src/explorer/models/cspFileNode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class CSPFileNode extends NodeBase {
1717
collapsibleState: vscode.TreeItemCollapsibleState.None,
1818
command: {
1919
arguments: [itemUri],
20-
command: "vscode-objectscript.explorer.openCSPFile",
20+
command: "vscode-objectscript.explorer.open",
2121
title: "Open File",
2222
},
2323
resourceUri: isLocalFile ? itemUri : undefined,

src/explorer/models/routineNode.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ export class RoutineNode extends NodeBase {
1717
collapsibleState: vscode.TreeItemCollapsibleState.None,
1818
command: {
1919
arguments: [itemUri],
20-
command: "vscode-objectscript.explorer.openRoutine",
21-
title: "Open routine",
20+
command: "vscode-objectscript.explorer.open",
21+
title: "Open Routine",
2222
},
2323
resourceUri: isLocalFile ? itemUri : undefined,
2424
contextValue: "dataNode:routineNode",

src/extension.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ import { StatusCodeError } from "request-promise/errors";
5959
import { AtelierAPI } from "./api";
6060
import { ObjectScriptDebugAdapterDescriptorFactory } from "./debug/debugAdapterFactory";
6161
import { ObjectScriptConfigurationProvider } from "./debug/debugConfProvider";
62-
import { ObjectScriptExplorerProvider } from "./explorer/explorer";
62+
import { ObjectScriptExplorerProvider, registerExplorerOpen } from "./explorer/explorer";
6363
import { WorkspaceNode } from "./explorer/models/workspaceNode";
6464
import { FileSystemProvider } from "./providers/FileSystemPovider/FileSystemProvider";
6565
import { WorkspaceSymbolProvider } from "./providers/WorkspaceSymbolProvider";
@@ -579,9 +579,8 @@ export async function activate(context: vscode.ExtensionContext): Promise<void>
579579
vscode.commands.registerCommand("vscode-objectscript.serverActions", serverActions),
580580
vscode.commands.registerCommand("vscode-objectscript.touchBar.viewOthers", viewOthers),
581581
vscode.commands.registerCommand("vscode-objectscript.explorer.refresh", () => explorerProvider.refresh()),
582-
vscode.commands.registerCommand("vscode-objectscript.explorer.openClass", vscode.window.showTextDocument),
583-
vscode.commands.registerCommand("vscode-objectscript.explorer.openRoutine", vscode.window.showTextDocument),
584-
vscode.commands.registerCommand("vscode-objectscript.explorer.openCSPFile", vscode.window.showTextDocument),
582+
// Register the vscode-objectscript.explorer.open command elsewhere
583+
registerExplorerOpen(explorerProvider),
585584
vscode.commands.registerCommand("vscode-objectscript.explorer.export", (item, items) =>
586585
exportExplorerItem(items && items.length ? items : [item])
587586
),

0 commit comments

Comments
 (0)