-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrated StartupActivities to the ProjectActivity
- Loading branch information
Showing
14 changed files
with
312 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
mojo/core/src/main/java/com/perl5/lang/mojolicious/model/MojoProjectManagerStarter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2015-2024 Alexandr Evstigneev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.perl5.lang.mojolicious.model | ||
|
||
import com.intellij.openapi.application.readAction | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.ProjectActivity | ||
|
||
private val log = Logger.getInstance(MojoProjectManagerStarter::class.java) | ||
|
||
class MojoProjectManagerStarter : ProjectActivity { | ||
override suspend fun execute(project: Project) { | ||
if (project.isDefault()) { | ||
return | ||
} | ||
readAction { | ||
if (!project.isDisposed()) { | ||
log.debug("Project is initialized") | ||
MojoProjectManager.getInstance(project).scheduleUpdate() | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 0 additions & 65 deletions
65
plugin/core/src/main/java/com/perl5/lang/perl/fileTypes/PerlFileTypeServiceWatcher.java
This file was deleted.
Oops, something went wrong.
44 changes: 44 additions & 0 deletions
44
plugin/core/src/main/java/com/perl5/lang/perl/fileTypes/PerlFileTypeServiceWatcher.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright 2015-2024 Alexandr Evstigneev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.perl5.lang.perl.fileTypes | ||
|
||
import com.intellij.openapi.module.Module | ||
import com.intellij.openapi.project.ModuleListener | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.roots.ModuleRootEvent | ||
import com.intellij.openapi.roots.ModuleRootListener | ||
import com.intellij.openapi.startup.ProjectActivity | ||
import com.intellij.util.Function | ||
import com.perl5.lang.perl.util.PerlPluginUtil | ||
|
||
class PerlFileTypeServiceWatcher : ProjectActivity, ModuleListener, ModuleRootListener { | ||
override suspend fun execute(project: Project) { | ||
project.messageBus.connect(PerlPluginUtil.getUnloadAwareDisposable(project)).let { | ||
it.subscribe(ModuleRootListener.TOPIC, this); | ||
it.subscribe(ModuleListener.TOPIC, this); | ||
} | ||
reset(); | ||
} | ||
|
||
override fun modulesAdded(project: Project, modules: List<Module?>) = reset() | ||
|
||
override fun modulesRenamed(project: Project, modules: List<Module?>, oldNameProvider: Function<in Module, String?>) = reset() | ||
|
||
override fun rootsChanged(event: ModuleRootEvent) = reset() | ||
|
||
private fun reset() = PerlFileTypeService.getInstance().reset() | ||
} |
86 changes: 0 additions & 86 deletions
86
plugin/core/src/main/java/com/perl5/lang/perl/idea/project/Perl5ProjectStartupActivity.java
This file was deleted.
Oops, something went wrong.
82 changes: 82 additions & 0 deletions
82
plugin/core/src/main/java/com/perl5/lang/perl/idea/project/Perl5ProjectStartupActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Copyright 2015-2024 Alexandr Evstigneev | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.perl5.lang.perl.idea.project | ||
|
||
import com.intellij.ide.startup.ServiceNotReadyException | ||
import com.intellij.notification.BrowseNotificationAction | ||
import com.intellij.notification.Notification | ||
import com.intellij.notification.NotificationType | ||
import com.intellij.notification.Notifications | ||
import com.intellij.openapi.application.ApplicationManager | ||
import com.intellij.openapi.diagnostic.Logger | ||
import com.intellij.openapi.project.DumbService | ||
import com.intellij.openapi.project.Project | ||
import com.intellij.openapi.startup.ProjectActivity | ||
import com.intellij.util.FileContentUtil | ||
import com.perl5.PerlBundle | ||
import com.perl5.lang.perl.idea.configuration.settings.PerlApplicationSettings | ||
import com.perl5.lang.perl.util.PerlPluginUtil | ||
|
||
private val log = Logger.getInstance(Perl5ProjectStartupActivity::class.java) | ||
|
||
class Perl5ProjectStartupActivity : ProjectActivity { | ||
override suspend fun execute(project: Project) { | ||
if (project.isDefault()) { | ||
return | ||
} | ||
val settings = PerlApplicationSettings.getInstance() | ||
if (settings.shouldShowAnnounce()) { | ||
|
||
settings.setAnnounceShown() | ||
val notification = Notification( | ||
"perl5.plugin.update.notification.group", | ||
PerlBundle.message("plugin.update.baloon.title", PerlPluginUtil.getPluginVersion()), | ||
PerlBundle.message("plugin.update.baloon.text"), | ||
NotificationType.INFORMATION | ||
).setImportant(true) | ||
.addAction( | ||
BrowseNotificationAction(PerlBundle.message("plugin.update.baloon.changes"), "https://plugins.jetbrains.com/plugin/7796") | ||
) | ||
.addAction( | ||
BrowseNotificationAction(PerlBundle.message("plugin.update.baloon.tracker"), "https://github.com/hurricup/Perl5-IDEA/issues") | ||
) | ||
|
||
Notifications.Bus.notify(notification) | ||
} | ||
if (!ApplicationManager.getApplication().isUnitTestMode()) { | ||
scheduleNamesUpdateWithReparse(project) | ||
} | ||
} | ||
|
||
private fun scheduleNamesUpdateWithReparse(project: Project) { | ||
ApplicationManager.getApplication().executeOnPooledThread { initNamesWithReparse(project) } | ||
} | ||
|
||
|
||
private fun initNamesWithReparse(project: Project) { | ||
if (project.isDisposed()) { | ||
return | ||
} | ||
try { | ||
PerlNamesCache.getInstance(project).forceCacheUpdate() | ||
ApplicationManager.getApplication().invokeLater(FileContentUtil::reparseOpenedFiles) | ||
} catch (e: ServiceNotReadyException) { | ||
log.warn(e) | ||
DumbService.getInstance(project).smartInvokeLater { scheduleNamesUpdateWithReparse(project) } | ||
} | ||
} | ||
} |
Oops, something went wrong.