Author: bback
Date: 2006-03-13 17:08:42 +0000 (Mon, 13 Mar 2006)
New Revision: 8239
Added:
trunk/apps/frost-0.7/source/frost/ext/AltEdit.java
Modified:
trunk/apps/frost-0.7/source/frost/ext/ErrorStreamThread.java
trunk/apps/frost-0.7/source/frost/ext/Execute.java
trunk/apps/frost-0.7/source/frost/ext/InputStreamThread.java
trunk/apps/frost-0.7/source/frost/ext/Transit.java
trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadPanel.java
trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadPanel.java
trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java
Log:
alternate editor feature now works again
Added: trunk/apps/frost-0.7/source/frost/ext/AltEdit.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/ext/AltEdit.java 2006-03-13 10:26:06 UTC
(rev 8238)
+++ trunk/apps/frost-0.7/source/frost/ext/AltEdit.java 2006-03-13 17:08:42 UTC
(rev 8239)
@@ -0,0 +1,200 @@
+/*
+AltEdit.java / Frost
+Copyright (C) 2006 Jan-Thomas Czornack <jantho at users.sourceforge.net>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+package frost.ext;
+
+import java.awt.*;
+import java.io.*;
+import java.util.*;
+import java.util.List;
+
+import javax.swing.*;
+
+import frost.*;
+
+/**
+ * Class provides alternate editor functionality.
+ *
+ * @author bback
+ */
+public class AltEdit {
+
+ private Frame parentFrame;
+ private String linesep = System.getProperty("line.separator");
+
+ private String oldSubject;
+ private String oldText;
+
+ private static final String SUBJECT_MARKER = "*--- Subject line
(changeable) ---*";
+ private static final String TEXT_MARKER = "*--- Enter your text after this
line ---*";
+
+ private String reportSubject = null;
+ private String reportText = null;
+
+ public AltEdit(String subject, String text, Frame parentFrame) {
+ this.parentFrame = parentFrame;
+ this.oldSubject = subject;
+ this.oldText = text;
+ }
+
+ public boolean run() {
+
+ // paranoia
+ if( Core.frostSettings.getBoolValue("useAltEdit") == false ) {
+ return false;
+ }
+
+ String editor = Core.frostSettings.getValue("altEdit");
+
+ if( editor == null || editor.length() == 0 ) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "No alternate editor configured.",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
+
+ if( editor.indexOf("%f") == -1 ) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "Configured alternate editor line must contain a '%f' as
placeholder for the filename.",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
+
+ // part before and after %f
+ String editor_pre_file = editor.substring(0, editor.indexOf("%f"));
+ String editor_post_file = editor.substring(editor.indexOf("%f") + 2,
editor.length());
+
+ File editFile = null;
+ try {
+ editFile = File.createTempFile("frostmsg", ".txt", new
File(Core.frostSettings.getValue("temp.dir")));
+ } catch (IOException e) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "Could not create message file for alternate editor:
"+editFile.getPath()+"\n"+e.toString(),
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
+ editFile.deleteOnExit();
+
+ StringBuffer sb = new StringBuffer();
+ sb.append(">>> This is a Frost alternate editor message file.
<<<").append(linesep);
+ sb.append(">>> You can edit the subject and add text at the end of the
file. <<<").append(linesep);
+ sb.append(">>> Don't change or delete the marker lines!
<<<").append(linesep).append(linesep);
+ sb.append(SUBJECT_MARKER).append(linesep);
+ sb.append(oldSubject).append(linesep).append(linesep);
+ sb.append(oldText).append(linesep); // contains new from-header-line
+ sb.append(TEXT_MARKER).append(linesep);
+
+ if( FileAccess.writeFile(sb.toString(), editFile) == false ) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "Could not create message file for alternate editor:
"+editFile.getPath(),
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ return false;
+ }
+ sb = null;
+
+ String editorCmdLine = editor_pre_file + editFile.getPath() +
editor_post_file;
+ try {
+ Execute.run(editorCmdLine, true);
+ } catch(Throwable t) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "Could not start alternate editor with command:
"+editorCmdLine+"\n"+t.toString(),
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ editFile.delete();
+ return false;
+ }
+
+ List lines = FileAccess.readLines(editFile);
+ if( lines.size() < 4 ) { // subject marker,subject,from line, text
marker
+ JOptionPane.showMessageDialog(parentFrame,
+ "The message file returned by the alternate editor is
invalid.",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ editFile.delete();
+ return false;
+ }
+
+ String newSubject = null;
+ StringBuffer newTextSb = new StringBuffer();
+
+ boolean inNewText = false;
+ for( Iterator it=lines.iterator(); it.hasNext(); ) {
+ String line = (String)it.next();
+
+ if( inNewText ) {
+ newTextSb.append(line).append(linesep);
+ continue;
+ }
+
+ if( line.equals(SUBJECT_MARKER) ) {
+ // next line is the new subject
+ if( it.hasNext() == false ) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "The message file returned by the alternate editor
is invalid.",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ editFile.delete();
+ return false;
+ }
+ line = (String)it.next();
+ if( line.equals(TEXT_MARKER) ) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "The message file returned by the alternate editor
is invalid.",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ editFile.delete();
+ return false;
+ }
+ newSubject = line.trim();
+ continue;
+ }
+
+ if( line.equals(TEXT_MARKER) ) {
+ // text begins
+ inNewText = true;
+ }
+ }
+
+ if( newSubject == null ) {
+ JOptionPane.showMessageDialog(parentFrame,
+ "The message file returned by the alternate editor is
invalid.",
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ editFile.delete();
+ return false;
+ }
+
+ // finished, we have a newSubject and a newText now
+ reportSubject = newSubject;
+ reportText = newTextSb.toString();
+
+ return true;
+ }
+
+ public String getNewSubject() {
+ return reportSubject;
+ }
+
+ public String getNewText() {
+ return reportText;
+ }
+}
Modified: trunk/apps/frost-0.7/source/frost/ext/ErrorStreamThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/ext/ErrorStreamThread.java
2006-03-13 10:26:06 UTC (rev 8238)
+++ trunk/apps/frost-0.7/source/frost/ext/ErrorStreamThread.java
2006-03-13 17:08:42 UTC (rev 8239)
@@ -1,46 +1,66 @@
-package frost.ext;
-
-import java.io.*;
-import java.util.logging.*;
-
-/**
- * Catches an Error Stream from a process
- * @author Jan-Thomas Czornack
- * @version 010711
- */
-class ErrorStreamThread extends Thread {
-
- private static Logger logger =
Logger.getLogger(ErrorStreamThread.class.getName());
-
- Process p;
- Transit data;
-
- public void run() {
-
- StringBuffer output = new StringBuffer();
- DataInputStream dis = new DataInputStream(p.getErrorStream());
-
- try {
- int result = 0;
-
- while((result = dis.read()) != -1) {
- output.append((char)result);
- }
- logger.warning(output.toString());
- }
- catch (IOException e) {
- logger.log(Level.SEVERE, "Can't get input stream.", e);
- }
-
- }
-
- /**
- * Constructor
- * @param p Process to get the Error Stream from
- */
- public ErrorStreamThread (Process p, Transit data) {
- this.p = p;
- this.data = data;
- }
-
-}
+/*
+ErrorStreamThread.java / Frost
+Copyright (C) 2001 Jan-Thomas Czornack <jantho at users.sourceforge.net>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+package frost.ext;
+
+import java.io.*;
+import java.util.logging.*;
+
+/**
+ * Catches an Error Stream from a process
+ * @author Jan-Thomas Czornack
+ * @version 010711
+ */
+class ErrorStreamThread extends Thread {
+
+ private static Logger logger =
Logger.getLogger(ErrorStreamThread.class.getName());
+
+ Process p;
+ Transit data;
+
+ public void run() {
+
+ StringBuffer output = new StringBuffer();
+ DataInputStream dis = new DataInputStream(p.getErrorStream());
+
+ try {
+ int result = 0;
+
+ while((result = dis.read()) != -1) {
+ output.append((char)result);
+ }
+ String s = output.toString().trim();
+ if( s.length() > 0 ) {
+ logger.warning("err output from external program: "+s);
+ }
+ }
+ catch (IOException e) {
+ logger.log(Level.SEVERE, "Can't get input stream.", e);
+ }
+ data.setString(output.toString());
+ }
+
+ /**
+ * Constructor
+ * @param p Process to get the Error Stream from
+ */
+ public ErrorStreamThread (Process p, Transit data) {
+ this.p = p;
+ this.data = data;
+ }
+}
Modified: trunk/apps/frost-0.7/source/frost/ext/Execute.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/ext/Execute.java 2006-03-13 10:26:06 UTC
(rev 8238)
+++ trunk/apps/frost-0.7/source/frost/ext/Execute.java 2006-03-13 17:08:42 UTC
(rev 8239)
@@ -1,54 +1,65 @@
-package frost.ext;
-
-import java.util.logging.*;
-
-
-/**
- * Supports execution of external programs
- * @author Jan-Thomas Czornack
- */
-public class Execute {
-
- private static Logger logger =
Logger.getLogger(Execute.class.getName());
-
- /**
- * start external program, and return their output
- * @param order the command to execute
- * @return the output generated by the program. Standard ouput and Error
output are captured.
- */
- public static String run(String order) {
-
logger.info("-------------------------------------------------------------------\n"
+
- "Execute: " + order + "\n" +
-
"-------------------------------------------------------------------");
-
- Transit inputData = new Transit();
- Transit errorData = new Transit();
-
- try {
- Process p = Runtime.getRuntime().exec(order);
-
- InputStreamThread ist = new InputStreamThread(p, inputData);
- ist.start();
-
- ErrorStreamThread est = new ErrorStreamThread(p, errorData);
- est.start();
-
-// ist.join();
-// est.join();
-
-// p.destroy();
-// System.out.println("process stopped");
-
- }
- catch(Exception exception) {
- logger.log(Level.SEVERE, "Error in exec", exception);
- }
-
- // System.out.println(inputData.getString() +
errorData.getString());
- return inputData.getString() + errorData.getString();
- }
-}
-
-
-
-
+/*
+Execute.java / Frost
+Copyright (C) 2001 Jan-Thomas Czornack <jantho at users.sourceforge.net>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+package frost.ext;
+
+import java.util.logging.*;
+
+/**
+ * Supports execution of external programs
+ * @author Jan-Thomas Czornack
+ */
+public class Execute {
+
+ private static Logger logger =
Logger.getLogger(Execute.class.getName());
+
+ /**
+ * start external program, and return their output
+ * @param order the command to execute
+ * @return the output generated by the program. Standard ouput and Error
output are captured.
+ */
+ public static void run(String order, boolean wait) throws Throwable {
+
logger.info("-------------------------------------------------------------------\n"
+
+ "Execute: " + order + "\n" +
+
"-------------------------------------------------------------------");
+
+ Transit inputData = new Transit();
+ Transit errorData = new Transit();
+
+ Process p = Runtime.getRuntime().exec(order);
+
+ InputStreamThread ist = new InputStreamThread(p, inputData);
+ ist.start();
+
+ ErrorStreamThread est = new ErrorStreamThread(p, errorData);
+ est.start();
+
+ if (wait) {
+ p.waitFor();
+ }
+ // ist.join();
+ // est.join();
+
+ // p.destroy();
+ // System.out.println("process stopped");
+
+
+ // System.out.println(inputData.getString() +
errorData.getString());
+// return inputData.getString() + errorData.getString();
+ }
+}
Modified: trunk/apps/frost-0.7/source/frost/ext/InputStreamThread.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/ext/InputStreamThread.java
2006-03-13 10:26:06 UTC (rev 8238)
+++ trunk/apps/frost-0.7/source/frost/ext/InputStreamThread.java
2006-03-13 17:08:42 UTC (rev 8239)
@@ -1,48 +1,67 @@
-package frost.ext;
-
-import java.io.*;
-import java.util.logging.*;
-
-/**
- * Catches an Input Stream from a process
- * @author Jan-Thomas Czornack
- * @version 010711
- */
-class InputStreamThread extends Thread {
-
- private static Logger logger =
Logger.getLogger(InputStreamThread.class.getName());
-
- Process p;
- Transit data;
-
- public void run() {
-
- StringBuffer output = new StringBuffer();
- DataInputStream dis = new DataInputStream(p.getInputStream());
-
- try {
- int result = 0;
-
- while((result = dis.read()) != -1) {
- output.append((char)result);
- }
- logger.info(output.toString());
-
- } catch (IOException e) {
- logger.log(Level.SEVERE, "Can't get input stream.", e);
- }
-
- data.setString(output.toString());
-
- }
-
- /**
- * Constructor
- * @param p Process to get the Input Stream from
- */
- public InputStreamThread (Process p, Transit data) {
- this.p = p;
- this.data = data;
- }
-
-}
+/*
+InputStreamThread.java / Frost
+Copyright (C) 2001 Jan-Thomas Czornack <jantho at users.sourceforge.net>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+package frost.ext;
+
+import java.io.*;
+import java.util.logging.*;
+
+/**
+ * Catches an Input Stream from a process
+ * @author Jan-Thomas Czornack
+ * @version 010711
+ */
+class InputStreamThread extends Thread {
+
+ private static Logger logger =
Logger.getLogger(InputStreamThread.class.getName());
+
+ Process p;
+ Transit data;
+
+ public void run() {
+
+ StringBuffer output = new StringBuffer();
+ DataInputStream dis = new DataInputStream(p.getInputStream());
+
+ try {
+ int result = 0;
+
+ while((result = dis.read()) != -1) {
+ output.append((char)result);
+ }
+ String s = output.toString().trim();
+ if( s.length() > 0 ) {
+ logger.info("Output from external program: "+s);
+ }
+
+ } catch (IOException e) {
+ logger.log(Level.SEVERE, "Can't get input stream.", e);
+ }
+
+ data.setString(output.toString());
+ }
+
+ /**
+ * Constructor
+ * @param p Process to get the Input Stream from
+ */
+ public InputStreamThread (Process p, Transit data) {
+ this.p = p;
+ this.data = data;
+ }
+}
Modified: trunk/apps/frost-0.7/source/frost/ext/Transit.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/ext/Transit.java 2006-03-13 10:26:06 UTC
(rev 8238)
+++ trunk/apps/frost-0.7/source/frost/ext/Transit.java 2006-03-13 17:08:42 UTC
(rev 8239)
@@ -1,49 +1,67 @@
-package frost.ext;
-
-import java.util.Vector;
-
-/**
- * Transports any kind of data
- * @author Jan-Thomas Czornack
- * @version 010729
- */
-class Transit {
-
- String string;
- Vector vector;
- Transit transit;
-
-
- public void setString(String string) {
- this.string = string;
- }
-
- public String getString() {
- return string;
- }
-
-
- public void setVector(Vector vector) {
- this.vector = vector;
- }
-
- public Vector getVector() {
- return vector;
- }
-
-
- public void setTransit(Transit transit) {
- this.transit = transit;
- }
-
- public Transit getTransit() {
- return transit;
- }
-
-
- /**Constructor*/
- public Transit() {
-
- }
-
-}
+/*
+Transit.java / Frost
+Copyright (C) 2001 Jan-Thomas Czornack <jantho at users.sourceforge.net>
+
+This program is free software; you can redistribute it and/or
+modify it under the terms of the GNU General Public License as
+published by the Free Software Foundation; either version 2 of
+the License, or (at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+package frost.ext;
+
+import java.util.Vector;
+
+/**
+ * Transports any kind of data
+ * @author Jan-Thomas Czornack
+ * @version 010729
+ */
+class Transit {
+
+ String string;
+ Vector vector;
+ Transit transit;
+
+
+ public void setString(String string) {
+ this.string = string;
+ }
+
+ public String getString() {
+ return string;
+ }
+
+
+ public void setVector(Vector vector) {
+ this.vector = vector;
+ }
+
+ public Vector getVector() {
+ return vector;
+ }
+
+
+ public void setTransit(Transit transit) {
+ this.transit = transit;
+ }
+
+ public Transit getTransit() {
+ return transit;
+ }
+
+
+ /**Constructor*/
+ public Transit() {
+
+ }
+
+}
Modified:
trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadPanel.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadPanel.java
2006-03-13 10:26:06 UTC (rev 8238)
+++ trunk/apps/frost-0.7/source/frost/fileTransfer/download/DownloadPanel.java
2006-03-13 17:08:42 UTC (rev 8239)
@@ -874,7 +874,14 @@
File file = new File(execFilename);
logger.info("Executing: " + file.getPath());
if (file.exists()) {
- Execute.run("exec.bat" + " \"" + file.getPath()
+ "\"");
+ try {
+ Execute.run("exec.bat" + " \"" + file.getPath() + "\"",
false);
+ } catch(Throwable t) {
+ JOptionPane.showMessageDialog(this,
+ "Could not open the file:
"+file.getName()+"\n"+t.toString(),
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ }
}
}
}
Modified: trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadPanel.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadPanel.java
2006-03-13 10:26:06 UTC (rev 8238)
+++ trunk/apps/frost-0.7/source/frost/fileTransfer/upload/UploadPanel.java
2006-03-13 17:08:42 UTC (rev 8239)
@@ -706,8 +706,14 @@
File file = new File(ulItem.getFilePath());
logger.info("Executing: " + file.getPath());
if (file.exists()) {
- Execute.run("exec.bat" + " \"" + file.getPath()
+ "\"");
- }
+ try {
+ Execute.run("exec.bat" + " \"" + file.getPath() + "\"",
false);
+ } catch(Throwable t) {
+ JOptionPane.showMessageDialog(this,
+ "Could not open the file:
"+file.getName()+"\n"+t.toString(),
+ "Error",
+ JOptionPane.ERROR_MESSAGE);
+ } }
}
}
Modified: trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java
===================================================================
--- trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java 2006-03-13
10:26:06 UTC (rev 8238)
+++ trunk/apps/frost-0.7/source/frost/gui/MessageFrame.java 2006-03-13
17:08:42 UTC (rev 8239)
@@ -32,6 +32,7 @@
import frost.*;
import frost.boards.*;
+import frost.ext.*;
import frost.gui.model.*;
import frost.gui.objects.*;
import frost.identities.*;
@@ -538,7 +539,6 @@
private String from;
private String subject;
private String lastUsedDirectory;
- private String keypool;
private boolean state;
private SettingsClass frostSettings;
@@ -593,7 +593,6 @@
state = false;
frostSettings = newSettings;
lastUsedDirectory = frostSettings.getValue("lastUsedDirectory");
- keypool = frostSettings.getValue("keypool.dir");
String fontName =
frostSettings.getValue(SettingsClass.MESSAGE_BODY_FONT_NAME);
int fontStyle =
frostSettings.getIntValue(SettingsClass.MESSAGE_BODY_FONT_STYLE);
@@ -735,14 +734,22 @@
String text = newText;
String date = DateFun.getExtendedDate() + " - " +
DateFun.getFullExtendedTime() + "GMT";
+ String fromLine = "----- " + from + " ----- " + date + " -----";
if (isReply) {
text += "\n\n";
}
int headerAreaStart = text.length();//Beginning of
non-modifiable area
- text += "----- " + from + " ----- " + date + " -----\n\n";
+ text += fromLine + "\n\n";
int headerAreaEnd = text.length() - 2; //End of non-modifiable
area
oldSender = from;
+ if (frostSettings.getBoolValue("useAltEdit")) {
+ AltEdit ae = new AltEdit(subject, text, MainFrame.getInstance());
+ if( ae.run() ) {
+ subject = ae.getNewSubject();
+ text += ae.getNewText();
+ }
+ }
int caretPos = text.length();