-
Notifications
You must be signed in to change notification settings - Fork 5.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persist header and toolbar toggle status in nbconfig #1769
Conversation
If `notebook.header` or `notebook.toolbar` are `false`, hide them on load
@Carreau I am following your lead from c040464. However, neither the |
Yeah, nbconfig thing is complex. let me have a look. Thanks for that. |
So it seem you get the config right, the problem is the asynchronicity and the config return defaults before being completly loaded. if you You might want to add a The
Does that make sens ? |
The idea with the config is that you can create a // Get a value immediately, using the defaults if real values aren't loaded yet
visible = c.get_sync('toolbar_visible');
// Wait for the value if necessary
c.get('toolbar_visible').then(function(visible) {...}); |
@Carreau Your Two questions:
|
There's a configwd = ConfigWithDefaults(this.config, {
header: true,
toolbar: true,
});
configwd.get('header').then(function(header) {
if (!header) {
$('#header-container').hide();
...
}
}); |
Move toggle logic to `notebook.js` vs. `actions.js` to be consistent with `notebook.line_numbers`
Thanks @takluyver! I think this is ready for review... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's give the Review feature a try...
} | ||
}); | ||
|
||
this.class_config.get('Header').then(function(header) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To revisit my other question: Is there a better place to put this (like Notebook.load_notebook
)?
|
||
Object.defineProperty(this, 'header', { | ||
get: function() { | ||
return that.class_config.get_sync('Header'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I switched from ConfigSection to ConfigWithDefaults to take advantage of defaults.
handler : function(env){ | ||
$('div#maintoolbar').toggle(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also moved header/toolbar toggle logic from actions.js to notebook.js to be consistent with the line numbers toggle implementation.
} | ||
|
||
}) | ||
get: function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to update the line numbers toggle logic to use ConfigWithDefaults
(via that.class_config.get_sync
and that.class_config.set
) to be consistent with header and toolbar but it looks like the line numbers toggle status is being read from notebook.config.data
regardless. notebook.json
looks like:
{
"Notebook": {
"Toolbar": false,
"Cell": {
"cm_config": {
"lineNumbers": false
}
},
"Header": false
},
"Cell": {
"cm_config": {
"lineNumbers": true
}
}
}
The top-level Cell
is set using notebook.config.update
while Notebook.Cell
is set using notebook.class_config.set
. Changing the value of Notebook.Cell.cm_config.lineNumbers
has no effect even after changing the line numbers toggle logic, so the cells/Codemirror appear to be accessing Cell.cm_config.lineNumbers
directly vs. accessing notebook.lineNumbers
. I know this is probably confusing and that's because it is! It doesn't really matter because everything is working but it would be nice if these 3 properties shared the same implementation.
@@ -462,38 +462,23 @@ define(function(require){ | |||
env.notebook.show_command_palette(); | |||
} | |||
}, | |||
'show-all-line-numbers': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actions are quite public API - they're used to define keyboard shortcuts - so I'd rather not remove them without a good reason.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I added back the show/hide line numbers as well as adding show/hide actions for header and toolbar.
|
||
this.class_config.get('Header').then(function(header) { | ||
if (header === false) { | ||
that.header = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels a bit icky - it waits for the config to load, and then does something which sets the value from the config back into the config.
I think there should be a separate piece of API which actually hides/shows the toolbar on the page, and a higher level wrapper around that which also pushes the state into config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good point, thanks for the feedback. I just pushed a new commit that moves the toggle logic to the actions and then calls the actions to toggle the header/toolbar on notebook load.
@Carreau Would you care to review? It's working for me and I think it's quite a bit cleaner given @takluyver's feedback. Two questions for you:
|
I'm giving a seminar today and will talk to a lot of people before and On Thu, Sep 22, 2016 at 12:54 PM, Grant Nestor [email protected]
|
@Carreau Ok no problem! |
this is due to the fact that line number could be toggle per-cell. Currently here is how it seem to work...: Codemirror instances are created on the
Does that make (some) sens ? |
Yep, it makes perfect sense. The culprit was https://github.com/jupyter/notebook/blob/master/notebook/static/notebook/js/notebook.js#L1185. I ran into a little error but it's almost there... |
@Carreau Let's merge this and I will work off of another branch to try to get |
You are right, let's try ! Thanks ! |
A first stab at #1661