1) Fixed issue #705: Take the global 'Undo history size' to overwrite the default...
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / phpeditor / PHPUnitEditor.java
index c8991c4..370142e 100644 (file)
@@ -26,7 +26,7 @@ import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference;
 import net.sourceforge.phpdt.internal.ui.text.IPHPPartitions;
 import net.sourceforge.phpdt.internal.ui.text.JavaHeuristicScanner;
 import net.sourceforge.phpdt.internal.ui.text.JavaIndenter;
-import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
+//import net.sourceforge.phpdt.internal.ui.text.PHPPairMatcher;
 import net.sourceforge.phpdt.internal.ui.text.SmartBackspaceManager;
 import net.sourceforge.phpdt.internal.ui.text.SmartSemicolonAutoEditStrategy;
 import net.sourceforge.phpdt.internal.ui.text.comment.CommentFormattingContext;
@@ -37,7 +37,7 @@ import net.sourceforge.phpdt.internal.ui.text.link.LinkedPositionUI.ExitFlags;
 import net.sourceforge.phpdt.ui.IWorkingCopyManager;
 import net.sourceforge.phpdt.ui.PreferenceConstants;
 import net.sourceforge.phpdt.ui.actions.GenerateActionGroup;
-import net.sourceforge.phpdt.ui.text.JavaTextTools;
+//import net.sourceforge.phpdt.ui.text.JavaTextTools;
 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
 import net.sourceforge.phpeclipse.phpeditor.actions.RTrimAction;
 import net.sourceforge.phpeclipse.ui.WebUI;
@@ -58,7 +58,7 @@ import org.eclipse.jface.dialogs.ErrorDialog;
 import org.eclipse.jface.dialogs.IMessageProvider;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.preference.IPreferenceStore;
-import org.eclipse.jface.preference.PreferenceConverter;
+//import org.eclipse.jface.preference.PreferenceConverter;
 import org.eclipse.jface.text.BadLocationException;
 import org.eclipse.jface.text.DocumentCommand;
 import org.eclipse.jface.text.IAutoEditStrategy;
@@ -87,7 +87,7 @@ import org.eclipse.swt.custom.VerifyKeyListener;
 import org.eclipse.swt.events.VerifyEvent;
 import org.eclipse.swt.graphics.Color;
 import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.graphics.RGB;
