Skip to content

Commit

Permalink
Merge branch 'delete-timelines'
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed May 6, 2024
2 parents 38a15aa + c159a9a commit 664372a
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
18 changes: 18 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,16 @@
"command": "auxon.timelines.logSelected",
"when": "view == auxon.timelines && listMultiSelection"
},
{
"command": "auxon.timelines.delete",
"when": "view == auxon.timelines && viewItem == timeline && !listMultiSelection",
"group": "2_context@2"
},
{
"command": "auxon.timelines.deleteMany",
"when": "view == auxon.timelines && ((viewItem == timeline && listMultiSelection) || viewItem == timelineGroup)",
"group": "2_context@2"
},
{
"command": "auxon.events.createEventTimingNotebook",
"when": "view == auxon.events && viewItem == event"
Expand Down Expand Up @@ -621,6 +631,14 @@
"command": "auxon.timelines.logSelected",
"title": "Log Selected Timelines"
},
{
"command": "auxon.timelines.delete",
"title": "Delete Timeline"
},
{
"command": "auxon.timelines.deleteMany",
"title": "Delete Timelines"
},
{
"command": "auxon.timelines.transitionGraph",
"title": "View Transition Graph"
Expand Down
52 changes: 52 additions & 0 deletions vscode/src/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
import * as api from "./modalityApi";
import * as vscode from "vscode";
import * as modalityLog from "./modalityLog";
import * as config from "./config";
import * as transitionGraph from "./transitionGraph";
import * as workspaceState from "./workspaceState";
import * as child_process from "child_process";
import * as util from "util";

const execFile = util.promisify(child_process.execFile);

class TimelinesTreeMemento {
constructor(private readonly memento: vscode.Memento) {}
Expand Down Expand Up @@ -79,6 +84,18 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
vscode.commands.registerCommand("auxon.timelines.clearGroupTimelinesByNameComponents", () => {
this.disableTimelineGrouping();
}),
vscode.commands.registerCommand("auxon.timelines.delete", (itemData) => {
if (itemData.timelineId) {
this.deleteTimelines([itemData.timelineId]);
}
}),
vscode.commands.registerCommand("auxon.timelines.deleteMany", (itemData?: TimelineTreeItemData) => {
let timelineIds = this.view.selection.flatMap((data) => data.getTimelineIds());
if (itemData) {
timelineIds = timelineIds.concat(itemData.getTimelineIds());
}
this.deleteTimelines(timelineIds);
}),
this.wss.onDidChangeUsedSegments(() => this.refresh())
);
this.updateGroupingMenuContext();
Expand Down Expand Up @@ -197,6 +214,41 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
);
}

async deleteTimelines(timelineIds: api.TimelineId[]) {
timelineIds = [...new Set(timelineIds)]; // dedupe

if (timelineIds.length == 0) {
return;
}

let prefix = `Really delete ${timelineIds.length} timeline`;
if (timelineIds.length > 1) {
prefix += "s";
}

const answer = await vscode.window.showInformationMessage(
`${prefix}? This will delete all events on the selected timelines.`,
"Delete",
"Cancel"
);
if (answer == "Delete") {
let filterExpr = "";
timelineIds.forEach((tid, index) => {
const literalTimelineId = "%" + tid.replace(/-/g, "");
filterExpr += `_.timeline.id = ${literalTimelineId}`;
if (index < timelineIds.length - 1) {
filterExpr += " OR ";
}
});

const modality = config.toolPath("modality");
await execFile(modality, ["delete", "--force", filterExpr, ...config.extraCliArgs("modality delete")], {
encoding: "utf8",
});
this.refresh();
}
}

transitionGraph(item: TimelineTreeItemData) {
transitionGraph.promptForGraphGrouping((groupBy) => {
transitionGraph.showGraphForTimelines(item.getTimelineIds(), groupBy);
Expand Down

0 comments on commit 664372a

Please sign in to comment.