11package com .xwintop .xJavaFxTool .controller .littleTools ;
22
3+ import cn .hutool .core .swing .clipboard .ClipboardUtil ;
34import com .xwintop .xJavaFxTool .services .littleTools .FileSearchToolService ;
5+ import com .xwintop .xJavaFxTool .utils .ImgToolUtil ;
46import com .xwintop .xJavaFxTool .utils .JavaFxViewUtil ;
7+ import com .xwintop .xJavaFxTool .utils .XJavaFxSystemUtil ;
58import com .xwintop .xJavaFxTool .view .littleTools .FileSearchToolView ;
69import com .xwintop .xcore .util .javafx .FileChooserUtil ;
710import javafx .application .Platform ;
811import javafx .collections .FXCollections ;
912import javafx .collections .ObservableList ;
1013import javafx .embed .swing .SwingFXUtils ;
1114import javafx .event .ActionEvent ;
15+ import javafx .event .Event ;
1216import javafx .fxml .FXML ;
17+ import javafx .scene .control .ContextMenu ;
18+ import javafx .scene .control .MenuItem ;
1319import javafx .scene .control .TableCell ;
1420import javafx .scene .control .TableColumn ;
1521import javafx .scene .image .Image ;
1622import javafx .scene .image .ImageView ;
23+ import javafx .scene .input .MouseButton ;
24+ import javafx .scene .paint .Color ;
1725import javafx .util .Callback ;
1826import lombok .Getter ;
1927import lombok .Setter ;
2028import lombok .extern .slf4j .Slf4j ;
29+ import org .apache .commons .lang3 .StringUtils ;
2130
2231import javax .swing .*;
2332import javax .swing .filechooser .FileSystemView ;
@@ -73,6 +82,12 @@ protected void updateItem(String item, boolean empty) {
7382 }
7483 ImageIcon icon = (ImageIcon ) FileSystemView .getFileSystemView ().getSystemIcon (file );
7584 Image fxImage = SwingFXUtils .toFXImage ((BufferedImage ) icon .getImage (), null );
85+ if (file .isHidden ()) {
86+ this .setTextFill (Color .GREY );
87+ fxImage = ImgToolUtil .pixWithImage (8 , fxImage );
88+ } else {
89+ this .setTextFill (Color .BLACK );
90+ }
7691 ImageView imageView = new ImageView (fxImage );
7792 this .setGraphic (imageView );
7893 } catch (Exception e ) {
@@ -92,14 +107,54 @@ protected void updateItem(String item, boolean empty) {
92107 JavaFxViewUtil .setTableColumnMapValueFactory (lastModifiedTableColumn , "lastModified" , false );
93108 searchResultTableVIew .setItems (searchResultTableData );
94109
95- searchDirectoryTextField .setText ("D:\\ TestXf\\ " );
110+ // searchDirectoryTextField.setText("D:\\TestXf\\");
111+ searchDirectoryTextField .setText (StringUtils .removeEnd (new File ("./" ).getAbsolutePath (), "." ));
96112 }
97113
98114 private void initEvent () {
99115 FileChooserUtil .setOnDrag (searchDirectoryTextField , FileChooserUtil .FileType .FOLDER );
116+
117+ searchResultTableVIew .setOnMouseClicked (event -> {
118+ if (event .getButton () == MouseButton .SECONDARY ) {
119+ MenuItem menuOpen = new MenuItem ("打开" );
120+ menuOpen .setOnAction (event1 -> {
121+ String absolutePath = searchResultTableVIew .getSelectionModel ().getSelectedItem ().get ("absolutePath" );
122+ XJavaFxSystemUtil .openDirectory (absolutePath );
123+ });
124+ MenuItem menuOpenPath = new MenuItem ("打开路径" );
125+ menuOpenPath .setOnAction (event1 -> {
126+ String absolutePath = searchResultTableVIew .getSelectionModel ().getSelectedItem ().get ("absolutePath" );
127+ File file = new File (absolutePath );
128+ if (!file .isDirectory ()) {
129+ absolutePath = file .getParent ();
130+ }
131+ XJavaFxSystemUtil .openDirectory (absolutePath );
132+ });
133+ MenuItem menuCopyFileName = new MenuItem ("复制文件名" );
134+ menuCopyFileName .setOnAction (event1 -> {
135+ ClipboardUtil .setStr (searchResultTableVIew .getSelectionModel ().getSelectedItem ().get ("fileName" ));
136+ });
137+ MenuItem menuCopyFilePath = new MenuItem ("复制完整路径" );
138+ menuCopyFilePath .setOnAction (event1 -> {
139+ ClipboardUtil .setStr (searchResultTableVIew .getSelectionModel ().getSelectedItem ().get ("absolutePath" ));
140+ });
141+ searchResultTableVIew .setContextMenu (new ContextMenu (menuOpen , menuOpenPath , menuCopyFileName , menuCopyFilePath ));
142+ }
143+ });
100144 }
101145
102146 private void initService () {
147+ if (autoRefreshIndexCheckBox .isSelected ()) {
148+ fileSearchToolService .autoRefreshIndexAction ();
149+ }
150+ }
151+
152+ public void autoRefreshIndexAction () throws Exception {
153+ if (autoRefreshIndexCheckBox .isSelected ()) {
154+ fileSearchToolService .autoRefreshIndexAction ();
155+ } else {
156+ fileSearchToolService .stopAutoRefreshIndexTimer ();
157+ }
103158 }
104159
105160 public void searchContentAction () throws Exception {
@@ -118,4 +173,11 @@ private void searchDirectoryAction(ActionEvent event) throws Exception {
118173 searchDirectoryTextField .setText (file .getPath ());
119174 }
120175 }
176+
177+ /**
178+ * 父控件被移除前调用
179+ */
180+ public void onCloseRequest (Event event ) {
181+ fileSearchToolService .stopAutoRefreshIndexTimer ();
182+ }
121183}
0 commit comments