View.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. export default class View{viewId(){}
  2. title(){}
  3. isCloseable(){}
  4. isTransient(){}
  5. toolbarItems(){}
  6. widget(){}
  7. disposeView(){}}
  8. export const _symbol=Symbol('view');export const _widgetSymbol=Symbol('widget');export class SimpleView extends UI.VBox{constructor(title,isWebComponent){super(isWebComponent);this._title=title;this._toolbarItems=[];this[_symbol]=this;}
  9. viewId(){return this._title;}
  10. title(){return this._title;}
  11. isCloseable(){return false;}
  12. isTransient(){return false;}
  13. toolbarItems(){return Promise.resolve(this.syncToolbarItems());}
  14. syncToolbarItems(){return this._toolbarItems;}
  15. widget(){return(Promise.resolve(this));}
  16. addToolbarItem(item){this._toolbarItems.push(item);}
  17. revealView(){return UI.viewManager.revealView(this);}
  18. disposeView(){}}
  19. export class ProvidedView{constructor(extension){this._extension=extension;}
  20. viewId(){return this._extension.descriptor()['id'];}
  21. title(){return this._extension.title();}
  22. isCloseable(){return this._extension.descriptor()['persistence']==='closeable';}
  23. isTransient(){return this._extension.descriptor()['persistence']==='transient';}
  24. toolbarItems(){const actionIds=this._extension.descriptor()['actionIds'];if(actionIds){const result=actionIds.split(',').map(id=>UI.Toolbar.createActionButtonForId(id.trim()));return Promise.resolve(result);}
  25. if(this._extension.descriptor()['hasToolbar']){return this.widget().then(widget=>(widget).toolbarItems());}
  26. return Promise.resolve([]);}
  27. async widget(){this._widgetRequested=true;const widget=await this._extension.instance();if(!(widget instanceof UI.Widget)){throw new Error('view className should point to a UI.Widget');}
  28. widget[_symbol]=this;return(widget);}
  29. async disposeView(){if(!this._widgetRequested){return;}
  30. const widget=await this.widget();widget.ownerViewDisposed();}}
  31. export class ViewLocation{appendApplicableItems(locationName){}
  32. appendView(view,insertBefore){}
  33. showView(view,insertBefore,userGesture){}
  34. removeView(view){}
  35. widget(){}}
  36. export class TabbedViewLocation extends ViewLocation{tabbedPane(){}
  37. enableMoreTabsButton(){}}
  38. export class ViewLocationResolver{resolveLocation(location){}}
  39. self.UI=self.UI||{};UI=UI||{};UI.View=View;UI.View.widgetSymbol=_widgetSymbol;UI.SimpleView=SimpleView;UI.ProvidedView=ProvidedView;UI.ViewLocation=ViewLocation;UI.TabbedViewLocation=TabbedViewLocation;UI.ViewLocationResolver=ViewLocationResolver;