From 07feaca3a1dca0146203a6aac11890408d355dea Mon Sep 17 00:00:00 2001 From: "David A. Mellis" Date: Sun, 24 May 2009 15:04:18 +0000 Subject: [PATCH] Adding a "Copy as HTML" item to the Tools menu. --- app/Editor.java | 14 +++++++++++++- app/tools/DiscourseFormat.java | 23 +++++++++++++---------- 2 files changed, 26 insertions(+), 11 deletions(-) diff --git a/app/Editor.java b/app/Editor.java index 8029fdf0f..7284241cf 100644 --- a/app/Editor.java +++ b/app/Editor.java @@ -752,7 +752,19 @@ public class Editor extends JFrame public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { 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(); } }); } diff --git a/app/tools/DiscourseFormat.java b/app/tools/DiscourseFormat.java index f9dbdeffc..240cf56b3 100644 --- a/app/tools/DiscourseFormat.java +++ b/app/tools/DiscourseFormat.java @@ -64,15 +64,18 @@ public class DiscourseFormat { JEditTextArea parent; //JFrame frame; + + boolean html; /** * Creates a new window with the formated (YaBB tags) sketchcode * from the actual Processing Tab ready to send to the processing discourse * web (copy & paste) */ - public DiscourseFormat(Editor editor) { + public DiscourseFormat(Editor editor, boolean html) { this.editor = editor; this.parent = editor.textarea; + this.html = html; /* textarea = new JEditTextArea(new PdeTextAreaDefaults()); @@ -110,14 +113,14 @@ public class DiscourseFormat { // Format and render sketchcode // [code] tag cancels other tags, using [quote] - StringBuffer cf = new StringBuffer("[quote] \n \n"); + StringBuffer cf = new StringBuffer(html ? "
 \n" : "[quote] \n");
 
     // Line by line
     for (int i = 0; i < parent.getLineCount(); i++) {
       cf.append(formatCode(i));
     }
 
-    cf.append("\n [/quote]");
+    cf.append(html ? "
" : "[/quote]"); /* // Send the text to the textarea @@ -135,8 +138,8 @@ public class DiscourseFormat { } }); - editor.message("Discourse-formatted code has been " + - "copied to the clipboard."); + editor.message((html ? "HTML" : "Forum") + "-formatted code has " + + "been copied to the clipboard."); } @@ -213,12 +216,12 @@ public class DiscourseFormat { } else { // Place open tags [] //cf.append("[color=" + color() + "]"); - cf.append("[color=#"); + cf.append(html ? "" : "]"); if (styles[id].isBold()) - cf.append("[b]"); + cf.append(html ? "" : "[b]"); fm = styles[id].getFontMetrics(defaultFont); } @@ -229,9 +232,9 @@ public class DiscourseFormat { cf.append(c); // Place close tags [/] if (j == (length - 1) && id != Token.NULL && styles[id].isBold()) - cf.append("[/b]"); + cf.append(html ? "" : "[/b]"); if (j == (length - 1) && id != Token.NULL) - cf.append("[/color]"); + cf.append(html ? "" : "[/color]"); int charWidth; if (c == '\t') { charWidth = (int) painter