# HG changeset patch
# User insilmaril
# Date 1268123349 0
# Node ID 25a950c2eb98c7a74f73118ea25f918a329d36fa
# Parent  b5537d24516558347309a18d13d8a4bf35d6f101
Introduce loadNote and saveNote commands

diff -r b5537d245165 -r 25a950c2eb98 file.cpp
--- a/file.cpp	Tue Mar 09 08:28:49 2010 +0000
+++ b/file.cpp	Tue Mar 09 08:29:09 2010 +0000
@@ -1,9 +1,9 @@
+#include <QDebug>
 #include <QDir>
 #include <QMessageBox>
 #include <QPixmap>
 #include <QLabel>
 #include <QTextStream>
-#include <iostream>
 
 #include "file.h"
 #include "process.h"
diff -r b5537d245165 -r 25a950c2eb98 file.h
--- a/file.h	Tue Mar 09 08:28:49 2010 +0000
+++ b/file.h	Tue Mar 09 08:29:09 2010 +0000
@@ -24,8 +24,8 @@
 void makeSubDirs (const QString &);
 ErrorCode zipDir (const QDir &,const QString&);
 ErrorCode unzipDir (const QDir &,const QString&);
-bool loadStringFromDisk (const QString &, QString &);
-bool saveStringToDisk (const QString &, const QString &s);
+bool loadStringFromDisk (const QString &fn, QString &s);
+bool saveStringToDisk (const QString &fn, const QString &s);
 
 /////////////////////////////////////////////////////////////////////////////
 #include <QLabel>
diff -r b5537d245165 -r 25a950c2eb98 findresultmodel.cpp
--- a/findresultmodel.cpp	Tue Mar 09 08:28:49 2010 +0000
+++ b/findresultmodel.cpp	Tue Mar 09 08:29:09 2010 +0000
@@ -9,9 +9,7 @@
 {
     QVector<QVariant> rootData;
 	rootData << "Heading";
-
     rootItem = new FindResultItem(rootData);
-    //setupModelData(data.split(QString("\n")), rootItem);
 }
 
 FindResultModel::~FindResultModel()
@@ -22,10 +20,7 @@
 void FindResultModel::clear()
 {
 	if (rootItem->childCount()>0)
-	{
-		//QModelIndex ix=createIndex(0,0,rootItem);
 		removeRows (0,rowCount (QModelIndex ()));
-	}
 }
 
 int FindResultModel::columnCount(const QModelIndex & /* parent */) const
diff -r b5537d245165 -r 25a950c2eb98 highlighter.cpp
--- a/highlighter.cpp	Tue Mar 09 08:28:49 2010 +0000
+++ b/highlighter.cpp	Tue Mar 09 08:29:09 2010 +0000
@@ -56,6 +56,7 @@
 					<< "\\bimportDir\\b"
 					<< "\\blinkTo\\b" 
 					<< "\\bloadImage\\b"
+					<< "\\bloadNote\\b"
 					<< "\\bmoveBranchUp\\b" 
 					<< "\\bmoveBranchDown\\b"
 					<< "\\bmove\\b" 
@@ -64,6 +65,7 @@
 					<< "\\bpaste\\b" 
 					<< "\\bqa\\b" 
 					<< "\\bsaveImage\\b" 
+					<< "\\bsaveNote\\b" 
 					<< "\\bscroll\\b" 
 					<< "\\bselect\\b" 
 					<< "\\bselectLastBranch\\b" 
diff -r b5537d245165 -r 25a950c2eb98 tex/vym.changelog
--- a/tex/vym.changelog	Tue Mar 09 08:28:49 2010 +0000
+++ b/tex/vym.changelog	Tue Mar 09 08:29:09 2010 +0000
@@ -1,3 +1,11 @@
+-------------------------------------------------------------------
+Mon Mar  8 07:45:34 CET 2010 - vym@insilmaril.de
+
+- Feature: New widget to display all results of Find action.
+           Also opened with CTRL-F once FindWidget is open
+- Feature: loadNote and saveNote commands to allow changing of note 
+           from external
+
 -------------------------------------------------------------------
 Fri Feb 19 08:05:02 CET 2010 - vym@insilmaril.de
 
diff -r b5537d245165 -r 25a950c2eb98 version.h
--- a/version.h	Tue Mar 09 08:28:49 2010 +0000
+++ b/version.h	Tue Mar 09 08:29:09 2010 +0000
@@ -7,7 +7,7 @@
 #define __VYM_VERSION "1.13.0"
 //#define __VYM_CODENAME "Codename: RC-1"
 #define __VYM_CODENAME "Codename: development version, not for production!"
-#define __VYM_BUILD_DATE "2010-03-08"
+#define __VYM_BUILD_DATE "2010-03-09"
 
 
 bool checkVersion(const QString &);
