Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 102461 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java (+1 lines)
Lines 815-820 Link Here
815
	public static String CommitCommentArea_2;
815
	public static String CommitCommentArea_2;
816
	public static String CommitCommentArea_3;
816
	public static String CommitCommentArea_3;
817
	public static String CommitCommentArea_4;
817
	public static String CommitCommentArea_4;
818
    public static String CommitCommentArea_5;
818
819
819
	public static String CheckoutProjectOperation_8;
820
	public static String CheckoutProjectOperation_8;
820
	public static String CheckoutProjectOperation_9;
821
	public static String CheckoutProjectOperation_9;
(-)src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java (-5 / +25 lines)
Lines 125-137 Link Here
125
        
125
        
126
        private final String fMessage;
126
        private final String fMessage;
127
        private final String [] fComments;
127
        private final String [] fComments;
128
        private final String[] fCannedComments;
128
        private final Combo fCombo;
129
        private final Combo fCombo;
129
        
130
        
130
        
131
        
131
        public ComboBox(Composite composite, String message, String [] options) {
132
        public ComboBox(Composite composite, String message, String [] options,
133
                String[] cannedComments) {
132
            
134
            
133
            fMessage= message;
135
            fMessage= message;
134
            fComments= options;
136
            fComments= options;
137
            fCannedComments = cannedComments;
135
            
138
            
136
            fCombo = new Combo(composite, SWT.READ_ONLY);
139
            fCombo = new Combo(composite, SWT.READ_ONLY);
137
            fCombo.setLayoutData(SWTUtils.createHFillGridData());
140
            fCombo.setLayoutData(SWTUtils.createHFillGridData());
Lines 141-146 Link Here
141
            for (int i = 0; i < fComments.length; i++) {
144
            for (int i = 0; i < fComments.length; i++) {
142
                fCombo.add(HistoryView.flattenText(fComments[i]));
145
                fCombo.add(HistoryView.flattenText(fComments[i]));
143
            }
146
            }
147
            for (int i = 0; i < fCannedComments.length; i++) {
148
                fCombo.add(HistoryView.flattenText(fCannedComments[i]));
149
            }
144
            fCombo.setText(fMessage);
150
            fCombo.setText(fMessage);
145
            
151
            
146
            // We don't want to have an initial selection
152
            // We don't want to have an initial selection
Lines 150-159 Link Here
150
        }
156
        }
151
        
157
        
152
        public void widgetSelected(SelectionEvent e) {
158
        public void widgetSelected(SelectionEvent e) {
153
            final int index = fCombo.getSelectionIndex();
159
            int index = fCombo.getSelectionIndex();
154
            if (index > 0) {
160
            if (index > 0) {
161
                index--;
155
                setChanged();
162
                setChanged();
156
                notifyObservers(fComments[index - 1]);
163
                String message;
164
                if (index < fComments.length) {
165
                    message = fComments[index];
166
                } else {
167
                    message = fCannedComments[index - fComments.length];
168
                }
169
                notifyObservers(message);
157
            }
170
            }
158
        }
171
        }
159
        
172
        
Lines 182-193 Link Here
182
    
195
    
183
    private static final String EMPTY_MESSAGE= CVSUIMessages.CommitCommentArea_0; //$NON-NLS-1$
196
    private static final String EMPTY_MESSAGE= CVSUIMessages.CommitCommentArea_0; //$NON-NLS-1$
184
    private static final String COMBO_MESSAGE= CVSUIMessages.CommitCommentArea_1; //$NON-NLS-1$
197
    private static final String COMBO_MESSAGE= CVSUIMessages.CommitCommentArea_1; //$NON-NLS-1$
198
    private static final String ADD_AS_CANNED_MESSAGE= CVSUIMessages.CommitCommentArea_5; //$NON-NLS-1$
185
    
199
    
186
    public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$
200
    public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$
187
    public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$
201
    public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$
188
    
202
    
189
    private TextBox fTextBox;
203
    private TextBox fTextBox;
190
    private ComboBox fComboBox;
204
    private ComboBox fComboBox;
205
    private Button fAddCanned;
191
    
206
    
192
    private IProject fMainProject;
207
    private IProject fMainProject;
193
    private String fProposedComment;
208
    private String fProposedComment;
Lines 205-212 Link Here
205
        
