|
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 PERMANENT_COMMENTS_FILE = "permanentComments.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_PERMANENT_COMMENTS = "PermanentCommitComments"; //$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 |
static String[] permanentComments = new String[0]; |
| 59 |
|
62 |
|
| 60 |
public static boolean notifyRepoView = true; |
63 |
public static boolean notifyRepoView = true; |
| 61 |
|
64 |
|
|
Lines 303-308
Link Here
|
| 303 |
public void startup() { |
306 |
public void startup() { |
| 304 |
loadState(); |
307 |
loadState(); |
| 305 |
loadCommentHistory(); |
308 |
loadCommentHistory(); |
|
|
309 |
loadPermanentComments(); |
| 306 |
CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() { |
310 |
CVSProviderPlugin.getPlugin().addRepositoryListener(new ICVSListener() { |
| 307 |
public void repositoryAdded(ICVSRepositoryLocation root) { |
311 |
public void repositoryAdded(ICVSRepositoryLocation root) { |
| 308 |
rootAdded(root); |
312 |
rootAdded(root); |
|
Lines 316-321
Link Here
|
| 316 |
public void shutdown() throws TeamException { |
320 |
public void shutdown() throws TeamException { |
| 317 |
saveState(); |
321 |
saveState(); |
| 318 |
saveCommentHistory(); |
322 |
saveCommentHistory(); |
|
|
323 |
savePermanentComments(); |
| 319 |
} |
324 |
} |
| 320 |
|
325 |
|
| 321 |
private void loadState() { |
326 |
private void loadState() { |
|
Lines 372-377
Link Here
|
| 372 |
CVSUIPlugin.log(e); |
377 |
CVSUIPlugin.log(e); |
| 373 |
} |
378 |
} |
| 374 |
} |
379 |
} |
|
|
380 |
private void loadPermanentComments() { |
| 381 |
IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation().append(PERMANENT_COMMENTS_FILE); |
| 382 |
File file = pluginStateLocation.toFile(); |
| 383 |
if (!file.exists()) return; |
| 384 |
try { |
| 385 |
BufferedInputStream is = new BufferedInputStream(new FileInputStream(file)); |
| 386 |
try { |
| 387 |
readPermanentComments(is); |
| 388 |
} finally { |
| 389 |
is.close(); |
| 390 |
} |
| 391 |
} catch (IOException e) { |
| 392 |
CVSUIPlugin.log(Status.ERROR, CVSUIMessages.RepositoryManager_ioException, e); //$NON-NLS-1$ |
| 393 |
} catch (TeamException e) { |
| 394 |
CVSUIPlugin.log(e); |
| 395 |
} |
| 396 |
} |
| 375 |
|
397 |
|
| 376 |
protected void saveState() throws TeamException { |
398 |
protected void saveState() throws TeamException { |
| 377 |
IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); |
399 |
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$ |
452 |
throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { COMMENT_HIST_FILE }), ex); //$NON-NLS-1$ |
| 431 |
} |
453 |
} |
| 432 |
} |
454 |
} |
|
|
455 |
private void readPermanentComments(InputStream stream) throws IOException, TeamException { |
| 456 |
try { |
| 457 |
SAXParserFactory factory = SAXParserFactory.newInstance(); |
| 458 |
SAXParser parser = factory.newSAXParser(); |
| 459 |
parser.parse(new InputSource(stream), new PermanentCommentsContentHandler()); |
| 460 |
} catch (SAXException ex) { |
| 461 |
throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { PERMANENT_COMMENTS_FILE }), ex); //$NON-NLS-1$ |
| 462 |
} catch (ParserConfigurationException ex) { |
| 463 |
throw new CVSException(NLS.bind(CVSUIMessages.RepositoryManager_parsingProblem, new String[] { PERMANENT_COMMENTS_FILE }), ex); //$NON-NLS-1$ |
| 464 |
} |
| 465 |
} |
| 433 |
|
466 |
|
| 434 |
private void readOldState(DataInputStream dis) throws IOException, TeamException { |
467 |
private void readOldState(DataInputStream dis) throws IOException, TeamException { |
| 435 |
int repoSize = dis.readInt(); |
468 |
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$ |
545 |
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 |
} |
546 |
} |
| 514 |
} |
547 |
} |
|
|
548 |
protected void savePermanentComments() throws TeamException { |
| 549 |
IPath pluginStateLocation = CVSUIPlugin.getPlugin().getStateLocation(); |
| 550 |
File tempFile = pluginStateLocation.append(PERMANENT_COMMENTS_FILE + ".tmp").toFile(); //$NON-NLS-1$ |
| 551 |
File histFile = pluginStateLocation.append(PERMANENT_COMMENTS_FILE).toFile(); |
| 552 |
try { |
| 553 |
XMLWriter writer = new XMLWriter(new BufferedOutputStream(new FileOutputStream(tempFile))); |
| 554 |
try { |
| 555 |
writePermanentComments(writer); |
| 556 |
} finally { |
| 557 |
writer.close(); |
| 558 |
} |
| 559 |
if (histFile.exists()) { |
| 560 |
histFile.delete(); |
| 561 |
} |
| 562 |
boolean renamed = tempFile.renameTo(histFile); |
| 563 |
if (!renamed) { |
| 564 |
throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_rename, new String[] { tempFile.getAbsolutePath() }), null)); //$NON-NLS-1$ |
| 565 |
} |
| 566 |
} catch (IOException e) { |
| 567 |
throw new TeamException(new Status(Status.ERROR, CVSUIPlugin.ID, TeamException.UNABLE, NLS.bind(CVSUIMessages.RepositoryManager_save, new String[] { histFile.getAbsolutePath() }), e)); //$NON-NLS-1$ |
| 568 |
} |
| 569 |
} |
| 515 |
private void writeCommentHistory(XMLWriter writer) { |
570 |
private void writeCommentHistory(XMLWriter writer) { |
| 516 |
writer.startTag(ELEMENT_COMMIT_HISTORY, null, false); |
571 |
writer.startTag(ELEMENT_COMMIT_HISTORY, null, false); |
| 517 |
for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++) |
572 |
for (int i=0; i<previousComments.length && i<MAX_COMMENTS; i++) |
| 518 |
writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]); |
573 |
writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, previousComments[i]); |
| 519 |
writer.endTag(ELEMENT_COMMIT_HISTORY); |
574 |
writer.endTag(ELEMENT_COMMIT_HISTORY); |
| 520 |
} |
575 |
} |
|
|
576 |
private void writePermanentComments(XMLWriter writer) { |
| 577 |
writer.startTag(ELEMENT_PERMANENT_COMMENTS, null, false); |
| 578 |
for (int i=0; i<permanentComments.length; i++) |
| 579 |
writer.printSimpleTag(ELEMENT_COMMIT_COMMENT, permanentComments[i]); |
| 580 |
writer.endTag(ELEMENT_PERMANENT_COMMENTS); |
| 581 |
} |
| 521 |
|
582 |
|
| 522 |
public void addRepositoryListener(IRepositoryListener listener) { |
583 |
public void addRepositoryListener(IRepositoryListener listener) { |
| 523 |
listeners.add(listener); |
584 |
listeners.add(listener); |
|
Lines 778-798
Link Here
|
| 778 |
return previousComments; |
839 |
return previousComments; |
| 779 |
} |
840 |
} |
| 780 |
|
841 |
|
|
|
842 |
/** |
| 843 |
* Get list of permanent comments. |
| 844 |
*/ |
| 845 |
public String[] getPermanentComments() { |
| 846 |
return permanentComments; |
| 847 |
} |
| 848 |
|
| 781 |
/** |
849 |
/** |
| 782 |
* Method addComment. |
850 |
* Method addComment. |
| 783 |
* @param string |
851 |
* @param string |
| 784 |
*/ |
852 |
*/ |
| 785 |
public void addComment(String comment) { |
853 |
public void addComment(String comment, boolean permanent) { |
| 786 |
// Only add the comment if its not there already |
854 |
if (permanent) { |
| 787 |
if (containsComment(comment)) return; |
855 |
addPermanentComment(comment); |
| 788 |
// Insert the comment as the first element |
856 |
} else { |
| 789 |
String[] newComments = new String[Math.min(previousComments.length + 1, MAX_COMMENTS)]; |
857 |
addComment(comment); |
| 790 |
newComments[0] = comment; |
858 |
} |
| 791 |
for (int i = 1; i < newComments.length; i++) { |
859 |
} |
| 792 |
newComments[i] = previousComments[i-1]; |
860 |
|
| 793 |
} |
861 |
private void addPermanentComment(String comment) { |
| 794 |
previousComments = newComments; |
862 |
// Only add the comment if its not there already |
| 795 |
} |
863 |
if (containsPermanentComment(comment)) |
|
|
864 |
return; |
| 865 |
|
| 866 |
// remove from list of regular comments if there |
| 867 |
if (containsComment(comment)) { |
| 868 |
List newComments = new ArrayList(); |
| 869 |
for (int i = 0; i < previousComments.length; i++) { |
| 870 |
if (!previousComments[i].equals(comment)) |
| 871 |
newComments.add(previousComments[i]); |
| 872 |
} |
| 873 |
previousComments = (String[]) newComments.toArray(new String[0]); |
| 874 |
} |
| 875 |
|
| 876 |
// Insert the comment as first element |
| 877 |
String[] newComments = new String[permanentComments.length + 1]; |
| 878 |
System.arraycopy(permanentComments, 0, newComments, 1, permanentComments.length); |
| 879 |
newComments[0] = comment; |
| 880 |
permanentComments = newComments; |
| 881 |
} |
| 882 |
|
| 883 |
private void addComment(String comment) { |
| 884 |
// Only add the comment if its not there already |
| 885 |
if (containsComment(comment)) |
| 886 |
return; |
| 887 |
|
| 888 |
// remove from list of permanent comments if there |
| 889 |
if (containsPermanentComment(comment)) { |
| 890 |
List newComments = new ArrayList(); |
| 891 |
for (int i = 0; i < permanentComments.length; i++) { |
| 892 |
if (!permanentComments[i].equals(comment)) |
| 893 |
newComments.add(permanentComments[i]); |
| 894 |
} |
| 895 |
permanentComments = (String[]) newComments.toArray(new String[0]); |
| 896 |
} |
| 897 |
|
| 898 |
// Insert the comment as the first element |
| 899 |
String[] newComments = new String[Math.min( |
| 900 |
previousComments.length + 1, MAX_COMMENTS)]; |
| 901 |
newComments[0] = comment; |
| 902 |
for (int i = 1; i < newComments.length; i++) { |
| 903 |
newComments[i] = previousComments[i - 1]; |
| 904 |
} |
| 905 |
previousComments = newComments; |
| 906 |
} |
| 796 |
|
907 |
|
| 797 |
private boolean containsComment(String comment) { |
908 |
private boolean containsComment(String comment) { |
| 798 |
for (int i = 0; i < previousComments.length; i++) { |
909 |
for (int i = 0; i < previousComments.length; i++) { |
|
Lines 802-805
Link Here
|
| 802 |
} |
913 |
} |
| 803 |
return false; |
914 |
return false; |
| 804 |
} |
915 |
} |
|
|
916 |
|
| 917 |
private boolean containsPermanentComment(String comment) { |
| 918 |
for (int i = 0; i < permanentComments.length; i++) { |
| 919 |
if (permanentComments[i].equals(comment)) { |
| 920 |
return true; |
| 921 |
} |
| 922 |
} |
| 923 |
return false; |
| 924 |
} |
| 805 |
} |
925 |
} |