Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 24301 Details for
Bug 102461
(PatchAttached) Allow for keeping commit comments permanent
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
patch for org.eclipse.team.cvs.ui to add canned comments feature
canned-comments.patch (text/plain), 16.66 KB, created by
Maik Schreiber
on 2005-07-03 10:45:01 EDT
(
hide
)
Description:
patch for org.eclipse.team.cvs.ui to add canned comments feature
Filename:
MIME Type:
Creator:
Maik Schreiber
Created:
2005-07-03 10:45:01 EDT
Size:
16.66 KB
patch
obsolete
>Index: src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java,v >retrieving revision 1.1 >diff -u -r1.1 CVSUIMessages.java >--- src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 3 Jul 2005 14:29:39 -0000 1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 3 Jul 2005 14:41:43 -0000 >@@ -815,6 +815,7 @@ > public static String CommitCommentArea_2; > public static String CommitCommentArea_3; > public static String CommitCommentArea_4; >+ public static String CommitCommentArea_5; > > public static String CheckoutProjectOperation_8; > public static String CheckoutProjectOperation_9; >Index: src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java,v >retrieving revision 1.1 >diff -u -r1.1 CommitCommentArea.java >--- src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java 3 Jul 2005 14:29:39 -0000 1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java 3 Jul 2005 14:41:44 -0000 >@@ -125,13 +125,16 @@ > > private final String fMessage; > private final String [] fComments; >+ private final String[] fCannedComments; > private final Combo fCombo; > > >- public ComboBox(Composite composite, String message, String [] options) { >+ public ComboBox(Composite composite, String message, String [] options, >+ String[] cannedComments) { > > fMessage= message; > fComments= options; >+ fCannedComments = cannedComments; > > fCombo = new Combo(composite, SWT.READ_ONLY); > fCombo.setLayoutData(SWTUtils.createHFillGridData()); >@@ -141,6 +144,9 @@ > for (int i = 0; i < fComments.length; i++) { > fCombo.add(HistoryView.flattenText(fComments[i])); > } >+ for (int i = 0; i < fCannedComments.length; i++) { >+ fCombo.add(HistoryView.flattenText(fCannedComments[i])); >+ } > fCombo.setText(fMessage); > > // We don't want to have an initial selection >@@ -150,10 +156,17 @@ > } > > public void widgetSelected(SelectionEvent e) { >- final int index = fCombo.getSelectionIndex(); >+ int index = fCombo.getSelectionIndex(); > if (index > 0) { >+ index--; > setChanged(); >- notifyObservers(fComments[index - 1]); >+ String message; >+ if (index < fComments.length) { >+ message = fComments[index]; >+ } else { >+ message = fCannedComments[index - fComments.length]; >+ } >+ notifyObservers(message); > } > } > >@@ -182,12 +195,14 @@ > > private static final String EMPTY_MESSAGE= CVSUIMessages.CommitCommentArea_0; //$NON-NLS-1$ > private static final String COMBO_MESSAGE= CVSUIMessages.CommitCommentArea_1; //$NON-NLS-1$ >+ private static final String ADD_AS_CANNED_MESSAGE= CVSUIMessages.CommitCommentArea_5; //$NON-NLS-1$ > > public static final String OK_REQUESTED = "OkRequested";//$NON-NLS-1$ > public static final String COMMENT_MODIFIED = "CommentModified";//$NON-NLS-1$ > > private TextBox fTextBox; > private ComboBox fComboBox; >+ private Button fAddCanned; > > private IProject fMainProject; > private String fProposedComment; >@@ -205,8 +220,12 @@ > > fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment()); > >+ fAddCanned = new Button(fComposite, SWT.CHECK | SWT.LEFT); >+ fAddCanned.setText(ADD_AS_CANNED_MESSAGE); >+ > final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments(); >- fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments); >+ final String[] cannedComments = CVSUIPlugin.getPlugin().getRepositoryManager().getCannedComments(); >+ fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments, cannedComments); > > fComboBox.addObserver(fTextBox); > } >@@ -218,7 +237,8 @@ > > final String stripped= strip(comment); > if (save && comment.length() > 0) >- CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment); >+ CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment, >+ fAddCanned.getSelection()); > > return stripped; > } >Index: src/org/eclipse/team/internal/ccvs/ui/messages.properties >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties,v >retrieving revision 1.1 >diff -u -r1.1 messages.properties >--- src/org/eclipse/team/internal/ccvs/ui/messages.properties 3 Jul 2005 14:29:39 -0000 1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/messages.properties 3 Jul 2005 14:41:45 -0000 >@@ -849,10 +849,11 @@ > CommitAction_jobName=CVS Commit > > CommitCommentArea_0=<Click here to enter a commit comment> >-CommitCommentArea_1=<Choose a previously entered comment> >+CommitCommentArea_1=<Choose a previously entered or canned comment> > CommitCommentArea_2=Empty commit comment > CommitCommentArea_3=The commit comment is empty. Are you sure you would like to continue with an empty comment? > CommitCommentArea_4=Re&member decision? >+CommitCommentArea_5=Add as canned comment > > > >Index: src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java >=================================================================== >RCS file: /home/mickey/cvsroot/org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java,v >retrieving revision 1.1 >diff -u -r1.1 RepositoryManager.java >--- src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java 3 Jul 2005 14:29:39 -0000 1.1 >+++ src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java 3 Jul 2005 14:41:46 -0000 >@@ -47,8 +47,10 @@ > // new state file > private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$ > private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$ >+ private static final String CANNED_COMMENTS_FILE = "cannedComments.xml"; //$NON-NLS-1$ > static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$ > static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$ >+ static final String ELEMENT_CANNED_COMMENTS = "CannedCommitComments"; //$NON-NLS-1$ > > private Map repositoryRoots = new HashMap(); > >@@ -56,6 +58,8 @@ > > // The previously remembered comment > static String[] previousComments = new String[0]; >+ >+ static String[] cannedComments = new String[0]; > > public static boolean notifyRepoView = true; > >@@ -303,6 +307,7 @@ > public void startup() { > loadState(); > loadCommentHistory(); >+ loadCannedComments(); > CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() { > public void repositoryAdded(ICVSRepositoryLocation root) { > rootAdded(root); >@@ -316,6 +321,7 @@ > public void shutdown() throws TeamException { > saveState(); > saveCommentHistory(); >+ saveCannedComments(); > } > > private void loadState() { >@@ -372,6 +378,23 @@ > CVSUIPlugin.log(e); > } > } >+ private void loadCannedComments() { >+ IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(CANNED_COMMENTS_FILE); >+ File file = pluginStateLocation.toFile(); >+ if (!file.exists()) return; >+ try { >+ BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); >+ try { >+ readCannedComments(is); >+ } finally { >+ is.close(); >+ } >+ } catch (IOException e) { >+ CVSUIPlugin.log(Status.ERROR, CVSUIMessages.RepositoryManager_ioException, e); //$NON-NLS-1$ >+ } catch (TeamException e) { >+ CVSUIPlugin.log(e); >+ } >+ } > > protected void saveState() throws TeamException { > IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); >@@ -430,6 +453,17 @@ > throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$ > } > } >+ private void readCannedComments(InputStream stream) throws IOException, TeamException { >+ try { >+ SAXParserFactory factory = SAXParserFactory.newInstance(); >+ SAXParser parser = factory.newSAXParser(); >+ parser.parse(new InputSource(stream), new CannedCommentsContentHandler()); >+ } catch (SAXException ex) { >+ throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { CANNED_COMMENTS_FILE }), ex); //$NON-NLS-1$ >+ } catch (ParserConfigurationException ex) { >+ throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { CANNED_COMMENTS_FILE }), ex); //$NON-NLS-1$ >+ } >+ } > > private void readOldState(DataInputStream dis) throws IOException, TeamException { > int repoSize = dis.readInt(); >@@ -512,12 +546,40 @@ > throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$ > } > } >+ protected void saveCannedComments() throws TeamException { >+ IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); >+ File tempFile = pluginStateLocation.append(CANNED_COMMENTS_FILE + ".tmp").toFile(); //$NON-NLS-1$ >+ File histFile = pluginStateLocation.append(CANNED_COMMENTS_FILE).toFile(); >+ try { >+ XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile))); >+ try { >+ writeCannedComments(writer); >+ } finally { >+ writer.close(); >+ } >+ if (histFile.exists()) { >+ histFile.delete(); >+ } >+ boolean renamed = tempFile.renameTo(histFile); >+ if (!renamed) { >+ throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_rename, new String[] { tempFile.getAbsolutePath() }), null)); //$NON-NLS-1$ >+ } >+ } catch (IOException e) { >+ throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$ >+ } >+ } > private void writeCommentHistory(XMLWriter writer) { > writer.startTag(ELEMENT_COMMIT_HISTORY, null, false); > for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++) > writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]); > writer.endTag(ELEMENT_COMMIT_HISTORY); > } >+ private void writeCannedComments(XMLWriter writer) { >+ writer.startTag(ELEMENT_CANNED_COMMENTS, null, false); >+ for (int i=0; i<cannedComments.length; i++) >+ writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, cannedComments[i]); >+ writer.endTag(ELEMENT_CANNED_COMMENTS); >+ } > > public void addRepositoryListener(IRepositoryListener listener) { > listeners.add(listener); >@@ -778,20 +840,38 @@ > return previousComments; > } > >+ /** >+ * Get list of canned comments. >+ */ >+ public String[] getCannedComments() { >+ return cannedComments; >+ } >+ > /** > * Method addComment. > * @param string > */ >- public void addComment(String comment) { >- // Only add the comment if its not there already >- if (containsComment(comment)) return; >- // Insert the comment as the first element >- String[] newComments = new String[Math.min(previousComments.length + 1, MAX_COMMENTS)]; >- newComments[0] = comment; >- for (int i = 1; i < newComments.length; i++) { >- newComments[i] = previousComments[i-1]; >- } >- previousComments = newComments; >+ public void addComment(String comment, boolean canned) { >+ // Only add the comment if its not there already >+ if (containsComment(comment)) >+ return; >+ >+ if (canned) { >+ // Insert the comment as last element >+ String[] newComments = new String[cannedComments.length + 1]; >+ System.arraycopy(cannedComments, 0, newComments, 0, cannedComments.length); >+ newComments[newComments.length - 1] = comment; >+ cannedComments = newComments; >+ } else { >+ // Insert the comment as the first element >+ String[] newComments = new String[Math.min( >+ previousComments.length + 1, MAX_COMMENTS)]; >+ newComments[0] = comment; >+ for (int i = 1; i < newComments.length; i++) { >+ newComments[i] = previousComments[i - 1]; >+ } >+ previousComments = newComments; >+ } > } > > private boolean containsComment(String comment) { >@@ -800,6 +880,11 @@ > return true; > } > } >+ for (int i = 0; i < cannedComments.length; i++) { >+ if (cannedComments[i].equals(comment)) { >+ return true; >+ } >+ } > return false; > } > } >Index: src/org/eclipse/team/internal/ccvs/ui/repo/CannedCommentsContentHandler.java >=================================================================== >RCS file: src/org/eclipse/team/internal/ccvs/ui/repo/CannedCommentsContentHandler.java >diff -N src/org/eclipse/team/internal/ccvs/ui/repo/CannedCommentsContentHandler.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/team/internal/ccvs/ui/repo/CannedCommentsContentHandler.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,85 @@ >+/******************************************************************************* >+ * Copyright (c) 2000, 2003 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.team.internal.ccvs.ui.repo; >+ >+import java.util.Vector; >+ >+import org.xml.sax.SAXException; >+import org.xml.sax.helpers.DefaultHandler; >+import org.xml.sax.Attributes; >+ >+class CannedCommentsContentHandler extends DefaultHandler { >+ >+ private StringBuffer buffer; >+ private Vector comments; >+ public CannedCommentsContentHandler() { >+ } >+ >+ /** >+ * @see ContentHandler#characters(char[], int, int) >+ */ >+ public void characters(char[] chars, int startIndex, int length) throws SAXException { >+ if (buffer == null) return; >+ buffer.append(chars, startIndex, length); >+ } >+ >+ /** >+ * @see ContentHandler#startElement(java.lang.String, java.lang.String, java.lang.String, org.xml.sax.Attributes) >+ */ >+ public void startElement( >+ String namespaceURI, >+ String localName, >+ String qName, >+ Attributes atts) >+ throws SAXException { >+ >+ String elementName = getElementName(namespaceURI, localName, qName); >+ if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) { >+ buffer = new StringBuffer(); >+ return; >+ } >+ if (elementName.equals(RepositoryManager.ELEMENT_CANNED_COMMENTS)) { >+ comments = new Vector(); >+ return; >+ } >+ } >+ >+ /** >+ * @see org.xml.sax.ContentHandler#endElement(java.lang.String, java.lang.String, java.lang.String) >+ */ >+ public void endElement(String namespaceURI, String localName, String qName) { >+ String elementName = getElementName(namespaceURI, localName, qName); >+ if (elementName.equals(RepositoryManager.ELEMENT_COMMIT_COMMENT)) { >+ comments.add(buffer.toString()); >+ buffer = null; >+ return; >+ } >+ if (elementName.equals(RepositoryManager.ELEMENT_CANNED_COMMENTS)) { >+ RepositoryManager.cannedComments = new String[comments.size()]; >+ comments.copyInto(RepositoryManager.cannedComments); >+ return; >+ } >+ } >+ >+ /* >+ * Couldn't figure out from the SAX API exactly when localName vs. qName is used. >+ * However, the XML for project sets doesn't use namespaces so either of the two names >+ * is fine. Therefore, use whichever one is provided. >+ */ >+ private String getElementName(String namespaceURI, String localName, String qName) { >+ if (localName != null && localName.length() > 0) { >+ return localName; >+ } else { >+ return qName; >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 102461
:
24301
|
24310
|
24894
|
24963
|
25364