Commit d73b1713 authored by techird's avatar techird

merge from dev

parents 159539c2 edf5ede9
...@@ -62,6 +62,10 @@ function DraftManager( minder ) { ...@@ -62,6 +62,10 @@ function DraftManager( minder ) {
return current; return current;
} }
function getCurrent() {
return current;
}
function openByPath( path ) { function openByPath( path ) {
for ( var i = 0; i < drafts.length; i++ ) { for ( var i = 0; i < drafts.length; i++ ) {
if ( drafts[ i ].path == path ) return open( i ); if ( drafts[ i ].path == path ) return open( i );
...@@ -76,11 +80,17 @@ function DraftManager( minder ) { ...@@ -76,11 +80,17 @@ function DraftManager( minder ) {
current.path = path || current.path; current.path = path || current.path;
current.name = minder.getMinderTitle(); current.name = minder.getMinderTitle();
current.data = minder.exportData( "json" ); current.data = minder.exportData( "json" );
current.sync = false;
current.update = new Date(); current.update = new Date();
store(); store();
} }
} }
function sync() {
current.sync = true;
store();
}
function list() { function list() {
return drafts.slice(); return drafts.slice();
} }
...@@ -103,6 +113,8 @@ function DraftManager( minder ) { ...@@ -103,6 +113,8 @@ function DraftManager( minder ) {
create: create, create: create,
list: list, list: list,
remove: remove, remove: remove,
clear: clear clear: clear,
getCurrent: getCurrent,
sync: sync
}; };
} }
\ No newline at end of file
...@@ -191,6 +191,11 @@ $( function () { ...@@ -191,6 +191,11 @@ $( function () {
} else if ( currentAccount ) { } else if ( currentAccount ) {
$user_btn.text( '* ' + minder.getMinderTitle() ); $user_btn.text( '* ' + minder.getMinderTitle() );
} }
if ( saved ) {
$save_btn.disabled( true ).text( '已保存' );
} else {
$save_btn.disabled( false ).text( '保存' );
}
} }
// 检查是否在 Cookie 中登录过了 // 检查是否在 Cookie 中登录过了
...@@ -313,9 +318,23 @@ $( function () { ...@@ -313,9 +318,23 @@ $( function () {
// 点击文件菜单 // 点击文件菜单
function openFile( e ) { function openFile( e ) {
setRemotePath( $( this ).data( 'value' ), true ); var path = $( this ).data( 'value' );
var draft = draftManager.getCurrent();
if ( draft.path == path ) {
if ( !draft.sync && window.confirm( '“' + getFileName( path ) + '”在草稿箱包含未保存的更改,确定加载网盘版本覆盖草稿箱中的版本吗?' ) ) {
setRemotePath( path, true );
loadRemote(); loadRemote();
} }
} else {
draft = draftManager.openByPath( path );
setRemotePath( path, !draft );
if ( draft ) {
draftManager.load();
} else {
loadRemote();
}
}
}
// 新建文件 // 新建文件
function newFile() { function newFile() {
...@@ -356,8 +375,8 @@ $( function () { ...@@ -356,8 +375,8 @@ $( function () {
addToRecentMenu( [ savedFile ] ); addToRecentMenu( [ savedFile ] );
} }
setRemotePath( savedFile.path, true ); setRemotePath( savedFile.path, true );
$save_btn.text( '已保存!' );
draftManager.save( remotePath ); draftManager.save( remotePath );
draftManager.sync();
clearTimeout( timeout ); clearTimeout( timeout );
} else { } else {
error( '保存到云盘失败,可能是网络问题导致!' ); error( '保存到云盘失败,可能是网络问题导致!' );
...@@ -534,10 +553,11 @@ $( function () { ...@@ -534,10 +553,11 @@ $( function () {
isRemote = draft.path.indexOf( '/apps/kityminder' ) === 0; isRemote = draft.path.indexOf( '/apps/kityminder' ) === 0;
if ( isRemote ) { if ( isRemote ) {
setRemotePath( draft.path, false ); setRemotePath( draft.path, draft.sync );
} }
watchingChanges = false;
draftManager.load(); draftManager.load();
watchingChanges = true;
if ( !isRemote ) { if ( !isRemote ) {
setRemotePath( null, false ); setRemotePath( null, false );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment