Permalink
Browse files

Working output formatter w/ mime type annotation. Allow widgets to be…

… appended.
  • Loading branch information...
1 parent af77159 commit 33bc4ccb5719b5c05c35c65da1fa9af6bc1206b4 @unconed unconed committed Apr 17, 2011
View
@@ -36,7 +36,7 @@ tc.prototype = {
this.sessions[session.id] = session;
},
- deregister: function (session) {
+ remove: function (session) {
delete this.sessions[session.id];
},
View
@@ -47,40 +47,38 @@ tc.shell.prototype = {
dispatch: function (method, args) {
var that = this;
- console.log('viewstream', method, args);
switch (method) {
- case 'stream.open':
+ case 'view.open':
var frame = this.frames[args.rel];
// Allocate views.
if (frame) {
// Add views to viewstream list.
- frame.allocate(args.streams.length);
- for (i in args.streams) (function (id) {
+ frame.allocate(args.views.length);
+ for (i in args.views) (function (id) {
view = frame.get(+i);
view.callback(function (method, args) {
// Lock callback to this view.
- args.stream = id;
+ args.view = id;
- console.log('upstream', method, args);
that.notify(method, args);
});
that.views[id] = view;
- })(args.streams[i]);
+ })(args.views[i]);
}
break;
- case 'stream.close':
+ case 'view.close':
// Remove views from active viewstream list.
- for (i in args.streams) {
- delete this.views[args.streams[i]];
+ for (i in args.views) {
+ delete this.views[args.views[i]];
}
break;
default:
var view;
- if (args.stream && (view = this.views[args.stream])) {
+ if (args.view && (view = this.views[args.view])) {
view.dispatch(method, args);
}
}
@@ -123,7 +123,6 @@ cv.command.prototype = {
for (n = 0; trigger.hasOwnProperty(n); ++n);
if (n < 1) return;
- //console.log('match '+ n);
var match;
// Match the multi-regexp on the tokens starting at [index].
@@ -70,58 +70,147 @@ widgets.raw.prototype = $.extend(new ov.outputNode(), {
});
-
/**
- * Widget: File reference
+ * Widget: File icon.
+ *
+ * Icon loading is collectively throttled.
*/
-widgets.file = function (properties) {
+widgets.icon = function (properties) {
// Initialize node.
ov.outputNode.call(this, properties);
- this.$icon = this.$element.find('.icon');
- this.$name = this.$element.find('.name');
- this.$meta = this.$element.find('.meta');
this.updateElement();
+
+ this.queue();
};
-widgets.file.prototype = $.extend(new ov.outputNode(), {
+// Process icon updates.
+widgets.icon.queue = [];
+widgets.icon.limit = 4;
+widgets.icon.process = function () {
+ if (widgets.icon.queue.length && widgets.icon.limit > 0) {
+ widgets.icon.limit--;
+
+ var icon = widgets.icon.queue.shift();
+ icon.process();
+ }
+};
+
+widgets.icon.prototype = $.extend(new ov.outputNode(), {
// Return active markup for this widget.
$markup: function () {
- var $outputNode = $('<div class="termkitOutputNode widgetFile"><div class="icon"></div><div class="name"></div><div class="meta"></div></div>').data('controller', this);
- var that = this;
+ var $outputNode = $('<div class="termkitOutputNode widgetIcon"></div>').data('controller', this);
return $outputNode;
},
- // Update markup to match.
- updateElement: function () {
+ setDefaultIcon: function (callback) {
var that = this;
- this.$element.data('controller', this);
-
// Set default icon.
- var extension = (this.properties.stats.mode & 0x4000) ? '/' : this.properties.name.split('.').pop(),
+ var image = new Image(),
+ extension = (this.properties.stats.mode & 0x4000) ? '...' : this.properties.name.split('.').pop(),
defaultUrl = 'termkit-icon-default:///' + encodeURIComponent(extension);
- this.$icon.css({
- background: 'url('+ defaultUrl +')',
- backgroundSize: '32px 32px',
- });
-
+
+ image.onload = function () {
+ that.$element.css({
+ background: 'url('+ defaultUrl +')',
+ backgroundSize: '32px 32px',
+ });
+ callback && callback();
+ };
+
+ image.src = defaultUrl;
+ },
+
+ setOwnIcon: function (callback) {
+ var that = this;
+
// Set file-specific icon.
var image = new Image(),
path = this.properties.path + '/' + this.properties.name,
previewUrl = 'termkit-icon-preview:///' + encodeURIComponent(path);
+
image.onload = function () {
- that.$icon.css({
+ that.$element.css({
background: 'url('+ previewUrl +')'
});
+ callback && callback();
};
+
image.src = previewUrl;
+ },
+
+ // Queue icon updates to avoid choking webkit.
+ queue: function () {
+ widgets.icon.queue.push(this);
+ widgets.icon.process();
+ },
+
+ // Process the icon update.
+ process: function () {
+ function yield() {
+ widgets.icon.process();
+ }
+
+ this.setOwnIcon(yield);
+ widgets.icon.limit++;
+ },
+
+ // Update markup to match.
+ updateElement: function () {
+ var that = this;
+
+ this.setDefaultIcon();
+
+ this.$element.data('controller', this);
+ },
+
+});
+
+/**
+ * Widget: File reference
+ */
+widgets.file = function (properties) {
+
+ // Initialize node.
+ ov.outputNode.call(this, properties);
+
+ this.$icon = this.$element.find('.icon');
+ this.$name = this.$element.find('.name');
+ this.$meta = this.$element.find('.meta');
+
+ this.icon = new widgets.icon(this.properties);
+ this.$icon.append(this.icon.$element);
+ this.icon.updateElement();
+
+ this.updateElement();
+};
+
+widgets.file.prototype = $.extend(new ov.outputNode(), {
+
+ // Return active markup for this widget.
+ $markup: function () {
+ var $outputNode = $('<div class="termkitOutputNode widgetFile" draggable="true"><div class="icon"></div><div class="name"></div><div class="meta"></div></div>').data('controller', this);
+ var that = this;
+ return $outputNode;
+ },
+
+ // Update markup to match.
+ updateElement: function () {
+ var that = this;
+
+ this.$element.data('controller', this);
+
// Set text labels.
this.$name.text(this.properties.name);
this.$meta.text(formatSize(this.properties.stats.size));
+
+ if (this.properties.name[0] == '.') {
+ this.$element.addClass('file-hidden');
+ }
},
});
@@ -33,13 +33,11 @@ of.prototype = {
// Update the element's markup in response to internal changes.
allocate: function (views) {
- console.log('allocate from', this.views.length, ' to ', views);
if (this.views.length < views) {
views -= this.views.length;
while (views--) {
this.views.push(new termkit.outputView());
this.$element.append(this.views[this.views.length - 1].$element);
- console.log('allocate -- ', this.views.length, views);
};
}
},
@@ -132,8 +132,15 @@ ov.outputNode.prototype = {
},
// Update node's own properties.
- update: function (properties) {
- this.properties = $.extend({}, this.properties, properties || {});
+ update: function (properties, append) {
+ if (append) {
+ for (i in properties) {
+ this.properties[i] += properties[i];
+ }
+ }
+ else {
+ this.properties = $.extend({}, this.properties, properties || {});
+ }
this.root && this.updateElement();
},
@@ -146,8 +153,6 @@ ov.outputNode.prototype = {
*/
getNode: function (target) {
- console.log('getNode', target, typeof target);
-
if ((target == null) || (typeof target != 'object') || (target.constructor != [].constructor)) {
target = [target];
}
@@ -18,7 +18,7 @@ ov.prototype = {
var $outputView = $('<div class="termkitOutputView"><div class="isolate"></div></div>').data('controller', this);
var that = this;
- this.tree = new ov.outputNode({}, this);
+ this.tree = new ov.outputNode({});
$outputView.find('.isolate').append(this.tree.$element);
return $outputView;
@@ -60,7 +60,8 @@ ov.prototype = {
break;
case 'view.update':
- target.update(args.properties);
+ console.log('updating', target, args.properties, args.append);
+ target.update(args.properties, args.append);
break;
}
View
@@ -51,11 +51,10 @@ body {
overflow: hidden;
}
-.termkitOutputView .widgetFile .icon {
+.termkitOutputView .widgetFile .icon, .termkitOutputView .widgetFile .icon * {
float: left;
width: 32px;
height: 32px;
- background: #333;
}
.termkitOutputView .widgetFile .name, .termkitOutputView .widgetFile .meta {
@@ -65,6 +64,14 @@ body {
.termkitOutputView .widgetFile .name {
}
+.termkitOutputView .widgetFile.file-hidden .icon {
+/* opacity: 0.5; */
+}
+
+.termkitOutputView .widgetRaw .contents {
+ white-space: pre-wrap;
+}
+
/************/
.termkitCommandView {
View
@@ -8,9 +8,7 @@ $(document).ready(function () {
var client = new termkit.client();
client.onConnect = function () {
- console.log('client conn');
var shell = new termkit.client.shell(client, {}, function () {
- console.log('shell conn');
var view = new termkit.commandView(shell);
$('#terminal').append(view.$element);
view.newCommand();
View
@@ -185,10 +185,8 @@ tf.tokenQuoted.prototype = $.extend(new tf.token(), {
});
tf.tokenQuoted.resetEscape = function () {
- console.log('resetEscape');
tf.tokenQuoted.timer && clearTimeout(tf.tokenQuoted.timer);
tf.tokenQuoted.timer = setTimeout(function () {
- console.log('resetEscape ping');
tf.tokenQuoted.escapeWaiting = false;
}, 1500);
};
@@ -208,8 +206,6 @@ tf.tokenQuoted.triggerQuote = function (offset, event) {
}
out.push(new tf.tokenQuoted(after));
- console.log('wtf', this);
-
tf.tokenQuoted.setEscape();
return out;
View
@@ -74,8 +74,20 @@ exports.whenDone = function (done) {
* Execute a function asynchronously.
*/
exports.async = function (func) {
- var that = this;
- setTimeout(function () { func.call(that); }, 0);
+ var that = this,
+ args = [].slice.call(arguments, 1);
+ setTimeout(function () { func.apply(that, args); }, 0);
+}
+
+/**
+ * Make an asynchronously executed callback.
+ */
+exports.asyncCallback = function (func) {
+ var that = this,
+ args = [].slice.call(arguments, 1);
+ return function () {
+ setTimeout(function () { func.apply(that, args); }, 0);
+ };
}
/**
Oops, something went wrong.

0 comments on commit 33bc4cc

Please sign in to comment.