Skip to content

Commit ceabd92

Browse files
committed
Create a confirmation box for adding a new snippet
1 parent f496b20 commit ceabd92

File tree

2 files changed

+34
-23
lines changed

2 files changed

+34
-23
lines changed

src/CodeSnippetWidget.tsx

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ import { IRenderMimeRegistry } from '@jupyterlab/rendermime';
3838
import { copyIcon, addIcon, closeIcon } from '@jupyterlab/ui-components';
3939
import { Message } from '@lumino/messaging';
4040
import { Signal } from '@lumino/signaling';
41-
import { Widget, PanelLayout } from '@lumino/widgets';
41+
import { Widget } from '@lumino/widgets';
4242

4343
import { IDragEvent } from '@lumino/dragdrop';
4444
import { MimeData } from '@lumino/coreutils';
@@ -268,7 +268,6 @@ export class CodeSnippetWidget extends ReactWidget {
268268
this.getCurrentWidget = getCurrentWidget;
269269
this.codeSnippetManager = new CodeSnippetService();
270270
this.renderCodeSnippetsSignal = new Signal<this, ICodeSnippet[]>(this);
271-
this.layout = new Private.SnippetPanelLayout();
272271
}
273272
// Request code snippets from server
274273
async fetchData(): Promise<ICodeSnippet[]> {
@@ -481,22 +480,6 @@ namespace Private {
481480
const data = mime.getData('text/plain');
482481
return data;
483482
}
484-
485-
/**
486-
* A custom panel layout for the notebook.
487-
*/
488-
export class SnippetPanelLayout extends PanelLayout {
489-
/**
490-
* A message handler invoked on an `'update-request'` message.
491-
*
492-
* #### Notes
493-
* This is a reimplementation of the base class method,
494-
* and is a no-op.
495-
*/
496-
protected onUpdateRequest(msg: Message): void {
497-
// This is a no-op.
498-
}
499-
}
500483
}
501484

502485
/**

src/index.ts

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import '../style/index.css';
22

33
import { codeSnippetIcon } from '@elyra/ui-components';
4+
import checkSVGstr from '../style/check.svg';
5+
// import { LabIcon } from '@jupyterlab/ui-components';
46

57
import {
68
JupyterFrontEnd,
@@ -13,11 +15,11 @@ import { ICommandPalette } from '@jupyterlab/apputils';
1315

1416
import { CodeSnippetWidget } from './CodeSnippetWidget';
1517

18+
import { showMessage } from './ConfirmMessage';
1619

1720
import { RequestHandler } from '@elyra/application';
1821
// import { URLExt } from '@jupyterlab/coreutils';
1922

20-
2123
/////////////////////////////////////////////////////////////////////////////////////////////////////////////
2224
import { Dialog, showDialog} from '@jupyterlab/apputils';
2325

@@ -58,11 +60,11 @@ export interface IFileContainer extends JSONObject {
5860
* Rename a file with a dialog. This is what actually displays everything.
5961
* Result.value is the value retrieved from .getValue(). ---> .getValue() returns an array of inputs.
6062
*/
61-
export function renameDialog(
63+
export async function renameDialog(
6264
url: string,
6365
inputCode: string
6466
): Promise<Contents.IModel | null> {
65-
return showDialog({
67+
return await showDialog({
6668
title: 'Save Code Snippet',
6769
body: new RenameHandler(),
6870
focusNodeSelector: 'input',
@@ -90,6 +92,14 @@ export function renameDialog(
9092
}),
9193
false
9294
);
95+
showMessage({
96+
body: /*"Saved as Snippet"*/new MessageHandler()
97+
});
98+
// showDialog({
99+
// body: new ConfirmHandler(),
100+
// buttons: []
101+
// });
102+
// new ConfirmHandler();
93103
}
94104
// if (!isValidFileName(result.value)) {
95105
// void showErrorMessage(
@@ -174,6 +184,11 @@ class RenameHandler extends Widget {
174184
}
175185
}
176186

187+
class MessageHandler extends Widget {
188+
constructor() {
189+
super({ node: Private.createConfirmMessageNode() });
190+
}
191+
}
177192
/**
178193
* A namespace for private data.
179194
*/
@@ -211,6 +226,19 @@ namespace Private {
211226
body.appendChild(name3);
212227
return body;
213228
}
229+
230+
export function createConfirmMessageNode(): HTMLElement {
231+
const body = document.createElement('div');
232+
body.innerHTML = checkSVGstr;
233+
234+
const messageContainer = document.createElement('div');
235+
messageContainer.className = 'jp-confirm-text';
236+
const message = document.createElement('text');
237+
message.textContent = 'Saved as Snippet!';
238+
messageContainer.appendChild(message)
239+
body.append(messageContainer);
240+
return body;
241+
}
214242
}
215243

216244
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -284,8 +312,8 @@ const code_snippet_extension: JupyterFrontEndPlugin<void> = {
284312
// }),
285313
// false
286314
// );
287-
288-
renameDialog(url,temp);
315+
renameDialog(url,temp)
316+
289317
console.log(`Highlight trial: ${temp}`);
290318
}});
291319

0 commit comments

Comments
 (0)