Skip to content

Commit

Permalink
Add timelines grouping mode context menu checkboxes
Browse files Browse the repository at this point in the history
  • Loading branch information
jonlamb-gh committed Nov 17, 2023
1 parent 4320cb1 commit 8b91faf
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 12 deletions.
38 changes: 34 additions & 4 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -182,19 +182,34 @@
"when": "view == auxon.timelines",
"group": "navigation@1"
},
{
"command": "auxon.timelines.groupTimelinesAsFlatList",
"when": "view == auxon.timelines && auxon:timelinesGroupingMode != 'FLAT_LIST'",
"group": "7_modification@1"
},
{
"command": "auxon.timelines.disableTimelineGrouping",
"when": "view == auxon.timelines",
"when": "view == auxon.timelines && auxon:timelinesGroupingMode == 'FLAT_LIST'",
"group": "7_modification@1"
},
{
"command": "auxon.timelines.setGroupingAttrs",
"when": "view == auxon.timelines",
"when": "view == auxon.timelines && auxon:timelinesGroupingMode != 'BY_ATTRIBUTES'",
"group": "7_modification@2"
},
{
"command": "auxon.timelines.clearGroupingAttrs",
"when": "view == auxon.timelines && auxon:timelinesGroupingMode == 'BY_ATTRIBUTES'",
"group": "7_modification@2"
},
{
"command": "auxon.timelines.groupTimelinesByNameComponents",
"when": "view == auxon.timelines",
"when": "view == auxon.timelines && auxon:timelinesGroupingMode != 'BY_NAME_COMPONENTS'",
"group": "7_modification@3"
},
{
"command": "auxon.timelines.clearGroupTimelinesByNameComponents",
"when": "view == auxon.timelines && auxon:timelinesGroupingMode == 'BY_NAME_COMPONENTS'",
"group": "7_modification@3"
},
{
Expand Down Expand Up @@ -255,20 +270,35 @@
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.disableTimelineGrouping",
"command": "auxon.timelines.groupTimelinesAsFlatList",
"title": "Show timelines in flat list",
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.disableTimelineGrouping",
"title": "✓ Show timelines in flat list",
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.setGroupingAttrs",
"title": "Group timelines by attribute",
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.clearGroupingAttrs",
"title": "✓ Group timelines by attribute",
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.groupTimelinesByNameComponents",
"title": "Group timelines by name components",
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.clearGroupTimelinesByNameComponents",
"title": "✓ Group timelines by name components",
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.inspect",
"title": "Inspect Timeline"
Expand Down
52 changes: 44 additions & 8 deletions vscode/src/timelines.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ class TimelinesTreeMemento {
}
}

enum TimelinesGroupingMode {
FlatList = "FLAT_LIST",
ByAttributes = "BY_ATTRIBUTES",
ByNameComponents = "BY_NAME_COMPONENTS",
}

export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<TimelineTreeItemData> {
activeWorkspaceVersionId: string;
usedSegmentConfig: cliConfig.ContextSegment;
Expand All @@ -49,6 +55,9 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
canSelectMany: true,
});

// Load initial grouping menu context from state or default to FlatList
this.updateGroupingMenuContext();

context.subscriptions.push(
this.view,
vscode.commands.registerCommand("auxon.timelines.refresh", () => this.refresh()),
Expand All @@ -62,13 +71,24 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
vscode.commands.registerCommand("auxon.timelines.transitionGraphForSelection", () =>
this.transitionGraphForSelection()
),
vscode.commands.registerCommand("auxon.timelines.disableTimelineGrouping", () =>
this.disableTimelineGrouping()
),
vscode.commands.registerCommand("auxon.timelines.setGroupingAttrs", () => this.setGroupingAttrs()),
vscode.commands.registerCommand("auxon.timelines.groupTimelinesByNameComponents", () =>
this.groupTimelinesByNameComponents()
)
vscode.commands.registerCommand("auxon.timelines.groupTimelinesAsFlatList", () => {
this.disableTimelineGrouping();
}),
vscode.commands.registerCommand("auxon.timelines.disableTimelineGrouping", () => {
this.disableTimelineGrouping();
}),
vscode.commands.registerCommand("auxon.timelines.setGroupingAttrs", () => {
this.setGroupingAttrs();
}),
vscode.commands.registerCommand("auxon.timelines.clearGroupingAttrs", () => {
this.disableTimelineGrouping();
}),
vscode.commands.registerCommand("auxon.timelines.groupTimelinesByNameComponents", () => {
this.groupTimelinesByNameComponents();
}),
vscode.commands.registerCommand("auxon.timelines.clearGroupTimelinesByNameComponents", () => {
this.disableTimelineGrouping();
})
);
}

Expand Down Expand Up @@ -206,9 +226,11 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
this.workspaceState.setGroupingAttrKeys([]);
this.workspaceState.setGroupByTimelineNameComponents(false);
this.refresh();
this.updateGroupingMenuContext();
}

async setGroupingAttrs() {
this.workspaceState.setGroupByTimelineNameComponents(false);
const tlAttrs = await this.getAvailableTimelineAttrKeys();
const groupingAttrKeys = this.workspaceState.getGroupingAttrKeys();
const pickItems: vscode.QuickPickItem[] = tlAttrs.map((tlAttr) => {
Expand All @@ -218,17 +240,19 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
});

const pickedItems = await vscode.window.showQuickPick(pickItems, { canPickMany: true });
if(pickedItems) {
if (pickedItems) {
// User actually selected some attributes to use
this.workspaceState.setGroupingAttrKeys(pickedItems.map((pi) => pi.label).sort());
this.refresh();
}
this.updateGroupingMenuContext();
}

groupTimelinesByNameComponents() {
this.workspaceState.setGroupingAttrKeys([]);
this.workspaceState.setGroupByTimelineNameComponents(true);
this.refresh();
this.updateGroupingMenuContext();
}

async getAvailableTimelineAttrKeys(): Promise<string[]> {
Expand Down Expand Up @@ -256,6 +280,18 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
}
}
}

// We use this to manage the context menu sort option checkboxes.
// It's not elegant, but it's all we can do since the
updateGroupingMenuContext() {
let groupingMode = TimelinesGroupingMode.FlatList;
if (this.workspaceState.getGroupByTimelineNameComponents()) {
groupingMode = TimelinesGroupingMode.ByNameComponents;
} else if (this.workspaceState.getGroupingAttrKeys().length > 0) {
groupingMode = TimelinesGroupingMode.ByAttributes;
}
vscode.commands.executeCommand("setContext", "auxon:timelinesGroupingMode", groupingMode);
}
}

// This is the base of all the tree item data classes
Expand Down

0 comments on commit 8b91faf

Please sign in to comment.