MCPcopy Index your code
hub / github.com/processing/processing / setCode

Method setCode

app/src/processing/app/ui/Editor.java:1798–1890  ·  view source on GitHub ↗

Switch between tabs, this swaps out the Document object that's currently being manipulated.

(SketchCode code)

Source from the content-addressed store, hash-verified

1796 * that's currently being manipulated.
1797 */
1798 public void setCode(SketchCode code) {
1799 SyntaxDocument document = (SyntaxDocument) code.getDocument();
1800
1801 if (document == null) { // this document not yet inited
1802 document = new SyntaxDocument() {
1803 @Override
1804 public void beginCompoundEdit() {
1805 if (compoundEdit == null)
1806 startCompoundEdit();
1807 super.beginCompoundEdit();
1808 }
1809
1810 @Override
1811 public void endCompoundEdit() {
1812 stopCompoundEdit();
1813 super.endCompoundEdit();
1814 }
1815 };
1816 code.setDocument(document);
1817
1818 // turn on syntax highlighting
1819 document.setTokenMarker(mode.getTokenMarker(code));
1820
1821 // insert the program text into the document object
1822 try {
1823 document.insertString(0, code.getProgram(), null);
1824 } catch (BadLocationException bl) {
1825 bl.printStackTrace();
1826 }
1827
1828 // set up this guy's own undo manager
1829// code.undo = new UndoManager();
1830
1831 document.addDocumentListener(new DocumentListener() {
1832
1833 public void removeUpdate(DocumentEvent e) {
1834 if (isInserting && isDirectEdit() && !textarea.isOverwriteEnabled()) {
1835 endTextEditHistory();
1836 }
1837 isInserting = false;
1838 }
1839
1840 public void insertUpdate(DocumentEvent e) {
1841 if (!isInserting && !textarea.isOverwriteEnabled() && isDirectEdit()) {
1842 endTextEditHistory();
1843 }
1844
1845 if (!textarea.isOverwriteEnabled()) {
1846 isInserting = true;
1847 }
1848 }
1849
1850 public void changedUpdate(DocumentEvent e) {
1851 endTextEditHistory();
1852 }
1853 });
1854
1855 // connect the undo listener to the editor

Callers 1

setCurrentCodeMethod · 0.45

Calls 14

setTokenMarkerMethod · 0.95
insertStringMethod · 0.80
getProgramMethod · 0.80
addDocumentListenerMethod · 0.80
getUndoMethod · 0.80
updateUndoStateMethod · 0.80
updateRedoStateMethod · 0.80
getDocumentMethod · 0.45
setDocumentMethod · 0.45
getTokenMarkerMethod · 0.45
printStackTraceMethod · 0.45
getSelectionStartMethod · 0.45

Tested by

no test coverage detected