File size: 1,409 Bytes
b3787d8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
"use babel";

const Metadata = require('lupa').Metadata;
const getMetadata = Metadata.getMetadata;

const getLines = (f) => {
    const item = getMetadata(f).filter((item) => item.type == 'lines')[0] || {}
    return item.data || 0;
}


const React = require('react');
const div = React.createFactory('div');
const span = React.createFactory('span');
const LineCount = require('./LineCount');


class FileName extends React.Component {
    render() {
        const f = this.props.file;
        const preview = this.props.preview;
        const onClick = () => {
            // if !fs.existsSync(path)
            //     path = getFileForRequire(allFiles, path).path

            preview.getBuffer().setPath(f.path)
            preview.setText(f.contents + '');
            console.log("ON CHANGEX", this.props.onChange, this.props.line)
            this.props.onChange && this.props.onChange(this.props.line);
            preview.scrollToBufferPosition([this.props.line || 0, 0]);
            //atom.workspace.open(f.path, {initialLine: this.props.line || 0});
        };
        return div({className: 'lupa-file', onClick: onClick}, [
            this.props.desc? <span>
                {this.props.desc}
                <span style={{fontSize: 8}}>{f.path}</span>
            </span> : f.path,
            React.createElement(LineCount, {lines: getLines(f)})
        ])
    }
}

module.exports = FileName;