mirror of https://github.com/noisymime/Arduino.git
Adding a "Copy as HTML" item to the Tools menu.
This commit is contained in:
parent
7357e38cf6
commit
07feaca3a1
|
@ -752,7 +752,19 @@ public class Editor extends JFrame
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
SwingUtilities.invokeLater(new Runnable() {
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
new DiscourseFormat(Editor.this).show();
|
new DiscourseFormat(Editor.this, false).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
menu.add(item);
|
||||||
|
|
||||||
|
item = new JMenuItem("Copy as HTML");
|
||||||
|
item.addActionListener(new ActionListener() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
public void run() {
|
||||||
|
new DiscourseFormat(Editor.this, true).show();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,14 +65,17 @@ public class DiscourseFormat {
|
||||||
|
|
||||||
//JFrame frame;
|
//JFrame frame;
|
||||||
|
|
||||||
|
boolean html;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new window with the formated (YaBB tags) sketchcode
|
* Creates a new window with the formated (YaBB tags) sketchcode
|
||||||
* from the actual Processing Tab ready to send to the processing discourse
|
* from the actual Processing Tab ready to send to the processing discourse
|
||||||
* web (copy & paste)
|
* web (copy & paste)
|
||||||
*/
|
*/
|
||||||
public DiscourseFormat(Editor editor) {
|
public DiscourseFormat(Editor editor, boolean html) {
|
||||||
this.editor = editor;
|
this.editor = editor;
|
||||||
this.parent = editor.textarea;
|
this.parent = editor.textarea;
|
||||||
|
this.html = html;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
textarea = new JEditTextArea(new PdeTextAreaDefaults());
|
textarea = new JEditTextArea(new PdeTextAreaDefaults());
|
||||||
|
@ -110,14 +113,14 @@ public class DiscourseFormat {
|
||||||
// Format and render sketchcode
|
// Format and render sketchcode
|
||||||
|
|
||||||
// [code] tag cancels other tags, using [quote]
|
// [code] tag cancels other tags, using [quote]
|
||||||
StringBuffer cf = new StringBuffer("[quote] \n \n");
|
StringBuffer cf = new StringBuffer(html ? "<pre> \n" : "[quote] \n");
|
||||||
|
|
||||||
// Line by line
|
// Line by line
|
||||||
for (int i = 0; i < parent.getLineCount(); i++) {
|
for (int i = 0; i < parent.getLineCount(); i++) {
|
||||||
cf.append(formatCode(i));
|
cf.append(formatCode(i));
|
||||||
}
|
}
|
||||||
|
|
||||||
cf.append("\n [/quote]");
|
cf.append(html ? "</pre>" : "[/quote]");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// Send the text to the textarea
|
// Send the text to the textarea
|
||||||
|
@ -135,8 +138,8 @@ public class DiscourseFormat {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
editor.message("Discourse-formatted code has been " +
|
editor.message((html ? "HTML" : "Forum") + "-formatted code has " +
|
||||||
"copied to the clipboard.");
|
"been copied to the clipboard.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -213,12 +216,12 @@ public class DiscourseFormat {
|
||||||
} else {
|
} else {
|
||||||
// Place open tags []
|
// Place open tags []
|
||||||
//cf.append("[color=" + color() + "]");
|
//cf.append("[color=" + color() + "]");
|
||||||
cf.append("[color=#");
|
cf.append(html ? "<span style=\"color: #" : "[color=#");
|
||||||
cf.append(PApplet.hex(styles[id].getColor().getRGB() & 0xFFFFFF, 6));
|
cf.append(PApplet.hex(styles[id].getColor().getRGB() & 0xFFFFFF, 6));
|
||||||
cf.append("]");
|
cf.append(html ? ";\">" : "]");
|
||||||
|
|
||||||
if (styles[id].isBold())
|
if (styles[id].isBold())
|
||||||
cf.append("[b]");
|
cf.append(html ? "<b>" : "[b]");
|
||||||
|
|
||||||
fm = styles[id].getFontMetrics(defaultFont);
|
fm = styles[id].getFontMetrics(defaultFont);
|
||||||
}
|
}
|
||||||
|
@ -229,9 +232,9 @@ public class DiscourseFormat {
|
||||||
cf.append(c);
|
cf.append(c);
|
||||||
// Place close tags [/]
|
// Place close tags [/]
|
||||||
if (j == (length - 1) && id != Token.NULL && styles[id].isBold())
|
if (j == (length - 1) && id != Token.NULL && styles[id].isBold())
|
||||||
cf.append("[/b]");
|
cf.append(html ? "</b>" : "[/b]");
|
||||||
if (j == (length - 1) && id != Token.NULL)
|
if (j == (length - 1) && id != Token.NULL)
|
||||||
cf.append("[/color]");
|
cf.append(html ? "</span>" : "[/color]");
|
||||||
int charWidth;
|
int charWidth;
|
||||||
if (c == '\t') {
|
if (c == '\t') {
|
||||||
charWidth = (int) painter
|
charWidth = (int) painter
|
||||||
|
|
Loading…
Reference in New Issue