Changeset 821:b14dbd44fad1
- Timestamp:
- 08/09/08 16:01:06 (4 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/com/vectrace/MercurialEclipse/dialogs/CommitDialog.java
r767 r821 19 19 import org.eclipse.compare.ResourceNode; 20 20 import org.eclipse.core.resources.IResource; 21 import org.eclipse.core.runtime.Platform; 22 import org.eclipse.core.runtime.content.IContentType; 23 import org.eclipse.core.runtime.content.IContentTypeManager; 21 24 import org.eclipse.jface.dialogs.TrayDialog; 25 import org.eclipse.jface.text.Document; 26 import org.eclipse.jface.text.IDocument; 27 import org.eclipse.jface.text.ITextListener; 28 import org.eclipse.jface.text.TextEvent; 29 import org.eclipse.jface.text.source.AnnotationModel; 30 import org.eclipse.jface.text.source.ISourceViewer; 31 import org.eclipse.jface.text.source.SourceViewer; 22 32 import org.eclipse.jface.viewers.ArrayContentProvider; 23 33 import org.eclipse.jface.viewers.CheckboxTableViewer; … … 45 55 import org.eclipse.swt.widgets.Table; 46 56 import org.eclipse.swt.widgets.TableColumn; 47 import org.eclipse.swt.widgets.Text; 57 import org.eclipse.ui.PlatformUI; 58 import org.eclipse.ui.editors.text.EditorsUI; 59 import org.eclipse.ui.texteditor.AnnotationPreference; 60 import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; 61 import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; 62 import org.eclipse.ui.texteditor.spelling.SpellingAnnotation; 63 import org.eclipse.ui.texteditor.spelling.SpellingContext; 64 import org.eclipse.ui.texteditor.spelling.SpellingService; 48 65 49 66 import com.vectrace.MercurialEclipse.TableColumnSorter; … … 51 68 import com.vectrace.MercurialEclipse.model.HgRoot; 52 69 import com.vectrace.MercurialEclipse.team.IStorageMercurialRevision; 70 import com.vectrace.MercurialEclipse.ui.TextSpellingProblemCollector; 53 71 import com.vectrace.MercurialEclipse.utils.CompareUtils; 54 72 … … 86 104 private String defaultCommitMessage = "(no commit message)"; 87 105 88 private TextcommitTextBox;106 private ISourceViewer commitTextBox; 89 107 private Label commitTextLabel; 90 108 private Label commitFilesLabel; … … 104 122 private File[] filesToRemove; 105 123 private List<IResource> resourcesToRemove; 124 private IDocument commitTextDocument; 125 private SourceViewerDecorationSupport decorationSupport; 106 126 107 127 /** … … 110 130 public CommitDialog(Shell shell, HgRoot root, IResource[] inResources) { 111 131 super(shell); 112 setShellStyle(getShellStyle() | SWT.RESIZE | SWT.TITLE); 132 setShellStyle(getShellStyle() | SWT.RESIZE | SWT.TITLE); 113 133 this.root = root; 114 134 this.inResources = inResources; … … 116 136 this.committableFilesFilter = new CommittableFilesFilter(); 117 137 this.selectableFiles = true; 138 this.commitTextDocument = new Document(); 118 139 } 119 140 … … 152 173 commitTextLabel = new Label(container, SWT.NONE); 153 174 commitTextLabel.setText("Commit comments"); 175 176 // commitTextBox = new Text(container, SWT.V_SCROLL | SWT.MULTI 177 // | SWT.BORDER | SWT.WRAP); 178 179 commitTextBox = new SourceViewer(container, null, SWT.V_SCROLL 180 | SWT.MULTI | SWT.BORDER | SWT.WRAP); 181 commitTextBox.setEditable(true); 182 183 // set up spell-check annotations 154 184 155 commitTextBox = new Text(container, SWT.V_SCROLL | SWT.MULTI 156 | SWT.BORDER | SWT.WRAP); 185 AnnotationModel annotationModel = new AnnotationModel(); 186 commitTextBox.setDocument(commitTextDocument, annotationModel); 187 188 decorationSupport = new SourceViewerDecorationSupport(commitTextBox, 189 null, new DefaultMarkerAnnotationAccess(), EditorsUI 190 .getSharedTextColors()); 191 192 AnnotationPreference pref = new AnnotationPreference(); 193 pref.setAnnotationType(SpellingAnnotation.TYPE); 194 pref.setColorPreferenceKey("spellingIndicationColor"); 195 pref.setHighlightPreferenceKey("spellingIndicationHighlighting"); 196 pref.setTextPreferenceKey("spellingIndication"); 197 198 decorationSupport.setAnnotationPreference(pref); 199 decorationSupport.install(EditorsUI.getPreferenceStore()); 200 201 ITextListener textListener = new ITextListener() { 202 203 private SpellingService spellService; 204 private SpellingContext spellContext; 205 private TextSpellingProblemCollector collector; 206 207 public void textChanged(TextEvent event) { 208 // reset foreground color 209 commitTextBox.setTextColor(PlatformUI.getWorkbench() 210 .getDisplay().getSystemColor( 211 SWT.COLOR_WIDGET_FOREGROUND), 0, 212 commitTextDocument.getLength(), false); 213 214 // connect to spell service if necessary 215 if (spellService == null) { 216 spellService = EditorsUI.getSpellingService(); 217 } 218 219 if (spellContext == null) { 220 spellContext = new SpellingContext(); 221 IContentType contentType = Platform.getContentTypeManager() 222 .getContentType(IContentTypeManager.CT_TEXT); 223 spellContext.setContentType(contentType); 224 } 225 226 if (collector == null) { 227 collector = new TextSpellingProblemCollector(commitTextBox); 228 } 229 230 // check and highlight errors 231 spellService.check(commitTextDocument, spellContext, collector, 232 null); 233 } 234 }; 235 commitTextBox.addTextListener(textListener); 157 236 158 237 commitFilesLabel = new Label(container, SWT.NONE); … … 161 240 commitFilesList = createFilesList(container, selectableFiles); 162 241 163 164 165 242 final FormData fd_commitTextLabel = new FormData(); 166 243 fd_commitTextLabel.top = new FormAttachment(0, 20); … … 170 247 171 248 final FormData fd_commitTextBox = new FormData(); 172 fd_commitTextBox.top = new FormAttachment(commitTextLabel, 3, SWT.BOTTOM); 249 fd_commitTextBox.top = new FormAttachment(commitTextLabel, 3, 250 SWT.BOTTOM); 173 251 fd_commitTextBox.left = new FormAttachment(0, 9); 174 252 fd_commitTextBox.bottom = new FormAttachment(0, 200); 175 253 fd_commitTextBox.right = new FormAttachment(100, -9); 176 commitTextBox. setLayoutData(fd_commitTextBox);254 commitTextBox.getTextWidget().setLayoutData(fd_commitTextBox); 177 255 178 256 final FormData fd_commitFilesLabel = new FormData(); 179 fd_commitFilesLabel.top = new FormAttachment(commitTextBox, 3); 257 fd_commitFilesLabel.top = new FormAttachment(commitTextBox 258 .getTextWidget(), 3); 180 259 fd_commitFilesLabel.left = new FormAttachment(0, 9); 181 260 fd_commitFilesLabel.right = new FormAttachment(100, -9); 182 261 commitFilesLabel.setLayoutData(fd_commitFilesLabel); 183 262 184 185 263 Table table = commitFilesList.getTable(); 186 264 final FormData fd_table = new FormData(); … … 195 273 selectAllButton = new Button(container, SWT.CHECK); 196 274 selectAllButton.setText("Select/unselect all"); 197 275 198 276 showUntrackedFilesButton = new Button(container, SWT.CHECK); 199 277 showUntrackedFilesButton.setText("Show added/removed files"); … … 202 280 203 281 final FormData fd_selectAllButton = new FormData(); 204 fd_selectAllButton.bottom = new FormAttachment(showUntrackedFilesButton); 282 fd_selectAllButton.bottom = new FormAttachment( 283 showUntrackedFilesButton); 205 284 fd_selectAllButton.left = new FormAttachment(0, 9); 206 285 fd_selectAllButton.right = new FormAttachment(100, -9); … … 218 297 219 298 private void makeActions() { 220 commitTextBox.setCapture(true);299 // commitTextBox.setCapture(true); 221 300 commitFilesList.addDoubleClickListener(new IDoubleClickListener() { 222 301 public void doubleClick(DoubleClickEvent event) { … … 236 315 .getResource())); 237 316 238 CompareUtils.openCompareDialog(leftNode, rightNode, false); 317 CompareUtils.openCompareDialog(leftNode, rightNode, false); 239 318 } 240 319 } … … 291 370 292 371 private void setupDefaultCommitMessage() { 293 commitText Box.setText(defaultCommitMessage);294 commitTextBox.setSelect ion(0, defaultCommitMessage.length());372 commitTextDocument.set(defaultCommitMessage); 373 commitTextBox.setSelectedRange(0, defaultCommitMessage.length()); 295 374 } 296 375 … … 341 420 List<CommitResource> tracked = new ArrayList<CommitResource>(); 342 421 for (CommitResource commitResource : commitResources) { 343 if ( commitResource.getStatus() != CommitDialog.FILE_UNTRACKED) {422 if (commitResource.getStatus() != CommitDialog.FILE_UNTRACKED) { 344 423 tracked.add(commitResource); 345 424 } … … 398 477 return list.toArray(new File[0]); 399 478 } 400 479 401 480 private File[] getToRemoveList(Object[] objs) { 402 481 ArrayList<File> list = new ArrayList<File>(); … … 432 511 return list; 433 512 } 434 513 435 514 private List<IResource> getToRemoveResourceList(Object[] objs) { 436 515 ArrayList<IResource> list = new ArrayList<IResource>(); … … 459 538 resourcesToAdd = getToAddResourceList(commitFilesList 460 539 .getCheckedElements()); 461 540 462 541 filesToCommit = convertToFiles(commitFilesList.getCheckedElements()); 463 542 resourcesToCommit = convertToResource(commitFilesList … … 465 544 466 545 filesToRemove = getToRemoveList(commitFilesList.getCheckedElements()); 467 resourcesToRemove = getToRemoveResourceList(commitFilesList.getCheckedElements()); 468 commitMessage = commitTextBox.getText(); 546 resourcesToRemove = getToRemoveResourceList(commitFilesList 547 .getCheckedElements()); 548 commitMessage = commitTextDocument.get(); 469 549 470 550 super.okPressed();