mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
[lvcs] use SearchTextField for filtering by file name
When filtering by file name, having multiple lines in the filter component is not necessary and SearchTextField should be used in this case. Since SearchTextField and SearchTextArea have no common api, this commit adds SearchFieldComponent interface to use them interchangeably. GitOrigin-RevId: 7bc84e9ed55c9630d6fa571b9e303c3d38871f81
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a5b1cbfb22
commit
1d03a0db67
@@ -707,7 +707,7 @@ c:com.intellij.history.integration.ui.views.FileHistoryDialog
|
||||
- s:findLeftEditor(javax.swing.JComponent):com.intellij.openapi.editor.Editor
|
||||
- p:getHelpId():java.lang.String
|
||||
- p:setDiffBorder(javax.swing.border.Border):V
|
||||
- s:updateEditorSearch(com.intellij.openapi.project.Project,com.intellij.find.SearchTextArea,com.intellij.openapi.editor.Editor):V
|
||||
- s:updateEditorSearch(com.intellij.openapi.project.Project,javax.swing.text.JTextComponent,com.intellij.openapi.editor.Editor):V
|
||||
a:com.intellij.history.integration.ui.views.HistoryDialog
|
||||
- com.intellij.openapi.ui.FrameWrapper
|
||||
- pf:myFile:com.intellij.openapi.vfs.VirtualFile
|
||||
|
||||
@@ -46,6 +46,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import javax.swing.*;
|
||||
import javax.swing.border.Border;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.text.JTextComponent;
|
||||
import java.awt.*;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.Collections;
|
||||
@@ -171,18 +172,18 @@ public class FileHistoryDialog extends HistoryDialog<FileHistoryDialogModel> {
|
||||
private void updateEditorSearch() {
|
||||
Editor editor = findLeftEditor();
|
||||
if (editor == null) return;
|
||||
updateEditorSearch(myProject, mySearchTextArea, editor);
|
||||
updateEditorSearch(myProject, mySearchTextArea.getTextArea(), editor);
|
||||
}
|
||||
|
||||
public static void updateEditorSearch(@NotNull Project project, @NotNull SearchTextArea searchTextArea, @NotNull Editor editor) {
|
||||
String filter = searchTextArea.getTextArea().getText();
|
||||
public static void updateEditorSearch(@NotNull Project project, @NotNull JTextComponent searchTextComponent, @NotNull Editor editor) {
|
||||
String filter = searchTextComponent.getText();
|
||||
EditorSearchSession session = EditorSearchSession.get(editor);
|
||||
if (StringUtil.isEmpty(filter)) {
|
||||
if (session != null) {
|
||||
boolean focused = searchTextArea.getTextArea().isFocusOwner();
|
||||
boolean focused = searchTextComponent.isFocusOwner();
|
||||
session.close();
|
||||
if (focused) {
|
||||
IdeFocusManager.getInstance(project).requestFocus(searchTextArea.getTextArea(), false);
|
||||
IdeFocusManager.getInstance(project).requestFocus(searchTextComponent, false);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -31,10 +31,7 @@ import com.intellij.platform.lvcs.impl.statistics.LocalHistoryCounter
|
||||
import com.intellij.platform.lvcs.impl.ui.SingleFileActivityDiffPreview.Companion.DIFF_PLACE
|
||||
import com.intellij.platform.util.coroutines.childScope
|
||||
import com.intellij.ui.*
|
||||
import com.intellij.ui.components.JBPanel
|
||||
import com.intellij.ui.components.JBTextArea
|
||||
import com.intellij.ui.components.ProgressBarLoadingDecorator
|
||||
import com.intellij.ui.components.TextComponentEmptyText
|
||||
import com.intellij.ui.components.*
|
||||
import com.intellij.ui.content.ContentFactory
|
||||
import com.intellij.util.ui.JBUI
|
||||
import com.intellij.util.ui.ProportionKey
|
||||
@@ -48,8 +45,10 @@ import java.awt.BorderLayout
|
||||
import java.awt.Component
|
||||
import java.awt.event.KeyEvent
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JPanel
|
||||
import javax.swing.ScrollPaneConstants
|
||||
import javax.swing.event.DocumentEvent
|
||||
import javax.swing.text.JTextComponent
|
||||
|
||||
class ActivityView(private val project: Project, gateway: IdeaGateway, val activityScope: ActivityScope,
|
||||
private val isFrameDiffPreview: Boolean = false) :
|
||||
@@ -82,7 +81,7 @@ class ActivityView(private val project: Project, gateway: IdeaGateway, val activ
|
||||
frameDiffPreview?.setToolbarVerticalSizeReferent(toolbarComponent)
|
||||
|
||||
val filterProgress = searchField.let { field ->
|
||||
object : ProgressBarLoadingDecorator(field, this@ActivityView, 500) {
|
||||
object : ProgressBarLoadingDecorator(field.containerComponent, this@ActivityView, 500) {
|
||||
override fun isOnTop() = false
|
||||
}.also {
|
||||
toolbarComponent.add(it.component, BorderLayout.CENTER)
|
||||
@@ -142,7 +141,7 @@ class ActivityView(private val project: Project, gateway: IdeaGateway, val activ
|
||||
isFocusCycleRoot = true
|
||||
focusTraversalPolicy = object: ComponentsListFocusTraversalPolicy() {
|
||||
override fun getOrderedComponents(): List<Component> {
|
||||
return listOfNotNull(activityList, changesBrowser?.preferredFocusedComponent, searchField.textArea,
|
||||
return listOfNotNull(activityList, changesBrowser?.preferredFocusedComponent, searchField.textComponent,
|
||||
frameDiffPreview?.preferredFocusedComponent)
|
||||
}
|
||||
}
|
||||
@@ -202,39 +201,39 @@ class ActivityView(private val project: Project, gateway: IdeaGateway, val activ
|
||||
return diffViewer
|
||||
}
|
||||
|
||||
private fun createSearchField(): SearchTextArea {
|
||||
val textArea = JBTextArea()
|
||||
textArea.emptyText.text = when (model.filterKind) {
|
||||
FilterKind.FILE -> LocalHistoryBundle.message("activity.filter.empty.text.fileName")
|
||||
FilterKind.CONTENT -> LocalHistoryBundle.message("activity.filter.empty.text.content")
|
||||
}
|
||||
TextComponentEmptyText.setupPlaceholderVisibility(textArea)
|
||||
private fun createSearchField(): SearchFieldComponent {
|
||||
val searchField = when (model.filterKind) {
|
||||
FilterKind.FILE -> SearchFieldComponent.SingleLine().also { field ->
|
||||
field.textComponent.emptyText.text = LocalHistoryBundle.message("activity.filter.empty.text.fileName")
|
||||
}
|
||||
FilterKind.CONTENT -> SearchFieldComponent.MultiLine().also { field ->
|
||||
field.containerComponent.setBorder(JBUI.Borders.compound(IdeBorderFactory.createBorder(SideBorder.RIGHT),
|
||||
field.containerComponent.border))
|
||||
field.textComponent.emptyText.text = LocalHistoryBundle.message("activity.filter.empty.text.content")
|
||||
|
||||
val searchTextArea = SearchTextArea(textArea, true)
|
||||
searchTextArea.setBorder(JBUI.Borders.compound(IdeBorderFactory.createBorder(SideBorder.RIGHT), searchTextArea.border))
|
||||
|
||||
if (model.filterKind == FilterKind.CONTENT) {
|
||||
dumbAwareAction { selectNextOccurence(true) }.registerCustomShortcutSet(Utils.shortcutSetOf(
|
||||
Utils.shortcutsOf(IdeActions.ACTION_FIND_NEXT) + Utils.shortcutsOf(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)
|
||||
), searchTextArea)
|
||||
dumbAwareAction { selectNextOccurence(false) }.registerCustomShortcutSet(Utils.shortcutSetOf(
|
||||
Utils.shortcutsOf(IdeActions.ACTION_FIND_PREVIOUS) + Utils.shortcutsOf(IdeActions.ACTION_EDITOR_MOVE_CARET_UP)
|
||||
), searchTextArea)
|
||||
dumbAwareAction { selectNextOccurence(true) }.registerCustomShortcutSet(Utils.shortcutSetOf(
|
||||
Utils.shortcutsOf(IdeActions.ACTION_FIND_NEXT) + Utils.shortcutsOf(IdeActions.ACTION_EDITOR_MOVE_CARET_DOWN)
|
||||
), field.containerComponent)
|
||||
dumbAwareAction { selectNextOccurence(false) }.registerCustomShortcutSet(Utils.shortcutSetOf(
|
||||
Utils.shortcutsOf(IdeActions.ACTION_FIND_PREVIOUS) + Utils.shortcutsOf(IdeActions.ACTION_EDITOR_MOVE_CARET_UP)
|
||||
), field.containerComponent)
|
||||
}
|
||||
}
|
||||
TextComponentEmptyText.setupPlaceholderVisibility(searchField.textComponent)
|
||||
dumbAwareAction {
|
||||
IdeFocusManager.getInstance(project).requestFocus(searchTextArea.textArea, true)
|
||||
IdeFocusManager.getInstance(project).requestFocus(searchField.textComponent, true)
|
||||
}.registerCustomShortcutSet(Utils.shortcutSetOf(Utils.shortcutsOf(IdeActions.ACTION_FIND)), activityList)
|
||||
dumbAwareAction {
|
||||
searchTextArea.textArea.text = ""
|
||||
searchField.textComponent.text = ""
|
||||
IdeFocusManager.getInstance(project).requestFocus(activityList, true)
|
||||
}.registerCustomShortcutSet(CustomShortcutSet(KeyEvent.VK_ESCAPE), searchTextArea.textArea)
|
||||
searchTextArea.textArea.document.addDocumentListener(object : DocumentAdapter() {
|
||||
}.registerCustomShortcutSet(CustomShortcutSet(KeyEvent.VK_ESCAPE), searchField.textComponent)
|
||||
searchField.textComponent.document.addDocumentListener(object : DocumentAdapter() {
|
||||
override fun textChanged(e: DocumentEvent) {
|
||||
if (!model.isFilterSet) LocalHistoryCounter.logFilterUsed(activityScope)
|
||||
model.setFilter(searchTextArea.textArea.getText())
|
||||
model.setFilter(searchField.textComponent.text)
|
||||
}
|
||||
})
|
||||
return searchTextArea
|
||||
return searchField
|
||||
}
|
||||
|
||||
private fun getDiffComponent(): JComponent? {
|
||||
@@ -248,7 +247,7 @@ class ActivityView(private val project: Project, gateway: IdeaGateway, val activ
|
||||
val diffComponent = getDiffComponent() ?: return
|
||||
val editor = FileHistoryDialog.findLeftEditor(diffComponent) ?: return
|
||||
|
||||
FileHistoryDialog.updateEditorSearch(project, searchField, editor)
|
||||
FileHistoryDialog.updateEditorSearch(project, searchField.textComponent, editor)
|
||||
}
|
||||
|
||||
private fun selectNextOccurence(forward: Boolean) {
|
||||
@@ -373,4 +372,18 @@ private fun dumbAwareAction(runnable: () -> Unit): DumbAwareAction {
|
||||
return object : DumbAwareAction() {
|
||||
override fun actionPerformed(e: AnActionEvent) = runnable()
|
||||
}
|
||||
}
|
||||
|
||||
private sealed interface SearchFieldComponent {
|
||||
val containerComponent: JPanel
|
||||
val textComponent: JTextComponent
|
||||
class SingleLine: SearchFieldComponent {
|
||||
override val containerComponent = SearchTextField("Lvcs.FileFilter.History")
|
||||
override val textComponent: JBTextField get() = containerComponent.textEditor
|
||||
}
|
||||
class MultiLine: SearchFieldComponent {
|
||||
private val textArea = JBTextArea()
|
||||
override val containerComponent = SearchTextArea(textArea, true)
|
||||
override val textComponent = textArea
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user