Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
fix up context menus
  • Loading branch information
sawka committed Mar 11, 2026
commit 45188d0a1946b44f62d191009867c5bd314c368a
57 changes: 55 additions & 2 deletions frontend/app/view/preview/preview-directory-utils.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2025, Command Line Inc.
// Copyright 2026, Command Line Inc.
// SPDX-License-Identifier: Apache-2.0

import { globalStore } from "@/app/store/global";
import { getSettingsKeyAtom, globalStore } from "@/app/store/global";
import { RpcApi } from "@/app/store/wshclientapi";
import { TabRpcClient } from "@/app/store/wshrpcutil";
import { fireAndForget, isBlank } from "@/util/util";
Expand Down Expand Up @@ -152,3 +152,56 @@ export function handleFileDelete(
model.refreshCallback();
});
}

export function makeDirectoryDefaultMenuItems(model: PreviewModel): ContextMenuItem[] {
const defaultSort = globalStore.get(getSettingsKeyAtom("preview:defaultsort")) ?? "name";
const showHiddenFiles = globalStore.get(model.showHiddenFiles) ?? true;
return [
{
label: "Directory Sort Order",
submenu: [
{
label: "Name",
type: "checkbox",
checked: defaultSort === "name",
click: () =>
fireAndForget(() => RpcApi.SetConfigCommand(TabRpcClient, { "preview:defaultsort": "name" })),
},
{
label: "Last Modified",
type: "checkbox",
checked: defaultSort === "modtime",
click: () =>
fireAndForget(() =>
RpcApi.SetConfigCommand(TabRpcClient, { "preview:defaultsort": "modtime" })
),
},
],
},
{
label: "Show Hidden Files",
submenu: [
{
label: "On",
type: "checkbox",
checked: showHiddenFiles,
click: () => {
globalStore.set(model.showHiddenFiles, true);
fireAndForget(() => RpcApi.SetConfigCommand(TabRpcClient, { "preview:showhiddenfiles": true }));
},
},
{
label: "Off",
type: "checkbox",
checked: !showHiddenFiles,
click: () => {
globalStore.set(model.showHiddenFiles, false);
fireAndForget(() =>
RpcApi.SetConfigCommand(TabRpcClient, { "preview:showhiddenfiles": false })
);
},
},
],
},
];
}
12 changes: 9 additions & 3 deletions frontend/app/view/preview/preview-directory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
handleFileDelete,
handleRename,
isIconValid,
makeDirectoryDefaultMenuItems,
mergeError,
overwriteError,
} from "./preview-directory-utils";
Expand Down Expand Up @@ -159,9 +160,7 @@ function DirectoryTable({
sortingFn: "alphanumeric",
}),
columnHelper.accessor("modtime", {
cell: (info) => (
<span className="dir-table-lastmod">{getLastModifiedTime(info.getValue())}</span>
),
cell: (info) => <span className="dir-table-lastmod">{getLastModifiedTime(info.getValue())}</span>,
header: () => <span>Last Modified</span>,
size: 91,
minSize: 65,
Expand Down Expand Up @@ -409,6 +408,13 @@ function TableBody({
];
addOpenMenuItems(menu, conn, finfo);
menu.push(
{
type: "separator",
},
{
label: "Default Settings",
submenu: makeDirectoryDefaultMenuItems(model),
},
Comment on lines 410 to +417
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Expose the new submenu from the background context menu too.

These items are only added to row menus here. The container-level menu in the same file still omits them, so an empty directory has no path to the new Default Settings feature at all. Mirror this submenu into the background/whitespace context menu as well.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@frontend/app/view/preview/preview-directory.tsx` around lines 410 - 417, The
background/whitespace/container-level context menu is missing the "Default
Settings" submenu that you added to row menus; update the container-level menu
builder in preview-directory.tsx to mirror the same entries by pushing the
separator and an item with label "Default Settings" and submenu set to
makeDirectoryDefaultMenuItems(model) (same as the existing row-menu push).
Locate where the container/background context menu is constructed in this file
and add the same menu entry so empty directories can access the Default Settings
feature.

{
type: "separator",
},
Expand Down
56 changes: 3 additions & 53 deletions frontend/app/view/preview/preview-model.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { loadable } from "jotai/utils";
import type * as MonacoTypes from "monaco-editor";
import { createRef } from "react";
import { PreviewView } from "./preview";
import { makeDirectoryDefaultMenuItems } from "./preview-directory-utils";

// TODO drive this using config
const BOOKMARKS: { label: string; path: string }[] = [
Expand Down Expand Up @@ -795,60 +796,9 @@ export class PreviewModel implements ViewModel {
});
}
if (loadableSV.state == "hasData" && loadableSV.data.specializedView == "directory") {
const defaultSort = globalStore.get(getSettingsKeyAtom("preview:defaultsort")) ?? "name";
const showHiddenFiles = globalStore.get(this.showHiddenFiles) ?? true;
menuItems.push({ type: "separator" });
menuItems.push({ label: "Directory Defaults", enabled: false });
menuItems.push({
label: "Sort Order",
submenu: [
{
label: "Name",
type: "checkbox",
checked: defaultSort === "name",
click: () =>
fireAndForget(() =>
RpcApi.SetConfigCommand(TabRpcClient, { "preview:defaultsort": "name" })
),
},
{
label: "Last Modified",
type: "checkbox",
checked: defaultSort === "modtime",
click: () =>
fireAndForget(() =>
RpcApi.SetConfigCommand(TabRpcClient, { "preview:defaultsort": "modtime" })
),
},
],
});
menuItems.push({
label: "Show Hidden Files",
submenu: [
{
label: "On",
type: "checkbox",
checked: showHiddenFiles,
click: () => {
globalStore.set(this.showHiddenFiles, true);
fireAndForget(() =>
RpcApi.SetConfigCommand(TabRpcClient, { "preview:showhiddenfiles": true })
);
},
},
{
label: "Off",
type: "checkbox",
checked: !showHiddenFiles,
click: () => {
globalStore.set(this.showHiddenFiles, false);
fireAndForget(() =>
RpcApi.SetConfigCommand(TabRpcClient, { "preview:showhiddenfiles": false })
);
},
},
],
});
menuItems.push({ label: "Default Settings", enabled: false });
menuItems.push(...makeDirectoryDefaultMenuItems(this));
}
return menuItems;
}
Expand Down
Loading