diff -r b5537d245165 -r 25a950c2eb98 vymmodel.cpp
--- a/vymmodel.cpp	Tue Mar 09 08:28:49 2010 +0000
+++ b/vymmodel.cpp	Tue Mar 09 08:29:09 2010 +0000
@@ -1553,7 +1553,6 @@
 	TreeItem *selti=getSelectedItem();
 	if (selti) 
 	{
-		emitNoteHasChanged(selti);
 		saveState(
 			selti,
 			"setNote (\""+selti->getNote()+"\")", 
@@ -1561,7 +1560,8 @@
 			"setNote (\""+s+"\")", 
 			QString("Set note of %1 ").arg(getObjectName(selti)) );
 	}
-		selti->setNote(s);
+	selti->setNote(s);
+	emitNoteHasChanged(selti);
 }
 
 QString VymModel::getNote()
@@ -1573,6 +1573,39 @@
 		return QString();
 }
 
+void VymModel::loadNote (const QString &fn)
+{
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
+	{
+		QString n;
+		if (!loadStringFromDisk (fn,n))
+			qWarning ()<<"VymModel::loadNote Couldn't load "<<fn;
+		else
+			setNote (n);
+	} else
+		qWarning ("VymModel::loadNote no branch selected");
+}
+
+void VymModel::saveNote (const QString &fn)
+{
+	BranchItem *selbi=getSelectedBranch();
+	if (selbi)
+	{
+		QString n=selbi->getNote();
+		if (n.isEmpty())
+			qWarning ()<<"VymModel::saveNote  note is empty, won't save to "<<fn;
+		else
+		{
+			if (!saveStringToDisk (fn,n))
+				qWarning ()<<"VymModel::saveNote Couldn't save "<<fn;
+			else
+				selbi->setNote (n);
+		}	
+	} else
+		qWarning ("VymModel::saveNote no branch selected");
+}
+
 void VymModel::findDuplicateURLs()	// FIXME-3 needs GUI
 {
 	// Generate map containing _all_ URLs and branches
@@ -1612,6 +1645,7 @@
 void  VymModel::findAll (FindResultModel *rmodel, QString s, Qt::CaseSensitivity cs)   
 {
 	rmodel->clear();
+	int i=0;
 	BranchItem *cur=NULL;
 	BranchItem *prev=NULL;
 	nextBranch(cur,prev);
@@ -1621,7 +1655,14 @@
 		{
 			rmodel->addItem (cur);
 		}	
-		//if (cur->getNote().contains (s,cs))	//FIXME-2 does not detect multiple occurences
+		//if (cur->getNote().contains (s,cs))	//FIXME-2 does not detect multiple occurences yet
+		while (i>=0)
+		{
+			i=cur->getNote().indexOf (s,i,cs);
+			if (i>=0) i++;
+			qDebug()<<"i="<<i;
+
+		} 
 		nextBranch(cur,prev);
 	}
 }
@@ -3526,6 +3567,20 @@
 			if (ok) loadFloatImageInt (selbi,s);
 		}	
 	/////////////////////////////////////////////////////////////////////
+	} else if (com=="loadNote")
+	{
+		if (!selti)
+		{
+			parser.setError (Aborted,"Nothing selected");
+		} else if (! selbi )
+		{				  
+			parser.setError (Aborted,"Type of selection is not a branch");
+		} else if (parser.checkParCount(1))
+		{
+			s=parser.parString(ok,0);
+			if (ok) loadNote (s);
+		}	
+	/////////////////////////////////////////////////////////////////////
 	} else if (com=="moveUp")
 	{
 		if (!selti )
@@ -3691,6 +3746,20 @@
 			}
 		}	
 	/////////////////////////////////////////////////////////////////////
+	} else if (com=="saveNote")
+	{
+		if (!selti)
+		{
+			parser.setError (Aborted,"Nothing selected");
+		} else if (! selbi )
+		{				  
+			parser.setError (Aborted,"Type of selection is not a branch");
+		} else if (parser.checkParCount(1))
+		{
+			s=parser.parString(ok,0);
+			if (ok) saveNote (s);
+		}	
+	/////////////////////////////////////////////////////////////////////
 	} else if (com=="scroll")
 	{
 		if (!selti)
diff -r b5537d245165 -r 25a950c2eb98 vymmodel.h
--- a/vymmodel.h	Tue Mar 09 08:28:49 2010 +0000
+++ b/vymmodel.h	Tue Mar 09 08:29:09 2010 +0000
@@ -264,6 +264,8 @@
 	QString getHeading ();					//!< Get heading of item
 	void setNote(const QString &s);			//!< Set note text
 	QString getNote();						//!< Get note text
+	void loadNote (const QString &fn);		//!< Load note from file
+	void saveNote (const QString &fn);		//!< Save note to file
 
 private:
 	BranchItem* findCurrent;				// next object in find process