Skip to content

Commit 39e51d1

Browse files
committed
Remove save window, and simplify explorer
1 parent 47367d9 commit 39e51d1

File tree

8 files changed

+62
-232
lines changed

8 files changed

+62
-232
lines changed

src/main/java/com/github/introfog/gitwave/GitWaveLauncher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
public class GitWaveLauncher extends Application {
2626
@Override
2727
public void start(Stage stage) {
28-
StageFactory.createPrimaryStage("view/executor.fxml", "GitWave", stage).getStage().show();
28+
StageFactory.createPrimaryExecuteWindow(stage).getStage().show();
2929
AppConfig.getInstance().setHostServices(getHostServices());
3030
}
3131

src/main/java/com/github/introfog/gitwave/controller/ExecuteController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ protected void cleanSavedCommand() {
110110

111111
@FXML
112112
protected void chooseFromSaved() {
113-
FxmlStageHolder holder = StageFactory.createModalStage("view/explorer.fxml", "Command explorer");
113+
FxmlStageHolder holder = StageFactory.createModalExploreWindow();
114114

115115
ExploreController exploreController = holder.getFxmlLoader().getController();
116116
exploreController.setExecuteController(this);

src/main/java/com/github/introfog/gitwave/controller/ExploreController.java

Lines changed: 47 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@
1717
package com.github.introfog.gitwave.controller;
1818

1919
import com.github.introfog.gitwave.model.AppConfig;
20-
import com.github.introfog.gitwave.model.DialogFactory;
21-
import com.github.introfog.gitwave.model.StageFactory;
2220
import com.github.introfog.gitwave.model.StageFactory.FxmlStageHolder;
2321
import com.github.introfog.gitwave.model.dto.CommandDto;
2422

2523
import java.util.List;
26-
import javafx.application.Platform;
2724
import javafx.collections.FXCollections;
2825
import javafx.collections.ObservableList;
2926
import javafx.fxml.FXML;
3027
import javafx.scene.control.Button;
28+
import javafx.scene.control.TableCell;
3129
import javafx.scene.control.TableColumn;
32-
import javafx.scene.control.TableColumn.CellEditEvent;
3330
import javafx.scene.control.TableView;
3431
import javafx.scene.control.cell.PropertyValueFactory;
3532
import javafx.scene.control.cell.TextFieldTableCell;
3633
import javafx.scene.input.KeyCode;
34+
import javafx.scene.input.MouseEvent;
3735

3836
public class ExploreController extends BaseController {
3937
@FXML
@@ -54,54 +52,19 @@ public void initialize(FxmlStageHolder fxmlStageHolder) {
5452
fxmlStageHolder.getStage().close();
5553
}
5654
});
57-
Platform.runLater(() -> addNew.requestFocus());
5855
}
5956

6057
@FXML
61-
protected void commitCommand(CellEditEvent<CommandDto, String> event) {
62-
event.getRowValue().setCommand(event.getNewValue());
63-
AppConfig.getInstance().updateCommandScript(event.getRowValue(), event.getNewValue());
64-
}
65-
66-
@FXML
67-
protected void commitDescription(CellEditEvent<CommandDto, String> event) {
68-
event.getRowValue().setDescription(event.getNewValue());
69-
AppConfig.getInstance().updateCommandDescription(event.getRowValue(), event.getNewValue());
70-
}
71-
72-
@FXML
73-
protected void removeSelectedCommand() {
74-
CommandDto selectedItem = commandsTable.getSelectionModel().getSelectedItem();
75-
if (selectedItem != null) {
76-
commandsTable.getItems().remove(selectedItem);
77-
executeController.removeSavedCommand(selectedItem);
78-
AppConfig.getInstance().removeCommand(selectedItem);
79-
} else {
80-
DialogFactory.createErrorAlert("No row selected", "Please select a row to remove.");
81-
}
82-
}
83-
84-
@FXML
85-
protected void runSelectedCommand() {
86-
CommandDto selectedItem = commandsTable.getSelectionModel().getSelectedItem();
87-
if (selectedItem != null) {
88-
executeController.setCommand(selectedItem);
89-
closeStage();
90-
} else {
91-
DialogFactory.createErrorAlert("No row selected", "Please select a row to run.");
58+
protected void mouseClick(MouseEvent event) {
59+
if (event.getClickCount() >= 2) {
60+
final CommandDto selectedItem = commandsTable.getSelectionModel().getSelectedItem();
61+
if (selectedItem != null) {
62+
executeController.setCommand(selectedItem);
63+
closeStage();
64+
}
9265
}
9366
}
9467

95-
@FXML
96-
protected void addNewCommand() {
97-
FxmlStageHolder holder = StageFactory.createModalSaveWindow();
98-
99-
SaveController saveController = holder.getFxmlLoader().getController();
100-
saveController.setExploreController(this);
101-
102-
holder.getStage().showAndWait();
103-
}
104-
10568
void setExecuteController(ExecuteController executeController) {
10669
this.executeController = executeController;
10770
}
@@ -111,6 +74,15 @@ void addNewCommand(CommandDto commandDto) {
11174
commandsTable.getItems().add(commandDto);
11275
}
11376

77+
private void removeCommand(CommandDto item) {
78+
if (item == null) {
79+
return;
80+
}
81+
commandsTable.getItems().remove(item);
82+
executeController.removeSavedCommand(item);
83+
AppConfig.getInstance().removeCommand(item);
84+
}
85+
11486
private void fillTable() {
11587
List<CommandDto> commandsDtoList = AppConfig.getInstance().getCommands();
11688
ObservableList<CommandDto> itemList = FXCollections.observableArrayList(commandsDtoList);
@@ -123,5 +95,34 @@ private void fillTable() {
12395
final TableColumn<CommandDto, String> descriptionTableColumn = (TableColumn<CommandDto, String>) commandsTable.getColumns().get(1);
12496
descriptionTableColumn.setCellValueFactory(new PropertyValueFactory<>("description"));
12597
descriptionTableColumn.setCellFactory(TextFieldTableCell.forTableColumn());
98+
99+
TableColumn<CommandDto, String> removeTableColumn = (TableColumn<CommandDto, String>) commandsTable.getColumns().get(2);
100+
removeTableColumn.setCellValueFactory(new PropertyValueFactory<>("description"));
101+
removeTableColumn.setCellFactory(column -> new RemoveTableCell(this));
102+
}
103+
104+
private static class RemoveTableCell extends TableCell<CommandDto, String> {
105+
private final Button removeButton = new Button("X");
106+
107+
private final ExploreController exploreController;
108+
109+
public RemoveTableCell(ExploreController exploreController) {
110+
this.exploreController = exploreController;
111+
}
112+
113+
@Override
114+
protected void updateItem(String item, boolean empty) {
115+
super.updateItem(item, empty);
116+
if (item == null || empty) {
117+
setGraphic(null);
118+
setText(null);
119+
} else {
120+
setGraphic(removeButton);
121+
removeButton.setOnAction(event -> {
122+
CommandDto selectedItem = getTableView().getItems().get(getIndex());
123+
exploreController.removeCommand(selectedItem);
124+
});
125+
}
126+
}
126127
}
127128
}

src/main/java/com/github/introfog/gitwave/controller/SaveController.java

Lines changed: 0 additions & 83 deletions
This file was deleted.

src/main/java/com/github/introfog/gitwave/model/StageFactory.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ private StageFactory() {
3535
// private constructor
3636
}
3737

38-
public static FxmlStageHolder createModalSaveWindow() {
39-
FxmlStageHolder holder = createModalStage("view/saver.fxml", "Command saver");
40-
holder.getStage().setMinWidth(300);
41-
holder.getStage().setMinHeight(220);
42-
holder.getStage().setMaxHeight(220);
38+
public static FxmlStageHolder createModalExploreWindow() {
39+
FxmlStageHolder holder = StageFactory.createModalStage("view/explorer.fxml", "Command explorer");
4340
holder.getStage().setResizable(true);
4441
return holder;
4542
}
@@ -50,8 +47,8 @@ public static FxmlStageHolder createModalStage(String fxmlPath, String title) {
5047
return creteStage(fxmlPath, title, modalStage);
5148
}
5249

53-
public static FxmlStageHolder createPrimaryStage(String fxmlPath, String title, Stage stage) {
54-
final FxmlStageHolder holder = creteStage(fxmlPath, title, stage);
50+
public static FxmlStageHolder createPrimaryExecuteWindow(Stage stage) {
51+
final FxmlStageHolder holder = creteStage("view/executor.fxml", "GitWave", stage);
5552
holder.getStage().setMinWidth(400);
5653
holder.getStage().setMinHeight(340);
5754
holder.getStage().setResizable(true);

src/main/resources/com/github/introfog/gitwave/view/executor.fxml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,14 @@
109109
</TabPane>
110110
<AnchorPane prefHeight="200.0" prefWidth="200.0" GridPane.rowIndex="2" GridPane.vgrow="NEVER">
111111
<children>
112-
<Hyperlink layoutY="25.0" onAction="#foundIssue" text="Found an issue?" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0">
113-
<font>
114-
<Font name="Verdana" size="12.0" />
115-
</font></Hyperlink>
116112
<Button fx:id="run" layoutX="386.0" layoutY="36.0" mnemonicParsing="false" onAction="#runCommand" text="4. Run" AnchorPane.bottomAnchor="20.0" AnchorPane.rightAnchor="20.0">
117113
<font>
118114
<Font name="Verdana" size="12.0" />
119115
</font></Button>
116+
<Hyperlink layoutY="25.0" onAction="#foundIssue" text="Found an issue?" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0">
117+
<font>
118+
<Font name="Verdana" size="12.0" />
119+
</font></Hyperlink>
120120
</children>
121121
</AnchorPane>
122122
</children>
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,16 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?import javafx.scene.control.Button?>
43
<?import javafx.scene.control.TableColumn?>
54
<?import javafx.scene.control.TableView?>
65
<?import javafx.scene.layout.AnchorPane?>
7-
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="275.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.ExploreController">
6+
<AnchorPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="275.0" prefWidth="600.0" style="-fx-font-family: verdana; -fx-font-size: 12;" xmlns="http://javafx.com/javafx/17.0.2-ea" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.github.introfog.gitwave.controller.ExploreController">
87
<children>
9-
<TableView fx:id="commandsTable" editable="true" prefHeight="223.0" prefWidth="600.0">
8+
<TableView fx:id="commandsTable" onMouseClicked="#mouseClick" prefHeight="223.0" prefWidth="600.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
109
<columns>
11-
<TableColumn onEditCommit="#commitCommand" prefWidth="299.0" text="Command" />
12-
<TableColumn onEditCommit="#commitDescription" prefWidth="300.0" text="Description" />
10+
<TableColumn minWidth="283.0" prefWidth="-1.0" text="Command" />
11+
<TableColumn minWidth="283.0" prefWidth="-1.0" text="Description" />
12+
<TableColumn maxWidth="30.0" minWidth="30.0" prefWidth="30.0" resizable="false" />
1313
</columns>
1414
</TableView>
15-
<Button layoutX="72.0" layoutY="236.0" mnemonicParsing="false" onAction="#removeSelectedCommand" text="Remove selected" />
16-
<Button fx:id="addNew" layoutX="269.0" layoutY="236.0" mnemonicParsing="false" onAction="#addNewCommand" text="Add new" />
17-
<Button layoutX="423.0" layoutY="236.0" mnemonicParsing="false" onAction="#runSelectedCommand" text="Run selected" />
1815
</children>
1916
</AnchorPane>

src/main/resources/com/github/introfog/gitwave/view/saver.fxml

Lines changed: 0 additions & 82 deletions
This file was deleted.

0 commit comments

Comments
 (0)