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 28, 2023
1 parent 27f0739 commit 4338a01
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 22 deletions.
34 changes: 20 additions & 14 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -308,18 +308,23 @@
"group": "navigation@1"
},
{
"command": "auxon.timelines.disableTimelineGrouping",
"when": "view == auxon.timelines",
"group": "7_modification@1"
"command": "auxon.timelines.setGroupingAttrs",
"when": "view == auxon.timelines && auxon.timelinesGroupingMode != 'BY_ATTRIBUTES'",
"group": "7_modification@2"
},
{
"command": "auxon.timelines.setGroupingAttrs",
"when": "view == auxon.timelines",
"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 @@ -404,19 +409,20 @@
"icon": "$(refresh)"
},
{
"command": "auxon.timelines.disableTimelineGrouping",
"title": "Show Timelines in Flat List",
"icon": "$(refresh)"
"command": "auxon.timelines.setGroupingAttrs",
"title": "Group timelines by attribute"
},
{
"command": "auxon.timelines.setGroupingAttrs",
"title": "Group Timelines by Attribute",
"icon": "$(refresh)"
"command": "auxon.timelines.clearGroupingAttrs",
"title": "✓ Group timelines by attribute"
},
{
"command": "auxon.timelines.groupTimelinesByNameComponents",
"title": "Group Timelines by Name Components",
"icon": "$(refresh)"
"title": "Group timelines by name components"
},
{
"command": "auxon.timelines.clearGroupTimelinesByNameComponents",
"title": "✓ Group timelines by name components"
},
{
"command": "auxon.timelines.inspect",
Expand Down
41 changes: 33 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 Down Expand Up @@ -62,17 +68,23 @@ 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.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();
})
);
}

refresh(): void {
this.updateGroupingMenuContext();
this._onDidChangeTreeData.fire(undefined);
}

Expand Down Expand Up @@ -217,6 +229,7 @@ export class TimelinesTreeDataProvider implements vscode.TreeDataProvider<Timeli
}

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 @@ -226,7 +239,7 @@ 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();
Expand Down Expand Up @@ -264,6 +277,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 for now
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 4338a01

Please sign in to comment.