Skip to content

Commit 26efcb3

Browse files
committed
Robot's action tokens
1 parent 7f822d7 commit 26efcb3

File tree

1 file changed

+21
-13
lines changed
  • logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/robot

1 file changed

+21
-13
lines changed

logicaldoc-gui/src/main/java/com/logicaldoc/gui/frontend/client/ai/robot/MessageBox.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.logicaldoc.gui.common.client.util.AwesomeFactory;
88
import com.logicaldoc.gui.common.client.util.Util;
99
import com.logicaldoc.gui.frontend.client.document.DocumentsPanel;
10+
import com.logicaldoc.gui.frontend.client.folder.FolderNavigator;
1011
import com.smartgwt.client.types.Alignment;
1112
import com.smartgwt.client.widgets.Label;
1213

@@ -18,9 +19,9 @@
1819
*/
1920
class MessageBox extends Label {
2021

21-
private static final String CMD_END = "]cmd]";
22+
private static final String ACT_END = "]act]";
2223

23-
private static final String CMD_START = "[cmd[";
24+
private static final String ACT_START = "[act[";
2425

2526
private static final String ROBOT = "robot";
2627

@@ -66,33 +67,33 @@ private String prepareContent(String message) {
6667
@Override
6768
protected void onInit() {
6869
super.onInit();
69-
declareCommandOpenDocument(DocumentsPanel.get());
70+
declareOpenDocument(DocumentsPanel.get());
7071
}
7172

7273
protected boolean isRobotAnswer() {
7374
return ROBOT.equals(role);
7475
}
7576

7677
/**
77-
* Processes the answer looking for command tokens like
78-
* [cmd[<b>command</b>|<b>arg1</b>|<b>arg2</b>]cmd] and replace them with
78+
* Processes the answer looking for action tokens like
79+
* [act[<b>command</b>|<b>arg1</b>|<b>arg2</b>]act] and replace them with
7980
* proper rendering.
8081
*
8182
* @param message The original message from the robot
8283
*
8384
* @return The elaborated messages with command tokens expanded
8485
*/
8586
private String parseRobotAnswer(String message) {
86-
RegExp p = RegExp.compile("\\[cmd\\[[a-zA-Z]*\\|.*\\|.*\\]cmd\\]");
87+
RegExp p = RegExp.compile("\\[act\\[[a-zA-Z]*\\|.*\\|.*\\]act\\]");
8788
MatchResult result = p.exec(message);
8889

8990
if (result != null) {
9091
for (int i = 0; i < result.getGroupCount(); i++) {
9192
String match = result.getGroup(i);
92-
match = match.replace(CMD_START, "");
93-
match = match.replace(CMD_END, "");
93+
match = match.replace(ACT_START, "");
94+
match = match.replace(ACT_END, "");
9495
String link = processCommand(match.split("\\|"));
95-
message = message.replace(CMD_START + match + CMD_END, link);
96+
message = message.replace(ACT_START + match + ACT_END, link);
9697
}
9798
}
9899

@@ -101,8 +102,8 @@ private String parseRobotAnswer(String message) {
101102

102103
private String processCommand(String[] args) {
103104
String command = args[0];
104-
String link = "<a href='javascript:cmd" + command + "(";
105-
if ("OpenDocument".equals(command)) {
105+
String link = "<a style='cursor: pointer' onclick='act" + command + "(";
106+
if ("OpenDocument".equals(command) || "OpenFolder".equals(command)) {
106107
link += args[1] + ");'>" + args[2] + "</a>";
107108
}
108109
return link;
@@ -126,9 +127,16 @@ public int hashCode() {
126127
}
127128

128129
@UnsafeNativeLong
129-
public static native void declareCommandOpenDocument(DocumentsPanel panel) /*-{
130-
$wnd.cmdOpenDocument = function(docId) {
130+
public static native void declareOpenDocument(DocumentsPanel panel) /*-{
131+
$wnd.actOpenDocument = function(docId) {
131132
return panel.@com.logicaldoc.gui.frontend.client.document.DocumentsPanel::openInFolder(J)(docId);
132133
};
133134
}-*/;
135+
136+
@UnsafeNativeLong
137+
public static native void declareOpenFolder(FolderNavigator navigator) /*-{
138+
$wnd.actOpenFolder = function(folderId) {
139+
return navigator.@com.logicaldoc.gui.frontend.client.folder.FolderNavigator::openFolder(J)(folderId);
140+
};
141+
}-*/;
134142
}

0 commit comments

Comments
 (0)