Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork3.8k
Improve context handling#4453
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes from1 commit
7a5bd0078df852db400671e298d72e93f839c7c4a892d58d038167666ede2da0ff19f64aa4de658a7a4b3fc6bde1107f6912dfc8eaf12ced55f8b32631d0e18b3b7e1db7fc2dc90b59bc3496d1f7b03da78e85c3b60aaf51a6b58d11ffaafcbb1b6a6554c24b0a32345d9d5db7ecb3c8447ab04ebac5f0ae8b29b087d1d90468ec2ae892b4ba2802f672e84357b5c0799c6c455a21d5a7b618baec7d693d72fd54ce1abda5da476064212a65027e9ef12be487bb239a56e5766427a67e4efcad221040a0bf94b1ed031011dba0b63414fd43413f40163c41c13ab63726749792693810cac907afFile filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
- Loading branch information
Uh oh!
There was an error while loading.Please reload this page.
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -265,4 +265,33 @@ namespace MainAreaWidget { | ||
| */ | ||
| ready?: Promise<void>; | ||
| } | ||
| /** | ||
| * An options object for main area widget subclasses providing their own | ||
| * default content. | ||
| * | ||
| * #### Notes | ||
| * This makes it easier to have a subclass that provides its own default | ||
| * content. This can go away once we upgrade to TypeScript 2.8 and have an | ||
| * easy way to make a single property optional, ala | ||
| * https://stackoverflow.com/a/46941824 | ||
| */ | ||
| export | ||
| interface IOptionsOptionalContent<T extends Widget = Widget> extends Widget.IOptions { | ||
| /** | ||
| * The child widget to wrap. | ||
| */ | ||
| content?: T; | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. What is your current thinking on ownership issues for the content of a ContributorAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. It has to transfer ownership to the MainAreaWidget. In phosphor, widgets reparent/own their children, dispose their children, move their children in the DOM to be under them, etc. | ||
| /** | ||
| * The toolbar to use for the widget. Defaults to an empty toolbar. | ||
| */ | ||
| toolbar?: Toolbar; | ||
| /** | ||
| * An optional promise for when the content is ready to be shown. | ||
| */ | ||
| ready?: Promise<void>; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -166,6 +166,42 @@ namespace CSVViewer { | ||
| } | ||
| } | ||
| export | ||
| class CSVDocumentWidget extends DocumentWidget<CSVViewer> { | ||
Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. These aren't particularly complex classes and interfaces, but they are missing docstrings for the API docs. | ||
| constructor(options: CSVDocumentWidget.IOptions) { | ||
| let {content, context, delimiter, ready, ...other} = options; | ||
| content = content || Private.createContent(context); | ||
| ready = Promise.all([ready, content.ready]).then(() => undefined ); | ||
| super({content, context, ready, ...other}); | ||
| ||
| if (delimiter) { | ||
| content.delimiter = delimiter; | ||
| } | ||
| const csvDelimiter = new CSVDelimiter({ selected: content.delimiter }); | ||
| this.toolbar.addItem('delimiter', csvDelimiter); | ||
| csvDelimiter.delimiterChanged.connect((sender: CSVDelimiter, delimiter: string) => { content.delimiter = delimiter; }); | ||
| } | ||
| } | ||
| export | ||
| namespace CSVDocumentWidget { | ||
| // TODO: In TypeScript 2.8, we can make just the content property optional | ||
| // using something like https://stackoverflow.com/a/46941824, instead of | ||
| // inheriting from this IOptionsOptionalContent. | ||
| export | ||
| interface IOptions extends DocumentWidget.IOptionsOptionalContent<CSVViewer> { | ||
| delimiter?: string; | ||
| } | ||
| } | ||
| namespace Private { | ||
| export | ||
| function createContent(context: DocumentRegistry.IContext<DocumentRegistry.IModel>) { | ||
| return new CSVViewer({ context }); | ||
| } | ||
| } | ||
| /** | ||
| * A widget factory for CSV widgets. | ||
| @@ -176,11 +212,6 @@ class CSVViewerFactory extends ABCWidgetFactory<IDocumentWidget<CSVViewer>> { | ||
| * Create a new widget given a context. | ||
| */ | ||
| protected createNewWidget(context: DocumentRegistry.Context): IDocumentWidget<CSVViewer> { | ||
| return new CSVDocumentWidget({ context }); | ||
| } | ||
| } | ||