xyc
2025-02-21 664db98c9e8595ce4dd636a27f480e3a08b81ff5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* globals jQuery, svgCanvas */
// Note: This JavaScript file must be included as the last script on the main HTML editor page to override the open/save handlers
jQuery(function () {
  if (window.opera && window.opera.io && window.opera.io.filesystem) {
    svgCanvas.setCustomHandlers({
      open () {
        try {
          window.opera.io.filesystem.browseForFile(
            new Date().getTime(), /* mountpoint name */
            '', /* default location */
            function (file) {
              try {
                if (file) {
                  const fstream = file.open(file, 'r');
                  let output = '';
                  while (!fstream.eof) {
                    output += fstream.readLine();
                  }
 
                  svgCanvas.setSvgString(output); /* 'this' is bound to the filestream object here */
                }
              } catch (e) {
                console.log('Reading file failed.');
              }
            },
            false, /* not persistent */
            false, /* no multiple selections */
            '*.svg' /* file extension filter */
          );
        } catch (e) {
          console.log('Open file failed.');
        }
      },
      save (window, svg) {
        try {
          window.opera.io.filesystem.browseForSave(
            new Date().getTime(), /* mountpoint name */
            '', /* default location */
            function (file) {
              try {
                if (file) {
                  const fstream = file.open(file, 'w');
                  fstream.write(svg, 'UTF-8');
                  fstream.close();
                }
              } catch (e) {
                console.log('Write to file failed.');
              }
            },
            false /* not persistent */
          );
        } catch (e) {
          console.log('Save file failed.');
        }
      }
    });
  }
});