correctly loading menus
This commit is contained in:
parent
b19349a0de
commit
9fd14b1276
3 changed files with 21 additions and 8 deletions
|
|
@ -339,7 +339,7 @@ function checkSelectedBoxes(checkboxes = null) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//Save all prompts
|
//Save all prompts
|
||||||
function saveAll() { //TODO
|
async function saveAll() {
|
||||||
somethingChanged = false;
|
somethingChanged = false;
|
||||||
if(promptsList != null) {
|
if(promptsList != null) {
|
||||||
promptsList.reIndex();
|
promptsList.reIndex();
|
||||||
|
|
@ -354,8 +354,9 @@ function saveAll() { //TODO
|
||||||
let newDefaultPrompts = newPrompts.filter(item => item.is_default == 1);
|
let newDefaultPrompts = newPrompts.filter(item => item.is_default == 1);
|
||||||
console.log('>>>>>>>>>>>>> newDefaultPrompts: ' + JSON.stringify(newDefaultPrompts));
|
console.log('>>>>>>>>>>>>> newDefaultPrompts: ' + JSON.stringify(newDefaultPrompts));
|
||||||
let newCustomPrompts = newPrompts.filter(item => item.is_default == 0);
|
let newCustomPrompts = newPrompts.filter(item => item.is_default == 0);
|
||||||
setDefaultPromptsProperties(newDefaultPrompts);
|
await setDefaultPromptsProperties(newDefaultPrompts);
|
||||||
setCustomPrompts(newCustomPrompts);
|
await setCustomPrompts(newCustomPrompts);
|
||||||
|
browser.runtime.sendMessage({command: "reload_menus"});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,12 @@ export class mzta_Menus {
|
||||||
//this.addMenu(this.rootMenu);
|
//this.addMenu(this.rootMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async reload(){
|
||||||
|
this.rootMenu = [];
|
||||||
|
await this.initialize();
|
||||||
|
this.loadMenus();
|
||||||
|
}
|
||||||
|
|
||||||
addAction = (curr_prompt) => {
|
addAction = (curr_prompt) => {
|
||||||
|
|
||||||
let curr_menu_entry = {id: curr_prompt.id };
|
let curr_menu_entry = {id: curr_prompt.id };
|
||||||
|
|
@ -129,7 +135,7 @@ export class mzta_Menus {
|
||||||
|
|
||||||
browser.menus.create({
|
browser.menus.create({
|
||||||
id: id,
|
id: id,
|
||||||
title: this.getCustomTextAttribute(id) + browser.i18n.getMessage(id),
|
title: this.getCustomTextAttribute(id) + (browser.i18n.getMessage(id) || id),
|
||||||
contexts: this.getContexts(id),
|
contexts: this.getContexts(id),
|
||||||
parentId: root
|
parentId: root
|
||||||
});
|
});
|
||||||
|
|
@ -146,16 +152,18 @@ export class mzta_Menus {
|
||||||
};
|
};
|
||||||
|
|
||||||
getContexts(id){
|
getContexts(id){
|
||||||
|
console.log(">>>>>>>>> id: " + id);
|
||||||
const curr_prompt = this.allPrompts.find(p => p.id === id);
|
const curr_prompt = this.allPrompts.find(p => p.id === id);
|
||||||
|
console.log(">>>>>>>>>> curr_prompt: " + JSON.stringify(curr_prompt));
|
||||||
if (!curr_prompt) {
|
if (!curr_prompt) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
switch(curr_prompt.type){
|
switch(curr_prompt.type){
|
||||||
case 0:
|
case "0": console.log(">>>>>>>>>> curr_prompt.type: " + curr_prompt.type);
|
||||||
return [this.menu_context_compose, this.menu_context_display];
|
return [this.menu_context_compose, this.menu_context_display];
|
||||||
case 1:
|
case "1":
|
||||||
return [this.menu_context_display];
|
return [this.menu_context_display];
|
||||||
case 2:
|
case "2":
|
||||||
return [this.menu_context_compose];
|
return [this.menu_context_compose];
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
|
|
@ -168,7 +176,7 @@ export class mzta_Menus {
|
||||||
if (!curr_prompt) {
|
if (!curr_prompt) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
if(curr_prompt.need_custom_text === 1){
|
if(curr_prompt.need_custom_text === "1"){
|
||||||
return "*";
|
return "*";
|
||||||
}else{
|
}else{
|
||||||
return "";
|
return "";
|
||||||
|
|
|
||||||
|
|
@ -113,6 +113,10 @@ messenger.runtime.onMessage.addListener(async (message, sender, sendResponse) =>
|
||||||
await setBody(message.tabId, original_html);
|
await setBody(message.tabId, original_html);
|
||||||
await setBody(message.tabId, modified_html);
|
await setBody(message.tabId, modified_html);
|
||||||
break;
|
break;
|
||||||
|
case 'reload_menus':
|
||||||
|
await mzta_Menus.reload();
|
||||||
|
console.log('>>>>>>>>>>>>>>>>> Reloaded menus');
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue