|
Lines 7-12
Link Here
|
| 7 |
* |
7 |
* |
| 8 |
* Contributors: |
8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
9 |
* IBM Corporation - initial API and implementation |
|
|
10 |
* Maik Schreiber - bug 102461 |
| 10 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
| 11 |
package org.eclipse.team.internal.ccvs.ui.repo; |
12 |
package org.eclipse.team.internal.ccvs.ui.repo; |
| 12 |
|
13 |
|
|
Lines 47-54
Link Here
|
| 47 |
// new state file |
48 |
// new state file |
| 48 |
private static final String REPOSITORIES_VIEW_FILE = "repositoriesView.xml"; //$NON-NLS-1$ |
49 |
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$ |
50 |
private static final String COMMENT_HIST_FILE = "commitCommentHistory.xml"; //$NON-NLS-1$ |
|
|
51 |
private static final String COMMENT_TEMPLATES_FILE = "commentTemplates.xml"; //$NON-NLS-1$ |
| 50 |
static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$ |
52 |
static final String ELEMENT_COMMIT_COMMENT = "CommitComment"; //$NON-NLS-1$ |
| 51 |
static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$ |
53 |
static final String ELEMENT_COMMIT_HISTORY = "CommitComments"; //$NON-NLS-1$ |
|
|
54 |
static final String ELEMENT_COMMENT_TEMPLATES = "CommitCommentTemplates"; //$NON-NLS-1$ |
| 52 |
|
55 |
|
| 53 |
private Map repositoryRoots = new HashMap(); |
56 |
private Map repositoryRoots = new HashMap(); |
| 54 |
|
57 |
|
|
Lines 56-61
Link Here
|
| 56 |
|
59 |
|
| 57 |
// The previously remembered comment |
60 |
// The previously remembered comment |
| 58 |
static String[] previousComments = new String[0]; |
61 |
static String[] previousComments = new String[0]; |
|
|
62 |
static String[] commentTemplates = 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 |
loadCommentTemplates(); |
| 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 |
saveCommentTemplates(); |
| 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 loadCommentTemplates() { |
| 382 |
IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(COMMENT_TEMPLATES_FILE); |
| 383 |
File file = pluginStateLocation.toFile(); |
| 384 |
if (!file.exists()) return; |
| 385 |
try { |
| 386 |
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); |
| 387 |
try { |
| 388 |
readCommentTemplates(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 readCommentTemplates(InputStream stream) throws IOException, TeamException { |
| 457 |
try { |
| 458 |
SAXParserFactory factory = SAXParserFactory.newInstance(); |
| 459 |
SAXParser parser = factory.newSAXParser(); |
| 460 |
parser.parse(new InputSource(stream), new CommentTemplatesContentHandler()); |
| 461 |
} catch (SAXException ex) { |
| 462 |
throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_TEMPLATES_FILE }), ex); //$NON-NLS-1$ |
| 463 |
} catch (ParserConfigurationException ex) { |
| 464 |
throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_TEMPLATES_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 saveCommentTemplates() throws TeamException { |
| 550 |
IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); |
| 551 |
File tempFile = pluginStateLocation.append(COMMENT_TEMPLATES_FILE + ".tmp").toFile(); //$NON-NLS-1$ |
| 552 |
File histFile = pluginStateLocation.append(COMMENT_TEMPLATES_FILE).toFile(); |
| 553 |
try { |
| 554 |
XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile))); |
| 555 |
try { |
| 556 |
writeCommentTemplates(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 writeCommentTemplates(XMLWriter writer) { |
| 578 |
writer.startTag(ELEMENT_COMMENT_TEMPLATES, null, false); |
| 579 |
for (int i=0; i<commentTemplates.length; i++) |
| 580 |
writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, commentTemplates[i]); |
| 581 |
writer.endTag(ELEMENT_COMMENT_TEMPLATES); |
| 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-798
Link Here
|
| 778 |
return previousComments; |
840 |
return previousComments; |
| 779 |
} |
841 |
} |
| 780 |
|
842 |
|
|
|
843 |
/** |
| 844 |
* Get list of comment templates. |
| 845 |
*/ |
| 846 |
public String[] getCommentTemplates() { |
| 847 |
return commentTemplates; |
| 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 template) { |
| 786 |
// Only add the comment if its not there already |
855 |
if (template) { |
| 787 |
if (containsComment(comment)) return; |
856 |
addCommentTemplate(comment); |
| 788 |
// Insert the comment as the first element |
857 |
} else { |
| 789 |
String[] newComments = new String[Math.min(previousComments.length + 1, MAX_COMMENTS)]; |
858 |
addComment(comment); |
| 790 |
newComments[0] = comment; |
859 |
} |
| 791 |
for (int i = 1; i < newComments.length; i++) { |
860 |
} |
| 792 |
newComments[i] = previousComments[i-1]; |
861 |
|
| 793 |
} |
862 |
private void addCommentTemplate(String comment) { |
| 794 |
previousComments = newComments; |
863 |
// Only add the comment if its not there already |
| 795 |
} |
864 |
if (containsCommentTemplate(comment)) |
|
|
865 |
return; |
| 866 |
|
| 867 |
// remove from list of regular comments if there |
| 868 |
if (containsComment(comment)) { |
| 869 |
List newComments = new ArrayList(); |
| 870 |
for (int i = 0; i < previousComments.length; i++) { |
| 871 |
if (!previousComments[i].equals(comment)) |
| 872 |
newComments.add(previousComments[i]); |
| 873 |
} |
| 874 |
previousComments = (String[]) newComments.toArray(new String[0]); |
| 875 |
} |
| 876 |
|
| 877 |
// Insert the comment as first element |
| 878 |
String[] newComments = new String[commentTemplates.length + 1]; |
| 879 |
System.arraycopy(commentTemplates, 0, newComments, 1, commentTemplates.length); |
| 880 |
newComments[0] = comment; |
| 881 |
commentTemplates = newComments; |
| 882 |
} |
| 883 |
|
| 884 |
private void addComment(String comment) { |
| 885 |
// Only add the comment if its not there already |
| 886 |
if (containsComment(comment)) |
| 887 |
return; |
| 888 |
|
| 889 |
// remove from list of comment templates if there |
| 890 |
if (containsCommentTemplate(comment)) { |
| 891 |
List newComments = new ArrayList(); |
| 892 |
for (int i = 0; i < commentTemplates.length; i++) { |
| 893 |
if (!commentTemplates[i].equals(comment)) |
| 894 |
newComments.add(commentTemplates[i]); |
| 895 |
} |
| 896 |
commentTemplates = (String[]) newComments.toArray(new String[0]); |
| 897 |
} |
| 898 |
|
| 899 |
// Insert the comment as the first element |
| 900 |
String[] newComments = new String[Math.min( |
| 901 |
previousComments.length + 1, MAX_COMMENTS)]; |
| 902 |
newComments[0] = comment; |
| 903 |
for (int i = 1; i < newComments.length; i++) { |
| 904 |
newComments[i] = previousComments[i - 1]; |
| 905 |
} |
| 906 |
previousComments = newComments; |
| 907 |
} |
| 796 |
|
908 |
|
| 797 |
private boolean containsComment(String comment) { |
909 |
private boolean containsComment(String comment) { |
| 798 |
for (int i = 0; i < previousComments.length; i++) { |
910 |
for (int i = 0; i < previousComments.length; i++) { |
|
Lines 802-805
Link Here
|
| 802 |
} |
914 |
} |
| 803 |
return false; |
915 |
return false; |
| 804 |
} |
916 |
} |
|
|
917 |
|
| 918 |
private boolean containsCommentTemplate(String comment) { |
| 919 |
for (int i = 0; i < commentTemplates.length; i++) { |
| 920 |
if (commentTemplates[i].equals(comment)) { |
| 921 |
return true; |
| 922 |
} |
| 923 |
} |
| 924 |
return false; |
| 925 |
} |
| 926 |
|
| 927 |
public void replaceAndSaveCommentTemplates(String[] templates) throws TeamException { |
| 928 |
commentTemplates = templates; |
| 929 |
saveCommentTemplates(); |
| 930 |
} |
| 805 |
} |
931 |
} |