批量导出html完成, 支持导出笔记本下所有笔记

This commit is contained in:
life
2015-10-24 18:54:38 +08:00
parent 5f2ad33ffa
commit 29eaea0f7e
3 changed files with 154 additions and 38 deletions

View File

@@ -138,6 +138,17 @@ var Api = {
return me._exportMenus;
},
// 导出, 笔记本下
_exportMenusForNotebook: [],
addExportMenuForNotebook: function(menu) {
var me = this;
me._exportMenusForNotebook.push(menu);
},
getExportMenusForNotebook: function() {
var me = this;
return me._exportMenusForNotebook;
},
// 更多菜单
_moreMenus: [],
getMoreMenus: function() {

View File

@@ -1168,9 +1168,43 @@ Notebook.init = function() {
submenu: importSubmenus,
label: getMsg('Import notes')
});
this.menu.append(gui.getSeparatorMenu());
this.menu.append(this.imports);
}
// 导出
var exportsSubMenus = new gui.Menu();
var exportMenus = Api.getExportMenusForNotebook() || [];
for(var i = 0; i < exportMenus.length; ++i) {
(function(j) {
var menu = exportMenus[j];
var clickBac = menu.click;
var menuItem = new gui.MenuItem({
label: menu.label,
click: function(e) {
var notebookId = $(me.target).attr('notebookId');
clickBac && clickBac(notebookId);
}
});
exportMenus[i].menu = menuItem;
exportsSubMenus.append(menuItem);
})(i);
}
if(exportMenus.length > 0) {
this.exports = new gui.MenuItem({
label: getMsg('Export notes'),
submenu: exportsSubMenus,
click: function(e) {
}
});
this.menu.append(this.exports);
}
this.enable = function(name, ok) {
this[name].enabled = ok;
}

View File

@@ -167,13 +167,7 @@ define(function() {
});
},
loadingIsClosed: false,
exportHTML: function (noteIds) {
var me = this;
if (!noteIds || noteIds.length == 0) {
return;
}
getTargetPath: function(callback) {
// showSaveDialog 不支持property选择文件夹
Api.gui.dialog.showOpenDialog(Api.gui.getCurrentWindow(),
{
@@ -181,6 +175,19 @@ define(function() {
properties: ['openDirectory']
},
function(targetPath) {
callback(targetPath);
}
);
},
loadingIsClosed: false,
exportHTMLForNotebook: function (notebookId) {
var me = this;
if (!notebookId) {
return;
}
me.getTargetPath(function(targetPath) {
if (!targetPath) {
return;
}
@@ -192,8 +199,64 @@ define(function() {
isLarge: true,
onClose: function () {
me.loadingIsClosed = true;
setTimeout(function() {
me.hideLoading();
});
}});
Api.loading.setProgress(1);
Api.noteService.getNotes(notebookId, function(notes) {
if (!notes) {
me.hideLoading();
return;
}
var total = notes.length;
var i = 0;
async.eachSeries(notes, function(note, cb) {
if (me.loadingIsClosed) {
cb();
me.hideLoading();
return;
}
i++;
Api.loading.setProgress(100 * i / total);
me._exportHTML(note, targetPath, function() {
cb();
}, i, total);
}, function() {
me.hideLoading();
Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')});
});
});
});
},
hideLoading: function () {
setTimeout(function () {
Api.loading.hide();
}, 1000);
},
exportHTML: function (noteIds) {
var me = this;
if (!noteIds || noteIds.length == 0) {
return;
}
me.getTargetPath(function(targetPath) {
if (!targetPath) {
return;
}
me.loadingIsClosed = false;
Api.loading.show(Api.getMsg('plugin.export_html.Exporting'),
{
hasProgress: true,
isLarge: true,
onClose: function () {
me.loadingIsClosed = true;
setTimeout(function() {
me.hideLoading();
});
}});
Api.loading.setProgress(1);
@@ -207,8 +270,6 @@ define(function() {
return;
}
// setTimeout(function () {
i++;
Api.loading.setProgress(100 * i / total);
Api.noteService.getNote(noteId, function(note) {
@@ -217,10 +278,8 @@ define(function() {
}, i, total);
});
// }, i * 1000);
}, function () {
Api.loading.hide();
me.hideLoading();
Notify.show({title: 'Info', body: getMsg('plugin.export_html.exportSuccess')});
});
});
@@ -286,6 +345,18 @@ define(function() {
})()
};
Api.addExportMenu(menu);
Api.addExportMenuForNotebook({
label: Api.getMsg('plugin.export_html.export'),
enabled: function(notebookId) {
return true;
},
click: (function() {
return function(notebookId) {
me.exportHTMLForNotebook(notebookId);
}
})()
});
},
// 打开后
onOpenAfter: function() {