Explorar el Código

ensure default settings are always displayed in first position

Gildas hace 7 años
padre
commit
d80220ec37
Se han modificado 2 ficheros con 35 adiciones y 14 borrados
  1. 26 10
      extension/ui/bg/ui-menu.js
  2. 9 4
      extension/ui/bg/ui-options.js

+ 26 - 10
extension/ui/bg/ui-menu.js

@@ -110,15 +110,25 @@ singlefile.ui.menu = (() => {
 					title: browser.i18n.getMessage("menuSelectProfile"),
 					contexts: defaultContexts,
 				});
+				browser.menus.create({
+					id: MENU_ID_SELECT_PROFILE_PREFIX + "default",
+					type: "radio",
+					contexts: defaultContexts,
+					title: browser.i18n.getMessage("profileDefaultSettingsLabel"),
+					checked: tabsData.profileName == singlefile.config.DEFAULT_PROFILE_NAME,
+					parentId: MENU_ID_SELECT_PROFILE
+				});
 				Object.keys(config.profiles).forEach((profileName, profileIndex) => {
-					browser.menus.create({
-						id: MENU_ID_SELECT_PROFILE_PREFIX + profileIndex,
-						type: "radio",
-						contexts: defaultContexts,
-						title: profileName == singlefile.config.DEFAULT_PROFILE_NAME ? browser.i18n.getMessage("profileDefaultSettingsLabel") : profileName,
-						checked: tabsData.profileName ? tabsData.profileName == profileName : profileName == singlefile.config.DEFAULT_PROFILE_NAME,
-						parentId: MENU_ID_SELECT_PROFILE
-					});
+					if (profileName != singlefile.config.DEFAULT_PROFILE_NAME) {
+						browser.menus.create({
+							id: MENU_ID_SELECT_PROFILE_PREFIX + profileIndex,
+							type: "radio",
+							contexts: defaultContexts,
+							title: profileName,
+							checked: tabsData.profileName == profileName,
+							parentId: MENU_ID_SELECT_PROFILE
+						});
+					}
 				});
 			}
 			browser.menus.create({
@@ -216,9 +226,15 @@ singlefile.ui.menu = (() => {
 				}
 				if (event.menuItemId.startsWith(MENU_ID_SELECT_PROFILE_PREFIX)) {
 					const [config, tabsData] = await Promise.all([singlefile.config.get(), singlefile.tabsData.get()]);
-					const profileIndex = Number(event.menuItemId.split(MENU_ID_SELECT_PROFILE_PREFIX)[1]);
-					tabsData.profileName = Object.keys(config.profiles)[profileIndex];
+					const profileId = event.menuItemId.split(MENU_ID_SELECT_PROFILE_PREFIX)[1];
+					if (profileId == "default") {
+						tabsData.profileName = singlefile.core.DEFAULT_PROFILE_NAME;
+					} else {
+						const profileIndex = Number(profileId);
+						tabsData.profileName = Object.keys(config.profiles)[profileIndex];
+					}
 					await singlefile.tabsData.set(tabsData);
+					refresh();
 					refreshExternalComponents(tab.id, { autoSave: tabsData.autoSaveAll || tabsData.autoSaveUnpinned || (tabsData[tab.id] && tabsData[tab.id].autoSave) });
 				}
 			});

+ 9 - 4
extension/ui/bg/ui-options.js

@@ -243,11 +243,16 @@
 		profileNamesInput.childNodes.forEach(node => node.remove());
 		const profileNames = Object.keys(options.profiles);
 		profileNamesInput.options.length = 0;
+		const optionElement = document.createElement("option");
+		optionElement.value = singlefile.config.DEFAULT_PROFILE_NAME;
+		optionElement.textContent = browser.i18n.getMessage("profileDefaultSettingsLabel");
+		profileNamesInput.appendChild(optionElement);
 		profileNames.forEach(profileName => {
-			const optionElement = document.createElement("option");
-			optionElement.value = profileName;
-			optionElement.textContent = profileName == singlefile.config.DEFAULT_PROFILE_NAME ? browser.i18n.getMessage("profileDefaultSettingsLabel") : profileName;
-			profileNamesInput.appendChild(optionElement);
+			if (profileName != singlefile.config.DEFAULT_PROFILE_NAME) {
+				const optionElement = document.createElement("option");
+				optionElement.value = optionElement.textContent = profileName;
+				profileNamesInput.appendChild(optionElement);
+			}
 		});
 		profileNamesInput.value = selectedProfileName;
 		renameProfileButton.disabled = deleteProfileButton.disabled = profileNamesInput.value == singlefile.config.DEFAULT_PROFILE_NAME;