+//import org.eclipse.swt.graphics.RGB;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
@@ -417,6 +417,17 @@ public class PHPUnitEditor extends PHPEditor { // implements
                }
 
                /*
+                * Get the global 'Undo history size' setting 
+                *
+                */
+        protected int getUndoHistorySize () {
+                  IPreferenceStore store= getPreferenceStore ();
+                  
+                  return store != null ? store.getInt("undoHistorySize") : 1000;
+               }
+
+               
+               /*
                 * @see org.eclipse.jface.text.source.ISourceViewer#configure(org.eclipse.jface.text.source.SourceViewerConfiguration)
                 */
                public void configure(SourceViewerConfiguration configuration) {
@@ -431,6 +442,8 @@ public class PHPUnitEditor extends PHPEditor { // implements
                        prependAutoEditStrategy(smartSemi, IPHPPartitions.PHP_STRING_SQ);
                        prependAutoEditStrategy(smartSemi,
                                        IPHPPartitions.PHP_STRING_HEREDOC);
+            
+                       fUndoManager.setMaximalUndoLevel (this.getUndoHistorySize ());  // Set every editor to the global 'Undo history size'
                }
 
                /*
@@ -962,15 +975,15 @@ public class PHPUnitEditor extends PHPEditor { // implements
                }
        }
 
-       private static class BracketLevel {
-               int fOffset;
-
-               int fLength;
-
-               LinkedPositionManager fManager;
-
-               LinkedPositionUI fEditor;
-       };
+//     private static class BracketLevel {
+//             int fOffset;
+//
+//             int fLength;
+//
+//             LinkedPositionManager fManager;
+//
+//             LinkedPositionUI fEditor;
+//     };
 
        private class BracketInserter implements VerifyKeyListener,
                        LinkedPositionUI.ExitListener {
@@ -1012,21 +1025,21 @@ public class PHPUnitEditor extends PHPEditor { // implements
                        }
                }
 
-               private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
-                       try {
-                               int start = offset;
-                               IRegion startLine = document.getLineInformationOfOffset(start);
-                               int minStart = startLine.getOffset();
-                               while (start != minStart
-                                               && Character.isWhitespace(document.getChar(start - 1)))
-                                       --start;
-                               return start != minStart
-                                               && Scanner.isPHPIdentifierPart(document
-                                                               .getChar(start - 1));
-                       } catch (BadLocationException e) {
-                               return true;
-                       }
-               }
+//             private boolean hasIdentifierToTheLeft(IDocument document, int offset) {
+//                     try {
+//                             int start = offset;
+//                             IRegion startLine = document.getLineInformationOfOffset(start);
+//                             int minStart = startLine.getOffset();
+//                             while (start != minStart
+//                                             && Character.isWhitespace(document.getChar(start - 1)))
+//                                     --start;
+//                             return start != minStart
+//                                             && Scanner.isPHPIdentifierPart(document
+//                                                             .getChar(start - 1));
+//                     } catch (BadLocationException e) {
+//                             return true;
+//                     }
+//             }
 
                private boolean hasCharacterToTheLeft(IDocument document, int offset,
                                char character) {
@@ -1259,7 +1272,7 @@ public class PHPUnitEditor extends PHPEditor { // implements
        /** The editor's bracket painter */
        // private BracketPainter fBracketPainter;
        /** The editor's bracket matcher */
-       private PHPPairMatcher fBracketMatcher;
+       //private PHPPairMatcher fBracketMatcher;
 
        /** The editor's line painter */
        // private LinePainter fLinePainter;
@@ -1276,7 +1289,7 @@ public class PHPUnitEditor extends PHPEditor { // implements
        // private IPropertyChangeListener fPropertyChangeListener = new
        // PropertyChangeListener();
        /** The remembered java element */
-       private IJavaElement fRememberedElement;
+       //private IJavaElement fRememberedElement;
 
        /**
         * The remembered selection.
@@ -1286,7 +1299,7 @@ public class PHPUnitEditor extends PHPEditor { // implements
        private RememberedSelection fRememberedSelection = new RememberedSelection();
 
        /** The remembered php element offset */
-       private int fRememberedElementOffset;
+       //private int fRememberedElementOffset;
 
        /** The bracket inserter. */
        private BracketInserter fBracketInserter = new BracketInserter();
@@ -1346,52 +1359,52 @@ public class PHPUnitEditor extends PHPEditor { // implements
        // private final static String WARNING_INDICATION_COLOR =
        // PreferenceConstants.EDITOR_WARNING_INDICATION_COLOR;
        /** Preference key for task indication */
-       private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
+       //private final static String TASK_INDICATION = PreferenceConstants.EDITOR_TASK_INDICATION;
 
        /** Preference key for task color */
-       private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
+       //private final static String TASK_INDICATION_COLOR = PreferenceConstants.EDITOR_TASK_INDICATION_COLOR;
 
        /** Preference key for bookmark indication */
-       private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
+       //private final static String BOOKMARK_INDICATION = PreferenceConstants.EDITOR_BOOKMARK_INDICATION;
 
        /** Preference key for bookmark color */
-       private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
+       //private final static String BOOKMARK_INDICATION_COLOR = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_COLOR;
 
        /** Preference key for search result indication */
-       private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
+       //private final static String SEARCH_RESULT_INDICATION = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION;
 
        /** Preference key for search result color */
-       private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
+       //private final static String SEARCH_RESULT_INDICATION_COLOR = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_COLOR;
 
        /** Preference key for unknown annotation indication */
-       private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
+       //private final static String UNKNOWN_INDICATION = PreferenceConstants.EDITOR_UNKNOWN_INDICATION;
 
        /** Preference key for unknown annotation color */
-       private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
+       //private final static String UNKNOWN_INDICATION_COLOR = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_COLOR;
 
        /** Preference key for linked position color */
-       private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
+       //private final static String LINKED_POSITION_COLOR = PreferenceConstants.EDITOR_LINKED_POSITION_COLOR;
 
        /** Preference key for shwoing the overview ruler */
-       private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
+       //private final static String OVERVIEW_RULER = PreferenceConstants.EDITOR_OVERVIEW_RULER;
 
        /** Preference key for error indication in overview ruler */
-       private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
+       //private final static String ERROR_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_ERROR_INDICATION_IN_OVERVIEW_RULER;
 
        /** Preference key for warning indication in overview ruler */
-       private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
+       //private final static String WARNING_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_WARNING_INDICATION_IN_OVERVIEW_RULER;
 
        /** Preference key for task indication in overview ruler */
-       private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
+       //private final static String TASK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_TASK_INDICATION_IN_OVERVIEW_RULER;
 
        /** Preference key for bookmark indication in overview ruler */
-       private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
+       //private final static String BOOKMARK_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_BOOKMARK_INDICATION_IN_OVERVIEW_RULER;
 
        /** Preference key for search result indication in overview ruler */
-       private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
+       //private final static String SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER;
 
        /** Preference key for unknown annotation indication in overview ruler */
-       private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
+       //private final static String UNKNOWN_INDICATION_IN_OVERVIEW_RULER = PreferenceConstants.EDITOR_UNKNOWN_INDICATION_IN_OVERVIEW_RULER;
 
        /** Preference key for automatically closing double quoted strings */
        private final static String CLOSE_STRINGS_DQ_PHP = PreferenceConstants.EDITOR_CLOSE_STRINGS_DQ_PHP;
@@ -1406,22 +1419,22 @@ public class PHPUnitEditor extends PHPEditor { // implements
        private final static String CLOSE_BRACKETS_PHP = PreferenceConstants.EDITOR_CLOSE_BRACKETS_PHP;
 
        /** Preference key for automatically closing phpdocs and comments */
-       private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
+       //private final static String CLOSE_JAVADOCS = PreferenceConstants.EDITOR_CLOSE_JAVADOCS;
 
        /** Preference key for automatically adding phpdoc tags */
-       private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
+       //private final static String ADD_JAVADOC_TAGS = PreferenceConstants.EDITOR_ADD_JAVADOC_TAGS;
 
        /** Preference key for automatically formatting phpdocs */
        // private final static String FORMAT_JAVADOCS =
        // PreferenceConstants.EDITOR_FORMAT_JAVADOCS;
        /** Preference key for automatically closing strings */
-       private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
+       //private final static String CLOSE_STRINGS_HTML = PreferenceConstants.EDITOR_CLOSE_STRINGS_HTML;
 
        /** Preference key for automatically closing brackets and parenthesis */
-       private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
+       //private final static String CLOSE_BRACKETS_HTML = PreferenceConstants.EDITOR_CLOSE_BRACKETS_HTML;
 
        /** Preference key for smart paste */
-       private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
+       //private final static String SMART_PASTE = PreferenceConstants.EDITOR_SMART_PASTE;
 
        // private final static class AnnotationInfo {
        // public String fColorPreference;
@@ -1884,16 +1897,16 @@ public class PHPUnitEditor extends PHPEditor { // implements
                return store.getBoolean(SPACES_FOR_TABS);
        }
 
-       private Color getColor(String key) {
-               RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
-               return getColor(rgb);
-       }
+//     private Color getColor(String key) {
+//             RGB rgb = PreferenceConverter.getColor(getPreferenceStore(), key);
+//             return getColor(rgb);
+//     }
 
-       private Color getColor(RGB rgb) {
-               JavaTextTools textTools = WebUI.getDefault()
-                               .getJavaTextTools();
-               return textTools.getColorManager().getColor(rgb);
-       }
+//     private Color getColor(RGB rgb) {
+//             JavaTextTools textTools = WebUI.getDefault()
+//                             .getJavaTextTools();
+//             return textTools.getColorManager().getColor(rgb);
+//     }
 
        // private Color getColor(AnnotationType annotationType) {
        // AnnotationInfo info = (AnnotationInfo)
@@ -2121,19 +2134,19 @@ public class PHPUnitEditor extends PHPEditor { // implements
        // IVerticalRuler ruler, int styles) {
        // return new AdaptedSourceViewer(parent, ruler, styles);
        // }
-       private boolean isValidSelection(int offset, int length) {
-               IDocumentProvider provider = getDocumentProvider();
-               if (provider != null) {
-                       IDocument document = provider.getDocument(getEditorInput());
-                       if (document != null) {
-                               int end = offset + length;
-                               int documentLength = document.getLength();
-                               return 0 <= offset && offset <= documentLength && 0 <= end
-                                               && end <= documentLength;
-                       }
-               }
-               return false;
-       }
+//     private boolean isValidSelection(int offset, int length) {
+//             IDocumentProvider provider = getDocumentProvider();
+//             if (provider != null) {
+//                     IDocument document = provider.getDocument(getEditorInput());
+//                     if (document != null) {
+//                             int end = offset + length;
+//                             int documentLength = document.getLength();
+//                             return 0 <= offset && offset <= documentLength && 0 <= end
+//                                             && end <= documentLength;
+//                     }
+//             }
+//             return false;
+//     }
 
        /*
         * @see net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor#getInputElement()
@@ -2563,43 +2576,43 @@ public class PHPUnitEditor extends PHPEditor { // implements
        /**
         * Returns the updated java element for the old java element.
         */
-       private IJavaElement findElement(IJavaElement element) {
-               if (element == null)
-                       return null;
-               IWorkingCopyManager manager = WebUI.getDefault()
-                               .getWorkingCopyManager();
-               ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
-               if (unit != null) {
-                       try {
-                               synchronized (unit) {
-                                       unit.reconcile();
-                               }
-                               IJavaElement[] findings = unit.findElements(element);
-                               if (findings != null && findings.length > 0)
-                                       return findings[0];
-                       } catch (JavaModelException x) {
-                               PHPeclipsePlugin.log(x.getStatus());
-                               // nothing found, be tolerant and go on
-                       }
-               }
-               return null;
-       }
+//     private IJavaElement findElement(IJavaElement element) {
+//             if (element == null)
+//                     return null;
+//             IWorkingCopyManager manager = WebUI.getDefault()
+//                             .getWorkingCopyManager();
+//             ICompilationUnit unit = manager.getWorkingCopy(getEditorInput());
+//             if (unit != null) {
+//                     try {
+//                             synchronized (unit) {
+//                                     unit.reconcile();
+//                             }
+//                             IJavaElement[] findings = unit.findElements(element);
+//                             if (findings != null && findings.length > 0)
+//                                     return findings[0];
+//                     } catch (JavaModelException x) {
+//                             PHPeclipsePlugin.log(x.getStatus());
+//                             // nothing found, be tolerant and go on
+//                     }
+//             }
+//             return null;
+//     }
 
        /**
         * Returns the offset of the given Java element.
         */
-       private int getOffset(IJavaElement element) {
-               if (element instanceof ISourceReference) {
-                       ISourceReference sr = (ISourceReference) element;
-                       try {
-                               ISourceRange srcRange = sr.getSourceRange();
-                               if (srcRange != null)
-                                       return srcRange.getOffset();
-                       } catch (JavaModelException e) {
-                       }
-               }
-               return -1;
-       }
+//     private int getOffset(IJavaElement element) {
+//             if (element instanceof ISourceReference) {
+//                     ISourceReference sr = (ISourceReference) element;
+//                     try {
+//                             ISourceRange srcRange = sr.getSourceRange();
+//                             if (srcRange != null)
+//                                     return srcRange.getOffset();
+//                     } catch (JavaModelException e) {
+//                     }
+//             }
+//             return -1;
+//     }
 
        /*
         * @see AbstractTextEditor#restoreSelection()