@@ -2755,7 +2755,7 @@ define([
2755
2755
// In some cases the filesystem reports an inconsistent time,
2756
2756
// so we allow 0.5 seconds difference before complaining.
2757
2757
// This is configurable in nbconfig/notebook.json as `last_modified_check_margin`.
2758
- if ( ( last_modified . getTime ( ) - that . last_modified . getTime ( ) ) > last_modified_check_margin ) {
2758
+ if ( ( last_modified . getTime ( ) - that . last_modified . getTime ( ) ) > last_modified_check_margin ) {
2759
2759
console . warn ( "Last saving was done on `" + that . last_modified + "`(" + that . _last_modified + "), " +
2760
2760
"while the current file seem to have been saved on `" + data . last_modified + "`" ) ;
2761
2761
if ( that . _changed_on_disk_dialog !== null ) {
@@ -2845,6 +2845,91 @@ define([
2845
2845
}
2846
2846
} ;
2847
2847
2848
+
2849
+ Notebook . prototype . save_notebook_as = function ( ) {
2850
+ // If current notebook has some changes, save them
2851
+ if ( this . writable && this . dirty ) {
2852
+ this . save_notebook ( ) ;
2853
+ }
2854
+ var that = this ;
2855
+ var dialog_body = $ ( '<div/>' ) . append (
2856
+ $ ( "<p/>" ) . addClass ( "save-message" )
2857
+ . text ( i18n . msg . _ ( 'Enter a notebook path relative to notebook dir' ) )
2858
+ ) . append (
2859
+ $ ( "<br/>" )
2860
+ ) . append (
2861
+ $ ( '<input/>' ) . attr ( 'type' , 'text' ) . attr ( 'size' , '25' )
2862
+ . addClass ( 'form-control' ) . attr ( 'placeholder' , that . notebook_name )
2863
+ ) ;
2864
+
2865
+ var d = dialog . modal ( {
2866
+ title : 'Save As' ,
2867
+ body : dialog_body ,
2868
+ keyboard_manager : this . keyboard_manager ,
2869
+ notebook : this ,
2870
+ buttons : {
2871
+ Cancel : { } ,
2872
+ Save : {
2873
+ class : 'btn-primary' ,
2874
+ click : function ( ) {
2875
+ var nb_path = d . find ( 'input' ) . val ( ) ;
2876
+ var nb_name = nb_path . split ( '/' ) . slice ( - 1 ) . pop ( ) ;
2877
+ // If notebook name does not contain extension '.ipynb' add it
2878
+ var ext = utils . splitext ( nb_name ) ;
2879
+ if ( ext === '' ) {
2880
+ nb_name = nb_name + '.ipynb' ;
2881
+ }
2882
+ var model = {
2883
+ 'type' : 'notebook' ,
2884
+ 'content' : that . toJSON ( ) ,
2885
+ 'name' : nb_name
2886
+ } ;
2887
+
2888
+ var save_thunk = function ( ) {
2889
+ return that . contents . save ( nb_path , model )
2890
+ . then ( function ( data ) {
2891
+ window . open ( data . path , '_self' ) ;
2892
+ } , function ( error ) {
2893
+ console . error ( i18n . msg . _ ( error . message || 'Unknown error saving notebook' ) ) ;
2894
+ } ) ;
2895
+ }
2896
+ that . contents . get ( nb_path , { type : 'notebook' } ) . then ( function ( data ) {
2897
+ var warning_body = $ ( '<div/>' ) . append (
2898
+ $ ( "<p/>" ) . text ( i18n . msg . _ ( 'Notebook with that name exists.' ) ) ) ;
2899
+ dialog . modal ( {
2900
+ title : 'Save As' ,
2901
+ body : warning_body ,
2902
+ buttons : { Cancel : { } ,
2903
+ Overwrite : {
2904
+ class : 'btn-warning' ,
2905
+ click : function ( ) {
2906
+ return save_thunk ( ) ;
2907
+ }
2908
+ }
2909
+ }
2910
+ } ) ;
2911
+ } , function ( err ) {
2912
+ return save_thunk ( ) ;
2913
+ } )
2914
+ return false ;
2915
+ }
2916
+ } ,
2917
+ } ,
2918
+ open : function ( ) {
2919
+ /**
2920
+ * Upon ENTER, click the OK button.
2921
+ */
2922
+ d . find ( 'input[type="text"]' ) . keydown ( function ( event ) {
2923
+ if ( event . which === keyboard . keycodes . enter ) {
2924
+ d . find ( '.btn-primary' ) . first ( ) . click ( ) ;
2925
+ return false ;
2926
+ }
2927
+ } ) ;
2928
+ d . find ( 'input[type="text"]' ) . focus ( ) . select ( ) ;
2929
+ }
2930
+ } ) ;
2931
+ }
2932
+
2848
2933
/**
2849
2934
* Update the autosave interval based on the duration of the last save.
2850
2935
*
0 commit comments