1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is BlueGriffon.
16 * The Initial Developer of the Original Code is
17 * Disruptive Innovations SARL.
18 * Portions created by the Initial Developer are Copyright (C) 2006
19 * the Initial Developer. All Rights Reserved.
22 * Daniel Glazman <daniel.glazman@disruptive-innovations.com>, Original author
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 var RecentPagesHandler = {
40 appendRecentMenuitem: function(menupopup, title, url, menuIndex)
44 var menuItem = document.createElement("menuitem");
49 accessKey = String(menuIndex);
50 else if (menuIndex == 10)
55 var itemString = accessKey+" ";
57 // Show "title [url]" or just the URL
67 menuItem.setAttribute("label", itemString);
68 menuItem.setAttribute("crop", "center");
69 menuItem.setAttribute("value", url);
71 menuItem.setAttribute("accesskey", accessKey);
72 menupopup.appendChild(menuItem);
77 buildRecentPagesMenu: function()
79 var editor = EditorUtils.getCurrentEditor();
83 var popup = gDialog["menupopup_RecentFiles"];
87 // Delete existing menu
88 while (popup.firstChild)
89 popup.removeChild(popup.firstChild);
91 // Current page is the "0" item in the list we save in prefs,
92 // but we don't include it in the menu.
95 curUrl = UrlUtils.stripPassword(EditorUtils.getDocumentUrl());
96 var historyCount = 10;
98 historyCount = GetPrefs().getIntPref("bluegriffon.history.url_maximum");
102 for (var i = 0; i < historyCount; i++)
104 var url = GetUnicharPref("bluegriffon.history_url_"+i);
106 // Skip over current url
107 if (url && url != curUrl)
110 var title = GetUnicharPref("bluegriffon.history_title_"+i);
111 this.appendRecentMenuitem(popup, title, url, menuIndex);
117 saveRecentFilesPrefs: function()
119 // Can't do anything if no prefs
123 var curUrl = UrlUtils.stripPassword(EditorUtils.getDocumentUrl());
126 var historyCount = 10;
128 historyCount = GetPrefs().getIntPref("bluegriffon.history.url_maximum");
134 // XXX code below is suspect...
136 !UrlUtils.isUrlAboutBlank(curUrl) &&
137 UrlUtils.getScheme(curUrl) != "data")
139 titleArray.push(EditorUtils.getDocumentTitle());
140 urlArray.push(curUrl);
143 for (var i = 0; i < historyCount && urlArray.length < historyCount; i++)
145 var url = GetUnicharPref("bluegriffon.history_url_"+i);
147 // Continue if URL pref is missing because
148 // a URL not found during loading may have been removed
150 // Skip over current an "data" URLs
151 if (url && url != curUrl && UrlUtils.getScheme(url) != "data")
153 var title = GetUnicharPref("bluegriffon.history_title_"+i);
154 titleArray.push(title);
159 // Resave the list back to prefs in the new order
160 for (i = 0; i < urlArray.length; i++)
162 SetUnicharPref("bluegriffon.history_title_"+i, titleArray[i]);
163 SetUnicharPref("bluegriffon.history_url_"+i, urlArray[i]);