当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript dialog.showSaveDialog方法代码示例

本文整理汇总了TypeScript中electron.dialog.showSaveDialog方法的典型用法代码示例。如果您正苦于以下问题:TypeScript dialog.showSaveDialog方法的具体用法?TypeScript dialog.showSaveDialog怎么用?TypeScript dialog.showSaveDialog使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在electron.dialog的用法示例。


在下文中一共展示了dialog.showSaveDialog方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

 ipcMain.on("save", (event, arg) => {
   if (arg.pathToSave) {
     jsonfile.writeFile(arg.pathToSave, arg.spec, function(err) {
       if (!err) {
         event.sender.send("onSaveSuccess", {
           name: arg.name,
           path: arg.pathToSave
         });
       }
     });
   } else {
     dialog.showSaveDialog(
       {
         filters: [
           {
             name: "Json",
             extensions: ["json"]
           }
         ]
       },
       filename => {
         if (filename) {
           jsonfile.writeFile(filename, arg.spec, function(err) {
             if (!err) {
               event.sender.send("onSaveSuccess", {
                 name: arg.name,
                 path: filename
               });
             }
           });
         }
       }
     );
   }
 });
开发者ID:Raathigesh,项目名称:Atmo,代码行数:35,代码来源:messageHandler.ts

示例2: Date

export const saveAllTabs = (event, tabsDescriptor) => {
  const timeLabel = (new Date()).toISOString().replace(/[\/\\:]/g, '');

  dialog.showSaveDialog({
    title: 'Save charts as ...',
    defaultPath: `charts-${timeLabel}.gmstat`,
    filters: [{name: 'Gapminder stat document', extensions: ['gmstat']}]
  }, fileName => {
    if (!fileName) {
      return;
    }

    tabsDescriptor.forEach(tabDescriptor => {
      normalizeModelToSave(tabDescriptor.model, tabDescriptor.type);
    });

    fs.writeFile(fileName, JSON.stringify(tabsDescriptor, null, ' '), err => {
      if (err) {
        dialog.showErrorBox('File save error', err.message);
        ga.error('Charts was NOT saved: ' + err.toString());
        return;
      }

      ga.error('Charts successfully saved');
    });
  });
};
开发者ID:VS-work,项目名称:gapminder-offline,代码行数:27,代码来源:file-management.ts

示例3: Promise

  return new Promise((resolve, reject) => {
    const type = imageType(bytes);
    const options: SaveDialogOptions = {};

    const dateObj = new Date(Number(timestamp));
    if (dateObj.getTime() && !isNaN(dateObj.getTime())) {
      const momentObj = moment(dateObj);
      const filename = `Wire ${momentObj.format('YYYY-MM-DD')} at ${momentObj.format('H.mm.ss')}`;
      options.defaultPath = filename;
    }

    if (type && type.ext) {
      options.filters = [
        {
          extensions: [type.ext],
          name: 'Images',
        },
      ];
      options.defaultPath += `.${type.ext}`;
    }

    dialog.showSaveDialog(options, chosenPath => {
      if (chosenPath) {
        fs.writeFile(chosenPath, new Buffer(bytes.buffer), error => (error ? reject(error) : resolve()));
      }
    });
  });
开发者ID:wireapp,项目名称:wire-desktop,代码行数:27,代码来源:download.ts

示例4: renderPoster

 let posterWrapper = (window: Electron.BrowserWindow, month: number) => {
   dialog.showSaveDialog(window, {
     filters: [{ name: 'PDF', extensions: ['pdf']}],
   }, (filename: string) => {
     if (filename) {
       renderPoster(filename, month);
     }
   });
 };
开发者ID:molisani,项目名称:fcp-schedule,代码行数:9,代码来源:electron-main.ts

示例5:

export const saveAsSubtitleDialog = (webContents: Electron.WebContents) => {
  const path = dialog.showSaveDialog({
    filters: subtitleFilters,
  });

  if (!path) {
    return;
  }

  webContents.send('save-subtitle', path);
};
开发者ID:Heeryong-Kang,项目名称:jamak,代码行数:11,代码来源:fileDialogs.ts

示例6: getCurrentSchedule

 getCurrentSchedule((schedule) => {
   dialog.showSaveDialog(focusedWindow, {
     filters: [{ name: 'Schedules', extensions: ['json']}],
   }, (filename: string) => {
     if (filename) {
       fs.writeFile(filename, JSON.stringify(schedule, null, 2), 'utf8', (err) => {
         if (err) throw err;
       });
     }
   });
 });
开发者ID:molisani,项目名称:fcp-schedule,代码行数:11,代码来源:electron-main.ts

示例7: join

        return new Promise<void>((resolve, reject) => {
            const path = app.getPath('downloads');
            const options = { defaultPath: join(path, data.fileName) };

            dialog.showSaveDialog(this.main.mainWindow, options, function (filename) {
                if (filename) {
                    return write(filename, data.fileContent).then(resolve, reject);
                } else {
                    return reject(new Error('Cancel'));
                }
            });
        });
