add dialog to raw cell toolbar

MinRK 13 years ago
parent d087a213b3
commit f420b48aae

@ -14,6 +14,7 @@
var CellToolbar = IPython.CellToolbar;
var raw_cell_preset = [];
var utils = IPython.utils;
var select_type = CellToolbar.utils.select_ui_generator([
["None", "-"],
@ -22,27 +23,56 @@
["HTML", "text/html"],
["markdown", "text/markdown"],
["Python", "text/python"],
["Custom", , "dialog"],
["Custom", "dialog"],
],
// setter
function(cell, value) {
if (value === '-') {
delete cell.metadata.raw_mime;
if (value === "-") {
delete cell.metadata.raw_mimetype;
} else if (value === 'dialog'){
// IPython.dialog.modal(
// "Set custom raw cell format",
//
// OK
// )
//
var dialog = $('<div/>').append(
$("<p/>")
.html("Set the MIME type of the raw cell:")
).append(
$("<br/>")
).append(
$('<input/>').attr('type','text').attr('size','25')
.val(cell.metadata.raw_mimetype || "-")
);
IPython.dialog.modal({
title: "Raw Cell MIME Type",
body: dialog,
buttons : {
"Cancel": {},
"OK": {
class: "btn-primary",
click: function () {
console.log(cell);
cell.metadata.raw_mimetype = $(this).find('input').val();
console.log(cell.metadata);
}
}
},
open : function (event, ui) {
var that = $(this);
// Upon ENTER, click the OK button.
that.find('input[type="text"]').keydown(function (event, ui) {
if (event.which === utils.keycodes.ENTER) {
that.find('.btn-primary').first().click();
return false;
}
});
that.find('input[type="text"]').focus().select();
}
});
} else {
cell.metadata.raw_mime = value;
cell.metadata.raw_mimetype = value;
}
},
//getter
function(cell) {
return cell.metadata.raw_mime || "-";
return cell.metadata.raw_mimetype || "";
},
// name
"Raw NBConvert Format",

Loading…
Cancel
Save