220
        
206
        fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment());
221
        fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment());
207
        
222
        
223
        fAddCanned = new Button(fComposite, SWT.CHECK | SWT.LEFT);
224
        fAddCanned.setText(ADD_AS_CANNED_MESSAGE);
225
        
208
        final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments();
226
        final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments();
209
        fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments);
227
        final String[] cannedComments = CVSUIPlugin.getPlugin().getRepositoryManager().getCannedComments();
228
        fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments, cannedComments);
210
        
229
        
211
        fComboBox.addObserver(fTextBox);
230
        fComboBox.addObserver(fTextBox);
212
    }
231
    }
Lines 218-224 Link Here
218
        
237
        
219
        final String stripped= strip(comment);
238
        final String stripped= strip(comment);
220
        if (save && comment.length() > 0)
239
        if (save && comment.length() > 0)
221
            CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment);
240
            CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment,
241
                    fAddCanned.getSelection());
222
242
223
        return stripped;
243
        return stripped;
224
    }
244
    }
(-)src/org/eclipse/team/internal/ccvs/ui/messages.properties (-1 / +2 lines)
Lines 849-858 Link Here
849
CommitAction_jobName=CVS Commit
849
CommitAction_jobName=CVS Commit
850
850
851
CommitCommentArea_0=<Click here to enter a commit comment>
851
CommitCommentArea_0=<Click here to enter a commit comment>
852
CommitCommentArea_1=<Choose a previously entered comment>
852
CommitCommentArea_1=<Choose a previously entered or canned comment>
853
CommitCommentArea_2=Empty commit comment
853
CommitCommentArea_2=Empty commit comment
854
CommitCommentArea_3=The commit comment is empty. Are you sure you would like to continue with an empty comment?
854
CommitCommentArea_3=The commit comment is empty. Are you sure you would like to continue with an empty comment?
855
CommitCommentArea_4=Re&member decision?
855
CommitCommentArea_4=Re&member decision?
856
CommitCommentArea_5=Add as canned comment
856
857
857
858
858
859
(-)src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java (-10 / +95 lines)
Lines 47-54 Link Here
47
	// new state file
47
	// new state file
48
	private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$
48
	private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$
49
	private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$
49
	private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$
50
    private static final String CANNED_COMMENTS_FILE = "cannedComments.xml"; //$NON-NLS-1$
50
	static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$
51
	static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$
51
	static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$
52
	static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$
53
    static final String ELEMENT_CANNED_COMMENTS = "CannedCommitComments"; //$NON-NLS-1$
52
54
53
	private Map repositoryRoots = new HashMap();
55
	private Map repositoryRoots = new HashMap();
54
	
56
	
Lines 56-61 Link Here
56
58
57
	// The previously remembered comment
59
	// The previously remembered comment
58
	static String[] previousComments = new String[0];
60
	static String[] previousComments = new String[0];
61
    
62
    static String[] cannedComments = new String[0];
59
	
63
	
60
	public static boolean notifyRepoView = true;
64
	public static boolean notifyRepoView = true;
61
	
65
	
