/* * Alabastra Project - C++ Editor writed with QT Library V.4 * Copyright (C) Igor Maculan - geocronos@gmail.com Marco Buoncristiano - marco.buoncristiano@gmail.com * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "AlDocument.h" #include AlDocument::AlDocument (QObject *parent) : QTextDocument(parent){ common(); }; AlDocument::AlDocument (AlProject *a_prj) : QTextDocument(){ if (a_prj!=NULL) prj=a_prj; common(); }; AlDocument::AlDocument () :QTextDocument(){ common(); }; void AlDocument::common(){ filename=tr("Senza Nome"); saved=false; setModified(false); syntax=new AlSyntax(this); clear(); connect_signal(); }; void AlDocument::connect_signal(){ connect (this,SIGNAL(modificationChanged(bool)),this,SLOT(documentModified(bool))); }; QString AlDocument::getFileName(){ return filename; }; QString AlDocument::getShortFileName(){ return filename.right(filename.length()-filename.lastIndexOf('/')-1); }; bool AlDocument::isSaved(){ return saved; }; bool AlDocument::setFileName(QString tmp){ if (!tmp.isEmpty()) { emit fileNameChanged(tmp); emit fileNameChanged(); emit fileNameChanged(filename,tmp); filename=tmp; return true; } else return false; }; /** Salvataggio file gi esistente */ int AlDocument::save(){ if (saved) if (isModified()) { if ( save(filename) ) return 0; //OK SALVATO else return -1; //ERRORE DI SALVATAGGIO } else return 2; //SALVATO e NON MODIFICATO else return 1;//NON SALVATO }; /** Salvataggio File; */ bool AlDocument::save(QString fname){ QFile f(fname); if (!f.open(QIODevice::WriteOnly | QIODevice::Text)) return false; else{ QTextStream out(&f); out << toPlainText(); f.close(); setModified(false); documentModified(false); setFileName(fname); saved=true; emit fileNameChanged(); qDebug()<<"Documento Salvato"; return true; } }; /** Apertura file */ void AlDocument::open(QString fname){ setModified(false); setFileName(fname); saved=true; emit fileNameChanged(); refreshMethod(); }; /* * Emette un segnale quando il documento viene modificato */ void AlDocument::documentModified(bool mod){ emit modified(this,mod); }; /* * Restituisce l'estensione del file */ QString AlDocument::getExtension(){ int ppos=filename.lastIndexOf('.'); if (ppos>-1) return filename.right(filename.size()-(ppos+1)); else return ""; }; /* * Trova i metodi nel file */ void AlDocument::refreshMethod(){ qDebug()<setName(mName); QTextCharFormat chrMethodFormat; chrMethodFormat.setAnchor(true); chrMethodFormat.setAnchorName(mName); cM.setCharFormat(chrMethodFormat); alMethodList<]|[<])*[ ]*([A-Z]|[0-9]|[_])*[(]([A-Z]|[0-9]|[ ]|[,]|[*]|[_])*[)][;])|(class[ ]*([A-Z]|[0-9]|[_])*)", Qt::CaseInsensitive,QRegExp::RegExp2); cM=find(extMethod,cM); alMethodList.clear(); AlMethod* method; //memorizzo lo stato di modifica bool mod=isModified(); QString line; QString className; int spPos; while ( !cM.isNull() ){ line=cM.selectedText(); if (line.contains("class")){ className=line.mid(5).simplified(); } else{ line=line.left(line.size()-1); method=new AlMethod(); spPos=line.indexOf(" "); if (spPos>0){ //non un costruttore rName=line.left(spPos); method->setReturnName(rName); line=line.right(line.size()-(spPos+1)); } method->setName(line); if (!className.isEmpty()) method->setClassName(className); QTextCharFormat chrMethodFormat; chrMethodFormat.setAnchor(true); chrMethodFormat.setAnchorName(method->getName()); cM.setCharFormat(chrMethodFormat); alMethodList< AlDocument::getAlMethodList(){ return alMethodList; }; void AlDocument::setModified(bool m=true){ QTextDocument::setModified(m); emit modificationChanged(m); };