开发者ID:wavesplatform,项目名称:WavesGUI,代码行数:12,代码来源:Bridge.ts

示例8: zipdir

export const exportForWeb = (event, params) => {
  fsExtra.removeSync(`${WEB_PATH[process.platform]}`);

  Object.keys(params.model).forEach(key => {
    if ((key === 'data' || key.indexOf('data_') === 0) && typeof params.model[key] === 'object') {
      const pathKeys = params.model[key].path.split(path.sep);
      const pathKey = pathKeys[pathKeys.length - 1];

      fsExtra.copySync(params.model[key].path, `${WEB_PATH[process.platform]}/data/${pathKey}`);

      params.model[key].path = `./data/${pathKey}`;
      params.model[key].ddfPath = `./data/${pathKey}`;

      if (params.model[key].reader === 'ddf1-csv-ext') {
        params.model[key].reader = 'ddf';
      }
    }
  });

  params.model.chartType = params.chartType;
  params.model.locale.filePath = 'assets/translation/';

  const config = `var CONFIG = ${JSON.stringify(params.model, null, ' ')};`;

  fsExtra.copySync(`${WEB_RESOURCE_PATH[process.platform]}`, `${WEB_PATH[process.platform]}`);
  fsExtra.outputFileSync(`${WEB_PATH[process.platform]}/config.js`, config);

  let indexContent = fs.readFileSync(`${WEB_RESOURCE_PATH[process.platform]}/index.html`).toString();

  indexContent = indexContent.replace(/#chartType#/, params.chartType);

  fs.writeFileSync(`${WEB_PATH[process.platform]}/index.html`, indexContent, 'utf8');

  dialog.showSaveDialog({
    title: 'Export current chart as ...',
    filters: [{name: 'ZIP', extensions: ['zip']}]
  }, fileName => {
    if (!fileName) {
      return;
    }

    zipdir(`${WEB_PATH[process.platform]}`, {saveTo: fileName}, err => {
      if (err) {
        dialog.showMessageBox({message: 'This chart has NOT been exported.', buttons: ['OK']});
        ga.error('Export for Web was NOT completed: ' + err.toString());
        return;
      }

      dialog.showMessageBox({message: 'This chart has been exported.', buttons: ['OK']});
    });
  });
};
开发者ID:VS-work,项目名称:gapminder-offline,代码行数:52,代码来源:file-management.ts

示例9:

 ipcMain.on('save-as', () => {
     dialog.showSaveDialog(mainWindow, {
         title: 'Save Image',
         filters: [
             { name: '.png', extensions: ['png'] },
             { name: '.jpg', extensions: ['jpeg', 'jpg'] },
         ]
     }, filename => {
         if (filename) {
             let ext = filename.substr(filename.lastIndexOf('.') + 1);
             mainWindow.webContents.send('save-as', path.parse(filename));
         }
     });
 });
开发者ID:TheColorRed,项目名称:photo-editor,代码行数:14,代码来源:save.ts

示例10: buildMenu

export function buildMenu(window: Electron.WebContents): void {
  const template = [
    {
      label: 'File',
      submenu: [
        {
          label: 'New',
          click() { window.send('menu:file:new'); }
        },
        {
          label: 'Load Map',
          async click() {   // declare async because opening files taes a long time
            dialog.showOpenDialog(options, (paths: string[]) => {
              if (paths === undefined) return;

              console.log(paths[0]);
              IO.loadMap(window, paths[0]);
            });
          }
        },
        {
          label: 'Save Map',
          click() {
            window.send('menu:file:save');
          }
        },
        {
          label: 'Save Map As...',
          async click() {
            dialog.showSaveDialog(options, (filePath) => {
              if (filePath) {
                console.log(filePath);
                window.send('menu:file:save', filePath);
              }
            });
          }
        }
      ]
    }
  ];

  const menu = Menu.buildFromTemplate(template);
  Menu.setApplicationMenu(menu);
}
开发者ID:andrew-ni,项目名称:warcraft2-tools-unofficial,代码行数:44,代码来源:menubar.ts

示例11: normalizeModelToSave

export const saveFile = (event, params) => {
  dialog.showSaveDialog({
    title: 'Save current chart as ...',
    defaultPath: `${params.title}.gmstat`,
    filters: [{name: 'Gapminder stat document', extensions: ['gmstat']}]
  }, fileName => {
    if (!fileName) {
      return;
    }

    normalizeModelToSave(params.model, params.chartType);

    fs.writeFile(fileName, JSON.stringify(params.model, null, ' '), err => {
      if (err) {
        dialog.showErrorBox('File save error', err.message);
        ga.error('Chart state was NOT saved: ' + err.toString());
        return;
      }

      ga.error('Chart state successfully saved');
    });
  });
};
开发者ID:VS-work,项目名称:gapminder-offline,代码行数:23,代码来源:file-management.ts

示例12: send

      click: (item: object, focusedWindow: BrowserWindow) => {
        const opts: {
          title: string;
          filters: FileFilter[];
          defaultPath?: string;
        } = {
          title: "Save Notebook As",
          filters: [{ name: "Notebooks", extensions: ["ipynb"] }],
          defaultPath: undefined
        };

        if (process.cwd() === "/") {
          opts.defaultPath = app.getPath("home");
        }

        dialog.showSaveDialog(opts, filename => {
          if (!filename) {
            return;
          }

          const ext = path.extname(filename) === "" ? ".ipynb" : "";
          send(focusedWindow, "menu:save-as", `${filename}${ext}`);
        });
      },
开发者ID:nteract,项目名称:nteract,代码行数:24,代码来源:menu.ts

示例13:

 socket.on('showSaveDialog', (browserWindow, options, guid) => {
     var window = BrowserWindow.fromId(browserWindow.id);
     dialog.showSaveDialog(window, options, (filename) => {
         socket.emit('showSaveDialogComplete' + guid, filename || '');
     });
 });
开发者ID:E024,项目名称:Electron.NET,代码行数:6,代码来源:dialog.ts

示例14: createMenu

function createMenu(): Electron.Menu {
  let main = new Menu();
  let scheduleMenu = new Menu();
  let newSchedule = new MenuItem({
    label: 'New',
    accelerator: 'CmdOrCtrl+N',
    click(item, focusedWindow) { createNewSchedule(); }
  });
  scheduleMenu.append(newSchedule);
  let open = new MenuItem({
    label: 'Open',
    accelerator: 'CmdOrCtrl+O',
    click(item, focusedWindow) { openScheduleFileDialog(); }
  });
  scheduleMenu.append(open);
  let merge = new MenuItem({
    label: 'Merge',
    accelerator: 'CmdOrCtrl+M',
    click(item, focusedWindow) {
      if (focusedWindow) {
        dialog.showOpenDialog(focusedWindow, {
          filters: [{ name: 'Schedules', extensions: ['json']}],
          properties: ['openFile'],
        }, (filenames: string[]) => {
          if (filenames && filenames[0]) {
            fs.readFile(filenames[0], 'utf8', (err, data) => {
              if (err) throw err;
              let new_schedule: Schedule = JSON.parse(data);
              getCurrentSchedule((schedule) => {
                schedule.series = schedule.series.concat(new_schedule.series);
                mainWindow.webContents.send('open-schedule', schedule);
              });
            });
          }
        });
      }
    }
  });
  scheduleMenu.append(merge);
  save = new MenuItem({
    label: 'Save',
    enabled: false,
    accelerator: 'CmdOrCtrl+S',
    click(item, focusedWindow) {
      if (focusedWindow) {
        getCurrentSchedule((schedule) => {
          if (currentFile) {
            fs.writeFile(currentFile, JSON.stringify(schedule, null, 2), 'utf8', (err) => {
              if (err) throw err;
            });
          }
        });
      }
    }
  });
  scheduleMenu.append(save);
  let saveAs = new MenuItem({
    label: 'Save As...',
    accelerator: 'CmdOrCtrl+Shift+S',
    click(item, focusedWindow) {
      if (focusedWindow) {
        getCurrentSchedule((schedule) => {
          dialog.showSaveDialog(focusedWindow, {
            filters: [{ name: 'Schedules', extensions: ['json']}],
          }, (filename: string) => {
            if (filename) {
              fs.writeFile(filename, JSON.stringify(schedule, null, 2), 'utf8', (err) => {
                if (err) throw err;
              });
            }
          });
        });
      }
    }
  });
  scheduleMenu.append(saveAs);
  main.append(new MenuItem({
    label: 'Schedule',
    submenu: scheduleMenu
  }));
  let generateMenu = new Menu();
  let posterWrapper = (window: Electron.BrowserWindow, month: number) => {
    dialog.showSaveDialog(window, {
      filters: [{ name: 'PDF', extensions: ['pdf']}],
    }, (filename: string) => {
      if (filename) {
        renderPoster(filename, month);
      }
    });
  };
  let poster = new MenuItem({
    label: 'Poster',
    submenu: [
      {
        label: 'August', accelerator: 'F8',
        click(item, focusedWindow) { posterWrapper(focusedWindow, 7); }
      },
      {
        label: 'September', accelerator: 'F9',
        click(item, focusedWindow) { posterWrapper(focusedWindow, 8); }
//.........这里部分代码省略.........
开发者ID:molisani,项目名称:fcp-schedule,代码行数:101,代码来源:electron-main.ts


注:本文中的electron.dialog.showSaveDialog方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。