Lines 303-308 Link Here
303
	public void startup() {
307
	public void startup() {
304
		loadState();
308
		loadState();
305
		loadCommentHistory();
309
		loadCommentHistory();
310
        loadCannedComments();
306
		CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() {
311
		CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() {
307
			public void repositoryAdded(ICVSRepositoryLocation root) {
312
			public void repositoryAdded(ICVSRepositoryLocation root) {
308
				rootAdded(root);
313
				rootAdded(root);
Lines 316-321 Link Here
316
	public void shutdown() throws TeamException {
321
	public void shutdown() throws TeamException {
317
		saveState();
322
		saveState();
318
		saveCommentHistory();
323
		saveCommentHistory();
324
        saveCannedComments();
319
	}
325
	}
320
	
326
	
321
	private void loadState() {
327
	private void loadState() {
Lines 372-377 Link Here
372
			CVSUIPlugin.log(e);
378
			CVSUIPlugin.log(e);
373
		}
379
		}
374
	}
380
	}
381
    private void loadCannedComments() {
382
        IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(CANNED_COMMENTS_FILE);
383
        File file = pluginStateLocation.toFile();
384
        if (!file.exists()) return;
385
        try {
386
            BufferedInputStream is = new BufferedInputStream(new FileInputStream(file));
387
            try {
388
                readCannedComments(is);
389
            } finally {
390
                is.close();
391
            }
392
        } catch (IOException e) {
393
            CVSUIPlugin.log(Status.ERROR, CVSUIMessages.RepositoryManager_ioException, e); //$NON-NLS-1$
394
        } catch (TeamException e) {
395
            CVSUIPlugin.log(e);
396
        }
397
    }
375
	
398
	
376
	protected void saveState() throws TeamException {
399
	protected void saveState() throws TeamException {
377
		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
400
		IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
Lines 430-435 Link Here
430
			throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$
453
			throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$
431
		}
454
		}
432
	}
455
	}
456
    private void readCannedComments(InputStream stream) throws IOException, TeamException {
457
        try {
458
            SAXParserFactory factory = SAXParserFactory.newInstance();
459
            SAXParser parser = factory.newSAXParser();
460
            parser.parse(new InputSource(stream), new CannedCommentsContentHandler());
461
        } catch (SAXException ex) {
462
            throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { CANNED_COMMENTS_FILE }), ex); //$NON-NLS-1$
463
        } catch (ParserConfigurationException ex) {
464
            throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { CANNED_COMMENTS_FILE }), ex); //$NON-NLS-1$
465
        }
466
    }
433
	
467
	
434
	private void readOldState(DataInputStream dis) throws IOException, TeamException {
468
	private void readOldState(DataInputStream dis) throws IOException, TeamException {
435
		int repoSize = dis.readInt();
469
		int repoSize = dis.readInt();
Lines 512-523 Link Here
512
		 		 throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$
546
		 		 throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$
513
		 }
547
		 }
514
	}
548
	}
549
    protected void saveCannedComments() throws TeamException {
550
        IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation();
551
        File tempFile = pluginStateLocation.append(CANNED_COMMENTS_FILE + ".tmp").toFile(); //$NON-NLS-1$
552
        File histFile = pluginStateLocation.append(CANNED_COMMENTS_FILE).toFile();
553
        try {
554
                 XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile)));
555
                 try {
556
                         writeCannedComments(writer);
557
                 } finally {
558
                         writer.close();
559
                 }
560
                 if (histFile.exists()) {
561
                         histFile.delete();
562
                 }
563
                 boolean renamed = tempFile.renameTo(histFile);
564
                 if (!renamed) {
565
                         throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_rename, new String[] { tempFile.getAbsolutePath() }), null)); //$NON-NLS-1$
566
                 }
567
         } catch (IOException e) {
568
                 throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$
569
         }
570
    }
515
	private void writeCommentHistory(XMLWriter writer) {
571
	private void writeCommentHistory(XMLWriter writer) {
516
		writer.startTag(ELEMENT_COMMIT_HISTORY, null, false);
572
		writer.startTag(ELEMENT_COMMIT_HISTORY, null, false);
517
		for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++)
573
		for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++)
518
			writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]);
574
			writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]);
519
		writer.endTag(ELEMENT_COMMIT_HISTORY);
575
		writer.endTag(ELEMENT_COMMIT_HISTORY);
520
	}
576
	}
577
    private void writeCannedComments(XMLWriter writer) {
578
        writer.startTag(ELEMENT_CANNED_COMMENTS, null, false);
579
        for (int i=0; i<cannedComments.length; i++)
580
            writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, cannedComments[i]);
581
        writer.endTag(ELEMENT_CANNED_COMMENTS);
582
    }
521
		 
583
		 
522
	public void addRepositoryListener(IRepositoryListener listener) {
584
	public void addRepositoryListener(IRepositoryListener listener) {
523
		listeners.add(listener);
585
		listeners.add(listener);
Lines 778-797 Link Here
778
		return previousComments;
840
		return previousComments;
779
	}
841
	}
780
842
843
    /**
844
     * Get list of canned comments.
845
     */
846
    public String[] getCannedComments() {
847
        return cannedComments;
848
    }
849
    
781
	/**
850
	/**
782
	 * Method addComment.
851
	 * Method addComment.
783
	 * @param string
852
	 * @param string
784
	 */
853
	 */
