|
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 |
} |