Cat/classes/CatProject.js

54 lines
1.4 KiB
JavaScript

var fs = require('fs');
var os = require('os');
function CatProject() {
this.path = '';
this.title = '';
this.tab = null;
this.view = null;
this.frameTime = 0;
this.originalHTML = '';
this.hasChanges = false;
}
CatProject.prototype.init = function() {
if (this.view) {
this.view.addEventListener('loaded', evt => {
this.setTitle(this.view.getTitle());
console.log('our title is now: ' + this.getTitle());
});
}
}
CatProject.prototype.save = function(path, cb) {
//fs.writeFile(path, (new XMLSerializer().serializeToString(this.iframe.contentDocument))+this.iframe.contentDocument.outerHTML, 'utf-8', (err) => {
fs.writeFile(path, this.view.getContents(), 'utf-8', (err) => {
if (err) throw err;
this.path = path;
cb(err);
});
}
CatProject.prototype.load = function(path, cb) {
if (!path) path = this.path;
this.path = path;
fs.readFile(path, 'utf-8', (err, data) => {
if (err) throw err;
this.originalHTML = data;
this.view.setContents(data);
cb(err);
});
}
CatProject.prototype.setTitle = function(title) {
this.title = title;
}
CatProject.prototype.getTitle = function() {
let title = this.title;
if (title == '') {
title = this.path.split(os.platform() == 'win32' ? '\\' : '/');
title = title[title.length-1];
console.log(title);
}
if (title == '') title = 'New Project';
return title;
}
module.exports = CatProject;