785
	public void addComment(String comment) {
854
	public void addComment(String comment, boolean canned) {
786
		// Only add the comment if its not there already
855
	    // Only add the comment if its not there already
787
		if (containsComment(comment)) return;
856
	    if (containsComment(comment))
788
		// Insert the comment as the first element
857
	        return;
789
		String[] newComments = new String[Math.min(previousComments.length + 1, MAX_COMMENTS)];
858
790
		newComments[0] = comment;
859
        if (canned) {
791
		for (int i = 1; i < newComments.length; i++) {
860
            // Insert the comment as last element
792
			newComments[i] = previousComments[i-1];
861
            String[] newComments = new String[cannedComments.length + 1];
793
		}
862
            System.arraycopy(cannedComments, 0, newComments, 0, cannedComments.length);
794
		previousComments = newComments;
863
            newComments[newComments.length - 1] = comment;
864
            cannedComments = newComments;
865
        } else {
866
            // Insert the comment as the first element
867
            String[] newComments = new String[Math.min(
868
                    previousComments.length + 1, MAX_COMMENTS)];
869
            newComments[0] = comment;
870
            for (int i = 1; i < newComments.length; i++) {
871
                newComments[i] = previousComments[i - 1];
872
            }
873
            previousComments = newComments;
874
        }
795
	}
875
	}
796
876
797
	private boolean containsComment(String comment) {
877
	private boolean containsComment(String comment) {
Lines 800-805 Link Here
800
				return true;
880
				return true;
801
			}
881
			}
802
		}
882
		}
883
        for (int i = 0; i < cannedComments.length; i++) {
884
            if (cannedComments[i].equals(comment)) {
885
                return true;
886
            }
887
        }
803
		return false;
888
		return false;
804
	}
889
	}
805
}
890
}
(-)src/org/eclipse/team/internal/ccvs/ui/repo/CannedCommentsContentHandler.java (+85 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2000, 2003 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 * 
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
12
package org.eclipse.team.internal.ccvs.ui.repo;
13
14
import java.util.Vector;
15
16
import org.xml.sax.SAXException;
17
import org.xml.sax.helpers.DefaultHandler;
18
import org.xml.sax.Attributes;
19
20
class CannedCommentsContentHandler extends DefaultHandler {
21
22
	private StringBuffer buffer;
23
	private Vector comments;
24
	public CannedCommentsContentHandler() {
25
	}
26
27
	/**
28
	 * @see ContentHandler#characters(char[], int, int)
29
	 */
30
	public void characters(char[] chars, int startIndex, int length) throws SAXException {
31
		if (buffer == null) return;
32
		buffer.append(chars, startIndex, length);
33
	}
34
35
	/**
36
	 * @see ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes)
37
	 */
38
	public void startElement(
39
			String namespaceURI,
40
			String localName,
41
			String qName,
42
			Attributes atts)
43
			throws SAXException {
44
		
45
		String elementName = getElementName(namespaceURI, localName, qName);
46
		if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
47
			buffer = new StringBuffer();
48
			return;
49
		} 
50
		if (elementName.equals(RepositoryManager.ELEMENT_CANNED_COMMENTS)) {
51
			comments = new Vector();
52
			return;
53
		}
54
	}
55
	
56
	/**
57
	 * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
58
	 */
59
	public void endElement(String namespaceURI, String localName, String qName) {
60
		String elementName = getElementName(namespaceURI, localName, qName);
61
		if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) {
62
			comments.add(buffer.toString());
63
			buffer = null;
64
			return;
65
		} 
66
		if (elementName.equals(RepositoryManager.ELEMENT_CANNED_COMMENTS)) {
67
			RepositoryManager.cannedComments = new String[comments.size()];
68
			comments.copyInto(RepositoryManager.cannedComments);
69
			return;
70
		} 
71
	}
72
	
73
	/*
74
	 * Couldn't figure out from the SAX API exactly when localName vs. qName is used.
75
	 * However, the XML for project sets doesn't use namespaces so either of the two names
76
	 * is fine. Therefore, use whichever one is provided.
77
	 */
78
	private String getElementName(String namespaceURI, String localName, String qName) {
79
		if (localName != null && localName.length() > 0) {
80
			return localName;
81
		} else {
82
			return qName;
83
		}
84
	}
85
}

Return to bug 102461