Skip to content

Commit da38772

Browse files
committed
New tab that adds tabs when selected
1 parent 0fe3105 commit da38772

File tree

4 files changed

+51
-10
lines changed

4 files changed

+51
-10
lines changed

.idea/workspace.xml

Lines changed: 13 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/org/idaesbasic/controllers/MainController.java

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@
1313
import java.util.Timer;
1414
import java.util.TimerTask;
1515

16+
import javafx.beans.value.ChangeListener;
17+
import javafx.beans.value.ObservableValue;
18+
import javafx.event.Event;
19+
import javafx.event.EventHandler;
1620
import javafx.scene.control.*;
1721
import org.idaesbasic.controllers.calendar.CalendarController;
1822
import org.idaesbasic.controllers.todolist.TodolistController;
@@ -54,6 +58,9 @@ public NewFileDialogResult(Optional<ButtonType> result, String directory, String
5458
@FXML
5559
private Button timeButton;
5660

61+
@FXML
62+
private Tab plusTab;
63+
5764
@FXML
5865
private TreeView<String> fileExplorer;
5966

@@ -71,6 +78,17 @@ void initialize() {
7178
} catch (IOException e1) {
7279
e1.printStackTrace();
7380
}
81+
// Add new tab when "add tab" tab is selected
82+
tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<Tab>() {
83+
@Override
84+
public void changed(ObservableValue<? extends Tab> observable, Tab oldTab, Tab newTab) {
85+
if(newTab.equals (plusTab)) {
86+
addNewTab();
87+
tabPane.getTabs().remove(plusTab);
88+
tabPane.getTabs().add(plusTab);
89+
}
90+
}
91+
});
7492
// Set date from date button
7593
dateButton.setText(LocalDate.now().toString());
7694
Timer timer = new Timer();
@@ -295,7 +313,11 @@ void openFileExplorer(ActionEvent event) {
295313
}
296314

297315
@FXML
298-
void addTab(ActionEvent event) throws IOException {
316+
void addTabAction(ActionEvent event) throws IOException {
317+
addNewTab();
318+
}
319+
320+
void addNewTab() {
299321
// Open a new empty tab
300322
Tab newTab = new Tab();
301323
newTab.setText("New tab");

src/main/resources/fxml/MainView.fxml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<?import org.kordamp.ikonli.javafx.FontIcon?>
43
<?import javafx.scene.control.Button?>
54
<?import javafx.scene.control.Label?>
65
<?import javafx.scene.control.Menu?>
@@ -13,6 +12,7 @@
1312
<?import javafx.scene.layout.AnchorPane?>
1413
<?import javafx.scene.layout.BorderPane?>
1514
<?import javafx.scene.text.Font?>
15+
<?import org.kordamp.ikonli.javafx.FontIcon?>
1616

1717
<BorderPane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="737.0" prefWidth="1113.0" stylesheets="@../styles/main.css" xmlns="http://javafx.com/javafx/17" xmlns:fx="http://javafx.com/fxml/1" fx:controller="org.idaesbasic.controllers.MainController">
1818
<left>
@@ -39,6 +39,11 @@
3939
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="648.0" prefWidth="384.0" />
4040
</content>
4141
</Tab>
42+
<Tab fx:id="plusTab" closable="false" text="Add tab">
43+
<graphic>
44+
<FontIcon iconColor="WHITE" iconLiteral="fa-plus" />
45+
</graphic>
46+
</Tab>
4247
</tabs>
4348
</TabPane>
4449
</center>
@@ -93,7 +98,7 @@
9398
<graphic>
9499
<FontIcon iconColor="WHITE" iconLiteral="fa-window-close" iconSize="16" selectionEnd="0" />
95100
</graphic></MenuItem>
96-
<MenuItem fx:id="menuItemNewTab" mnemonicParsing="false" onAction="#addTab" text="New tab">
101+
<MenuItem fx:id="menuItemNewTab" mnemonicParsing="false" onAction="#addTabAction" text="New tab">
97102
<graphic>
98103
<FontIcon iconColor="WHITE" iconLiteral="fa-plus-square" iconSize="16" selectionEnd="0" />
99104
</graphic></MenuItem>

src/main/resources/styles/main.css

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@
227227
-fx-background-color: transparent;
228228
}
229229

230+
#plusTab {
231+
-fx-pref-width: 24px;
232+
}
233+
234+
#plusTab .tab-label {
235+
-fx-text-fill: transparent;
236+
}
237+
230238
.root {
231239
-fx-background-color: #232323
232240
}

0 commit comments

Comments
 (0)