# HG changeset patch # User MakeMyDay # Date 1514491258 -3600 # Do Dez 28 21:00:58 2017 +0100 # Node ID bcd1094e527e71632ff89d2c3b43e51a18c7e6a9 # Parent a9cb3d74581aa4cffe107af13f2b0fc482ff2a50 Bug 719351 - Prompt for a target calendar when pasting an event. r=philipp diff --git a/calendar/base/content/calendar-clipboard.js b/calendar/base/content/calendar-clipboard.js --- a/calendar/base/content/calendar-clipboard.js +++ b/calendar/base/content/calendar-clipboard.js @@ -1,28 +1,38 @@ /* 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/. */ +Components.utils.import("resource://gre/modules/Preferences.jsm"); Components.utils.import("resource://gre/modules/Services.jsm"); Components.utils.import("resource://calendar/modules/calUtils.jsm"); /* exported cutToClipboard, pasteFromClipboard */ /** * Test if a writable calendar is selected, and if the clipboard has items that * can be pasted into Calendar. The data must be of type "text/calendar" or * "text/unicode". * * @return If true, pasting is currently possible. */ function canPaste() { - let selectedCal = getSelectedCalendar(); - if (!selectedCal || !cal.isCalendarWritable(selectedCal)) { - return false; + if (Preferences.get("calendar.paste.intoSelectedCalendar", false)) { + let selectedCal = getSelectedCalendar(); + if (!selectedCal || !cal.isCalendarWritable(selectedCal)) { + return false; + } + } else { + let calendars = cal.getCalendarManager().getCalendars({}) + .filter(cal.isCalendarWritable) + .filter(cal.userCanAddItemsToCalendar); + if (!calendars.length) { + return false; + } } const flavors = ["text/calendar", "text/unicode"]; return Services.clipboard.hasDataMatchingFlavors(flavors, flavors.length, Components.interfaces.nsIClipboard.kGlobalClipboard); } @@ -122,17 +132,34 @@ function pasteFromClipboard() { // Ask transferable for the best flavor. let flavor = {}; let data = {}; trans.getAnyTransferData(flavor, data, {}); data = data.value.QueryInterface(Components.interfaces.nsISupportsString).data; switch (flavor.value) { case "text/calendar": case "text/unicode": { - let destCal = getSelectedCalendar(); + let destCal = null; + if (Preferences.get("calendar.paste.intoSelectedCalendar", false)) { + destCal = getSelectedCalendar(); + } else { + let calendars = cal.getCalendarManager().getCalendars({}) + .filter(cal.isCalendarWritable) + .filter(cal.userCanAddItemsToCalendar); + if (calendars.length > 1) { + let args = {}; + args.calendars = calendars; + args.onOk = (aCal) => { destCal = aCal; }; + args.promptText = cal.calGetString("calendar", "pastePrompt"); + window.openDialog("chrome://calendar/content/chooseCalendarDialog.xul", + "_blank", "chrome,titlebar,modal,resizable", args); + } else if (calendars.length == 1) { + destCal = calendars[0]; + } + } if (!destCal) { return; } let icsParser = Components.classes["@mozilla.org/calendar/ics-parser;1"] .createInstance(Components.interfaces.calIIcsParser); try { icsParser.parseString(data); diff --git a/calendar/lightning/content/lightning.js b/calendar/lightning/content/lightning.js --- a/calendar/lightning/content/lightning.js +++ b/calendar/lightning/content/lightning.js @@ -154,16 +154,19 @@ pref("calendar.view.showTodayPaneStatusL pref("calendar.filter.maxiterations", 50); // Edit events and tasks in a tab rather than a window. pref("calendar.item.editInTab", false); // Edit events and tasks in the new (HTML-based) UI for tabs and windows pref("calendar.item.useNewItemUI", false); +// Always use the currently selected calendar as target for paste operations +pref("calendar.paste.intoSelectedCalendar", false); + // Backend to use. false: libical, true: ical.js #ifdef NIGHTLY_BUILD pref("calendar.icaljs", true); #else pref("calendar.icaljs", false); #endif // Calendar integration notification diff --git a/calendar/locales/en-US/chrome/calendar/calendar.properties b/calendar/locales/en-US/chrome/calendar/calendar.properties --- a/calendar/locales/en-US/chrome/calendar/calendar.properties +++ b/calendar/locales/en-US/chrome/calendar/calendar.properties @@ -46,16 +46,17 @@ statusCompleted =Completed # Task priority, these should match the priority.level.* labels in calendar.dtd highPriority=High normalPriority=Normal lowPriority=Low importPrompt=Which calendar do you want to import these items into? exportPrompt=Which calendar do you want to export from? +pastePrompt=Which of your currently writable calendars do you want to paste into? publishPrompt=Which calendar do you want to publish? # LOCALIZATION NOTE (importItemsFailed): # %1$S will be replaced with number of failed items # %2$S will be replaced with last error code / error string importItemsFailed=%1$S items failed to import. The last error was: %2$S # LOCALIZATION NOTE (noItemsInCalendarFile): # %1$S will be replaced with file path