diff options
author | Rory MacQueen <rorymacqueen@gmail.com> | 2013-07-19 16:47:09 -0700 |
---|---|---|
committer | Philip Chimento <philip.chimento@gmail.com> | 2013-07-26 17:31:33 -0700 |
commit | 5852d75773d72d75995d07b3bc87f9e744b5f1b5 (patch) | |
tree | b773ffc22679a67756505b34c9d004b79fe3e2ec /wikipedia/src/endless_wikipedia/ArticleList.js | |
parent | ae9928b88ac2bcc82921e04e8cf4df5e18be174d (diff) |
Moved wikipedia source files into sdk
Moved the wikipedia source files into the sdk repo since they will be eventually be shared by many apps
[endlessm/eos-sdk#162]
Diffstat (limited to 'wikipedia/src/endless_wikipedia/ArticleList.js')
-rw-r--r-- | wikipedia/src/endless_wikipedia/ArticleList.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/wikipedia/src/endless_wikipedia/ArticleList.js b/wikipedia/src/endless_wikipedia/ArticleList.js new file mode 100644 index 0000000..b79e2e8 --- /dev/null +++ b/wikipedia/src/endless_wikipedia/ArticleList.js @@ -0,0 +1,50 @@ +const GObject = imports.gi.GObject; +const Gtk = imports.gi.Gtk; +const Lang = imports.lang; + +const ArticleList = new Lang.Class({ + Name: 'ArticleList', + Extends: Gtk.ScrolledWindow, + Signals: { + 'article-chosen': { + param_types: [GObject.TYPE_STRING, GObject.TYPE_STRING] + } + }, + + _init: function(props) { + props = props || {}; + props.hscrollbar_policy = Gtk.PolicyType.NEVER; + props.vscrollbar_policy = Gtk.PolicyType.AUTOMATIC, + this.parent(props); + + this._grid = new Gtk.Grid({ + orientation: Gtk.Orientation.VERTICAL, + vexpand: true + }); + this.add(this._grid); + }, + + // Takes a list of dictionaries with keys 'title' and 'url' + setArticles: function(articles) { + // Remove all existing article links + this._grid.get_children().forEach(function(element, index, obj) { + this._grid.remove(element); + }, this); + + // Create new ones + articles.forEach(function(element, index, obj) { + var button = Gtk.Button.new_with_label(element.title.toUpperCase()); + button.image = Gtk.Image.new_from_icon_name('go-next-symbolic', + Gtk.IconSize.BUTTON); + button.always_show_image = true; // Don't do this, see BackButton.js + button.image_position = Gtk.PositionType.RIGHT; + button.xalign = 0; + + button.connect('clicked', Lang.bind(this, function() { + this.emit('article-chosen', element.title, element.url); + })); + button.show(); + this._grid.add(button); + }, this); + } +}); |