|
1 | 1 | // Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. |
2 | | -package com.intellij.tasks.impl; |
3 | | - |
4 | | -import com.intellij.openapi.application.ApplicationManager; |
5 | | -import com.intellij.openapi.project.DumbAware; |
6 | | -import com.intellij.openapi.project.Project; |
7 | | -import com.intellij.openapi.vcs.CheckinProjectPanel; |
8 | | -import com.intellij.openapi.vcs.changes.CommitContext; |
9 | | -import com.intellij.openapi.vcs.checkin.CheckinHandler; |
10 | | -import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory; |
11 | | -import com.intellij.tasks.LocalTask; |
12 | | -import com.intellij.tasks.Task; |
13 | | -import com.intellij.tasks.TaskManager; |
14 | | -import com.intellij.tasks.TaskRepository; |
15 | | -import com.intellij.tasks.context.WorkingContextManager; |
16 | | -import org.jetbrains.annotations.NotNull; |
17 | | -import org.jetbrains.annotations.Nullable; |
18 | | - |
19 | | -import java.util.Date; |
20 | | - |
21 | | -public class TaskCheckinHandlerFactory extends CheckinHandlerFactory { |
22 | | - |
23 | | - @Override |
24 | | - public @NotNull CheckinHandler createHandler(final @NotNull CheckinProjectPanel panel, final @NotNull CommitContext commitContext) { |
25 | | - return new TaskCheckinHandler(panel); |
26 | | - } |
27 | | - |
28 | | - private static class TaskCheckinHandler extends CheckinHandler implements DumbAware { |
29 | | - final @NotNull CheckinProjectPanel panel; |
30 | | - |
31 | | - private TaskCheckinHandler(@NotNull CheckinProjectPanel panel) { |
32 | | - this.panel = panel; |
33 | | - } |
34 | | - |
35 | | - @Override |
36 | | - public void checkinSuccessful() { |
37 | | - final String message = panel.getCommitMessage(); |
38 | | - final Project project = panel.getProject(); |
39 | | - final TaskManagerImpl manager = (TaskManagerImpl)TaskManager.getManager(project); |
| 2 | +package com.intellij.tasks.impl |
| 3 | + |
| 4 | +import com.intellij.openapi.application.ApplicationManager |
| 5 | +import com.intellij.openapi.project.DumbAware |
| 6 | +import com.intellij.openapi.vcs.CheckinProjectPanel |
| 7 | +import com.intellij.openapi.vcs.changes.CommitContext |
| 8 | +import com.intellij.openapi.vcs.checkin.CheckinHandler |
| 9 | +import com.intellij.openapi.vcs.checkin.CheckinHandlerFactory |
| 10 | +import com.intellij.tasks.Task |
| 11 | +import com.intellij.tasks.TaskManager |
| 12 | +import com.intellij.tasks.context.WorkingContextManager |
| 13 | +import java.util.* |
| 14 | + |
| 15 | +class TaskCheckinHandlerFactory : CheckinHandlerFactory() { |
| 16 | + override fun createHandler(panel: CheckinProjectPanel, commitContext: CommitContext): CheckinHandler = |
| 17 | + TaskCheckinHandler(panel) |
| 18 | + |
| 19 | + private class TaskCheckinHandler(val panel: CheckinProjectPanel) : CheckinHandler(), DumbAware { |
| 20 | + override fun checkinSuccessful() { |
| 21 | + val message = panel.getCommitMessage() |
| 22 | + val project = panel.getProject() |
| 23 | + val manager = TaskManager.getManager(project) as TaskManagerImpl |
40 | 24 | if (manager.getState().saveContextOnCommit) { |
41 | | - Task task = findTaskInRepositories(message, manager); |
42 | | - if (task == null) { |
43 | | - task = manager.createLocalTask(message); |
44 | | - ((LocalTaskImpl)task).setClosed(true); |
45 | | - } |
46 | | - LocalTask localTask = manager.addTask(task); |
47 | | - localTask.setUpdated(new Date()); |
48 | | - |
49 | | - ApplicationManager.getApplication().invokeLater(() -> WorkingContextManager.getInstance(project).saveContext(localTask), project.getDisposed()); |
| 25 | + val task = findTaskInRepositories(message, manager) |
| 26 | + ?: manager.createLocalTask(message) |
| 27 | + .also { (it as LocalTaskImpl).isClosed = true } |
| 28 | + val localTask = manager.addTask(task) |
| 29 | + localTask.setUpdated(Date()) |
| 30 | + |
| 31 | + ApplicationManager.getApplication().invokeLater( |
| 32 | + { WorkingContextManager.getInstance(project).saveContext(localTask) }, project.getDisposed()) |
50 | 33 | } |
51 | 34 | } |
52 | 35 | } |
| 36 | +} |
53 | 37 |
|
54 | | - private static @Nullable Task findTaskInRepositories(String message, TaskManager manager) { |
55 | | - TaskRepository[] repositories = manager.getAllRepositories(); |
56 | | - for (TaskRepository repository : repositories) { |
57 | | - String id = repository.extractId(message); |
58 | | - if (id == null) continue; |
59 | | - LocalTask localTask = manager.findTask(id); |
60 | | - if (localTask != null) return localTask; |
61 | | - try { |
62 | | - Task task = repository.findTask(id); |
63 | | - if (task != null) { |
64 | | - return task; |
65 | | - } |
66 | | - } |
67 | | - catch (Exception ignore) { |
68 | | - |
69 | | - } |
| 38 | +private fun findTaskInRepositories(message: String, manager: TaskManager): Task? { |
| 39 | + val repositories = manager.getAllRepositories() |
| 40 | + for (repository in repositories) { |
| 41 | + val id = repository.extractId(message) ?: continue |
| 42 | + manager.findTask(id)?.let { return it } |
| 43 | + try { |
| 44 | + repository.findTask(id)?.let { return it } |
| 45 | + } |
| 46 | + catch (_: Exception) { |
70 | 47 | } |
71 | | - return null; |
72 | 48 | } |
| 49 | + return null |
73 | 50 | } |
0 commit comments