mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
do not enable reader mode for database source files
GitOrigin-RevId: 96c79e28d00112ff413835e481e9bde4c32e5f43
This commit is contained in:
committed by
intellij-monorepo-bot
parent
d23b168d15
commit
bc2c1f05b7
@@ -0,0 +1,18 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.codeInsight.actions
|
||||
|
||||
import com.intellij.codeInsight.actions.ReaderModeProvider.ReaderMode
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
|
||||
/**
|
||||
* Use it to override file <--> reader mode matching
|
||||
*/
|
||||
interface ReaderModeMatcher {
|
||||
/**
|
||||
* It's triggered on Reader Mode to check if file matches mode specified.
|
||||
*
|
||||
* @return null if unable to decide
|
||||
*/
|
||||
fun matches(project: Project, file: VirtualFile, mode: ReaderMode): Boolean?
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import com.intellij.psi.PsiManager
|
||||
class ReaderModeSettings : PersistentStateComponentWithModificationTracker<ReaderModeSettings.State> {
|
||||
companion object {
|
||||
private var EP_READER_MODE_PROVIDER = ExtensionPointName<ReaderModeProvider>("com.intellij.readerModeProvider")
|
||||
private var EP_READER_MODE_MATCHER = ExtensionPointName<ReaderModeMatcher>("com.intellij.readerModeMatcher")
|
||||
|
||||
@JvmStatic
|
||||
fun instance(project: Project): ReaderModeSettings {
|
||||
@@ -32,12 +33,19 @@ class ReaderModeSettings : PersistentStateComponentWithModificationTracker<Reade
|
||||
|
||||
fun matchMode(project: Project?, file: VirtualFile?): Boolean {
|
||||
if (project == null || file == null) return false
|
||||
return matchMode(project, file, instance(project).mode)
|
||||
}
|
||||
|
||||
val inLibraries = FileIndexFacade.getInstance(project).isInLibraryClasses(file) || FileIndexFacade.getInstance(
|
||||
project).isInLibrarySource(file)
|
||||
private fun matchMode(project: Project, file: VirtualFile, mode: ReaderMode): Boolean {
|
||||
for (m in EP_READER_MODE_MATCHER.iterable) {
|
||||
val matched = m.matches(project, file, mode)
|
||||
if (matched != null) return matched
|
||||
}
|
||||
val inLibraries = FileIndexFacade.getInstance(project).isInLibraryClasses(file)
|
||||
|| FileIndexFacade.getInstance(project).isInLibrarySource(file)
|
||||
val isWritable = file.isWritable
|
||||
|
||||
return when (instance(project).mode) {
|
||||
return when (mode) {
|
||||
ReaderMode.LIBRARIES_AND_READ_ONLY -> inLibraries || !isWritable
|
||||
ReaderMode.LIBRARIES -> inLibraries
|
||||
ReaderMode.READ_ONLY -> !isWritable
|
||||
|
||||
@@ -581,6 +581,7 @@
|
||||
<extensionPoint name="fileTypeStatisticProvider" interface="com.intellij.internal.statistic.fileTypes.FileTypeStatisticProvider" dynamic="true"/>
|
||||
<extensionPoint name="lang.directNavigationProvider" dynamic="true" interface="com.intellij.navigation.DirectNavigationProvider"/>
|
||||
<extensionPoint name="readerModeProvider" dynamic="true" interface="com.intellij.codeInsight.actions.ReaderModeProvider"/>
|
||||
<extensionPoint name="readerModeMatcher" dynamic="true" interface="com.intellij.codeInsight.actions.ReaderModeMatcher"/>
|
||||
</extensionPoints>
|
||||
</idea-plugin>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user