Skip to content

Commit dc9404d

Browse files
Copilotmikebarkmin
andcommitted
Hide open/download buttons and add show source command
- Add disableFileOperations prop to LearningMapEditor and EditorToolbar - Conditionally hide open and download buttons when disableFileOperations is true - Enable disableFileOperations in VS Code webview - Add "Learningmap: Show Source" command to view JSON source - Visual editor is now the default view (custom editors always open in custom view) - Users can use the new command to switch to source view when needed Co-authored-by: mikebarkmin <2592379+mikebarkmin@users.noreply.github.com>
1 parent ccd6d82 commit dc9404d

5 files changed

Lines changed: 41 additions & 8 deletions

File tree

packages/learningmap/src/EditorToolbar.tsx

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ import { getZIndexForNodeType } from "./zIndexHelper";
1414
interface EditorToolbarProps {
1515
defaultLanguage?: string;
1616
disableSharing?: boolean;
17+
disableFileOperations?: boolean;
1718
}
1819

1920
export const EditorToolbar: React.FC<EditorToolbarProps> = ({
2021
defaultLanguage = "en",
2122
disableSharing = false,
23+
disableFileOperations = false,
2224
}) => {
2325
const { screenToFlowPosition } = useReactFlow();
2426

@@ -114,12 +116,16 @@ export const EditorToolbar: React.FC<EditorToolbarProps> = ({
114116
</div>
115117
<div className="toolbar-group">
116118
<Menu menuButton={<MenuButton className="toolbar-button"><MenuI /></MenuButton>}>
117-
<MenuItem onClick={openRoadmap}>
118-
<FolderOpen size={16} /> <span>{t.open}</span>
119-
</MenuItem>
120-
<MenuItem onClick={downloadRoadmap}>
121-
<Download size={16} /> <span>{t.download}</span>
122-
</MenuItem>
119+
{!disableFileOperations && (
120+
<MenuItem onClick={openRoadmap}>
121+
<FolderOpen size={16} /> <span>{t.open}</span>
122+
</MenuItem>
123+
)}
124+
{!disableFileOperations && (
125+
<MenuItem onClick={downloadRoadmap}>
126+
<Download size={16} /> <span>{t.download}</span>
127+
</MenuItem>
128+
)}
123129
{!disableSharing && (
124130
<MenuItem onClick={postToJsonStore}>
125131
<Share2 size={16} /> <span>{t.share}</span>

packages/learningmap/src/LearningMapEditor.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ export interface LearningMapEditorProps {
1616
language?: string;
1717
jsonStore?: string;
1818
disableSharing?: boolean;
19+
disableFileOperations?: boolean;
1920
}
2021

2122
export function LearningMapEditor({
2223
roadmapData,
2324
language = "en",
2425
jsonStore = "https://json.openpatch.org",
2526
disableSharing = false,
27+
disableFileOperations = false,
2628
}: LearningMapEditorProps) {
2729
// Only get minimal state needed in this component
2830
const nodes = useEditorStore(state => state.nodes);
@@ -66,7 +68,7 @@ export function LearningMapEditor({
6668
<KeyboardShortcuts jsonStore={jsonStore} />
6769

6870
{/* Toolbar */}
69-
<EditorToolbar defaultLanguage={language} disableSharing={disableSharing} />
71+
<EditorToolbar defaultLanguage={language} disableSharing={disableSharing} disableFileOperations={disableFileOperations} />
7072

7173
{/* Preview or Edit mode */}
7274
{previewMode && <LearningMap roadmapData={getRoadmapData()} language={effectiveLanguage} />}

platforms/vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@
4747
"command": "learningmap.new",
4848
"title": "New Learningmap",
4949
"category": "Learningmap"
50+
},
51+
{
52+
"command": "learningmap.showSource",
53+
"title": "Show Source",
54+
"category": "Learningmap"
5055
}
5156
]
5257
},

platforms/vscode/src/extension.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@ export function activate(context: vscode.ExtensionContext) {
7373
})
7474
);
7575

76+
// Register command to show source
77+
context.subscriptions.push(
78+
vscode.commands.registerCommand('learningmap.showSource', async () => {
79+
const activeEditor = vscode.window.activeTextEditor;
80+
if (!activeEditor) {
81+
vscode.window.showErrorMessage('No active learningmap file');
82+
return;
83+
}
84+
85+
const uri = activeEditor.document.uri;
86+
if (!uri.path.endsWith('.learningmap')) {
87+
vscode.window.showErrorMessage('Active file is not a learningmap file');
88+
return;
89+
}
90+
91+
// Open the file with the default text editor
92+
await vscode.commands.executeCommand('vscode.openWith', uri, 'default');
93+
})
94+
);
95+
7696
console.log('Learningmap extension is now active');
7797
}
7898

platforms/vscode/src/webview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ function WebviewEditor() {
127127
return <div style={{ padding: '20px' }}>Loading editor...</div>;
128128
}
129129

130-
return <LearningMapEditor disableSharing={true} />;
130+
return <LearningMapEditor disableSharing={true} disableFileOperations={true} />;
131131
}
132132

133133
// Mount the React component

0 commit comments

Comments
 (0)