Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
teletha committed Feb 7, 2024
1 parent 079fdfd commit 853a057
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
25 changes: 21 additions & 4 deletions src/main/java/viewtify/ui/dock/DockProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
*/
package viewtify.ui.dock;

import java.lang.reflect.Modifier;
import java.util.Comparator;
import java.util.List;

Expand All @@ -19,6 +18,8 @@
import kiss.Model;
import kiss.Singleton;
import kiss.;
import viewtify.ui.UIContextMenu;
import viewtify.ui.UITab;

@Managed(Singleton.class)
public abstract class DockProvider implements Extensible {
Expand All @@ -37,7 +38,7 @@ protected DockProvider() {
private List<Dock> docks() {
if (docks == null) {
docks = I.signal(getClass().getFields())
.take(field -> Modifier.isFinal(field.getModifiers()) && field.getType() == Dock.class)
.take(field -> field.getType() == Dock.class)
.map(field -> (Dock) field.get(this))
.sort(Comparator.comparing(Dock::id))
.toList();
Expand All @@ -48,7 +49,7 @@ private List<Dock> docks() {
private List<<TypedDock, Class>> typed() {
if (typed == null) {
typed = I.signal(getClass().getFields())
.take(field -> Modifier.isFinal(field.getModifiers()) && field.getType() == TypedDock.class)
.take(field -> field.getType() == TypedDock.class)
.map(field -> I
.pair((TypedDock) field.get(this), (Class) Model.collectParameters(field.getGenericType(), TypedDock.class)[0]))
.toList();
Expand Down Expand Up @@ -79,7 +80,7 @@ public List<TypedDock> findTypedDocks() {
protected boolean register(String id) {
for (Dock dock : docks()) {
if (dock.id().equals(id)) {
dock.registration.accept(dock);
dock.show();
return true;
}
}
Expand All @@ -98,4 +99,20 @@ protected boolean register(String id) {

return false;
}

/**
* Hook view registration.
*
* @param tab
*/
protected void hookView(UITab tab) {
}

/**
* Hook menu registration.
*
* @param menu
*/
protected void hookMenu(UIContextMenu menu) {
}
}
38 changes: 26 additions & 12 deletions src/main/java/viewtify/ui/dock/DockSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.util.concurrent.TimeUnit;
import java.util.function.UnaryOperator;

import org.controlsfx.glyphfont.FontAwesome;

import javafx.application.Platform;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
Expand Down Expand Up @@ -57,7 +59,6 @@
import kiss.Storable;
import kiss.Variable;
import kiss.WiseConsumer;
import kiss.WiseRunnable;
import psychopath.Locator;
import viewtify.Viewtify;
import viewtify.ui.UILabel;
Expand Down Expand Up @@ -299,7 +300,30 @@ private static void openNewWindow(RootArea area, Bounds bounds, EventHandler<Win
static final List<WiseConsumer<UILabel>> menuBuilders = new ArrayList();

/**
* Register the layout.
* Initialize dock system with default menu.
*/
public static void initialize() {
initialize(icon -> {
icon.text(FontAwesome.Glyph.BARS).behaveLikeButton().context(menus -> {
menus.menu(I.translate("Open new page"), sub -> {
for (DockProvider provider : I.find(DockProvider.class)) {
for (Dock item : provider.findDocks()) {
sub.menu(item.title()).disableWhen(DockSystem.isOpened(item.id())).action(item::show);
}
}
});
for (DockProvider provider : I.find(DockProvider.class)) {
provider.hookMenu(menus);
}
menus.separator();
menus.menu(I.translate("Reboot")).action(Viewtify.application()::reactivate);
menus.menu(I.translate("Exit")).action(Viewtify.application()::deactivate);
});
});
}

/**
* Initialize dock system with your menu builder.
*/
public static void initialize(WiseConsumer<UILabel> menuBuilder) {
DockLayout layout = layout();
Expand Down Expand Up @@ -338,16 +362,6 @@ public static void initialize(WiseConsumer<UILabel> menuBuilder) {
}
}

public static void registerBuilder(String pattern, WiseRunnable builder) {
registerBuilder(pattern, null, I.wiseC(builder));
}

public static <T> void registerBuilder(String pattern, Class<T> type, WiseConsumer<T> builder) {
if (pattern != null && builder != null) {

}
}

/**
* Manage all docking windows and tabs.
*/
Expand Down

0 comments on commit 853a057

Please sign in to comment.