[Jsxe-cvs] SF.net SVN: jsxe: [1106] trunk/sourceview
Status: Inactive
Brought to you by:
ian_lewis
From: <ian...@us...> - 2006-08-05 21:41:22
|
Revision: 1106 Author: ian_lewis Date: 2006-08-05 14:41:13 -0700 (Sat, 05 Aug 2006) ViewCVS: http://svn.sourceforge.net/jsxe/?rev=1106&view=rev Log Message: ----------- Added Undo to the source view Modified Paths: -------------- trunk/sourceview/Changelog trunk/sourceview/src/sourceview/SourceView.java trunk/sourceview/src/sourceview/SourceViewDocument.java trunk/sourceview/src/sourceview/SourceViewPlugin.java Added Paths: ----------- trunk/sourceview/src/sourceview/action/RedoAction.java trunk/sourceview/src/sourceview/action/UndoAction.java Modified: trunk/sourceview/Changelog =================================================================== --- trunk/sourceview/Changelog 2006-08-05 20:24:09 UTC (rev 1105) +++ trunk/sourceview/Changelog 2006-08-05 21:41:13 UTC (rev 1106) @@ -1,3 +1,7 @@ +08/05/2006 Ian Lewis <Ian...@me...> + + * Added undo to the source view + 07/26/2006 Ian Lewis <Ian...@me...> * Addded support for the findnext action Modified: trunk/sourceview/src/sourceview/SourceView.java =================================================================== --- trunk/sourceview/src/sourceview/SourceView.java 2006-08-05 20:24:09 UTC (rev 1105) +++ trunk/sourceview/src/sourceview/SourceView.java 2006-08-05 21:41:13 UTC (rev 1106) @@ -155,13 +155,11 @@ m_editMenu = new JMenu(Messages.getMessage("Edit.Menu")); m_editMenu.setMnemonic('E'); // These don't do anything yet. - // JMenuItem menuItem = new JMenuItem("Undo"); - // menuItem.addActionListener( new EditUndoAction() ); - // menu.add( menuItem ); - // menuItem = new JMenuItem("Redo"); - // menuItem.addActionListener( new EditRedoAction() ); - // menu.add(menuItem); - // menu.addSeparator(); + menuItem = new JMenuItem(ActionManager.getAction("undo")); + m_editMenu.add( menuItem ); + menuItem = new JMenuItem(ActionManager.getAction("redo")); + m_editMenu.add(menuItem); + m_editMenu.addSeparator(); menuItem = new JMenuItem(ActionManager.getAction("cut")); m_editMenu.add(menuItem); menuItem = new JMenuItem(ActionManager.getAction("copy")); Modified: trunk/sourceview/src/sourceview/SourceViewDocument.java =================================================================== --- trunk/sourceview/src/sourceview/SourceViewDocument.java 2006-08-05 20:24:09 UTC (rev 1105) +++ trunk/sourceview/src/sourceview/SourceViewDocument.java 2006-08-05 21:41:13 UTC (rev 1106) @@ -55,6 +55,10 @@ import javax.swing.text.GapContent; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleContext; +import javax.swing.event.DocumentEvent; +import javax.swing.event.UndoableEditListener; +import javax.swing.event.UndoableEditEvent; +import javax.swing.undo.*; //}}} //{{{ DOM classes @@ -96,50 +100,103 @@ //buffer is actually loaded in the text area at any //given time(?) super.insertString(0, document.getText(0,document.getLength()), null); + m_initialized = true; } catch (BadLocationException ble) { Log.log(Log.ERROR, this, ble); } } + + addUndoableEditListener(new UndoableEditListener() { + public void undoableEditHappened(UndoableEditEvent e) { + m_undoManager.addEdit(e.getEdit()); + } + }); }//}}} //{{{ DefaultStyledDocument methods - //{{{ insertString() + // //{{{ insertString() - public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { + // public void insertString(int offs, String str, AttributeSet a) throws BadLocationException { + // Log.log(Log.DEBUG, this, "insert: "+str); + // try { + // super.insertString(offs, str, a); + // m_document.insertText(offs, str); + // } catch (DOMException dome) { + // Log.log(Log.ERROR, this, dome); + // Toolkit.getDefaultToolkit().beep(); + // } catch (IOException ioe) { + // Log.log(Log.ERROR, this, ioe); + // } + + // }//}}} + + // //{{{ remove() + + // public void remove(int offs, int len) throws BadLocationException { + // Log.log(Log.DEBUG, this, "remove"); + // try { + // super.remove(offs, len); + // m_document.removeText(offs, len); + // } catch (DOMException dome) { + // Log.log(Log.ERROR, this, dome); + // Toolkit.getDefaultToolkit().beep(); + // } catch (IOException ioe) { + // Log.log(Log.ERROR, this, ioe); + // } + // }//}}} + + protected void fireInsertUpdate(DocumentEvent e) { try { - super.insertString(offs, str, a); - m_document.insertText(offs, str); - } catch (DOMException dome) { - Log.log(Log.ERROR, this, dome); - Toolkit.getDefaultToolkit().beep(); + Log.log(Log.DEBUG, this, "insert: "+getText(e.getOffset(), e.getLength())); + if (m_initialized) { + m_document.insertText(e.getOffset(), getText(e.getOffset(), e.getLength())); + } + super.fireInsertUpdate(e); } catch (IOException ioe) { Log.log(Log.ERROR, this, ioe); + } catch (BadLocationException ble) { + Log.log(Log.ERROR, this, ble); } - - }//}}} - - //{{{ remove() + } - public void remove(int offs, int len) throws BadLocationException { - + protected void fireRemoveUpdate(DocumentEvent e) { try { - super.remove(offs, len); - m_document.removeText(offs, len); - } catch (DOMException dome) { - Log.log(Log.ERROR, this, dome); - Toolkit.getDefaultToolkit().beep(); + Log.log(Log.DEBUG, this, "remove: "+e.getOffset()+":"+e.getLength()); + if (m_initialized) { + m_document.removeText(e.getOffset(), e.getLength()); + } + super.fireRemoveUpdate(e); } catch (IOException ioe) { Log.log(Log.ERROR, this, ioe); } - - }//}}} - + } + //}}} + //{{{ undo() + public void undo() { + try { + m_undoManager.undo(); + } catch (CannotUndoException e) { + Log.log(Log.WARNING, this, "Cannot undo"); + } + }//}}} + + //{{{ redo() + public void redo() throws CannotUndoException { + try { + m_undoManager.redo(); + } catch (CannotUndoException e) { + Log.log(Log.WARNING, this, "Cannot redo"); + } + }//}}} + //{{{ Private members + private boolean m_initialized = false; private XMLDocument m_document; + private UndoManager m_undoManager = new UndoManager(); //}}} } Modified: trunk/sourceview/src/sourceview/SourceViewPlugin.java =================================================================== --- trunk/sourceview/src/sourceview/SourceViewPlugin.java 2006-08-05 20:24:09 UTC (rev 1105) +++ trunk/sourceview/src/sourceview/SourceViewPlugin.java 2006-08-05 21:41:13 UTC (rev 1106) @@ -65,6 +65,8 @@ addAction(new EditPasteAction()); addAction(new EditFindAction()); addAction(new EditFindNextAction()); + addAction(new UndoAction()); + addAction(new RedoAction()); }//}}} //{{{ newDocumentView() Added: trunk/sourceview/src/sourceview/action/RedoAction.java =================================================================== --- trunk/sourceview/src/sourceview/action/RedoAction.java (rev 0) +++ trunk/sourceview/src/sourceview/action/RedoAction.java 2006-08-05 21:41:13 UTC (rev 1106) @@ -0,0 +1,74 @@ +/* +RedoAction.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package sourceview.action; + +//{{{ imports + +import sourceview.*; + +//{{{ jsXe classes +import net.sourceforge.jsxe.jsXe; +import net.sourceforge.jsxe.ActionManager; +import net.sourceforge.jsxe.LocalizedAction; +import net.sourceforge.jsxe.gui.TabbedView; +import net.sourceforge.jsxe.gui.Messages; +import net.sourceforge.jsxe.gui.DocumentView; +import net.sourceforge.jsxe.util.Log; +//}}} + +//{{{ AWT classes +import java.awt.event.ActionEvent; +//}}} + +//}}} + +/** + * This action that redoes the last action made in the source view. + * + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + */ +public class RedoAction extends LocalizedAction { + + //{{{ RedoAction constructor + public RedoAction() { + super(SourceViewPlugin.PLUGIN_NAME+ActionManager.REDO_SUFFIX); + }//}}} + + //{{{ getLabel() + public String getLabel() { + return Messages.getMessage("common.redo"); + }//}}} + + //{{{ invoke() + public void invoke(TabbedView view, ActionEvent evt) { + DocumentView docView = view.getDocumentView(); + if (docView instanceof SourceView) { + SourceView sourceView = (SourceView)docView; + ((SourceViewDocument)sourceView.getTextArea().getDocument()).redo(); + } + }//}}} + +} Property changes on: trunk/sourceview/src/sourceview/action/RedoAction.java ___________________________________________________________________ Name: svn:executable + * Added: trunk/sourceview/src/sourceview/action/UndoAction.java =================================================================== --- trunk/sourceview/src/sourceview/action/UndoAction.java (rev 0) +++ trunk/sourceview/src/sourceview/action/UndoAction.java 2006-08-05 21:41:13 UTC (rev 1106) @@ -0,0 +1,74 @@ +/* +UndoAction.java +:tabSize=4:indentSize=4:noTabs=true: +:folding=explicit:collapseFolds=1: + +Copyright (C) 2006 Ian Lewis (Ian...@me...) + +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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +Optionally, you may find a copy of the GNU General Public License +from http://www.fsf.org/copyleft/gpl.txt +*/ + +package sourceview.action; + +//{{{ imports + +import sourceview.*; + +//{{{ jsXe classes +import net.sourceforge.jsxe.jsXe; +import net.sourceforge.jsxe.ActionManager; +import net.sourceforge.jsxe.LocalizedAction; +import net.sourceforge.jsxe.gui.TabbedView; +import net.sourceforge.jsxe.gui.Messages; +import net.sourceforge.jsxe.gui.DocumentView; +import net.sourceforge.jsxe.util.Log; +//}}} + +//{{{ AWT classes +import java.awt.event.ActionEvent; +//}}} + +//}}} + +/** + * This action that undoes the last action made in the source view. + * + * @author Ian Lewis (<a href="mailto:Ian...@me...">Ian...@me...</a>) + * @version $Id$ + */ +public class UndoAction extends LocalizedAction { + + //{{{ UndoAction constructor + public UndoAction() { + super(SourceViewPlugin.PLUGIN_NAME+ActionManager.UNDO_SUFFIX); + }//}}} + + //{{{ getLabel() + public String getLabel() { + return Messages.getMessage("common.undo"); + }//}}} + + //{{{ invoke() + public void invoke(TabbedView view, ActionEvent evt) { + DocumentView docView = view.getDocumentView(); + if (docView instanceof SourceView) { + SourceView sourceView = (SourceView)docView; + ((SourceViewDocument)sourceView.getTextArea().getDocument()).undo(); + } + }//}}} + +} Property changes on: trunk/sourceview/src/sourceview/action/UndoAction.java ___________________________________________________________________ Name: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |