Document cleanup after file prompt added. Build1052
authormentlicher@netbeans.org
Mon, 03 Jul 2000 21:14:19 +0000
changeset 4401b1f6d396c34
parent 439 46f52ddd5ba9
child 441 72a2a77cad2b
Document cleanup after file prompt added.
Needed by cvs commit.
vcs.advanced/src/org/netbeans/modules/vcs/advanced/CommandLineVcsFileSystem.java
     1.1 --- a/vcs.advanced/src/org/netbeans/modules/vcs/advanced/CommandLineVcsFileSystem.java	Mon Jul 03 17:28:31 2000 +0000
     1.2 +++ b/vcs.advanced/src/org/netbeans/modules/vcs/advanced/CommandLineVcsFileSystem.java	Mon Jul 03 21:14:19 2000 +0000
     1.3 @@ -31,7 +31,7 @@
     1.4  import org.openide.filesystems.DefaultAttributes;
     1.5  
     1.6  import org.netbeans.modules.vcs.*;
     1.7 -//import org.netbeans.modules.vcs.cmdline.*;
     1.8 +import org.netbeans.modules.vcs.cmdline.UserCommand;
     1.9  import org.netbeans.modules.vcs.util.*;
    1.10  
    1.11  /** Generic command line VCS filesystem.
    1.12 @@ -50,6 +50,7 @@
    1.13      private Hashtable additionalPossibleFileStatusesTable = null;
    1.14      private Vector localFilesFilteredOut = null;
    1.15      private boolean localFileFilterCaseSensitive = DEFAULT_LOCAL_FILE_FILTER_CASE_SENSITIVE;
    1.16 +    private Vector docCleanupRemoveItems = null;
    1.17  
    1.18      static final long serialVersionUID =-1017235664394970926L;
    1.19      //-------------------------------------------
    1.20 @@ -101,6 +102,31 @@
    1.21       */
    1.22      public void filePromptDocumentCleanup(javax.swing.JTextArea ta, int promptNum, Object docIdentif) {
    1.23          // Let the document unchanged by default
    1.24 +        javax.swing.text.Document doc = ta.getDocument();
    1.25 +        if (docIdentif instanceof UserCommand) {
    1.26 +            UserCommand cmd = (UserCommand) docIdentif;
    1.27 +            if (docCleanupRemoveItems != null) {
    1.28 +                for(int i = 0; i < docCleanupRemoveItems.size(); i++) {
    1.29 +                    CommandLineVcsFileSystem.DocCleanupRemoveItem item = (CommandLineVcsFileSystem.DocCleanupRemoveItem) docCleanupRemoveItems.get(i);
    1.30 +                    if (cmd.getName().equals(item.getCmdName()) && promptNum == item.getOrder()) {
    1.31 +                        String lineBegin = item.getLineBegin();
    1.32 +                        for(int line = 0; line < ta.getLineCount(); line++) {
    1.33 +                            try {
    1.34 +                                int begin = ta.getLineStartOffset(line);
    1.35 +                                int end = ta.getLineEndOffset(line);
    1.36 +                                String lineStr = doc.getText(begin, end - begin);
    1.37 +                                if (lineStr.regionMatches(0, lineBegin, 0, lineBegin.length())) {
    1.38 +                                    doc.remove(begin, end - begin);
    1.39 +                                    line--;
    1.40 +                                }
    1.41 +                            } catch (javax.swing.text.BadLocationException exc) {
    1.42 +                                org.openide.TopManager.getDefault().notifyException(exc);
    1.43 +                            }
    1.44 +                        }
    1.45 +                    }
    1.46 +                }
    1.47 +            }
    1.48 +        }
    1.49      }
    1.50  
    1.51      public void propertyChange (PropertyChangeEvent evt) {
    1.52 @@ -150,10 +176,31 @@
    1.53          } else localFilesFilteredOut = null;
    1.54      }
    1.55      
    1.56 +    private void setDocumentCleanupFromVars() {
    1.57 +        VcsConfigVariable docCleanupRemove;
    1.58 +        docCleanupRemoveItems = null;
    1.59 +        for(int i = 1; (docCleanupRemove = (VcsConfigVariable) variablesByName.get("DOCUMENT_CLEANUP_REMOVE"+i)) != null; i++) {
    1.60 +            String[] removeWhat = MiscStuff.getQuotedStrings(docCleanupRemove.getValue());
    1.61 +            if (removeWhat.length < 3) continue;
    1.62 +            int order = 0;
    1.63 +            try {
    1.64 +                order = Integer.parseInt(removeWhat[1]);
    1.65 +                order--;
    1.66 +            } catch (NumberFormatException exc) {
    1.67 +                org.openide.TopManager.getDefault().notifyException(exc);
    1.68 +                continue;
    1.69 +            }
    1.70 +            CommandLineVcsFileSystem.DocCleanupRemoveItem item = new CommandLineVcsFileSystem.DocCleanupRemoveItem(removeWhat[0], order, removeWhat[2]);
    1.71 +            if (docCleanupRemoveItems == null) docCleanupRemoveItems = new Vector();
    1.72 +            docCleanupRemoveItems.add(item);
    1.73 +        }
    1.74 +    }
    1.75 +    
    1.76      public void setVariables(Vector variables){
    1.77          super.setVariables(variables);
    1.78          setPossibleFileStatusesFromVars();
    1.79          setLocalFileFilterFromVars();
    1.80 +        setDocumentCleanupFromVars();
    1.81      }
    1.82  
    1.83      public FilenameFilter getLocalFileFilter() {
    1.84 @@ -172,6 +219,38 @@
    1.85          ("org.netbeans.modules.vcs.cmdline.BundleCVS").getString (s);
    1.86  }
    1.87      */
    1.88 +    
    1.89 +    private class DocCleanupRemoveItem implements Serializable {
    1.90 +        
    1.91 +        private String cmdName;
    1.92 +        private int order;
    1.93 +        private String lineBegin;
    1.94 +        
    1.95 +        static final long serialVersionUID =-1259352637936409072L;
    1.96 +        /**
    1.97 +         * Create new cleanup remove item.
    1.98 +         * @param cmdName The name of the command.
    1.99 +         * @param order the order of JTextArea in the VariableInputDialog.
   1.100 +         * @param lineBegin the beginning of lines which will be removed.
   1.101 +         */
   1.102 +        public DocCleanupRemoveItem(String cmdName, int order, String lineBegin) {
   1.103 +            this.cmdName = cmdName;
   1.104 +            this.order = order;
   1.105 +            this.lineBegin = lineBegin;
   1.106 +        }
   1.107 +        
   1.108 +        public String getCmdName() {
   1.109 +            return cmdName;
   1.110 +        }
   1.111 +        
   1.112 +        public int getOrder() {
   1.113 +            return order;
   1.114 +        }
   1.115 +        
   1.116 +        public String getLineBegin() {
   1.117 +            return lineBegin;
   1.118 +        }
   1.119 +    }
   1.120  }
   1.121  
   1.122  /*