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