Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Basthon
Basthon Notebook
Commits
19b6485f
Commit
19b6485f
authored
Oct 30, 2020
by
Romain Casati
Browse files
Open function goes from notebook to GUI.
parent
235ddb75
Changes
4
Hide whitespace changes
Inline
Side-by-side
notebook/basthon/gui.js
View file @
19b6485f
...
...
@@ -160,6 +160,40 @@ Un lien vers la page de Basthon avec le contenu actuel du script a été créé.
document
.
body
.
removeChild
(
anchor
);
};
/**
* Load a notebook.
*/
that
.
openNotebook
=
function
(
file
)
{
return
new
Promise
(
function
(
resolve
,
reject
)
{
var
input
=
document
.
createElement
(
'
input
'
);
input
.
type
=
'
file
'
;
input
.
style
.
display
=
"
none
"
;
input
.
onchange
=
async
function
(
event
)
{
for
(
var
file
of
event
.
target
.
files
)
{
const
ext
=
file
.
name
.
split
(
'
.
'
).
pop
();
var
reader
=
new
FileReader
();
if
(
ext
===
'
ipynb
'
)
{
reader
.
readAsText
(
file
);
reader
.
onload
=
function
(
event
)
{
/* TODO: connect filename to notebook name */
await
that
.
notebook
.
load
(
JSON
.
parse
(
event
.
target
.
result
));
resolve
();
};
}
else
{
reader
.
readAsArrayBuffer
(
file
);
reader
.
onload
=
function
(
event
)
{
await
Basthon
.
putFile
(
file
.
name
,
event
.
target
.
result
);
resolve
();
};
}
}
}
document
.
body
.
appendChild
(
input
);
input
.
click
();
document
.
body
.
removeChild
(
input
);
});
};
return
that
;
})();
...
...
notebook/static/notebook/js/actions.js
View file @
19b6485f
...
...
@@ -891,7 +891,7 @@ define([
help_index
:
'
fd
'
,
icon
:
'
fa-folder-open-o
'
,
handler
:
function
(
env
,
event
)
{
env
.
notebook
.
openNotebook
();
basthonGUI
.
openNotebook
();
if
(
event
){
event
.
preventDefault
();
}
...
...
notebook/static/notebook/js/menubar.js
View file @
19b6485f
...
...
@@ -159,7 +159,7 @@ define([
var
that
=
this
;
this
.
element
.
find
(
'
#open_notebook
'
).
click
(
function
()
{
that
.
notebook
.
openNotebook
();
basthonGUI
.
openNotebook
();
});
this
.
element
.
find
(
'
#copy_notebook
'
).
click
(
function
()
{
that
.
notebook
.
copy_notebook
();
...
...
notebook/static/notebook/js/notebook.js
View file @
19b6485f
...
...
@@ -3077,39 +3077,6 @@ define([
}
};
/**
* [Basthon]
* Open notebook from file.
*/
Notebook
.
prototype
.
openNotebook
=
function
()
{
var
that
=
this
;
var
input
=
document
.
createElement
(
'
input
'
);
input
.
type
=
'
file
'
;
input
.
style
.
display
=
"
none
"
;
input
.
onchange
=
function
(
event
)
{
for
(
var
file
of
event
.
target
.
files
)
{
const
ext
=
file
.
name
.
split
(
'
.
'
).
pop
();
var
reader
=
new
FileReader
();
if
(
ext
===
'
ipynb
'
)
{
/* TODO: connect filename to notebook name */
reader
.
readAsText
(
file
);
reader
.
onload
=
function
(
event
)
{
that
.
load
(
JSON
.
parse
(
event
.
target
.
result
));
};
}
else
{
reader
.
readAsArrayBuffer
(
file
);
reader
.
onload
=
function
(
event
)
{
Basthon
.
putFile
(
file
.
name
,
event
.
target
.
result
);
};
}
}
};
document
.
body
.
appendChild
(
input
);
input
.
click
();
document
.
body
.
removeChild
(
input
);
};
/**
* Explicitly trust the output of this notebook.
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment