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 24310 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]
new patch version
permanent-comments.patch (text/plain), 18.75 KB, created by
Maik Schreiber
on 2005-07-03 17:47:09 EDT
(
hide
)
Description:
new patch version
Filename:
MIME Type:
Creator:
Maik Schreiber
Created:
2005-07-03 17:47:09 EDT
Size:
18.75 KB
patch
obsolete
>diff -uNr org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java >--- org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java 2005-07-03 23:16:07.000000000 +0200 >+++ org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CommitCommentArea.java 2005-07-03 23:26:22.000000000 +0200 >@@ -125,13 +125,16 @@ > > private final String fMessage; > private final String [] fComments; >+ private final String[] fPermanentComments; > private final Combo fCombo; > > >- public ComboBox(Composite composite, String message, String [] options) { >+ public ComboBox(Composite composite, String message, String [] options, >+ String[] permanentComments) { > > fMessage= message; > fComments= options; >+ fPermanentComments = permanentComments; > > 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 < fPermanentComments.length; i++) { >+ fCombo.add(HistoryView.flattenText(fPermanentComments[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 = fPermanentComments[index - fComments.length]; >+ } >+ notifyObservers(message); > } > } > >@@ -178,16 +191,46 @@ > public void setEnabled(boolean enabled) { > fCombo.setEnabled(enabled); > } >+ >+ public boolean isPermanent(String comment) { >+ for (int i = 0; i < fPermanentComments.length; i++) { >+ if (fPermanentComments[i].equals(comment)) { >+ return true; >+ } >+ } >+ return false; >+ } >+ } >+ >+ private static final class PermanentCheckbox implements Observer { >+ private Button fKeepPermanent; >+ >+ private PermanentCheckbox(Composite parent, String label) { >+ fKeepPermanent = new Button(parent, SWT.CHECK | SWT.LEFT); >+ fKeepPermanent.setText(label); >+ } >+ >+ public void update(Observable o, Object arg) { >+ ComboBox cb = (ComboBox) o; >+ boolean permanent = cb.isPermanent((String) arg); >+ fKeepPermanent.setSelection(permanent); >+ } >+ >+ public boolean getSelection() { >+ return fKeepPermanent.getSelection(); >+ } > } > > 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 KEEP_PERMANENT_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 PermanentCheckbox fKeepPermanent; > > private IProject fMainProject; > private String fProposedComment; >@@ -205,10 +248,14 @@ > > fTextBox= new TextBox(fComposite, EMPTY_MESSAGE, getInitialComment()); > >+ fKeepPermanent = new PermanentCheckbox(fComposite, KEEP_PERMANENT_MESSAGE); >+ > final String [] comments = CVSUIPlugin.getPlugin().getRepositoryManager().getPreviousComments(); >- fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments); >+ final String[] permanentComments = CVSUIPlugin.getPlugin().getRepositoryManager().getPermanentComments(); >+ fComboBox= new ComboBox(fComposite, COMBO_MESSAGE, comments, permanentComments); > > fComboBox.addObserver(fTextBox); >+ fComboBox.addObserver(fKeepPermanent); > } > > public String getComment(boolean save) { >@@ -218,7 +265,8 @@ > > final String stripped= strip(comment); > if (save && comment.length() > 0) >- CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment); >+ CVSUIPlugin.getPlugin().getRepositoryManager().addComment(comment, >+ fKeepPermanent.getSelection()); > > return stripped; > } >diff -uNr org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java >--- org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 2005-07-03 23:16:07.000000000 +0200 >+++ org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/CVSUIMessages.java 2005-07-03 23:26:22.000000000 +0200 >@@ -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; >diff -uNr org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/messages.properties org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties >--- org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/messages.properties 2005-07-03 23:16:08.000000000 +0200 >+++ org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/messages.properties 2005-07-03 23:26:22.000000000 +0200 >@@ -853,6 +853,7 @@ > 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=Keep permanent > > > >diff -uNr org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/repo/PermanentCommentsContentHandler.java org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/PermanentCommentsContentHandler.java >--- org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/repo/PermanentCommentsContentHandler.java 1970-01-01 01:00:00.000000000 +0100 >+++ org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/PermanentCommentsContentHandler.java 2005-07-03 23:26:22.000000000 +0200 >@@ -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 PermanentCommentsContentHandler extends DefaultHandler { >+ >+ private StringBuffer buffer; >+ private Vector comments; >+ public PermanentCommentsContentHandler() { >+ } >+ >+ /** >+ * @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_PERMANENT_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_PERMANENT_COMMENTS)) { >+ RepositoryManager.permanentComments = new String[comments.size()]; >+ comments.copyInto(RepositoryManager.permanentComments); >+ 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; >+ } >+ } >+} >diff -uNr org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java >--- org.eclipse.team.cvs.ui~/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java 2005-07-03 23:16:11.000000000 +0200 >+++ org.eclipse.team.cvs.ui/src/org/eclipse/team/internal/ccvs/ui/repo/RepositoryManager.java 2005-07-03 23:26:22.000000000 +0200 >@@ -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 PERMANENT_COMMENTS_FILE = "permanentComments.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_PERMANENT_COMMENTS = "PermanentCommitComments"; //$NON-NLS-1$ > > private Map repositoryRoots = new HashMap(); > >@@ -56,6 +58,7 @@ > > // The previously remembered comment > static String[] previousComments = new String[0]; >+ static String[] permanentComments = new String[0]; > > public static boolean notifyRepoView = true; > >@@ -303,6 +306,7 @@ > public void startup() { > loadState(); > loadCommentHistory(); >+ loadPermanentComments(); > CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() { > public void repositoryAdded(ICVSRepositoryLocation root) { > rootAdded(root); >@@ -316,6 +320,7 @@ > public void shutdown() throws TeamException { > saveState(); > saveCommentHistory(); >+ savePermanentComments(); > } > > private void loadState() { >@@ -372,6 +377,23 @@ > CVSUIPlugin.log(e); > } > } >+ private void loadPermanentComments() { >+ IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(PERMANENT_COMMENTS_FILE); >+ File file = pluginStateLocation.toFile(); >+ if (!file.exists()) return; >+ try { >+ BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); >+ try { >+ readPermanentComments(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 +452,17 @@ > throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$ > } > } >+ private void readPermanentComments(InputStream stream) throws IOException, TeamException { >+ try { >+ SAXParserFactory factory = SAXParserFactory.newInstance(); >+ SAXParser parser = factory.newSAXParser(); >+ parser.parse(new InputSource(stream), new PermanentCommentsContentHandler()); >+ } catch (SAXException ex) { >+ throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { PERMANENT_COMMENTS_FILE }), ex); //$NON-NLS-1$ >+ } catch (ParserConfigurationException ex) { >+ throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { PERMANENT_COMMENTS_FILE }), ex); //$NON-NLS-1$ >+ } >+ } > > private void readOldState(DataInputStream dis) throws IOException, TeamException { > int repoSize = dis.readInt(); >@@ -512,12 +545,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 savePermanentComments() throws TeamException { >+ IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); >+ File tempFile = pluginStateLocation.append(PERMANENT_COMMENTS_FILE + ".tmp").toFile(); //$NON-NLS-1$ >+ File histFile = pluginStateLocation.append(PERMANENT_COMMENTS_FILE).toFile(); >+ try { >+ XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile))); >+ try { >+ writePermanentComments(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 writePermanentComments(XMLWriter writer) { >+ writer.startTag(ELEMENT_PERMANENT_COMMENTS, null, false); >+ for (int i=0; i<permanentComments.length; i++) >+ writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, permanentComments[i]); >+ writer.endTag(ELEMENT_PERMANENT_COMMENTS); >+ } > > public void addRepositoryListener(IRepositoryListener listener) { > listeners.add(listener); >@@ -778,21 +839,71 @@ > return previousComments; > } > >+ /** >+ * Get list of permanent comments. >+ */ >+ public String[] getPermanentComments() { >+ return permanentComments; >+ } >+ > /** > * 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 permanent) { >+ if (permanent) { >+ addPermanentComment(comment); >+ } else { >+ addComment(comment); >+ } >+ } >+ >+ private void addPermanentComment(String comment) { >+ // Only add the comment if its not there already >+ if (containsPermanentComment(comment)) >+ return; >+ >+ // remove from list of regular comments if there >+ if (containsComment(comment)) { >+ List newComments = new ArrayList(); >+ for (int i = 0; i < previousComments.length; i++) { >+ if (!previousComments[i].equals(comment)) >+ newComments.add(previousComments[i]); >+ } >+ previousComments = (String[]) newComments.toArray(new String[0]); >+ } >+ >+ // Insert the comment as first element >+ String[] newComments = new String[permanentComments.length + 1]; >+ System.arraycopy(permanentComments, 0, newComments, 1, permanentComments.length); >+ newComments[0] = comment; >+ permanentComments = newComments; >+ } >+ >+ private void addComment(String comment) { >+ // Only add the comment if its not there already >+ if (containsComment(comment)) >+ return; >+ >+ // remove from list of permanent comments if there >+ if (containsPermanentComment(comment)) { >+ List newComments = new ArrayList(); >+ for (int i = 0; i < permanentComments.length; i++) { >+ if (!permanentComments[i].equals(comment)) >+ newComments.add(permanentComments[i]); >+ } >+ permanentComments = (String[]) newComments.toArray(new String[0]); >+ } >+ >+ // 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) { > for (int i = 0; i < previousComments.length; i++) { >@@ -802,4 +913,13 @@ > } > return false; > } >+ >+ private boolean containsPermanentComment(String comment) { >+ for (int i = 0; i < permanentComments.length; i++) { >+ if (permanentComments[i].equals(comment)) { >+ return true; >+ } >+ } >+ return false; >+ } > }
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