Finishing first draft of RST and heading cells.

pull/37/head
Brian Granger 14 years ago
parent f65adcf33e
commit fd3d5edb66

@ -132,6 +132,24 @@ var IPython = (function (IPython) {
this.element.find('#to_rst').click(function () {
IPython.notebook.to_rst();
});
this.element.find('#to_heading1').click(function () {
IPython.notebook.to_heading(undefined, 1);
});
this.element.find('#to_heading2').click(function () {
IPython.notebook.to_heading(undefined, 2);
});
this.element.find('#to_heading3').click(function () {
IPython.notebook.to_heading(undefined, 3);
});
this.element.find('#to_heading4').click(function () {
IPython.notebook.to_heading(undefined, 4);
});
this.element.find('#to_heading5').click(function () {
IPython.notebook.to_heading(undefined, 5);
});
this.element.find('#to_heading6').click(function () {
IPython.notebook.to_heading(undefined, 6);
});
this.element.find('#toggle_output').click(function () {
IPython.notebook.toggle_output();
});

@ -140,6 +140,36 @@ var IPython = (function (IPython) {
that.to_rst();
that.control_key_active = false;
return false;
} else if (event.which === 49 && that.control_key_active) {
// To Heading 1 = 1
that.to_heading(undefined, 1);
that.control_key_active = false;
return false;
} else if (event.which === 50 && that.control_key_active) {
// To Heading 2 = 2
that.to_heading(undefined, 2);
that.control_key_active = false;
return false;
} else if (event.which === 51 && that.control_key_active) {
// To Heading 3 = 3
that.to_heading(undefined, 3);
that.control_key_active = false;
return false;
} else if (event.which === 52 && that.control_key_active) {
// To Heading 4 = 4
that.to_heading(undefined, 4);
that.control_key_active = false;
return false;
} else if (event.which === 53 && that.control_key_active) {
// To Heading 5 = 5
that.to_heading(undefined, 5);
that.control_key_active = false;
return false;
} else if (event.which === 54 && that.control_key_active) {
// To Heading 6 = 6
that.to_heading(undefined, 6);
that.control_key_active = false;
return false;
} else if (event.which === 84 && that.control_key_active) {
// Toggle output = t
that.toggle_output();
@ -483,6 +513,8 @@ var IPython = (function (IPython) {
cell = new IPython.HTMLCell(this);
} else if (type === 'rst') {
cell = new IPython.RSTCell(this);
} else if (type === 'heading') {
cell = new IPython.HeadingCell(this);
};
if (cell !== null) {
if (this.ncells() === 0) {
@ -515,6 +547,8 @@ var IPython = (function (IPython) {
cell = new IPython.HTMLCell(this);
} else if (type === 'rst') {
cell = new IPython.RSTCell(this);
} else if (type === 'heading') {
cell = new IPython.HeadingCell(this);
};
if (cell !== null) {
if (this.ncells() === 0) {
@ -615,6 +649,33 @@ var IPython = (function (IPython) {
};
};
Notebook.prototype.to_heading = function (index, level) {
level = level || 1;
var i = this.index_or_selected(index);
if (this.is_valid_cell_index(i)) {
var source_element = this.get_cell_element(i);
var source_cell = source_element.data("cell");
var target_cell = null;
if (source_cell instanceof IPython.HeadingCell) {
source_cell.set_level(level);
} else {
target_cell = this.insert_cell_below('heading',i);
var text = source_cell.get_text();
if (text === source_cell.placeholder) {
text = '';
};
// The edit must come before the set_text.
target_cell.set_level(level);
target_cell.edit();
target_cell.set_text(text);
source_element.remove();
this.dirty = true;
};
};
};
// Cut/Copy/Paste
Notebook.prototype.enable_paste = function () {

@ -299,17 +299,31 @@ var IPython = (function (IPython) {
HeadingCell.prototype = new TextCell();
HeadingCell.prototype.set_level = function (level) {
this.level = level;
if (this.rendered) {
this.rendered = false;
this.render();
};
};
HeadingCell.prototype.get_level = function () {
return this.level;
};
HeadingCell.prototype.set_rendered = function (text) {
var r = this.element.find("div.text_cell_render");
r.empty();
r.append($('<h1/>').html(text));
}
r.append($('<h'+this.level+'/>').html(text));
};
HeadingCell.prototype.get_rendered = function () {
var r = this.element.find("div.text_cell_render");
return r.children().first().html();
}
};
HeadingCell.prototype.render = function () {
@ -321,13 +335,14 @@ var IPython = (function (IPython) {
this.element.find('div.text_cell_input').hide();
this.element.find("div.text_cell_render").show();
this.rendered = true;
}
};
};
IPython.TextCell = TextCell;
IPython.HTMLCell = HTMLCell;
IPython.MarkdownCell = MarkdownCell;
IPython.RSTCell = RSTCell;
IPython.HeadingCell = HeadingCell;
return IPython;

@ -117,9 +117,15 @@
<li id="run_cell_in_place"><a href="#">Run in Place</a></li>
<li id="run_all_cells"><a href="#">Run All</a></li>
<hr/>
<li id="to_code"><a href="#">Code Cell</a></li>
<li id="to_markdown"><a href="#">Markdown Cell</a></li>
<li id="to_rst"><a href="#">RST Cell</a></li>
<li id="to_code"><a href="#">Code</a></li>
<li id="to_markdown"><a href="#">Markdown </a></li>
<li id="to_rst"><a href="#">RST</a></li>
<li id="to_heading1"><a href="#">Heading 1</a></li>
<li id="to_heading2"><a href="#">Heading 2</a></li>
<li id="to_heading3"><a href="#">Heading 3</a></li>
<li id="to_heading4"><a href="#">Heading 4</a></li>
<li id="to_heading5"><a href="#">Heading 5</a></li>
<li id="to_heading6"><a href="#">Heading 6</a></li>
<hr/>
<li id="toggle_output"><a href="#">Toggle Output</a></li>
<li id="clear_all_output"><a href="#">Clear All Output</a></li>

Loading…
Cancel
Save