Skip to content

Commit

Permalink
Allow recursive submenus
Browse files Browse the repository at this point in the history
  • Loading branch information
obany committed Jan 8, 2024
1 parent dabe06e commit 8c75269
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ async function buildButtonsFromEntries(
} else if ("action" in entry) {
await addEntryAsAction(buttons, entry, iconFolder, colorSchemeMode, isTopLevel);
} else if ("options" in entry) {
await addEntriesAsDropdown(buttons, entry, iconFolder, colorSchemeMode, platform);
await addEntriesAsDropdown(buttons, entry, iconFolder, colorSchemeMode, isTopLevel, platform);
} else if ("tags" in entry) {
await addEntriesByAppTag(buttons, entry, iconFolder, colorSchemeMode);
}
Expand Down Expand Up @@ -319,19 +319,23 @@ async function addEntryAsAction(
* @param entry The entry details.
* @param iconFolder The folder for icons.
* @param colorSchemeMode The color scheme
* @param isTopLevel Is this a top level entry.
* @param platform The workspace platform for checking conditions.
*/
async function addEntriesAsDropdown(
buttons: DockButton[],
entry: DockButtonDropdown,
iconFolder: string,
colorSchemeMode: ColorSchemeMode,
isTopLevel: boolean,
platform: WorkspacePlatformModule
): Promise<void> {
// Options are present so this is a drop down
// The items in the drop down can be an appId or a custom action
if (!isStringValue(entry.tooltip) || !isStringValue(entry.iconUrl)) {
logger.error("You must specify the tooltip and iconUrl for a DockButtonDropdown");
if (!isStringValue(entry.tooltip)) {
logger.error("You must specify the tooltip for a DockButtonDropdown");
} else if (isTopLevel && !isStringValue(entry.iconUrl)) {
logger.error("You must specify the iconUrl for a DockButtonDropdown");
} else {
const opts: (CustomButtonConfig | CustomDropdownConfig)[] = [];

Expand All @@ -351,7 +355,7 @@ async function addEntriesAsDropdown(
let optionTooltip = option.tooltip;
let action: CustomActionSpecifier | undefined;
let iconUrl;
let subOptions: CustomButtonConfig[] | undefined;
let subOptions: (CustomButtonConfig | CustomDropdownConfig)[] | undefined;

// If there are options this is a submenu
if ("options" in option) {
Expand All @@ -367,7 +371,11 @@ async function addEntriesAsDropdown(
action: dockButton.action
});
} else if (dockButton.type === DockButtonNames.DropdownButton) {
// Only single level of nesting supported
subOptions.push({
tooltip: dockButton.tooltip,
iconUrl: dockButton.iconUrl,
options: dockButton.options
});
}
}
} else if ("appId" in option) {
Expand Down
23 changes: 23 additions & 0 deletions how-to/workspace-platform-starter/public/manifest.fin.json
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,29 @@
"url": "https://github.com/openfin"
}
}
},
{
"tooltip": "Search",
"options": [
{
"tooltip": "Google",
"action": {
"id": "launch-view",
"customData": {
"url": "https://www.google.com/search?q=openfin"
}
}
},
{
"tooltip": "Bing",
"action": {
"id": "launch-view",
"customData": {
"url": "https://www.bing.com/search?q=openfin"
}
}
}
]
}
]
}
Expand Down

0 comments on commit 8c75269

Please sign in to comment.