git-svn-id: svn://euphorik.ch/pompage@45 02bbb61a-6d21-0410-aba0-cb053bdfd66a
[pompage.git] / doc / webdeveloper / options / dialogs / view_source_with.js
1 // Open a dialog to choose an application
2 function webdeveloper_chooseApplication()
3 {
4 var filePicker = Components.classes["@mozilla.org/filepicker;1"].createInstance(Components.interfaces.nsIFilePicker);
5
6 filePicker.init(window, document.getElementById("webdeveloper-string-bundle").getString("webdeveloper_chooseApplication"), filePicker.modeOpen);
7
8 // If the user selected an application
9 if(filePicker.show() == filePicker.returnOK)
10 {
11 document.getElementById("webdeveloper.view.source.with.path").value = filePicker.file.path;
12 }
13 }
14
15 // Clears the view source with option
16 function webdeveloper_clearViewSourceWith()
17 {
18 window.opener.webdeveloper_viewSourceWithDescription = null;
19 window.opener.webdeveloper_viewSourceWithKey = null;
20 window.opener.webdeveloper_viewSourceWithPath = null;
21 }
22
23 // Initializes the view source with dialog box
24 function webdeveloper_initializeViewSourceWith()
25 {
26 var modifiers = null;
27 var stringBundle = document.getElementById("webdeveloper-string-bundle");
28
29 // If running on a Mac
30 if(webdeveloper_isMac())
31 {
32 modifiers = stringBundle.getString("webdeveloper_keyboardShortcutModifiersMac");
33 }
34 else
35 {
36 modifiers = stringBundle.getString("webdeveloper_keyboardShortcutModifiers");
37 }
38
39 document.getElementById("webdeveloper-keyboard-shortcut-modifiers").value = modifiers;
40
41 // If the first argument equals add
42 if(window.arguments[0] == "add")
43 {
44 document.title = stringBundle.getString("webdeveloper_addViewSourceWith");
45 }
46 else
47 {
48 document.title = stringBundle.getString("webdeveloper_editViewSourceWith");
49
50 document.getElementById("webdeveloper.view.source.with.description").value = window.arguments[1];
51 document.getElementById("webdeveloper.view.source.with.path").value = window.arguments[2];
52 document.getElementById("webdeveloper.view.source.with.key").value = window.arguments[3];
53 }
54 }
55
56 // Saves the view source with option
57 function webdeveloper_saveViewSourceWith()
58 {
59 var description = document.getElementById("webdeveloper.view.source.with.description").value.trim();
60 var errors = "";
61 var key = document.getElementById("webdeveloper.view.source.with.key").value.trim();
62 var path = document.getElementById("webdeveloper.view.source.with.path").value.trim();
63 var stringBundle = document.getElementById("webdeveloper-string-bundle");
64
65 // If the description is empty
66 if(!description)
67 {
68 errors += stringBundle.getString("webdeveloper_emptyDescription") + "\n";
69 }
70
71 // If the path is empty
72 if(!path)
73 {
74 errors += stringBundle.getString("webdeveloper_emptyPath") + "\n";
75 }
76
77 // If there are errors
78 if(errors)
79 {
80 webdeveloper_error(errors.trim());
81
82 return false;
83 }
84 else
85 {
86 window.opener.webdeveloper_viewSourceWithDescription = description;
87 window.opener.webdeveloper_viewSourceWithKey = key;
88 window.opener.webdeveloper_viewSourceWithPath = path;
89
90 return true;
91 }
92 }