diff options
author | Einar Egilsson | 2009-10-14 11:13:03 +0000 |
---|---|---|
committer | Einar Egilsson | 2009-10-14 11:13:03 +0000 |
commit | cfc2965fb35256a3493485f32ff9bd605bf158b7 (patch) | |
tree | 2683fe502bac65c752c7ebd913cfa5c2e955abf4 /chrome | |
parent | 0065dc23b00c5039ec3036ff895b9a67341c05c0 (diff) |
Import and Export working, might need some more singular/plural fixes in language.
git-svn-id: http://einaregilsson.googlecode.com/svn/mozilla/redirector/trunk@266 119bf307-c92d-0410-89bd-8f53e6181181
Diffstat (limited to 'chrome')
-rw-r--r-- | chrome/content/code/redirector.prototype.js | 5 | ||||
-rw-r--r-- | chrome/content/code/settings.xul.js | 34 | ||||
-rw-r--r-- | chrome/content/ui/settings.xul | 13 | ||||
-rw-r--r-- | chrome/locale/en-US/redirector.properties | 5 | ||||
-rw-r--r-- | chrome/locale/en-US/settings.xul.dtd | 5 | ||||
-rw-r--r-- | chrome/skin/redirector.css | 1 |
6 files changed, 48 insertions, 15 deletions
diff --git a/chrome/content/code/redirector.prototype.js b/chrome/content/code/redirector.prototype.js index e364ecc..4e39fa6 100644 --- a/chrome/content/code/redirector.prototype.js +++ b/chrome/content/code/redirector.prototype.js @@ -85,7 +85,6 @@ Redirector.prototype = { if (!aContext || !aContext.loadURI) {
return nsIContentPolicy.ACCEPT;
}
- this.debug("START: " + new Date().getTime());
this.debug("Checking " + contentLocation.spec);
var url = contentLocation.spec;
@@ -107,7 +106,6 @@ Redirector.prototype = { } catch(e) {
this.debug(e);
}
- this.debug("END: " + new Date().getTime());
return nsIContentPolicy.ACCEPT;
},
@@ -170,7 +168,7 @@ Redirector.prototype = { var line = {value: null};
while (stream.readLine(line)) {
var redirect = new Redirect();
- redirect.deserialize(line.replace('\n', ''));
+ redirect.deserialize(line.value.replace('\n', ''));
if (this.containsRedirect(redirect)) {
existsCount++;
} else {
@@ -180,6 +178,7 @@ Redirector.prototype = { }
stream.close();
this.save();
+ return { imported : importCount, existed : existsCount };
},
containsRedirect : function(redirect) {
diff --git a/chrome/content/code/settings.xul.js b/chrome/content/code/settings.xul.js index 80fa8a4..3efe061 100644 --- a/chrome/content/code/settings.xul.js +++ b/chrome/content/code/settings.xul.js @@ -3,6 +3,7 @@ var Redirector = Components.classes["@einaregilsson.com/redirector;1"].getService(Components.interfaces.nsISupports).wrappedJSObject;
const Cc = Components.classes;
const Ci = Components.interfaces;
+const nsLocalFile = Components.Constructor("@mozilla.org/file/local;1", "nsILocalFile", "initWithPath");
var Settings = {
@@ -201,9 +202,9 @@ var Settings = { var picker = Cc["@mozilla.org/filepicker;1"].createInstance(Ci.nsIFilePicker);
picker.init(window, Redirector.getString(captionKey), mode);
picker.defaultExtension = ".rdx";
- var dir = Redirector.getDefaultDir();
+ var dir = Redirector.prefs.defaultDir;
if (dir) {
- picker.displayDirectory = dir;
+ picker.displayDirectory = new nsLocalFile(dir);
}
picker.appendFilter(Redirector.getString('redirectorFiles'), '*.rdx');
@@ -211,7 +212,8 @@ var Settings = { return;
}
try {
- func(picker.file);
+ Redirector.prefs.defaultDir = picker.displayDirectory.path;
+ return func(picker.file);
} catch (e) {
alert(e);
}
@@ -224,8 +226,30 @@ var Settings = { },
import : function() {
- this.importExport(Ci.nsIFilePicker.modeOpen, 'importCaption', function(file) {
- Redirector.importRedirects(file);
+ var result = this.importExport(Ci.nsIFilePicker.modeOpen, 'importCaption', function(file) {
+ return Redirector.importRedirects(file);
});
+
+ var msg;
+ if (result.imported > 0 && result.existed == 0) {
+ msg = this.strings.getFormattedString('importedMessage', [result.imported]);
+ } else if (result.imported > 0 && result.existed > 0) {
+ msg = this.strings.getFormattedString('importedAndExistedMessage', [result.imported, result.existed]);
+ } else if (result.imported == 0 && result.existed > 0) {
+ msg = this.strings.getFormattedString('importedNoneAllExisted', [result.existed]);
+ } else { //Both 0
+ msg = this.strings.getString('importedNone');
+ }
+
+ var title = this.strings.getString("importResult");
+ Cc["@mozilla.org/embedcomp/prompt-service;1"].getService(Ci.nsIPromptService).alert(null, title, msg);
+
+ if (result.imported > 0) {
+ var newlist = [];
+ for (var i = Redirector.list.length-result.imported; i < Redirector.list.length; i++) {
+ newlist.push(Redirector.list[i]);
+ }
+ this.addItemsToListBox(newlist);
+ }
}
};
diff --git a/chrome/content/ui/settings.xul b/chrome/content/ui/settings.xul index 7004d48..d61e893 100644 --- a/chrome/content/ui/settings.xul +++ b/chrome/content/ui/settings.xul @@ -94,14 +94,17 @@ </tabpanel>
<tabpanel>
<groupbox flex="1">
- <caption label="&grpImportExportDescription.label;" />
<vbox>
<hbox align="middle">
- <button id="btnImport" accesskey="&btnImport.accesskey;" onclick="Settings.import();" label="&btnImport.label;"/>
- <label value="Import redirects from a .rdx file" />
+ <button id="btnImport" accesskey="&btnImport.accesskey;" oncommand="Settings.import();" label="&btnImport.label;"/>
+ <label id="lblImport" value="&lblImport.label;" />
+ <spacer flex="1" />
+ </hbox>
+ <hbox>
+ <button id="btnExport" accesskey="&btnExport.accesskey;" oncommand="Settings.export();" label="&btnExport.label;"/>
+ <label id="lblExport" value="&lblExport.label;" />
+ <spacer flex="1" />
</hbox>
-
- <button id="btnExport" accesskey="&btnExport.accesskey;" onclick="Settings.export();" label="&btnExport.label;"/>
<spacer flex="1" />
</vbox>
</groupbox>
diff --git a/chrome/locale/en-US/redirector.properties b/chrome/locale/en-US/redirector.properties index b57025b..4395b5e 100644 --- a/chrome/locale/en-US/redirector.properties +++ b/chrome/locale/en-US/redirector.properties @@ -17,3 +17,8 @@ exportCaption=Export redirects... importCaption=Import redirects... deleteConfirmationText=Are you sure you want to permanently delete this redirect? deleteConfirmationTitle=Delete redirect? +importedMessage=%S redirects were imported. +importedAndExistedMessage=%S redirects were imported, %S redirects were identical to existing redirects and were therefore not imported. +importedNoneAllExisted=All %S redirects in the file are identical to existing redirects, no redirects were imported. +importedNone=There were no usable redirects in the given file, no redirects were imported. +importResult=Import results
\ No newline at end of file diff --git a/chrome/locale/en-US/settings.xul.dtd b/chrome/locale/en-US/settings.xul.dtd index 7a38165..ff55b68 100644 --- a/chrome/locale/en-US/settings.xul.dtd +++ b/chrome/locale/en-US/settings.xul.dtd @@ -46,7 +46,6 @@ <!-- Preferences --> <!ENTITY grpGeneralPreferences.label "General"> <!ENTITY grpDebuggingPreferences.label "Debugging"> -<!ENTITY grpImportExportDescription.label "Import / export redirects to file"> <!ENTITY chkEnableRedirector.label "Enable Redirector"> <!ENTITY chkEnableRedirector.accesskey "E"> @@ -61,4 +60,6 @@ <!ENTITY chkEnableDebugOutput.accesskey "d"> - +<!-- Import / Export --> +<!ENTITY lblExport.label "Export your redirects to a file"> +<!ENTITY lblImport.label "Import new redirects from a file"> diff --git a/chrome/skin/redirector.css b/chrome/skin/redirector.css index 1b32081..7ace38f 100644 --- a/chrome/skin/redirector.css +++ b/chrome/skin/redirector.css @@ -11,3 +11,4 @@ #btnDown[disabled=true] { list-style-image: url('chrome://redirector/skin/movedowndisabled.png'); }
#btnUp, #btnDown { width:25px; min-width:25px; }
+#lblExport, #lblImport { padding-top:5px; }
\ No newline at end of file |