mapeditor.cpp
changeset 502 f3465a5f0dc4
parent 500 d8c245d582a3
child 505 244e309b4047
     1.1 --- a/mapeditor.cpp	Thu Jun 14 10:21:40 2007 +0000
     1.2 +++ b/mapeditor.cpp	Thu Jun 14 10:21:41 2007 +0000
     1.3 @@ -133,6 +133,10 @@
     1.4  	// Create temporary files
     1.5  	makeTmpDirs();
     1.6  
     1.7 +	curStep=0;
     1.8 +	redosAvail=0;
     1.9 +	undosAvail=0;
    1.10 +
    1.11  	setAcceptDrops (true);	
    1.12  
    1.13  	mapCenter->reposition();	//	for positioning heading
    1.14 @@ -314,9 +318,6 @@
    1.15  
    1.16  	if (debug) cout << "ME::saveState() for  "<<mapName.ascii()<<endl;
    1.17  	
    1.18 -	int undosAvail=undoSet.readNumEntry ("/history/undosAvail",0);
    1.19 -	int redosAvail=undoSet.readNumEntry ("/history/redosAvail",0);
    1.20 -	int curStep=undoSet.readNumEntry ("/history/curStep",0);
    1.21  	// Find out current undo directory
    1.22  	if (undosAvail<stepsTotal) undosAvail++;
    1.23  	curStep++;
    1.24 @@ -587,6 +588,18 @@
    1.25  			QColor c=parser.parColor (ok,0);
    1.26  			if (ok) colorSubtree (c);
    1.27  		}	
    1.28 +	} else if (com=="copy")
    1.29 +	{
    1.30 +		if (xelection.isEmpty())
    1.31 +		{
    1.32 +			parser.setError (Aborted,"Nothing selected");
    1.33 +		} else if (! selb )
    1.34 +		{				  
    1.35 +			parser.setError (Aborted,"Type of selection is not a branch");
    1.36 +		} else if (parser.checkParamCount(0))
    1.37 +		{	
    1.38 +			//FIXME missing action for copy
    1.39 +		}	
    1.40  	} else if (com=="cut")
    1.41  	{
    1.42  		if (xelection.isEmpty())
    1.43 @@ -777,6 +790,8 @@
    1.44  				if (ok) moveRel (x,y);
    1.45  			}
    1.46  		}	
    1.47 +	} else if (com=="nop")
    1.48 +	{
    1.49  	} else if (com=="paste")
    1.50  	{
    1.51  		if (xelection.isEmpty() )
    1.52 @@ -785,9 +800,76 @@
    1.53  		} else if (! selb )
    1.54  		{				  
    1.55  			parser.setError (Aborted,"Type of selection is not a branch");
    1.56 -		} else if (parser.checkParamCount(0))
    1.57 +		} else if (parser.checkParamCount(1))
    1.58  		{	
    1.59 -			paste();
    1.60 +			x=parser.parInt (ok,0);
    1.61 +			if (ok) pasteNoSave(x);
    1.62 +		}	
    1.63 +	/////////////////////////////////////////////////////////////////////
    1.64 +	} else if (com=="qa")
    1.65 +	{
    1.66 +		if (xelection.isEmpty() )
    1.67 +		{
    1.68 +			parser.setError (Aborted,"Nothing selected");
    1.69 +		} else if (! selb )
    1.70 +		{				  
    1.71 +			parser.setError (Aborted,"Type of selection is not a branch");
    1.72 +		} else if (parser.checkParamCount(4))
    1.73 +		{	
    1.74 +			QString c,u;
    1.75 +			c=parser.parString (ok,0);
    1.76 +			if (!ok)
    1.77 +			{
    1.78 +				parser.setError (Aborted,"No comment given");
    1.79 +			} else
    1.80 +			{
    1.81 +				s=parser.parString (ok,1);
    1.82 +				if (!ok)
    1.83 +				{
    1.84 +					parser.setError (Aborted,"First parameter is not a string");
    1.85 +				} else
    1.86 +				{
    1.87 +					t=parser.parString (ok,2);
    1.88 +					if (!ok)
    1.89 +					{
    1.90 +						parser.setError (Aborted,"Condition is not a string");
    1.91 +					} else
    1.92 +					{
    1.93 +						u=parser.parString (ok,3);
    1.94 +						if (!ok)
    1.95 +						{
    1.96 +							parser.setError (Aborted,"Third parameter is not a string");
    1.97 +						} else
    1.98 +						{
    1.99 +							if (s!="heading")
   1.100 +							{
   1.101 +								parser.setError (Aborted,"Unknown type: "+s);
   1.102 +							} else
   1.103 +							{
   1.104 +								if (! (t=="eq") ) 
   1.105 +								{
   1.106 +									parser.setError (Aborted,"Unknown operator: "+t);
   1.107 +								} else
   1.108 +								{
   1.109 +									if (! selb    )
   1.110 +									{
   1.111 +										parser.setError (Aborted,"Type of selection is not a branch");
   1.112 +									} else
   1.113 +									{
   1.114 +										if (selb->getHeading() == u)
   1.115 +										{
   1.116 +											cout << "PASSED: " << c.ascii() << endl;
   1.117 +										} else
   1.118 +										{
   1.119 +											cout << "FAILED: " << c.ascii() << endl;
   1.120 +										}
   1.121 +									}
   1.122 +								}
   1.123 +							}
   1.124 +						} 
   1.125 +					} 
   1.126 +				} 
   1.127 +			}
   1.128  		}	
   1.129  	} else if (com=="saveImage")
   1.130  	{
   1.131 @@ -1613,23 +1695,18 @@
   1.132  	LinkableMapObj *sel=xelection.single();
   1.133  	if (sel)
   1.134  	{
   1.135 -		// write to directory
   1.136 -		QString saveFile=saveToDir (clipboardDir,clipboardFile+"-",true,QPointF(),sel ); // FIXME check FIO
   1.137 -		QFile file;
   1.138 -
   1.139 -		file.setName ( clipboardDir + "/"+clipboardFile);
   1.140 -		if ( !file.open( QIODevice::WriteOnly ) )
   1.141 +		if (redosAvail == 0)
   1.142  		{
   1.143 -			// This should neverever happen
   1.144 -			QMessageBox::critical (0,tr("Critical Export Error"),tr("MapEditor::exportXML couldn't open %1").arg(file.name()));
   1.145 -			return;
   1.146 -		}	
   1.147 -
   1.148 -		// Write it finally, and write in UTF8, no matter what 
   1.149 -		QTextStream ts( &file );
   1.150 -		ts.setEncoding (QTextStream::UnicodeUTF8);
   1.151 -		ts << saveFile;
   1.152 -		file.close();
   1.153 +			// Copy to history
   1.154 +			QString s=sel->getSelectString();
   1.155 +			saveState (PartOfMap, s, "nop ()", s, "copy ()","Copy to clipboard",sel  );
   1.156 +			curClipboard=curStep;
   1.157 +		}
   1.158 +
   1.159 +		// Copy also to global clipboard, because we are at last step in history
   1.160 +		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(curStep));
   1.161 +		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
   1.162 +		copyDir (bakMapDir,clipboardDir );
   1.163  
   1.164  		clipboardEmpty=false;
   1.165  		updateActions();
   1.166 @@ -1638,10 +1715,6 @@
   1.167  
   1.168  void MapEditor::redo()
   1.169  {
   1.170 -	// Restore variables
   1.171 -	int curStep=undoSet.readNumEntry (QString("/history/curStep"));
   1.172 -	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
   1.173 -	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
   1.174  	// Can we undo at all?
   1.175  	if (redosAvail<1) return;
   1.176  
   1.177 @@ -1722,14 +1795,11 @@
   1.178  
   1.179  void MapEditor::undo()
   1.180  {
   1.181 -	// Restore variables
   1.182 -	int curStep=undoSet.readNumEntry (QString("/history/curStep"));
   1.183 -	int undosAvail=undoSet.readNumEntry (QString("/history/undosAvail"));
   1.184 -	int redosAvail=undoSet.readNumEntry (QString("/history/redosAvail"));
   1.185 -
   1.186  	// Can we undo at all?
   1.187  	if (undosAvail<1) return;
   1.188  
   1.189 +	mainWindow->statusMessage (tr("Autosave disabled during undo."));
   1.190 +
   1.191  	bool blockSaveStateOrg=blockSaveState;
   1.192  	blockSaveState=true;
   1.193  	
   1.194 @@ -1902,11 +1972,19 @@
   1.195  	}		
   1.196  }
   1.197  
   1.198 -void MapEditor::pasteNoSave()
   1.199 +void MapEditor::pasteNoSave(const int &n)
   1.200  {
   1.201  	bool old=blockSaveState;
   1.202  	blockSaveState=true;
   1.203 -	load (clipboardDir+"/"+clipboardFile,ImportAdd);
   1.204 +	if (redosAvail > 0 || n!=0)
   1.205 +	{
   1.206 +		// Use the "historical" buffer
   1.207 +		QString bakMapName=QDir::convertSeparators (QString("history-%1").arg(n));
   1.208 +		QString bakMapDir=QDir::convertSeparators (tmpMapDir +"/"+bakMapName);
   1.209 +		load (bakMapDir+"/"+clipboardFile,ImportAdd);
   1.210 +	} else
   1.211 +		// Use the global buffer
   1.212 +		load (clipboardDir+"/"+clipboardFile,ImportAdd);
   1.213  	blockSaveState=old;
   1.214  }
   1.215  
   1.216 @@ -1918,10 +1996,10 @@
   1.217  		saveStateChangingPart(
   1.218  			sel,
   1.219  			sel,
   1.220 -			"paste ()",
   1.221 +			QString ("paste (%1)").arg(curClipboard),
   1.222  			QString("Paste to %1").arg( getName(sel))
   1.223  		);
   1.224 -		pasteNoSave();
   1.225 +		pasteNoSave(0);
   1.226  		mapCenter->reposition();
   1.227  	}
   1.228  }
   1.229 @@ -3759,7 +3837,8 @@
   1.230  
   1.231  void MapEditor::testFunction()
   1.232  {
   1.233 -	// This is the playground
   1.234 +	mainWindow->statusMessage("Biiiiiiiiiiiiiiing!");
   1.235 +	return;
   1.236  
   1.237  	BranchObj *bo=xelection.getBranch();
   1.238  	if (bo) animObjList.append( bo );