👔 完善标签页右键菜单

This commit is contained in:
gewuyou 2023-10-08 21:35:12 +08:00
parent 9b6ec0734e
commit 0e3b7dcaab
2 changed files with 19 additions and 7 deletions

View File

@ -1,5 +1,6 @@
package org.jcnc.jnotepad.util; package org.jcnc.jnotepad.util;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.scene.control.TextField; import javafx.scene.control.TextField;
import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCode;
@ -40,6 +41,7 @@ import static org.jcnc.jnotepad.util.FileUtil.getFileText;
public class TabUtil { public class TabUtil {
private static final ApplicationCacheManager CACHE_MANAGER = ApplicationCacheManager.getInstance(); private static final ApplicationCacheManager CACHE_MANAGER = ApplicationCacheManager.getInstance();
static Logger logger = LogUtil.getLogger(TabUtil.class); static Logger logger = LogUtil.getLogger(TabUtil.class);
private TabUtil() { private TabUtil() {
} }
@ -379,8 +381,9 @@ public class TabUtil {
}) })
.build(), tab.isRelevance()) .build(), tab.isRelevance())
.addSeparatorMenuItem() .addSeparatorMenuItem()
.addMenuItem("固定标签页", e -> centerTabPaneManager.updateTabPinnedState(tab), !tab.isFixed()) .addCheckMenuItem("固定标签页", e -> centerTabPaneManager.updateTabPinnedState(tab, (CheckMenuItem) e.getSource()))
.addMenuItem("取消固定", e -> centerTabPaneManager.updateTabPinnedState(tab), tab.isFixed()) .addSeparatorMenuItem()
.addCheckMenuItem("只读", e -> centerTabPaneManager.updateReadOnlyProperty(tab, (CheckMenuItem) e.getSource()))
.build()); .build());
} }
} }

View File

@ -2,6 +2,7 @@ package org.jcnc.jnotepad.views.manager;
import javafx.collections.ListChangeListener; import javafx.collections.ListChangeListener;
import javafx.collections.ObservableList; import javafx.collections.ObservableList;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.control.Tab; import javafx.scene.control.Tab;
import javafx.stage.Stage; import javafx.stage.Stage;
import org.jcnc.jnotepad.common.manager.ApplicationCacheManager; import org.jcnc.jnotepad.common.manager.ApplicationCacheManager;
@ -10,7 +11,6 @@ import org.jcnc.jnotepad.controller.config.UserConfigController;
import org.jcnc.jnotepad.model.enums.CacheExpirationTime; import org.jcnc.jnotepad.model.enums.CacheExpirationTime;
import org.jcnc.jnotepad.util.FileUtil; import org.jcnc.jnotepad.util.FileUtil;
import org.jcnc.jnotepad.util.PopUpUtil; import org.jcnc.jnotepad.util.PopUpUtil;
import org.jcnc.jnotepad.util.TabUtil;
import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTab; import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTab;
import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTabPane; import org.jcnc.jnotepad.views.root.center.main.center.tab.CenterTabPane;
import org.jcnc.jnotepad.views.root.top.menubar.TopMenuBar; import org.jcnc.jnotepad.views.root.top.menubar.TopMenuBar;
@ -273,11 +273,20 @@ public class CenterTabPaneManager {
* *
* @param tab the center tab to update * @param tab the center tab to update
*/ */
public void updateTabPinnedState(CenterTab tab) { public void updateTabPinnedState(CenterTab tab, CheckMenuItem checkMenuItem) {
tab.setFixed(!tab.isFixed()); tab.setFixed(!tab.isFixed());
TabUtil.updateTabContextMenu(tab); checkMenuItem.setSelected(tab.isFixed());
} }
/**
* Updates the read-only property of a given tab and its associated check menu item.
*
* @param tab the center tab to update
* @param checkMenuItem the check menu item associated with the tab
*/
public void updateReadOnlyProperty(CenterTab tab, CheckMenuItem checkMenuItem) {
TextCodeArea textCodeArea = tab.getTextCodeArea();
textCodeArea.setEditable(!textCodeArea.isEditable());
checkMenuItem.setSelected(!textCodeArea.isEditable());
}
} }