{
var newIndex = 0
for (var j = 0; j < this.props.navigation.notebooks.length; j++){
var n = this.props.navigation.notebooks[j]
if (n == original){
newIndex = j
this.refs.notebookList.setIndex(j, () => {
var nbitem = $(ReactDOM.findDOMNode(this.refs[n.title+newIndex]))
var cont = $('#notebook-list')
var newPos = 0
if(typeof nbitem.offset() != 'undefined'){
newPos = nbitem.offset().top - cont.offset().top + cont.scrollTop() - cont.height()/2;
}
$('#notebook-list').animate({
scrollTop: newPos
})
})
}
}
};
initDefaultNotebookPath = (notebook) => {
var nbPath = utils.getNotebookPath(notebook)
var dir = mkdirp.sync(nbPath)
var notePath = utils.getNotebookPath(notebook)
var meta = {
'name': notebook.title,
'uuid': notebook.uuid
}
var metaPath = path.join(nbPath, 'meta.json')
var t = jsfile.writeFileSync(metaPath, meta)
};
createNotebookPath = (notebook, callback) => {
mkdirp(notebook.path, (err) => {
if(err){
console.log('There was an error creating the directory '+notebook.path)
console.log(err)
}
else{
this.props.addNotebook(notebook)
this.createNotebookMeta(notebook, callback)
}
})
};
createNewNotebook = (callback) => {
var nbUuid = uuid.v4().toUpperCase()
var nbPath = utils.getNotebookPathFromUUID(nbUuid)
var notebook = {
'state': 'editing',
'title': '',
'uuid': nbUuid,
'path': nbPath,
'notes': 0
}
this.createNotebookPath(notebook, callback)
};
createNotebookMeta = (notebook, callback) => {
var notePath = utils.getNotebookPath(notebook)
var meta = {
'name': notebook.title,
'uuid': notebook.uuid
}
var metaPath = path.join(notePath, 'meta.json')
jsfile.writeFile(metaPath, meta, (err) => {
if(err){
console.log(err)
}
if(utils.isFunction(callback)){
callback(notebook, err)
}
})
};
newNotebookUnfocus = (i) => {
var nb = this.props.navigation.notebooks[i]
var tf = this.refs["textField"+i]
var notebookName = tf.getValue()
if (notebookName){
this.refs.mainList.setIndex(-1)
nb.title = notebookName
nb.state = 'displaying'
this.props.updateNotebook(nb, i, () => {
this.props.sortNotebooks(this.compareNotebooks, ()=>{
this.scrollToRenamedNotebook(nb)
})
})
this.createNotebookMeta(nb)
}
else if(nb.title){
nb.state = 'displaying'
this.props.updateNotebook(nb, i)
}
};
addNotebookTapped = (callback) => {
if(!utils.isFunction(callback)){
callback = () => {
if(this.refs['textField0']){
this.refs['textField0'].focus()
}
}
}
this.createNewNotebook(callback)
};
newNotebookTyped = (i) => {
};
menuItemClicked = (i, ev) => {
this.refs.notebookList.setIndex(-1)
var item = this.props.navigation.menuItems[i]
var type = 'leftClick'
var nativeEvent = ev.nativeEvent
if(nativeEvent.button == 2){
//Right click
type = 'rightClick'
}
if (item.isNotebook){
var notebook = utils.loadNotebookByName(item.name)
notebook = utils.updateObject(item, notebook)
this.props.updateSelection(notebook)
}
else if(item.glob){
this.props.updateSelection(item)
}
item.clicked(i, item, type, ev)
};
renameTapped = (i) => {
var nbs = this.props.navigation.notebooks
nbs[i].state = 'editing'
this.props.updateNotebook(nbs[i], i, () => {
this.refs['textField'+i].focus()
})
this.props.closeContextMenu()
}
deleteTapped = (i, callback) => {
var nbs = this.props.navigation.notebooks
var nb = nbs.slice(i, 1)[0]
rmdir(nb.path, (err)=>{
if(err){
console.log(err)
}
this.props.removeNotebook(i, () =>{
if(utils.isFunction(callback)){
callback(nb, err)
}
})
})
this.props.closeContextMenu()
}
contextMenuItems = (i) => {
return [
}
onTouchTap={this.renameTapped.bind(this, i)}/>,
,
} />
]
};
noteBookTapped = (i, ev) => {
var nativeEvent = ev.nativeEvent
if(nativeEvent.button == 2){
//Right click
var x = nativeEvent.pageX
var y = nativeEvent.pageY
this.props.updateContextMenu(this.contextMenuItems(i))
this.props.openContextMenu(x, y)
}
else{
this.props.updateSelection(this.props.navigation.notebooks[i])
}
this.refs.mainList.setIndex(-1)
};
preventEventProp = (ev) => {
ev.stopPropagation();
};
notebookList = () => {
return (
{this.props.navigation.notebooks.map((notebook, i) =>{
var l = null
if (notebook.state == 'editing'){
l = }
rightIcon={}>
}
else{
l =
}
rightIcon={}
/>
}
return l
})}
)
};
notebookIconTapped = (i, ev) => {
ev.stopPropagation()
};
stateChanged = () => {
const { store } = this.context
const state = store.getState()
if(utils.isFunction(state.navigation.callback)){
state.navigation.callback(state)
}
};
render(){
return (
{this.props.navigation.menuItems.map((item, i) => {
return }
value={i}
onTouchTap={this.menuItemClicked.bind(this, i)}/>;
})}
NoteBooks
}>
{this.notebookList()}
)
}
}
LibraryNav.contextTypes = {
store: React.PropTypes.object
}
LibraryNav.defaultProps = {
closeContextMenu: () => {},
updateSelection: () => {}
};