@@ -9,6 +9,7 @@ import { DeepnoteTreeDataProvider } from './deepnoteTreeDataProvider';
99import { type DeepnoteTreeItem , DeepnoteTreeItemType , type DeepnoteTreeItemContext } from './deepnoteTreeItem' ;
1010import { generateUuid } from '../../platform/common/uuid' ;
1111import type { DeepnoteFile , DeepnoteNotebook , DeepnoteBlock } from '../../platform/deepnote/deepnoteTypes' ;
12+ import { Commands } from '../../platform/common/constants' ;
1213
1314/**
1415 * Manages the Deepnote explorer tree view and related commands
@@ -40,72 +41,72 @@ export class DeepnoteExplorerView {
4041
4142 private registerCommands ( ) : void {
4243 this . extensionContext . subscriptions . push (
43- commands . registerCommand ( 'deepnote.refreshExplorer' , ( ) => this . refreshExplorer ( ) )
44+ commands . registerCommand ( Commands . RefreshDeepnoteExplorer , ( ) => this . refreshExplorer ( ) )
4445 ) ;
4546
4647 this . extensionContext . subscriptions . push (
47- commands . registerCommand ( 'deepnote.openNotebook' , ( context : DeepnoteTreeItemContext ) =>
48+ commands . registerCommand ( Commands . OpenDeepnoteNotebook , ( context : DeepnoteTreeItemContext ) =>
4849 this . openNotebook ( context )
4950 )
5051 ) ;
5152
5253 this . extensionContext . subscriptions . push (
53- commands . registerCommand ( 'deepnote.openFile' , ( treeItem : DeepnoteTreeItem ) => this . openFile ( treeItem ) )
54+ commands . registerCommand ( Commands . OpenDeepnoteFile , ( treeItem : DeepnoteTreeItem ) => this . openFile ( treeItem ) )
5455 ) ;
5556
5657 this . extensionContext . subscriptions . push (
57- commands . registerCommand ( 'deepnote.revealInExplorer' , ( ) => this . revealActiveNotebook ( ) )
58+ commands . registerCommand ( Commands . RevealInDeepnoteExplorer , ( ) => this . revealActiveNotebook ( ) )
5859 ) ;
5960
6061 this . extensionContext . subscriptions . push (
61- commands . registerCommand ( 'deepnote.newProject' , ( ) => this . newProject ( ) )
62+ commands . registerCommand ( Commands . NewProject , ( ) => this . newProject ( ) )
6263 ) ;
6364
6465 this . extensionContext . subscriptions . push (
65- commands . registerCommand ( 'deepnote.importNotebook' , ( ) => this . importNotebook ( ) )
66+ commands . registerCommand ( Commands . ImportNotebook , ( ) => this . importNotebook ( ) )
6667 ) ;
6768
6869 this . extensionContext . subscriptions . push (
69- commands . registerCommand ( 'deepnote.importJupyterNotebook' , ( ) => this . importJupyterNotebook ( ) )
70+ commands . registerCommand ( Commands . ImportJupyterNotebook , ( ) => this . importJupyterNotebook ( ) )
7071 ) ;
7172
7273 this . extensionContext . subscriptions . push (
73- commands . registerCommand ( 'deepnote.newNotebook' , ( ) => this . newNotebook ( ) )
74+ commands . registerCommand ( Commands . NewNotebook , ( ) => this . newNotebook ( ) )
7475 ) ;
7576
7677 // Context menu commands for tree items
7778 this . extensionContext . subscriptions . push (
78- commands . registerCommand ( 'deepnote.renameProject' , ( treeItem : DeepnoteTreeItem ) =>
79+ commands . registerCommand ( Commands . RenameProject , ( treeItem : DeepnoteTreeItem ) =>
7980 this . renameProject ( treeItem )
8081 )
8182 ) ;
8283
8384 this . extensionContext . subscriptions . push (
84- commands . registerCommand ( 'deepnote.deleteProject' , ( treeItem : DeepnoteTreeItem ) =>
85+ commands . registerCommand ( Commands . DeleteProject , ( treeItem : DeepnoteTreeItem ) =>
8586 this . deleteProject ( treeItem )
8687 )
8788 ) ;
8889
8990 this . extensionContext . subscriptions . push (
90- commands . registerCommand ( 'deepnote.renameNotebook' , ( treeItem : DeepnoteTreeItem ) =>
91+ commands . registerCommand ( Commands . RenameNotebook , ( treeItem : DeepnoteTreeItem ) =>
9192 this . renameNotebook ( treeItem )
9293 )
9394 ) ;
9495
9596 this . extensionContext . subscriptions . push (
96- commands . registerCommand ( 'deepnote.deleteNotebook' , ( treeItem : DeepnoteTreeItem ) =>
97+ commands . registerCommand ( Commands . DeleteNotebook , ( treeItem : DeepnoteTreeItem ) =>
9798 this . deleteNotebook ( treeItem )
9899 )
99100 ) ;
100101
101102 this . extensionContext . subscriptions . push (
102- commands . registerCommand ( 'deepnote.duplicateNotebook' , ( treeItem : DeepnoteTreeItem ) =>
103+ commands . registerCommand ( Commands . DuplicateNotebook , ( treeItem : DeepnoteTreeItem ) =>
103104 this . duplicateNotebook ( treeItem )
104105 )
105106 ) ;
106107
107108 this . extensionContext . subscriptions . push (
108- commands . registerCommand ( 'deepnote.addNotebookToProject' , ( treeItem : DeepnoteTreeItem ) =>
109+ commands . registerCommand ( Commands . AddNotebookToProject , ( treeItem : DeepnoteTreeItem ) =>
109110 this . addNotebookToProject ( treeItem )
110111 )
111112 ) ;
@@ -149,7 +150,10 @@ export class DeepnoteExplorerView {
149150 * @param suggestedName The default suggested name
150151 * @returns The entered notebook name, or undefined if cancelled
151152 */
152- private async promptForNotebookName ( suggestedName : string ) : Promise < string | undefined > {
153+ private async promptForNotebookName (
154+ suggestedName : string ,
155+ existingNames : Set < string >
156+ ) : Promise < string | undefined > {
153157 return await window . showInputBox ( {
154158 prompt : l10n . t ( 'Enter a name for the new notebook' ) ,
155159 placeHolder : suggestedName ,
@@ -158,6 +162,9 @@ export class DeepnoteExplorerView {
158162 if ( ! value || value . trim ( ) . length === 0 ) {
159163 return l10n . t ( 'Notebook name cannot be empty' ) ;
160164 }
165+ if ( existingNames . has ( value ) ) {
166+ return l10n . t ( 'A notebook with this name already exists' ) ;
167+ }
161168 return null ;
162169 }
163170 } ) ;
@@ -240,14 +247,22 @@ export class DeepnoteExplorerView {
240247 // Read the Deepnote project file
241248 const projectData = await this . readDeepnoteProjectFile ( fileUri ) ;
242249
250+ if ( projectData . project . id !== projectId ) {
251+ await window . showErrorMessage ( l10n . t ( 'Project ID mismatch' ) ) ;
252+ return null ;
253+ }
254+
243255 if ( ! projectData ?. project ) {
244256 await window . showErrorMessage ( l10n . t ( 'Invalid Deepnote file format' ) ) ;
245257 return null ;
246258 }
247259
248260 // Generate suggested name and prompt user
249261 const suggestedName = this . generateSuggestedNotebookName ( projectData ) ;
250- const notebookName = await this . promptForNotebookName ( suggestedName ) ;
262+ const notebookName = await this . promptForNotebookName (
263+ suggestedName ,
264+ new Set ( projectData . project . notebooks ?. map ( ( nb : DeepnoteNotebook ) => nb . name . toLowerCase ( ) ) ?? [ ] )
265+ ) ;
251266
252267 if ( ! notebookName ) {
253268 return null ;
@@ -921,7 +936,8 @@ export class DeepnoteExplorerView {
921936 ...block ,
922937 id : generateUuid ( ) ,
923938 blockGroup : generateUuid ( ) ,
924- executionCount : undefined
939+ executionCount : undefined ,
940+ ...( block . metadata != null ? { metadata : { ...block . metadata } } : { } )
925941 } ) )
926942 } ;
927943
0 commit comments