Skip to content
This repository has been archived by the owner on Nov 6, 2019. It is now read-only.

Commit

Permalink
remove the class name convenience manipulators from widget
Browse files Browse the repository at this point in the history
they aren't really needed, and this makes the api the same as the rest
of the code in the framework.
  • Loading branch information
sccolbert committed Apr 20, 2015
1 parent 148b4be commit d71288c
Show file tree
Hide file tree
Showing 16 changed files with 35 additions and 56 deletions.
10 changes: 5 additions & 5 deletions examples/boxpanel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@ import Widget = phosphor.widgets.Widget;

function createContent(text: string): Widget {
var widget = new Widget();
widget.addClass('content');
widget.node.classList.add('content');
widget.node.innerHTML = '<span>' + text + '</span>';
return widget;
}


function main(): void {
var ttb = new BoxPanel(Direction.TopToBottom);
ttb.addClass('red');
ttb.node.classList.add('red');
ttb.addWidget(createContent('Top'));
ttb.addWidget(createContent('To'));
ttb.addWidget(createContent('Bottom'));
ttb.addStretch(0);

var btt = new BoxPanel(Direction.BottomToTop);
btt.addClass('green');
btt.node.classList.add('green');
btt.addWidget(createContent('Top'));
btt.addWidget(createContent('To'));
btt.addWidget(createContent('Bottom'));
btt.addStretch(0);

var ltr = new BoxPanel(Direction.LeftToRight);
ltr.addClass('yellow');
ltr.node.classList.add('yellow');
ltr.addWidget(createContent('Left'));
ltr.addWidget(createContent('To'));
ltr.addWidget(createContent('Right'));
ltr.addStretch(0);

var rtl = new BoxPanel(Direction.RightToLeft);
rtl.addClass('blue');
rtl.node.classList.add('blue');
rtl.addWidget(createContent('Left'));
rtl.addWidget(createContent('To'));
rtl.addWidget(createContent('Right'));
Expand Down
4 changes: 2 additions & 2 deletions examples/dockarea/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Content extends Widget {

constructor(title: string) {
super();
this.addClass('content');
this.addClass(title.toLowerCase());
this.node.classList.add('content');
this.node.classList.add(title.toLowerCase());
this._tab = new Tab(title);
this._tab.closable = true;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/nested/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class Content extends Widget {

constructor(title: string) {
super();
this.addClass('content');
this.addClass(title.toLowerCase());
this.node.classList.add('content');
this.node.classList.add(title.toLowerCase());
this._tab = new Tab(title);
}

Expand Down
4 changes: 2 additions & 2 deletions examples/splitpanel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import Widget = phosphor.widgets.Widget;

function createContent(name: string): Widget {
var widget = new Widget();
widget.addClass('content');
widget.addClass(name);
widget.node.classList.add('content');
widget.node.classList.add(name);
return widget;
}

Expand Down
4 changes: 2 additions & 2 deletions examples/tabpanel/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ class Content extends Widget {

constructor(title: string) {
super();
this.addClass('content');
this.addClass(title.toLowerCase());
this.node.classList.add('content');
this.node.classList.add(title.toLowerCase());
this._tab = new Tab(title);
}

Expand Down
2 changes: 1 addition & 1 deletion src/lib/codemirrorwidget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class CodeMirrorWidget extends Widget {
*/
constructor(config?: CodeMirror.EditorConfiguration) {
super();
this.addClass(CODE_MIRROR_WIDGET_CLASS);
this.node.classList.add(CODE_MIRROR_WIDGET_CLASS);
this._editor = CodeMirror(this.node, config);
this.setSizePolicy(SizePolicy.Expanding, SizePolicy.Expanding);
}
Expand Down
2 changes: 1 addition & 1 deletion src/shell/shellpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class ShellPanel extends Widget {
*/
constructor(direction: Direction) {
super();
this.addClass(SHELL_PANEL_CLASS);
this.node.classList.add(SHELL_PANEL_CLASS);
this.layout = new BoxLayout(direction, 0);
this.setFlag(WidgetFlag.DisallowLayoutChange);
}
Expand Down
12 changes: 6 additions & 6 deletions src/shell/shellview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ShellView extends Widget implements IShellView {
*/
constructor() {
super();
this.addClass(SHELL_VIEW_CLASS);
this.node.classList.add(SHELL_VIEW_CLASS);

this._menuBar = new MenuBar();
this._topPanel = new ShellPanel(Direction.TopToBottom);
Expand All @@ -69,11 +69,11 @@ class ShellView extends Widget implements IShellView {
this._centerPanel = new ShellPanel(Direction.TopToBottom);
this._menuManager = new MenuManager(this._menuBar);

this._topPanel.addClass(TOP_CLASS);
this._leftPanel.addClass(LEFT_CLASS);
this._rightPanel.addClass(RIGHT_CLASS);
this._bottomPanel.addClass(BOTTOM_CLASS);
this._centerPanel.addClass(CENTER_CLASS);
this._topPanel.node.classList.add(TOP_CLASS);
this._leftPanel.node.classList.add(LEFT_CLASS);
this._rightPanel.node.classList.add(RIGHT_CLASS);
this._bottomPanel.node.classList.add(BOTTOM_CLASS);
this._centerPanel.node.classList.add(CENTER_CLASS);

this._menuBar.hide();
this._topPanel.verticalSizePolicy = SizePolicy.Fixed;
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/boxpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class BoxPanel extends Panel {
*/
constructor(direction = Direction.TopToBottom, spacing = 8) {
super(new BoxLayout(direction, spacing));
this.addClass(BOX_PANEL_CLASS);
this.node.classList.add(BOX_PANEL_CLASS);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/widgets/dockarea.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class DockArea extends Widget {
*/
constructor() {
super();
this.addClass(DOCK_AREA_CLASS);
this.node.classList.add(DOCK_AREA_CLASS);
this._root = this._createSplitter(Orientation.Horizontal);

var layout = new BoxLayout(Direction.TopToBottom, 0);
Expand Down Expand Up @@ -904,7 +904,7 @@ class DockPanel extends Widget {
*/
constructor() {
super();
this.addClass(DOCK_PANEL_CLASS);
this.node.classList.add(DOCK_PANEL_CLASS);
this._tabBar = new TabBar();
this._stackedPanel = new StackedPanel();
this._overlayNode = this.createOverlay();
Expand Down Expand Up @@ -1069,7 +1069,7 @@ class DockSplitter extends SplitPanel {
*/
constructor(orientation: Orientation) {
super(orientation);
this.addClass(DOCK_SPLITTER_CLASS);
this.node.classList.add(DOCK_SPLITTER_CLASS);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/widgets/menubar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class MenuBar extends Widget {
*/
constructor(items?: MenuItem[]) {
super();
this.addClass(MENU_BAR_CLASS);
this.node.classList.add(MENU_BAR_CLASS);
this.verticalSizePolicy = SizePolicy.Fixed;
if (items) items.forEach(it => this.addItem(it));
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/splitpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class SplitPanel extends Panel {
*/
constructor(orientation = Orientation.Horizontal) {
super(new SplitLayout(orientation));
this.addClass(SPLIT_PANEL_CLASS);
this.node.classList.add(SPLIT_PANEL_CLASS);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/stackedpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class StackedPanel extends Panel {
*/
constructor() {
super(new StackedLayout());
this.addClass(STACKED_PANEL_CLASS);
this.node.classList.add(STACKED_PANEL_CLASS);
var layout = <StackedLayout>this.layout;
layout.widgetRemoved.connect(this._sl_widgetRemoved, this);
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/tabbar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ class TabBar extends Widget {
*/
constructor(options?: ITabBarOptions) {
super();
this.addClass(TAB_BAR_CLASS);
this.node.classList.add(TAB_BAR_CLASS);
this.verticalSizePolicy = SizePolicy.Fixed;
if (options) this._initFrom(options);
}
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/tabpanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class TabPanel extends Widget {
*/
constructor() {
super();
this.addClass(TAB_PANEL_CLASS);
this.node.classList.add(TAB_PANEL_CLASS);
this.layout = new BoxLayout(Direction.TopToBottom, 0);
this.setFlag(WidgetFlag.DisallowLayoutChange);

Expand Down
31 changes: 5 additions & 26 deletions src/widgets/widget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class Widget implements IMessageHandler, IDisposable {
*/
constructor() {
this._node = this.createNode();
this.addClass(WIDGET_CLASS);
this._node.classList.add(WIDGET_CLASS);
}

/**
Expand Down Expand Up @@ -342,27 +342,6 @@ class Widget implements IMessageHandler, IDisposable {
return this._children[index];
}

/**
* Test whether the widget's DOM node has the given class name.
*/
hasClass(name: string): boolean {
return this._node.classList.contains(name);
}

/**
* Add a class name to the widget's DOM node.
*/
addClass(name: string): void {
this._node.classList.add(name);
}

/**
* Remove a class name from the widget's DOM node.
*/
removeClass(name: string): void {
this._node.classList.remove(name);
}

/**
* Test whether the given widget flag is set.
*/
Expand Down Expand Up @@ -396,11 +375,11 @@ class Widget implements IMessageHandler, IDisposable {
var parent = this._parent;
if (this.isAttached && (!parent || parent.isVisible)) {
sendMessage(this, new Message('before-show'));
this.removeClass(HIDDEN_CLASS);
this._node.classList.remove(HIDDEN_CLASS);
this.clearFlag(WidgetFlag.IsHidden);
sendMessage(this, new Message('after-show'));
} else {
this.removeClass(HIDDEN_CLASS);
this._node.classList.remove(HIDDEN_CLASS);
this.clearFlag(WidgetFlag.IsHidden);
}
if (parent) {
Expand All @@ -421,11 +400,11 @@ class Widget implements IMessageHandler, IDisposable {
var parent = this._parent;
if (this.isAttached && (!parent || parent.isVisible)) {
sendMessage(this, new Message('before-hide'));
this.addClass(HIDDEN_CLASS);
this._node.classList.add(HIDDEN_CLASS);
this.setFlag(WidgetFlag.IsHidden);
sendMessage(this, new Message('after-hide'));
} else {
this.addClass(HIDDEN_CLASS);
this._node.classList.add(HIDDEN_CLASS);
this.setFlag(WidgetFlag.IsHidden);
}
if (parent) {
Expand Down

0 comments on commit d71288c

Please sign in to comment.