@@ -36,13 +36,7 @@ import {
36
36
import { CodeEditor , IEditorServices } from '@jupyterlab/codeeditor' ;
37
37
import * as nbformat from '@jupyterlab/nbformat' ;
38
38
import { JupyterFrontEnd } from '@jupyterlab/application' ;
39
- import {
40
- Cell ,
41
- CodeCellModel ,
42
- ICodeCellModel ,
43
- MarkdownCell ,
44
- CodeCell ,
45
- } from '@jupyterlab/cells' ;
39
+ import { CodeCellModel , MarkdownCell , CodeCell } from '@jupyterlab/cells' ;
46
40
47
41
import { Widget } from '@lumino/widgets' ;
48
42
import { find , StringExt } from '@lumino/algorithm' ;
@@ -51,8 +45,8 @@ import { MimeData } from '@lumino/coreutils';
51
45
52
46
import React from 'react' ;
53
47
import { CodeSnippetService , ICodeSnippet } from './CodeSnippetService' ;
54
- import { FilterTools } from './FilterTools ' ;
55
- import { showPreview } from './PreviewSnippet ' ;
48
+ import { FilterTools } from './CodeSnippetFilterTools ' ;
49
+ import { showPreview } from './CodeSnippetPreview ' ;
56
50
import { showMoreOptions } from './CodeSnippetMenu' ;
57
51
58
52
import { CodeSnippetContentsService } from './CodeSnippetContentsService' ;
@@ -98,6 +92,7 @@ import {
98
92
sasIcon ,
99
93
} from './CodeSnippetLanguages' ;
100
94
import { ICodeSnippetEditorMetadata } from './CodeSnippetEditor' ;
95
+ import { showMessage } from './CodeSnippetMessage' ;
101
96
102
97
/**
103
98
* The CSS class added to code snippet widget.
@@ -127,6 +122,7 @@ const CODE_SNIPPET_MORE_OTPIONS_DOWNLOAD =
127
122
'jp-codeSnippet-more-options-download' ;
128
123
const CODE_SNIPPET_CREATE_NEW_BTN = 'jp-createSnippetBtn' ;
129
124
const CODE_SNIPPET_NAME = 'jp-codeSnippet-name' ;
125
+ const OPTIONS_BODY = 'jp-codeSnippet-options-body' ;
130
126
131
127
/**
132
128
* The threshold in pixels to start a drag event.
@@ -695,8 +691,7 @@ export class CodeSnippetDisplay extends React.Component<
695
691
) : Promise < void > {
696
692
const target = event . target as HTMLElement ;
697
693
698
- const modelFactory = new ModelFactory ( ) ;
699
- const model = modelFactory . createCodeCell ( { } ) ;
694
+ const model = new CodeCellModel ( { } ) ;
700
695
model . value . text = codeSnippet . code . join ( '\n' ) ;
701
696
model . metadata ;
702
697
@@ -1295,7 +1290,9 @@ export class CodeSnippetDisplay extends React.Component<
1295
1290
title : 'Insert, copy, edit, and delete' ,
1296
1291
icon : moreOptionsIcon ,
1297
1292
onClick : ( event : React . MouseEvent < HTMLElement , MouseEvent > ) : void => {
1298
- showMoreOptions ( { body : new OptionsHandler ( this , codeSnippet ) } ) ;
1293
+ showMoreOptions ( {
1294
+ body : new OptionsHandler ( this , codeSnippet ) ,
1295
+ } ) ;
1299
1296
this . _setOptionsPosition ( event ) ;
1300
1297
} ,
1301
1298
} ,
@@ -1316,7 +1313,9 @@ export class CodeSnippetDisplay extends React.Component<
1316
1313
event : React . MouseEvent < HTMLElement , MouseEvent >
1317
1314
) : void => {
1318
1315
event . preventDefault ( ) ;
1319
- showMoreOptions ( { body : new OptionsHandler ( this , codeSnippet ) } ) ;
1316
+ showMoreOptions ( {
1317
+ body : new OptionsHandler ( this , codeSnippet ) ,
1318
+ } ) ;
1320
1319
this . _setOptionsPosition ( event ) ;
1321
1320
} }
1322
1321
>
@@ -1456,11 +1455,10 @@ export class CodeSnippetDisplay extends React.Component<
1456
1455
title : 'Delete snippet?' ,
1457
1456
body : 'Are you sure you want to delete "' + codeSnippet . name + '"? ' ,
1458
1457
buttons : [
1459
- Dialog . okButton ( {
1458
+ Dialog . cancelButton ( ) ,
1459
+ Dialog . warnButton ( {
1460
1460
label : 'Delete' ,
1461
- displayType : 'warn' ,
1462
1461
} ) ,
1463
- Dialog . cancelButton ( ) ,
1464
1462
] ,
1465
1463
} ) . then ( ( response : any ) : void => {
1466
1464
if ( response . button . accept ) {
@@ -1518,6 +1516,7 @@ export class CodeSnippetDisplay extends React.Component<
1518
1516
format : 'text' ,
1519
1517
content : JSON . stringify ( codeSnippet ) ,
1520
1518
} ) ;
1519
+ showMessage ( 'download' ) ;
1521
1520
}
1522
1521
} ) ;
1523
1522
}
@@ -1533,6 +1532,7 @@ export class CodeSnippetDisplay extends React.Component<
1533
1532
// create dropdown menu
1534
1533
public createOptionsNode ( codeSnippet : ICodeSnippet ) : HTMLElement {
1535
1534
const body = document . createElement ( 'div' ) ;
1535
+ body . className = OPTIONS_BODY ;
1536
1536
1537
1537
const optionsContainer = document . createElement ( 'div' ) ;
1538
1538
optionsContainer . className = CODE_SNIPPET_MORE_OTPIONS_CONTENT ;
@@ -1548,7 +1548,7 @@ export class CodeSnippetDisplay extends React.Component<
1548
1548
copySnip . textContent = 'Copy snippet to clipboard' ;
1549
1549
copySnip . onclick = ( ) : void => {
1550
1550
Clipboard . copyToSystem ( codeSnippet . code . join ( '\n' ) ) ;
1551
- alert ( 'saved to clipboard ') ;
1551
+ showMessage ( 'copy ') ;
1552
1552
this . removeOptionsNode ( ) ;
1553
1553
} ;
1554
1554
const editSnip = document . createElement ( 'div' ) ;
@@ -1677,40 +1677,3 @@ class Private {
1677
1677
return this . createPreviewContent ( ) ;
1678
1678
}
1679
1679
}
1680
-
1681
- /**
1682
- * A content factory for console children.
1683
- */
1684
- export interface IContentFactory extends Cell . IContentFactory {
1685
- /**
1686
- * Create a new code cell widget.
1687
- */
1688
- createCodeCell ( options : CodeCell . IOptions ) : CodeCell ;
1689
- }
1690
-
1691
- /**
1692
- * The default implementation of an `IModelFactory`.
1693
- */
1694
- export class ModelFactory {
1695
- /**
1696
- * The factory for output area models.
1697
- */
1698
- readonly codeCellContentFactory : CodeCellModel . IContentFactory ;
1699
-
1700
- /**
1701
- * Create a new code cell.
1702
- *
1703
- * @param source - The data to use for the original source data.
1704
- *
1705
- * @returns A new code cell. If a source cell is provided, the
1706
- * new cell will be initialized with the data from the source.
1707
- * If the contentFactory is not provided, the instance
1708
- * `codeCellContentFactory` will be used.
1709
- */
1710
- createCodeCell ( options : CodeCellModel . IOptions ) : ICodeCellModel {
1711
- if ( ! options . contentFactory ) {
1712
- options . contentFactory = this . codeCellContentFactory ;
1713
- }
1714
- return new CodeCellModel ( options ) ;
1715
- }
1716
- }
0 commit comments