Skip to content

Commit

Permalink
add: action name
Browse files Browse the repository at this point in the history
  • Loading branch information
windingwind committed Sep 15, 2023
1 parent b870c45 commit 0f57d9e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 8 deletions.
1 change: 1 addition & 0 deletions addon/locale/en-US/addon.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
prefs-title = Actions & Tags
prefs-rule-name = Name
prefs-rule-event = Event
prefs-rule-operation = Operation
prefs-rule-data = Data
Expand Down
1 change: 1 addition & 0 deletions addon/locale/zh-CN/addon.ftl
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
prefs-title = Actions & Tags
prefs-rule-name = 名称
prefs-rule-event = 事件
prefs-rule-operation = 操作
prefs-rule-data = 数据
Expand Down
33 changes: 28 additions & 5 deletions src/modules/preferenceWindow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,16 @@ async function initUI() {
if (!isWindowAlive(addon.data.prefs.window)) return;
updateCachedActionKeys();
addon.data.prefs.tableHelper = new ztoolkit.VirtualizedTable(
addon.data.prefs.window!,
addon.data.prefs.window!
)
.setContainerId(`${config.addonRef}-table-container`)
.setProp({
id: `${config.addonRef}-prefs-table`,
columns: [
{
dataKey: "name",
label: getString("prefs-rule-name"),
},
{
dataKey: "event",
label: getString("prefs-rule-event"),
Expand Down Expand Up @@ -165,12 +169,13 @@ function getRowData(index: number) {
return {
event: getString(`prefs-rule-event-${ActionEventTypes[action.event]}`),
operation: getString(
`prefs-rule-operation-${ActionOperationTypes[action.operation]}`,
`prefs-rule-operation-${ActionOperationTypes[action.operation]}`
),
data: action.data,
shortcut: action.shortcut,
enabled: action.enabled,
menu: action.menu || "❌",
name: action.name || "",
};
}

Expand Down Expand Up @@ -198,6 +203,23 @@ async function editAction(currentKey?: string) {
columnGap: "5px",
},
children: [
{
tag: "label",
namespace: "html",
properties: {
textContent: getString("prefs-rule-name"),
},
},
{
tag: "input",
attributes: {
"data-bind": "name",
"data-prop": "value",
},
styles: {
width: "fit-content",
},
},
{
tag: "label",
namespace: "html",
Expand Down Expand Up @@ -286,7 +308,7 @@ async function editAction(currentKey?: string) {
const content = await openEditorWindow(dialogData.data);
(
dialog.window.document.querySelector(
"#data-input",
"#data-input"
) as HTMLTextAreaElement
).value = content;
dialogData.data = content;
Expand Down Expand Up @@ -320,7 +342,7 @@ async function editAction(currentKey?: string) {
const key = ev.target as HTMLElement;
const win = dialog.window;
key.textContent = `[${getString(
"prefs-rule-edit-shortcut-placeholder",
"prefs-rule-edit-shortcut-placeholder"
)}]`;
dialogData.shortcut = "";
const keyDownListener = (e: KeyboardEvent) => {
Expand Down Expand Up @@ -414,6 +436,7 @@ async function editAction(currentKey?: string) {
shortcut: dialogData.shortcut.replace(/\[(.*?)\]/g, ""),
enabled: dialogData.enabled,
menu: dialogData.menu,
name: dialogData.name,
});
updateUI();
}
Expand All @@ -430,7 +453,7 @@ async function openEditorWindow(content: string) {
const editorWin = addon.data.prefs.window?.openDialog(
"chrome://scaffold/content/monaco/monaco.html",
"monaco",
"chrome,centerscreen,dialog=no,resizable,scrollbars=yes,width=800,height=600",
"chrome,centerscreen,dialog=no,resizable,scrollbars=yes,width=800,height=600"
) as
| (Window & {
loadMonaco: (options: Record<string, any>) => Promise<{ editor: any }>;
Expand Down
10 changes: 7 additions & 3 deletions src/utils/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ interface ActionData<T extends ActionOperationTypes = ActionOperationTypes> {
shortcut?: string;
enabled?: boolean;
menu?: string;
name?: string;
}

const defaultActions: ActionMap = new Map([
[
"default0",
{
name: "Add Unread When Create Item",
event: ActionEventTypes.createItem,
operation: ActionOperationTypes.add,
data: "/unread",
Expand All @@ -62,6 +64,7 @@ const defaultActions: ActionMap = new Map([
[
"default1",
{
name: "Remove Unread When Close Tab",
event: ActionEventTypes.closeTab,
operation: ActionOperationTypes.remove,
data: "/unread",
Expand All @@ -78,6 +81,7 @@ const emptyAction: ActionData = {
shortcut: "",
enabled: true,
menu: "",
name: "",
};

type ActionMap = Map<string, ActionData>;
Expand All @@ -91,7 +95,7 @@ function initActions() {
addon.data.actions.map = new ztoolkit.LargePref(
`${config.prefsPrefix}.rules`,
`${config.prefsPrefix}.rules.`,
"parser",
"parser"
).asMapLike() as ActionMap;
if (!getPref("rulesInit")) {
for (const key of defaultActions.keys()) {
Expand Down Expand Up @@ -132,7 +136,7 @@ async function applyAction(rule: ActionData, data: ActionDataData) {
item?.removeTag(tag);
}
message = `Remove tag ${tags.join(",")} from item ${item?.getField(
"title",
"title"
)}`;
break;
}
Expand All @@ -145,7 +149,7 @@ async function applyAction(rule: ActionData, data: ActionDataData) {
}
}
message = `Toggle tag ${tags.join(",")} to item ${item?.getField(
"title",
"title"
)}`;
break;
}
Expand Down

0 comments on commit 0f57d9e

Please sign in to comment.