Commit 8f055633 authored by techird's avatar techird

草稿箱大小限制;文件编辑状态调整

parent 8057635b
function DraftManager( minder ) { function DraftManager( minder ) {
var current = null, var current = null,
localStorage = window.localStorage, localStorage = window.localStorage,
drafts; drafts,
MAX_SIZE = 15;
init(); init();
...@@ -32,7 +33,7 @@ function DraftManager( minder ) { ...@@ -32,7 +33,7 @@ function DraftManager( minder ) {
} }
function store() { function store() {
localStorage.setItem( 'drafts', JSON.stringify( drafts ) ); localStorage.setItem( 'drafts', JSON.stringify( drafts.slice( 0, MAX_SIZE ) ) );
} }
function create( path ) { function create( path ) {
...@@ -84,6 +85,7 @@ function DraftManager( minder ) { ...@@ -84,6 +85,7 @@ function DraftManager( minder ) {
current.update = new Date(); current.update = new Date();
store(); store();
} }
return current;
} }
function sync() { function sync() {
...@@ -92,7 +94,7 @@ function DraftManager( minder ) { ...@@ -92,7 +94,7 @@ function DraftManager( minder ) {
} }
function list() { function list() {
return drafts.slice(); return drafts.slice( 0, 15 );
} }
function remove( remove_index ) { function remove( remove_index ) {
......
...@@ -328,7 +328,9 @@ $( function () { ...@@ -328,7 +328,9 @@ $( function () {
draft = draftManager.openByPath( path ); draft = draftManager.openByPath( path );
setRemotePath( path, !draft || draft.sync ); setRemotePath( path, !draft || draft.sync );
if ( draft ) { if ( draft ) {
watchingChanges = false;
draftManager.load(); draftManager.load();
watchingChanges = true;
} else { } else {
loadRemote(); loadRemote();
} }
...@@ -338,12 +340,9 @@ $( function () { ...@@ -338,12 +340,9 @@ $( function () {
// 新建文件 // 新建文件
function newFile() { function newFile() {
setRemotePath( null, true ); setRemotePath( null, true );
watchingChanges = false;
minder.importData( '新建脑图', 'plain' );
draftManager.create(); draftManager.create();
watchingChanges = true; minder.importData( '新建脑图', 'plain' );
minder.execCommand( 'camera', minder.getRoot() ); minder.execCommand( 'camera', minder.getRoot() );
$user_btn.text( '<新建脑图>' );
} }
function generateRemotePath() { function generateRemotePath() {
...@@ -471,14 +470,10 @@ $( function () { ...@@ -471,14 +470,10 @@ $( function () {
function watchChanges() { function watchChanges() {
minder.on( 'contentchange', function () { minder.on( 'contentchange', function () {
if ( !watchingChanges ) return; if ( !watchingChanges ) return;
var currentData = minder.exportData( 'json' ); var current = draftManager.save();
if ( watchChanges.lastData != currentData ) { if ( currentAccount ) {
if ( currentAccount ) { $save_btn.disabled( current.sync ).text( '保存' );
$save_btn.disabled( false ).text( '保存' ); setRemotePath( remotePath, current.sync );
watchChanges.lastData = currentData;
setRemotePath( remotePath, false );
}
draftManager.save();
} }
} ); } );
} }
......
...@@ -89,6 +89,7 @@ KityMinder.registerModule( 'View', function () { ...@@ -89,6 +89,7 @@ KityMinder.registerModule( 'View', function () {
} else { } else {
minder.rollbackStatus(); minder.rollbackStatus();
} }
this.setContentChanged( false );
}, },
queryState: function ( minder ) { queryState: function ( minder ) {
......
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