Skip to content

Commit

Permalink
open link menu removed instead of disabled if there is no link #743
Browse files Browse the repository at this point in the history
  • Loading branch information
afdia committed Nov 30, 2023
1 parent 60a909d commit e4a736f
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class MenuConstants {
public static final String LAYER = "Layer";
public static final String LAYER_UP = "to front (layer +1)";
public static final String LAYER_DOWN = "to back (layer -1)";
public static final String OPEN_LINK = "Open Link";
public static final String OPEN_LINK = "Open Link"; // currently only supported in standalone Umlet

// OTHERS
public static final String SEARCH = "Search";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,19 @@
import com.baselet.element.facet.PropertiesParserState;

public class LinkFacet extends FirstRunKeyValueFacet {
public static final String LINK = "link";

public static final LinkFacet INSTANCE = new LinkFacet();

private LinkFacet() {}

@Override
public KeyValue getKeyValue() {
return new KeyValue("link", false, "../../dummyLink.uxf", "path to a uxf file relative to the path of current file.");
return new KeyValue(LINK, false, "../diagram.uxf", "path to another uxf file (absolute or relative)");
}

@Override
public void handleValue(String value, PropertiesParserState state) {
/* Empty at first. */
// only a marker facet to add a context menu entry to open the linked diagram
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.baselet.control.constants.FacetConstants;
import com.baselet.control.enums.LineType;
import com.baselet.diagram.draw.DoubleStroke;
import com.baselet.element.facet.common.LinkFacet;

public abstract class Utils {

Expand Down Expand Up @@ -54,7 +55,7 @@ private static Vector<String> decomposeStringsWFilter(String fullString, String
String compatibleFullString = fullString.replaceAll("\r\n", delimiter); // compatibility to windows \r\n

for (String line : compatibleFullString.split("\\" + delimiter)) {
if (filterComments && line.matches("((//)|(fg=)|(bg=)|(autoresize=)|(layer=)|(group=)|(link=)).*")) {
if (filterComments && line.matches("((//)|(fg=)|(bg=)|(autoresize=)|(layer=)|(group=)|(" + LinkFacet.LINK + "=)).*")) {
continue;
}
else if (filterNewLines && line.isEmpty()) {
Expand Down
15 changes: 5 additions & 10 deletions umlet-swing/src/main/java/com/baselet/gui/BaseGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
import javax.swing.UIManager;
import javax.swing.plaf.InsetsUIResource;

import com.baselet.util.logging.Logger;
import com.baselet.util.logging.LoggerFactory;

import com.baselet.control.CanCloseProgram;
import com.baselet.control.HandlerElementMap;
import com.baselet.control.config.Config;
Expand All @@ -27,6 +24,8 @@
import com.baselet.element.old.custom.CustomElementHandler;
import com.baselet.gui.menu.MenuFactorySwing;
import com.baselet.gui.pane.OwnSyntaxPane;
import com.baselet.util.logging.Logger;
import com.baselet.util.logging.LoggerFactory;

public abstract class BaseGUI {

Expand Down Expand Up @@ -60,7 +59,9 @@ public JPopupMenu getContextMenu(GridElement e) {
MenuFactorySwing menuFactory = MenuFactorySwing.getInstance();

JPopupMenu contextMenu = new JPopupMenu();
contextMenu.add(createOpenLinkMenu(menuFactory));
if (selected_elements.size() == 1 && selected_elements.iterator().next().getSetting("link") != null) {
contextMenu.add(menuFactory.createOpenLinkMenu());
}
if (e instanceof CustomElement) {
contextMenu.add(menuFactory.createEditSelected());
}
Expand Down Expand Up @@ -91,12 +92,6 @@ public JPopupMenu getContextMenu(GridElement e) {
return contextMenu;
}

private JMenuItem createOpenLinkMenu(MenuFactorySwing menuFactory) {
JMenuItem item = menuFactory.createOpenLinkMenu();
item.setEnabled((selected_elements.size() == 1) && (selected_elements.iterator().next().getSetting("link") != null));
return item;
}

private JMenu createLayerMenu(MenuFactorySwing menuFactory) {
JMenu layerMenu = menuFactory.createLayerUp();
layerMenu.setEnabled(!selected_elements.isEmpty());
Expand Down
35 changes: 16 additions & 19 deletions umlet-swing/src/main/java/com/baselet/gui/menu/MenuFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,9 @@
import static com.baselet.control.constants.MenuConstants.UNGROUP;
import static com.baselet.control.constants.MenuConstants.VIDEO_TUTORIAL;

import java.io.File;

import java.awt.MouseInfo;
import java.awt.Point;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -64,6 +63,7 @@
import com.baselet.diagram.io.ClassChooser;
import com.baselet.element.facet.common.GroupFacet;
import com.baselet.element.facet.common.LayerFacet;
import com.baselet.element.facet.common.LinkFacet;
import com.baselet.element.interfaces.GridElement;
import com.baselet.element.old.custom.CustomElement;
import com.baselet.generator.ClassDiagramConverter;
Expand Down Expand Up @@ -244,24 +244,21 @@ else if (menuItem.equals(LAYER) && actualHandler != null && actualSelector != nu
valueMap.put(e, Integer.toString(e.getLayer() + change));
}
actualHandler.getController().executeCommand(new ChangeElementSetting(LayerFacet.KEY, valueMap));
}
}
else if (menuItem.equals(OPEN_LINK) && actualHandler != null && actualSelector != null) {
List<GridElement> v = actualSelector.getSelectedElements();
if (v.size() == 1) {
GridElement e = v.get(0);
String absoluteLinkName = e.getSetting("link");
File link = new File(absoluteLinkName);
if (!link.isAbsolute()) {
File file = new File(actualHandler.getFileHandler().getFullPathName());
String parentDir = file.getParent();
try {
File canonical = new File(parentDir + "/" + absoluteLinkName).getCanonicalFile();
absoluteLinkName = canonical.getAbsolutePath();
} catch (Exception exc) {
exc.printStackTrace();
}
}
main.doOpen(absoluteLinkName);
List<GridElement> elements = actualSelector.getSelectedElements();
if (elements.size() == 1) {
String absoluteLink = elements.get(0).getSetting(LinkFacet.LINK);
File link = new File(absoluteLink);
if (!link.isAbsolute()) {
String parentDir = new File(actualHandler.getFileHandler().getFullPathName()).getParent(); // relative paths are relative to the currently opened diagram
try {
absoluteLink = new File(parentDir + "/" + absoluteLink).getCanonicalFile().getAbsolutePath();
} catch (Exception ex) {
throw new RuntimeException("Cannot get link path", ex);
}
}
main.doOpen(absoluteLink);
}
}
}
Expand Down

0 comments on commit e4a736f

Please sign in to comment.