no message
This commit is contained in:
213
src/_VisualDVM/Windows/SearchReplaceForm.form
Normal file
213
src/_VisualDVM/Windows/SearchReplaceForm.form
Normal file
@@ -0,0 +1,213 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="_VisualDVM.Windows.SearchReplaceForm">
|
||||
<grid id="cbd77" binding="MainPanel" layout-manager="GridLayoutManager" row-count="1" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="10" left="10" bottom="10" right="10"/>
|
||||
<constraints>
|
||||
<xy x="48" y="54" width="723" height="433"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="7e504" layout-manager="GridLayoutManager" row-count="11" column-count="5" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="8f101" class="javax.swing.JTextField" binding="tfFind" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="1e6aa" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="90" height="20"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<horizontalAlignment value="0"/>
|
||||
<text value="поиск"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="20f14" class="javax.swing.JCheckBox" binding="replaceOn">
|
||||
<constraints>
|
||||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="4" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="90" height="27"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="замена"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7a05a" class="javax.swing.JTextField" binding="tfReplace" custom-create="true">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<enabled value="false"/>
|
||||
<font name="Times New Roman" size="16"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ab9" class="javax.swing.JCheckBox" binding="registerOn">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="Учитывать регистр"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="71774" class="javax.swing.JCheckBox" binding="wholeWordOn">
|
||||
<constraints>
|
||||
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="Слово целиком"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6e6a7" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16"/>
|
||||
<text value="Направление поиска"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="ceb1a" class="javax.swing.JRadioButton" binding="rbUp">
|
||||
<constraints>
|
||||
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<selected value="false"/>
|
||||
<text value="Вверх"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="a5775" class="javax.swing.JRadioButton" binding="rbDown">
|
||||
<constraints>
|
||||
<grid row="7" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<selected value="true"/>
|
||||
<text value="Вниз"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="7c480" class="javax.swing.JButton" binding="bNext">
|
||||
<constraints>
|
||||
<grid row="10" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="144" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="3"/>
|
||||
<text value="Найти далее"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="6eff3" class="javax.swing.JCheckBox" binding="loopOn">
|
||||
<constraints>
|
||||
<grid row="4" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="2"/>
|
||||
<text value="Зациклить поиск"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="dd8e2" class="javax.swing.JButton" binding="bAll">
|
||||
<constraints>
|
||||
<grid row="10" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="127" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="3"/>
|
||||
<text value="Найти всё"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="905c1" class="javax.swing.JButton" binding="bSearchInFiles">
|
||||
<constraints>
|
||||
<grid row="10" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="127" height="30"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16" style="3"/>
|
||||
<text value="Найти в файлах"/>
|
||||
<visible value="true"/>
|
||||
</properties>
|
||||
</component>
|
||||
<scrollpane id="3dd41">
|
||||
<constraints>
|
||||
<grid row="0" column="3" row-span="9" col-span="2" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<grid id="4e002" binding="filesTreePanel" layout-manager="BorderLayout" hgap="0" vgap="0">
|
||||
<constraints/>
|
||||
<properties/>
|
||||
<border type="none"/>
|
||||
<children/>
|
||||
</grid>
|
||||
</children>
|
||||
</scrollpane>
|
||||
<hspacer id="a2529">
|
||||
<constraints>
|
||||
<grid row="10" column="4" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
</hspacer>
|
||||
<component id="8e0e8" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="9" column="3" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16"/>
|
||||
<text value="Всего совпадений в файлах:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="bc3e5" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16"/>
|
||||
<text value="Найдено совпадений:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="3e591" class="javax.swing.JLabel" binding="lCount">
|
||||
<constraints>
|
||||
<grid row="9" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16"/>
|
||||
<text value="0"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="fde6a" class="javax.swing.JLabel" binding="lFilesMatchesCount">
|
||||
<constraints>
|
||||
<grid row="9" column="4" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<font name="Times New Roman" size="16"/>
|
||||
<text value="0"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
253
src/_VisualDVM/Windows/SearchReplaceForm.java
Normal file
253
src/_VisualDVM/Windows/SearchReplaceForm.java
Normal file
@@ -0,0 +1,253 @@
|
||||
package _VisualDVM.Windows;
|
||||
import Common.Utils.CommonUtils;
|
||||
import Common.Visual.CommonUI;
|
||||
import Common.Visual.Windows.Form;
|
||||
import Common_old.Current;
|
||||
import Common_old.UI.TextField.StyledTextField;
|
||||
import Common_old.UI.Trees.StyledTree;
|
||||
import Common_old.UI.UI;
|
||||
import Visual_DVM_2021.Passes.PassCode_2021;
|
||||
import Visual_DVM_2021.Passes.Pass_2021;
|
||||
import javafx.util.Pair;
|
||||
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
|
||||
import org.fife.ui.rtextarea.SearchContext;
|
||||
import org.fife.ui.rtextarea.SearchEngine;
|
||||
import org.fife.ui.rtextarea.SearchResult;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.KeyAdapter;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.util.LinkedHashMap;
|
||||
public class SearchReplaceForm extends Form {
|
||||
public JPanel MainPanel;
|
||||
public boolean forward = true;
|
||||
SearchContext context = null;
|
||||
RSyntaxTextArea editor = null;
|
||||
boolean replace_mode = false;
|
||||
private JTextField tfFind;
|
||||
private JTextField tfReplace;
|
||||
private JCheckBox replaceOn;
|
||||
private JCheckBox registerOn;
|
||||
private JCheckBox wholeWordOn;
|
||||
private JRadioButton rbUp;
|
||||
private JRadioButton rbDown;
|
||||
private JButton bAll;
|
||||
private JButton bNext;
|
||||
private JCheckBox loopOn;
|
||||
private JLabel lCount;
|
||||
private SearchResult result = null;
|
||||
//https://techarks.ru/qa/java/kak-uznat-kakoj-iz-jlist-s-Y4/
|
||||
public void ClearMarkers() {
|
||||
//сброс выделения. решается подсовыванием пустой строки
|
||||
context.setSearchFor("");
|
||||
SearchEngine.find(editor, context);
|
||||
DropMatchCount();
|
||||
}
|
||||
public void DropMatchCount() {
|
||||
lCount.setText("0");
|
||||
}
|
||||
public void updateEditor(RSyntaxTextArea editor_in) {
|
||||
editor = editor_in;
|
||||
if (isVisible())
|
||||
requestFocus();
|
||||
}
|
||||
@Override
|
||||
protected JPanel getMainPanel() {
|
||||
return MainPanel;
|
||||
}
|
||||
@Override
|
||||
public void Close() {
|
||||
ClearMarkers();
|
||||
super.Close();
|
||||
}
|
||||
public void setMode(boolean replace) {
|
||||
replace_mode = replace;
|
||||
tfReplace.setEnabled(replace_mode);
|
||||
String prefix = replace_mode ? "Заменить" : "Найти";
|
||||
bNext.setText(prefix + " далее");
|
||||
bAll.setText(prefix + " всё");
|
||||
}
|
||||
public void ShowMode() {
|
||||
replaceOn.setSelected(replace_mode);
|
||||
}
|
||||
@Override
|
||||
public Component getRelative() {
|
||||
return (Component) UI.getMainWindow();
|
||||
}
|
||||
@Override
|
||||
public int getDefaultWidth() {
|
||||
return 650;
|
||||
}
|
||||
@Override
|
||||
public int getDefaultHeight() {
|
||||
return 400;
|
||||
}
|
||||
public void Refresh() {
|
||||
String text = editor.getSelectedText();
|
||||
if ((text != null) && !text.isEmpty())
|
||||
tfFind.setText(text);
|
||||
tfFind.requestFocus();
|
||||
}
|
||||
//-------------------------------
|
||||
public void SwitchDirection(boolean direction_in) {
|
||||
forward = direction_in;
|
||||
if (forward) {
|
||||
rbUp.setSelected(false);
|
||||
rbDown.setSelected(true);
|
||||
} else {
|
||||
rbDown.setSelected(false);
|
||||
rbUp.setSelected(true);
|
||||
}
|
||||
}
|
||||
public void applyParams() {
|
||||
String toFind = CommonUtils.hideRegularMetasymbols(tfFind.getText());
|
||||
String toReplace = CommonUtils.hideRegularMetasymbols(tfReplace.getText());
|
||||
context.setSearchFor(toFind);
|
||||
context.setMatchCase(registerOn.isSelected());
|
||||
context.setWholeWord(wholeWordOn.isSelected());
|
||||
if (replace_mode)
|
||||
context.setReplaceWith(toReplace);
|
||||
DropMatchCount();
|
||||
}
|
||||
public void onAll() {
|
||||
applyParams();
|
||||
result = replace_mode ?
|
||||
SearchEngine.replaceAll(editor, context) : SearchEngine.markAll(editor, context);
|
||||
lCount.setText(String.valueOf(
|
||||
replace_mode ? result.getCount() : result.getMarkedCount()));
|
||||
}
|
||||
public void onNext() {
|
||||
applyParams();
|
||||
context.setSearchForward(forward);
|
||||
result = replace_mode ? SearchEngine.replace(editor, context) : SearchEngine.find(editor, context);
|
||||
if (loopOn.isSelected() && !result.wasFound()) SwitchDirection(!forward);
|
||||
lCount.setText(String.valueOf(result.getMarkedCount()));
|
||||
}
|
||||
@Override
|
||||
protected String getFormKey() {
|
||||
return "SearchReplace";
|
||||
}
|
||||
private void createUIComponents() {
|
||||
// TODO: place custom component creation code here
|
||||
tfFind = new StyledTextField();
|
||||
tfReplace = new StyledTextField();
|
||||
}
|
||||
//------------------
|
||||
//-
|
||||
private JButton bSearchInFiles;
|
||||
private JPanel filesTreePanel;
|
||||
private JLabel lFilesMatchesCount;
|
||||
public static String lastProjectPath = "";
|
||||
public static LinkedHashMap<String, Long> matches = new LinkedHashMap<>();
|
||||
public void dropFilesMatches() {
|
||||
matches = new LinkedHashMap<>();
|
||||
}
|
||||
public void showNoFilesMatches() {
|
||||
lFilesMatchesCount.setText("—");
|
||||
CommonUI.Clear(filesTreePanel);
|
||||
}
|
||||
public void showFilesMatches() {
|
||||
long total = 0;
|
||||
DefaultMutableTreeNode res = new DefaultMutableTreeNode("файлов " + matches.size());
|
||||
for (String fileName : matches.keySet()) {
|
||||
DefaultMutableTreeNode fileNode = new DefaultMutableTreeNode(new Pair(fileName, matches.get(fileName)) {
|
||||
@Override
|
||||
public String toString() {
|
||||
return getKey() + ":" + getValue();
|
||||
}
|
||||
});
|
||||
res.add(fileNode);
|
||||
total += matches.get(fileName);
|
||||
}
|
||||
StyledTree matchesTree = new StyledTree(res) {
|
||||
{
|
||||
setRootVisible(false);
|
||||
}
|
||||
@Override
|
||||
public void LeftMouseAction2() {
|
||||
DefaultMutableTreeNode selectedFile = (DefaultMutableTreeNode) getLastSelectedPathComponent();
|
||||
if (selectedFile != null) {
|
||||
Pair<String, Long> info = (Pair<String, Long>) selectedFile.getUserObject();
|
||||
if (Current.getProject().db.files.containsKey(info.getKey())) {
|
||||
Pass_2021.passes.get(PassCode_2021.OpenCurrentFile).Do(Current.getProject().db.files.get(info.getKey()));
|
||||
//--->>>
|
||||
replaceOn.setSelected(false);
|
||||
setMode(false);
|
||||
SwitchDirection(true);
|
||||
//-
|
||||
bNext.requestFocus();
|
||||
bNext.doClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
filesTreePanel.add(matchesTree);
|
||||
filesTreePanel.revalidate();
|
||||
filesTreePanel.repaint();
|
||||
lFilesMatchesCount.setText(String.valueOf(total));
|
||||
}
|
||||
@Override
|
||||
public void Show() {
|
||||
super.Show();
|
||||
//------->>
|
||||
showNoFilesMatches();
|
||||
if (lastProjectPath.equals(Current.getProject().Home.getAbsolutePath()))
|
||||
showFilesMatches();
|
||||
else
|
||||
dropFilesMatches();
|
||||
//------->>
|
||||
Refresh();
|
||||
// setAlwaysOnTop(true);
|
||||
}
|
||||
public SearchReplaceForm() {
|
||||
context = new SearchContext();
|
||||
//-
|
||||
context.setRegularExpression(true);
|
||||
//-
|
||||
rbDown.addActionListener(e -> SwitchDirection(!forward));
|
||||
rbUp.addActionListener(e -> SwitchDirection(!forward));
|
||||
bAll.addActionListener(e -> onAll());
|
||||
bNext.addActionListener(e -> onNext());
|
||||
replaceOn.addActionListener(e -> {
|
||||
setMode(replaceOn.isSelected());
|
||||
});
|
||||
bNext.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if (e.getKeyCode() == KeyEvent.VK_ENTER)
|
||||
bNext.doClick();
|
||||
}
|
||||
});
|
||||
tfFind.addKeyListener(new KeyAdapter() {
|
||||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
switch (e.getKeyCode()) {
|
||||
case KeyEvent.VK_ENTER:
|
||||
bNext.requestFocus();
|
||||
bNext.doClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
bSearchInFiles.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
showNoFilesMatches();
|
||||
lastProjectPath = Current.getProject().Home.getAbsolutePath();
|
||||
matches = Current.getProject().getMatches(
|
||||
tfFind.getText(),
|
||||
registerOn.isSelected(),
|
||||
wholeWordOn.isSelected());
|
||||
showFilesMatches();
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user