|
11 | 11 | import com.intellij.openapi.project.Project; |
12 | 12 | import com.intellij.openapi.ui.ComboBox; |
13 | 13 | import com.intellij.openapi.vfs.VirtualFile; |
| 14 | +import com.intellij.psi.PsiFile; |
| 15 | +import com.intellij.psi.search.EverythingGlobalScope; |
| 16 | +import com.intellij.psi.search.FilenameIndex; |
14 | 17 | import com.intellij.ui.EditorTextField; |
15 | 18 | import com.reveal.metrics.CKNumberReader; |
16 | 19 | import com.reveal.metrics.MaxCKNumber; |
17 | | -import com.reveal.metrics.Metrics; |
18 | 20 | import org.jetbrains.annotations.NotNull; |
19 | 21 | import org.jetbrains.annotations.Nullable; |
20 | 22 |
|
@@ -360,6 +362,8 @@ public void actionPerformed(ActionEvent e) |
360 | 362 | else |
361 | 363 | gitHelper.checkoutCommitID(commitList.get(TTMWindow.activeCommit_cIndex).getCommitID()); |
362 | 364 |
|
| 365 | + updateVirtualFileIfNeeded(); |
| 366 | + |
363 | 367 | checkoutProjectLatestCommitBtn.setText("*"+CHECKOUT_LATEST_PROJECT_COMMIT_BUTTON_TEXT); |
364 | 368 | CodeTimeMachineAction.getCodeTimeMachine(project).getToolWindow().hide(null); |
365 | 369 | } |
@@ -394,6 +398,29 @@ public void actionPerformed(ActionEvent e) |
394 | 398 | this.add(checkoutProjectLatestCommitBtn); // As there's no layout, we should set Bound it. we'll do this in "ComponentResized()" event |
395 | 399 | } |
396 | 400 |
|
| 401 | + void updateVirtualFileIfNeeded() |
| 402 | + { |
| 403 | + Document document = FileDocumentManager.getInstance().getDocument(virtualFile); |
| 404 | + // if after reverting project, package names or ... changes the virtualFile path get invalid. |
| 405 | + // So we search for the new path of file. |
| 406 | + // Since we assume filename has not changed, we use valid part of old virtualFile (the filename). |
| 407 | + if(document==null) |
| 408 | + { |
| 409 | + PsiFile[] filesByName = FilenameIndex.getFilesByName(project, virtualFile.getName(), new EverythingGlobalScope(project)); |
| 410 | + if(filesByName.length>0) |
| 411 | + { |
| 412 | + virtualFile = filesByName[0].getVirtualFile(); |
| 413 | + document = FileDocumentManager.getInstance().getDocument(virtualFile); |
| 414 | + |
| 415 | + if(document == null) |
| 416 | + { |
| 417 | + // It means that the filename has also changed. |
| 418 | + //#TODO: in such case, we can't renew virtualFile variable. |
| 419 | + } |
| 420 | + } |
| 421 | + } |
| 422 | + } |
| 423 | + |
397 | 424 | private void addMouseMotionListener() |
398 | 425 | { |
399 | 426 | this.addMouseMotionListener(new MouseMotionListener() |
|
0 commit comments