From c3ee54f07c0dbbcafab0d954561d41f8d0f1becf Mon Sep 17 00:00:00 2001 From: Andrea Marchesini Date: Wed, 20 Jan 2016 09:16:49 +0000 Subject: [PATCH] Bug 1239848 - Revert ProfileManager changes until a better UX/UI is ready, r=ehsan --- toolkit/content/aboutProfiles.js | 50 +--- .../chrome/global/aboutProfiles.properties | 1 - .../mozapps/profile/profileSelection.dtd | 20 ++ .../profile/profileSelection.properties | 19 +- toolkit/profile/content/profileSelection.js | 220 ++++++++++++++++-- toolkit/profile/content/profileSelection.xul | 41 +++- toolkit/themes/osx/mozapps/jar.mn | 1 + .../osx/mozapps/profile/profileSelection.css | 29 +++ toolkit/themes/shared/non-mac.jar.inc.mn | 1 + .../mozapps/profile/profileSelection.css | 25 ++ 10 files changed, 338 insertions(+), 69 deletions(-) create mode 100644 toolkit/themes/osx/mozapps/profile/profileSelection.css create mode 100644 toolkit/themes/windows/mozapps/profile/profileSelection.css diff --git a/toolkit/content/aboutProfiles.js b/toolkit/content/aboutProfiles.js index c0ec5036236..6f3cc1f995d 100644 --- a/toolkit/content/aboutProfiles.js +++ b/toolkit/content/aboutProfiles.js @@ -17,8 +17,6 @@ XPCOMUtils.defineLazyServiceGetter( 'nsIToolkitProfileService' ); -const gManage = window.location.href.indexOf('?manage') != -1; - const bundle = Services.strings.createBundle( 'chrome://global/locale/aboutProfiles.properties'); @@ -54,24 +52,8 @@ function findCurrentProfile() { } function initializeUI() { - if (gManage) { - document.getElementById('about-profile-action-box').style.display = 'none'; - document.getElementById('profile-manager-action-box').style.display = 'block'; - - let autoSelect = document.getElementById("auto-select"); - autoSelect.checked = ProfileService.startWithLastProfile; - autoSelect.addEventListener('change', function() { - ProfileService.startWithLastProfile = autoSelect.checked; - }); - - let offline = document.getElementById("work-offline"); - offline.addEventListener('change', function() { - ProfileService.startOffline = offline.checked; - }); - } else { - document.getElementById('about-profile-action-box').style.display = 'block'; - document.getElementById('profile-manager-action-box').style.display = 'none'; - } + document.getElementById('about-profile-action-box').style.display = 'block'; + document.getElementById('profile-manager-action-box').style.display = 'none'; refreshUI(); } @@ -122,33 +104,11 @@ function display(profileData) { let nameStr = bundle.formatStringFromName('name', [profileData.profile.name], 1); let name = document.createElement('h2'); - - if (gManage) { - let checkBox = document.createElement('input'); - checkBox.setAttribute('type', 'radio'); - checkBox.setAttribute('name', 'profile'); - checkBox.setAttribute('id', profileData.profile.name); - if (profileData.isCurrentProfile) { - checkBox.setAttribute('checked', 'checked'); - } - name.appendChild(checkBox); - - checkBox.addEventListener('change', function() { - ProfileService.selectedProfile = profileData.profile; - ProfileService.flush(); - }); - - let label = document.createElement('label'); - label.appendChild(document.createTextNode(nameStr)); - label.setAttribute('for', profileData.profile.name); - name.appendChild(label); - } else { - name.appendChild(document.createTextNode(nameStr)); - } + name.appendChild(document.createTextNode(nameStr)); div.appendChild(name); - if (!gManage && profileData.isCurrentProfile) { + if (profileData.isCurrentProfile) { let currentProfile = document.createElement('h3'); let currentProfileStr = bundle.GetStringFromName('currentProfile'); currentProfile.appendChild(document.createTextNode(currentProfileStr)); @@ -209,7 +169,7 @@ function display(profileData) { }; div.appendChild(renameButton); - if (gManage || !profileData.isCurrentProfile) { + if (!profileData.isCurrentProfile) { let removeButton = document.createElement('button'); removeButton.appendChild(document.createTextNode(bundle.GetStringFromName('remove'))); removeButton.onclick = function() { diff --git a/toolkit/locales/en-US/chrome/global/aboutProfiles.properties b/toolkit/locales/en-US/chrome/global/aboutProfiles.properties index 69a78c29177..7b335ffba48 100644 --- a/toolkit/locales/en-US/chrome/global/aboutProfiles.properties +++ b/toolkit/locales/en-US/chrome/global/aboutProfiles.properties @@ -17,7 +17,6 @@ currentProfile = This is the profile in use and it cannot be deleted. rename = Rename remove = Remove setAsDefault = Set as default profile -open = Open yes = yes no = no diff --git a/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.dtd b/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.dtd index 535f47873d3..87741a82e6a 100644 --- a/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.dtd +++ b/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.dtd @@ -7,5 +7,25 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties b/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties index c3453a8de85..adac95a3351 100644 --- a/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties +++ b/toolkit/locales/en-US/chrome/mozapps/profile/profileSelection.properties @@ -13,13 +13,30 @@ restartMessageNoUnlockerMac=A copy of %S is already open. Only one copy of %S ca restartMessageUnlockerMac=A copy of %S is already open. The running copy of %S will quit in order to open this one. # Profile manager +# LOCALIZATION NOTE (profileTooltip): First %S is the profile name, second %S is the path to the profile folder. +profileTooltip=Profile: '%S' - Path: '%S' + +pleaseSelectTitle=Select Profile +pleaseSelect=Please select a profile to begin %S, or create a new profile. + profileLockedTitle=Profile In Use profileLocked2=%S cannot use the profile "%S" because it is in use.\n\nTo continue, close the running instance of %S or choose a different profile. +renameProfileTitle=Rename Profile +renameProfilePrompt=Rename the profile "%S" to: + +profileNameInvalidTitle=Invalid profile name +profileNameInvalid=The profile name "%S" is not allowed. + chooseFolder=Choose Profile Folder profileNameEmpty=An empty profile name is not allowed. invalidChar=The character "%S" is not allowed in profile names. Please choose a different name. +deleteTitle=Delete Profile +deleteProfileConfirm=Deleting a profile will remove the profile from the list of available profiles and cannot be undone.\nYou may also choose to delete the profile data files, including your settings, certificates and other user-related data. This option will delete the folder "%S" and cannot be undone.\nWould you like to delete the profile data files? +deleteFiles=Delete Files +dontDeleteFiles=Don't Delete Files + profileCreationFailed=Profile couldn't be created. Probably the chosen folder isn't writable. profileCreationFailedTitle=Profile Creation failed profileExists=A profile with this name already exists. Please choose another name. @@ -28,8 +45,6 @@ profileFinishText=Click Finish to create this new profile. profileFinishTextMac=Click Done to create this new profile. profileMissing=Your %S profile cannot be loaded. It may be missing or inaccessible. profileMissingTitle=Profile Missing -pleaseSelectTitle=Select Profile -pleaseSelect=Please select a profile to begin %S, or create a new profile. # Profile reset # LOCALIZATION NOTE (resetBackupDirectory): Directory name for the profile directory backup created during reset. This directory is placed in a location users will see it (ie. their desktop). %S is the application name. diff --git a/toolkit/profile/content/profileSelection.js b/toolkit/profile/content/profileSelection.js index cf6d0eee448..1cbdf6e1321 100644 --- a/toolkit/profile/content/profileSelection.js +++ b/toolkit/profile/content/profileSelection.js @@ -4,10 +4,11 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -const {classes: Cc, interfaces: Ci, utils: Cu, results: Cr} = Components; +Components.utils.import("resource://gre/modules/AppConstants.jsm"); +Components.utils.import("resource://gre/modules/Services.jsm"); -Cu.import("resource://gre/modules/AppConstants.jsm"); -Cu.import("resource://gre/modules/Services.jsm"); +const C = Components.classes; +const I = Components.interfaces; const ToolkitProfileService = "@mozilla.org/toolkit/profile-service;1"; @@ -18,22 +19,57 @@ var gProfileService; function startup() { - gDialogParams = window.arguments[0].QueryInterface(Ci.nsIDialogParamBlock); + try { + gDialogParams = window.arguments[0]. + QueryInterface(I.nsIDialogParamBlock); - gProfileService = Cc[ToolkitProfileService].getService(Ci.nsIToolkitProfileService); + gProfileService = C[ToolkitProfileService].getService(I.nsIToolkitProfileService); - gProfileManagerBundle = document.getElementById("bundle_profileManager"); - gBrandBundle = document.getElementById("bundle_brand"); + gProfileManagerBundle = document.getElementById("bundle_profileManager"); + gBrandBundle = document.getElementById("bundle_brand"); - document.documentElement.centerWindowOnScreen(); - document.documentElement.getButton('accept').focus(); + document.documentElement.centerWindowOnScreen(); + + var profilesElement = document.getElementById("profiles"); + + var profileList = gProfileService.profiles; + while (profileList.hasMoreElements()) { + var profile = profileList.getNext().QueryInterface(I.nsIToolkitProfile); + + var listitem = profilesElement.appendItem(profile.name, ""); + + var tooltiptext = + gProfileManagerBundle.getFormattedString("profileTooltip", [profile.name, profile.rootDir.path]); + listitem.setAttribute("tooltiptext", tooltiptext); + listitem.setAttribute("class", "listitem-iconic"); + listitem.profile = profile; + try { + if (profile === gProfileService.selectedProfile) { + setTimeout(function(a) { + profilesElement.ensureElementIsVisible(a); + profilesElement.selectItem(a); + }, 0, listitem); + } + } + catch(e) { } + } + + var autoSelectLastProfile = document.getElementById("autoSelectLastProfile"); + autoSelectLastProfile.checked = gProfileService.startWithLastProfile; + profilesElement.focus(); + } + catch(e) { + window.close(); + throw (e); + } } function acceptDialog() { var appName = gBrandBundle.getString("brandShortName"); - var selectedProfile = gProfileService.selectedProfile; + var profilesElement = document.getElementById("profiles"); + var selectedProfile = profilesElement.selectedItem; if (!selectedProfile) { var pleaseSelectTitle = gProfileManagerBundle.getString("pleaseSelectTitle"); var pleaseSelect = @@ -46,10 +82,10 @@ function acceptDialog() var profileLock; try { - profileLock = selectedProfile.lock({ value: null }); + profileLock = selectedProfile.profile.lock({ value: null }); } catch (e) { - if (!selectedProfile.rootDir.exists()) { + if (!selectedProfile.profile.rootDir.exists()) { var missingTitle = gProfileManagerBundle.getString("profileMissingTitle"); var missing = gProfileManagerBundle.getFormattedString("profileMissing", [appName]); @@ -59,21 +95,175 @@ function acceptDialog() var lockedTitle = gProfileManagerBundle.getString("profileLockedTitle"); var locked = - gProfileManagerBundle.getFormattedString("profileLocked2", [appName, selectedProfile.name, appName]); + gProfileManagerBundle.getFormattedString("profileLocked2", [appName, selectedProfile.profile.name, appName]); Services.prompt.alert(window, lockedTitle, locked); return false; } - gDialogParams.objects.insertElementAt(profileLock.nsIProfileLock, 0, false); + gProfileService.selectedProfile = selectedProfile.profile; + gProfileService.defaultProfile = selectedProfile.profile; + updateStartupPrefs(); + gDialogParams.SetInt(0, 1); - gDialogParams.SetString(0, selectedProfile.name); + + gDialogParams.SetString(0, selectedProfile.profile.name); return true; } function exitDialog() { + updateStartupPrefs(); + + return true; +} + +function updateStartupPrefs() +{ + var autoSelectLastProfile = document.getElementById("autoSelectLastProfile"); + gProfileService.startWithLastProfile = autoSelectLastProfile.checked; + + /* Bug 257777 */ + gProfileService.startOffline = document.getElementById("offlineState").checked; +} + +// handle key event on listboxes +function onProfilesKey(aEvent) +{ + switch( aEvent.keyCode ) + { + case KeyEvent.DOM_VK_BACK_SPACE: + if (AppConstants.platform != "macosx") + break; + case KeyEvent.DOM_VK_DELETE: + ConfirmDelete(); + break; + case KeyEvent.DOM_VK_F2: + RenameProfile(); + break; + } +} + +function onProfilesDblClick(aEvent) +{ + if(aEvent.target.localName == "listitem") + document.documentElement.acceptDialog(); +} + +// invoke the createProfile Wizard +function CreateProfileWizard() +{ + window.openDialog('chrome://mozapps/content/profile/createProfileWizard.xul', + '', 'centerscreen,chrome,modal,titlebar', gProfileService); +} + +/** + * Called from createProfileWizard to update the display. + */ +function CreateProfile(aProfile) +{ + var profilesElement = document.getElementById("profiles"); + + var listitem = profilesElement.appendItem(aProfile.name, ""); + + var tooltiptext = + gProfileManagerBundle.getFormattedString("profileTooltip", [aProfile.name, aProfile.rootDir.path]); + listitem.setAttribute("tooltiptext", tooltiptext); + listitem.setAttribute("class", "listitem-iconic"); + listitem.profile = aProfile; + + profilesElement.ensureElementIsVisible(listitem); + profilesElement.selectItem(listitem); +} + +// rename the selected profile +function RenameProfile() +{ + var profilesElement = document.getElementById("profiles"); + var selectedItem = profilesElement.selectedItem; + if (!selectedItem) { + return false; + } + + var selectedProfile = selectedItem.profile; + + var oldName = selectedProfile.name; + var newName = {value: oldName}; + + var dialogTitle = gProfileManagerBundle.getString("renameProfileTitle"); + var msg = + gProfileManagerBundle.getFormattedString("renameProfilePrompt", [oldName]); + + if (Services.prompt.prompt(window, dialogTitle, msg, newName, null, {value:0})) { + newName = newName.value; + + // User hasn't changed the profile name. Treat as if cancel was pressed. + if (newName == oldName) + return false; + + try { + selectedProfile.name = newName; + } + catch (e) { + var alTitle = gProfileManagerBundle.getString("profileNameInvalidTitle"); + var alMsg = gProfileManagerBundle.getFormattedString("profileNameInvalid", [newName]); + Services.prompt.alert(window, alTitle, alMsg); + return false; + } + + selectedItem.label = newName; + var tiptext = gProfileManagerBundle. + getFormattedString("profileTooltip", + [newName, selectedProfile.rootDir.path]); + selectedItem.setAttribute("tooltiptext", tiptext); + + return true; + } + + return false; +} + +function ConfirmDelete() +{ + var deleteButton = document.getElementById("delbutton"); + var profileList = document.getElementById( "profiles" ); + + var selectedItem = profileList.selectedItem; + if (!selectedItem) { + return false; + } + + var selectedProfile = selectedItem.profile; + var deleteFiles = false; + + if (selectedProfile.rootDir.exists()) { + var dialogTitle = gProfileManagerBundle.getString("deleteTitle"); + var dialogText = + gProfileManagerBundle.getFormattedString("deleteProfileConfirm", + [selectedProfile.rootDir.path]); + + var buttonPressed = Services.prompt.confirmEx(window, dialogTitle, dialogText, + (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_0) + + (Services.prompt.BUTTON_TITLE_CANCEL * Services.prompt.BUTTON_POS_1) + + (Services.prompt.BUTTON_TITLE_IS_STRING * Services.prompt.BUTTON_POS_2), + gProfileManagerBundle.getString("dontDeleteFiles"), + null, + gProfileManagerBundle.getString("deleteFiles"), + null, {value:0}); + if (buttonPressed == 1) + return false; + + if (buttonPressed == 2) + deleteFiles = true; + } + + selectedProfile.remove(deleteFiles); + profileList.removeChild(selectedItem); + if (profileList.firstChild != undefined) { + profileList.selectItem(profileList.firstChild); + } + return true; } diff --git a/toolkit/profile/content/profileSelection.xul b/toolkit/profile/content/profileSelection.xul index 872cb0670a4..e5dfabb42d7 100644 --- a/toolkit/profile/content/profileSelection.xul +++ b/toolkit/profile/content/profileSelection.xul @@ -1,4 +1,4 @@ - + - + @@ -17,12 +17,12 @@ - + &pmDescription.label; + + + + + + diff --git a/toolkit/themes/osx/mozapps/jar.mn b/toolkit/themes/osx/mozapps/jar.mn index 997355f5b13..11b0ca8925f 100644 --- a/toolkit/themes/osx/mozapps/jar.mn +++ b/toolkit/themes/osx/mozapps/jar.mn @@ -48,6 +48,7 @@ toolkit.jar: skin/classic/mozapps/plugins/pluginGeneric-16.png (plugins/pluginGeneric-16.png) skin/classic/mozapps/plugins/pluginHelp-16.png (plugins/pluginHelp-16.png) skin/classic/mozapps/profile/profileicon.png (profile/profileicon.png) + skin/classic/mozapps/profile/profileSelection.css (profile/profileSelection.css) skin/classic/mozapps/profile/profileicon-selected.png (profile/profileicon-selected.png) skin/classic/mozapps/update/buttons.png (update/buttons.png) * skin/classic/mozapps/update/updates.css (update/updates.css) diff --git a/toolkit/themes/osx/mozapps/profile/profileSelection.css b/toolkit/themes/osx/mozapps/profile/profileSelection.css new file mode 100644 index 00000000000..cc3ab451c7a --- /dev/null +++ b/toolkit/themes/osx/mozapps/profile/profileSelection.css @@ -0,0 +1,29 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +@import url("chrome://global/skin/global.css"); + +@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); + +#profiles > listitem { + list-style-image: url("chrome://mozapps/skin/profile/profileicon.png"); +} + +#profiles:focus > listitem[selected="true"] { + list-style-image: url("chrome://mozapps/skin/profile/profileicon-selected.png"); +} + +#profiles > listitem > listcell > image { + width: 16px; + height: 16px; +} + +box#managebuttons > button { + min-width: 8em; +} + +#managebuttons { + padding-top: 1em; +} diff --git a/toolkit/themes/shared/non-mac.jar.inc.mn b/toolkit/themes/shared/non-mac.jar.inc.mn index a3d1ae46458..ab3ad7f08c6 100644 --- a/toolkit/themes/shared/non-mac.jar.inc.mn +++ b/toolkit/themes/shared/non-mac.jar.inc.mn @@ -155,6 +155,7 @@ #endif skin/classic/mozapps/plugins/pluginBlocked-64.png (../../windows/mozapps/plugins/pluginBlocked-64.png) skin/classic/mozapps/plugins/pluginHelp-16.png (../../windows/mozapps/plugins/pluginHelp-16.png) + skin/classic/mozapps/profile/profileSelection.css (../../windows/mozapps/profile/profileSelection.css) skin/classic/mozapps/update/downloadButtons.png (../../windows/mozapps/update/downloadButtons.png) * skin/classic/mozapps/xpinstall/xpinstallConfirm.css (../../windows/mozapps/extensions/xpinstallConfirm.css) diff --git a/toolkit/themes/windows/mozapps/profile/profileSelection.css b/toolkit/themes/windows/mozapps/profile/profileSelection.css new file mode 100644 index 00000000000..7e9495d00a9 --- /dev/null +++ b/toolkit/themes/windows/mozapps/profile/profileSelection.css @@ -0,0 +1,25 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + + +@import url("chrome://global/skin/global.css"); + +@namespace url("http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"); + +#profiles > listitem { + list-style-image: url("chrome://mozapps/skin/profile/profileicon.png"); +} + +#profiles > listitem > listcell > image { + width: 16px; + height: 16px; +} + +box#managebuttons > button { + min-width: 8em; +} + +#managebuttons { + padding-top: 1em; +}