Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
K
kityminder-core
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
吴志俊
kityminder-core
Commits
a87ee4c9
Commit
a87ee4c9
authored
Jan 20, 2014
by
Akikonata
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test
parent
fefd5329
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
55 deletions
+57
-55
dev.html
demo/dev.html
+0
-2
history.js
src/module/history.js
+44
-44
layout.default.js
src/module/layout.default.js
+13
-9
No files found.
demo/dev.html
View file @
a87ee4c9
...
...
@@ -23,8 +23,6 @@
minder
.
execCommand
(
"appendsiblingnode"
,
new
MinderNode
(
"test4"
));
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
(
"test5"
));
minder
.
execCommand
(
"appendsiblingnode"
,
new
MinderNode
(
"test6"
));
minder
.
execCommand
(
"appendchildnode"
,
new
MinderNode
(
"test7"
));
minder
.
execCommand
(
"appendsiblingnode"
,
new
MinderNode
(
"test8"
));
//minder.execCommand("switchlayout","green");
</script>
</html>
\ No newline at end of file
src/module/history.js
View file @
a87ee4c9
KityMinder
.
registerModule
(
"HistoryModule"
,
function
()
{
var
Scene
=
kity
.
createClass
(
'Scene'
,
{
constructor
:
function
(
root
)
{
var
Scene
=
kity
.
createClass
(
'Scene'
,
{
constructor
:
function
(
root
)
{
this
.
data
=
root
.
clone
();
},
getData
:
function
()
{
getData
:
function
()
{
return
this
.
data
;
},
cloneData
:
function
()
{
cloneData
:
function
()
{
return
this
.
getData
().
clone
();
},
equals
:
function
(
scene
)
{
return
this
.
getData
().
equals
(
scene
.
getData
()
)
equals
:
function
(
scene
)
{
return
this
.
getData
().
equals
(
scene
.
getData
()
)
}
});
var
HistoryManager
=
kity
.
createClass
(
'HistoryManager'
,
{
constructor
:
function
(
km
)
{
}
);
var
HistoryManager
=
kity
.
createClass
(
'HistoryManager'
,
{
constructor
:
function
(
km
)
{
this
.
list
=
[];
this
.
index
=
0
;
this
.
hasUndo
=
false
;
this
.
hasRedo
=
false
;
this
.
km
=
km
;
},
undo
:
function
()
{
if
(
this
.
hasUndo
)
{
if
(
!
this
.
list
[
this
.
index
-
1
]
&&
this
.
list
.
length
==
1
)
{
undo
:
function
()
{
if
(
this
.
hasUndo
)
{
if
(
!
this
.
list
[
this
.
index
-
1
]
&&
this
.
list
.
length
==
1
)
{
this
.
reset
();
return
;
}
while
(
this
.
list
[
this
.
index
].
equals
(
this
.
list
[
this
.
index
-
1
])
)
{
while
(
this
.
list
[
this
.
index
].
equals
(
this
.
list
[
this
.
index
-
1
]
)
)
{
this
.
index
--
;
if
(
this
.
index
==
0
)
{
return
this
.
restore
(
0
);
if
(
this
.
index
==
0
)
{
return
this
.
restore
(
0
);
}
}
this
.
restore
(
--
this
.
index
);
this
.
restore
(
--
this
.
index
);
}
},
redo
:
function
()
{
if
(
this
.
hasRedo
)
{
while
(
this
.
list
[
this
.
index
].
equals
(
this
.
list
[
this
.
index
+
1
])
)
{
redo
:
function
()
{
if
(
this
.
hasRedo
)
{
while
(
this
.
list
[
this
.
index
].
equals
(
this
.
list
[
this
.
index
+
1
]
)
)
{
this
.
index
++
;
if
(
this
.
index
==
this
.
list
.
length
-
1
)
{
return
this
.
restore
(
this
.
index
);
if
(
this
.
index
==
this
.
list
.
length
-
1
)
{
return
this
.
restore
(
this
.
index
);
}
}
this
.
restore
(
++
this
.
index
);
this
.
restore
(
++
this
.
index
);
}
},
restore
:
function
()
{
var
scene
=
this
.
list
[
this
.
index
];
this
.
km
.
setRoot
(
scene
.
cloneData
()
);
restore
:
function
()
{
var
scene
=
this
.
list
[
this
.
index
];
this
.
km
.
setRoot
(
scene
.
cloneData
()
);
this
.
km
.
initStyle
();
this
.
update
();
},
getScene
:
function
()
{
return
new
Scene
(
this
.
km
.
getRoot
()
)
getScene
:
function
()
{
return
new
Scene
(
this
.
km
.
getRoot
()
)
},
saveScene
:
function
()
{
saveScene
:
function
()
{
var
currentScene
=
this
.
getScene
();
var
lastScene
=
this
.
list
[
this
.
index
];
if
(
lastScene
&&
lastScene
.
equals
(
currentScene
))
{
var
lastScene
=
this
.
list
[
this
.
index
];
if
(
lastScene
&&
lastScene
.
equals
(
currentScene
)
)
{
return
}
this
.
list
=
this
.
list
.
slice
(
0
,
this
.
index
+
1
);
this
.
list
.
push
(
currentScene
);
this
.
list
=
this
.
list
.
slice
(
0
,
this
.
index
+
1
);
this
.
list
.
push
(
currentScene
);
//如果大于最大数量了,就把最前的剔除
if
(
this
.
list
.
length
>
this
.
km
.
getOptions
(
'maxUndoCount'
)
)
{
if
(
this
.
list
.
length
>
this
.
km
.
getOptions
(
'maxUndoCount'
)
)
{
this
.
list
.
shift
();
}
this
.
index
=
this
.
list
.
length
-
1
;
//跟新undo/redo状态
this
.
update
();
},
update
:
function
()
{
this
.
hasRedo
=
!!
this
.
list
[
this
.
index
+
1
];
this
.
hasUndo
=
!!
this
.
list
[
this
.
index
-
1
];
update
:
function
()
{
this
.
hasRedo
=
!!
this
.
list
[
this
.
index
+
1
];
this
.
hasUndo
=
!!
this
.
list
[
this
.
index
-
1
];
},
reset
:
function
()
{
reset
:
function
()
{
this
.
list
=
[];
this
.
index
=
0
;
this
.
hasUndo
=
false
;
this
.
hasRedo
=
false
;
}
});
}
);
//为km实例添加history管理
this
.
historyManager
=
new
HistoryManager
(
this
);
this
.
historyManager
=
new
HistoryManager
(
this
);
return
{
defaultOptions
:{
maxUndoCount
:
20
defaultOptions
:
{
maxUndoCount
:
20
},
"commands"
:
{
"undo"
:
kity
.
createClass
(
"UndoCommand"
,
{
"undo"
:
kity
.
createClass
(
"UndoCommand"
,
{
base
:
Command
,
execute
:
function
(
km
)
{
...
...
@@ -103,7 +103,7 @@ KityMinder.registerModule( "HistoryModule", function () {
queryState
:
function
(
km
)
{
km
.
historyManager
.
hasUndo
?
0
:
-
1
;
},
isNeedUndo
:
true
isNeedUndo
:
true
}
),
"redo"
:
kity
.
createClass
(
"RedoCommand"
,
{
base
:
Command
,
...
...
@@ -115,7 +115,7 @@ KityMinder.registerModule( "HistoryModule", function () {
queryState
:
function
(
km
)
{
return
km
.
historyManager
.
hasRedo
?
0
:
-
1
;
},
isNeedUndo
:
true
isNeedUndo
:
true
}
)
},
...
...
src/module/layout.default.js
View file @
a87ee4c9
...
...
@@ -369,8 +369,12 @@ KityMinder.registerModule( "LayoutDefault", function () {
drawNode
(
node
);
},
initStyle
:
function
()
{
var
_root
=
this
.
getRoot
()
;
//清空节点上附加的数据
;
var
minder
=
this
;
var
_root
=
minder
.
getRoot
();
_root
.
preTraverse
(
function
(
node
)
{
node
.
clearLayout
();
}
);
var
Layout
=
_root
.
getData
(
"layout"
);
Layout
.
style
=
{
radius
:
10
,
...
...
@@ -396,14 +400,14 @@ KityMinder.registerModule( "LayoutDefault", function () {
translateNode
(
_root
);
//如果是从其他style切过来的,需要重新布局
var
_buffer
=
_root
.
getChildren
();
while
(
_buffer
.
length
!==
0
)
{
_buffer
=
_buffer
.
concat
(
_buffer
[
0
].
getChildren
()
);
var
prt
=
_buffer
[
0
].
getParent
();
_buffer
[
0
].
children
=
[];
this
.
appendChildNode
(
prt
,
_buffer
[
0
]
);
_buffer
.
shift
();
}
//
var _buffer = _root.getChildren();
//
while ( _buffer.length !== 0 ) {
//
_buffer = _buffer.concat( _buffer[ 0 ].getChildren() );
//
var prt = _buffer[ 0 ].getParent();
//
_buffer[ 0 ].children = [];
//
this.appendChildNode( prt, _buffer[ 0 ] );
//
_buffer.shift();
//
}
},
appendChildNode
:
function
(
parent
,
node
,
index
)
{
if
(
!
node
.
getData
(
"layout"
)
)
node
.
setData
(
"layout"
,
{}
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment