Пример #1
0
void GuiShowFile::updateContents()
{
	setWindowTitle(onlyFileName(toqstr(filename_.absFileName())));

	QString contents = toqstr(filename_.fileContents("UTF-8"));
	if (contents.isEmpty())
		contents = qt_("Error -> Cannot load file!");

	textTB->setPlainText(contents);
}
// ---
bool VSWAEImportContentWindow::verifyContent ()
{
	// By default the verification will be true...
	bool result = true;

	// Switch off all the warning indicators...
	switchOffWarnings ();
	
	// First of all, it verifies all the mandatoty fields
	// are introduced. If not the result will be nok.
	if (_name -> text () == QString (__NULL_STRING__) || 
		_implementationFile -> fileName () ==  QString (__NULL_STRING__) ||
		_type -> currentText () == QString (__NULL_STRING__))
		result &= false;

	// If the name introduce already exists...
	// Then a indication is switched on, and the ok button woill not be enabled...
	// But only if something has been introduced.
	if (_name -> text () != QString (__NULL_STRING__))
	{
		bool nameExists = (_contentNames.indexOf (_name -> text ()) != -1);
		if (nameExists) result &= false;
		_nameTF -> setPixmap (QPixmap (nameExists ? 
			":/VSWAdvancedEditor/Resources/Error.png" : ":/VSWAdvancedEditor/Resources/Ok.png"));
	}

	// If the definition directory is not a directory o the directory is not 
	// contained in the basic path, then there is mistake...
	if (_definitionDirName -> dirName () != QString (__NULL_STRING__) && 
		_name -> text () != QString (__NULL_STRING__))
	{
		bool isValidDir = validateDir (_definitionDirName -> dirName ());
		Poco::File defFile = Poco::File ((_definitionDirName -> dirName () + QString (__PATH_SEPARATOR__) + 
			_name -> text () + QString (".xml")).toStdString ());
		if (!isValidDir) result &= false;
		_definitionDirNameTF -> setPixmap (QPixmap (isValidDir ? 
			":/VSWAdvancedEditor/Resources/Ok.png" : ":/VSWAdvancedEditor/Resources/Error.png"));
		if (isValidDir &&  defFile.exists ()) // Being valid, the definition file already exists...
			_definitionDirNameTF -> setPixmap (QPixmap (":/VSWAdvancedEditor/Resources/Warning.png"));
	}

	// If the implementation directory is not a directory o the directory is not 
	// contained in the basic path, then there is mistake...
	if (_implementationDirName -> dirName () != QString (__NULL_STRING__) && 
		_name -> text () != QString (__NULL_STRING__))
	{
		QString iF = _implementationFile -> fileName ();
		#ifdef __WINDOWSPLATFORM__
		iF.replace ("/","\\");
		#endif

		bool isValidDir = validateDir (_implementationDirName -> dirName ());
		Poco::File defFile = Poco::File ((_implementationDirName -> dirName () + QString (__PATH_SEPARATOR__) + 
			QString (onlyFileName (iF.toStdString ()).c_str ())).toStdString ());
		if (!isValidDir) result &= false;
		_implementationDirNameTF -> setPixmap (QPixmap (isValidDir ? 
			":/VSWAdvancedEditor/Resources/Ok.png" : ":/VSWAdvancedEditor/Resources/Error.png"));
		if (isValidDir &&  defFile.exists ()) // Being valid, the implementation file already exists...
			_implementationDirNameTF -> setPixmap (QPixmap (":/VSWAdvancedEditor/Resources/Warning.png"));
	}

	// Test also the destination of the ocon name,
	// to show a warning icon if an element with the same name already exists in the destination...
	if (_implementationDirName -> dirName () != QString (__NULL_STRING__) && 
		_iconFile -> fileName () != QString (__NULL_STRING__))
	{
		QString iF = _iconFile -> fileName ();
		#ifdef __WINDOWSPLATFORM__
		iF.replace ("/","\\");
		#endif

		bool isValidDir = validateDir (_implementationDirName -> dirName ());
		Poco::File defFile = Poco::File ((_implementationDirName -> dirName () + QString (__PATH_SEPARATOR__) + 
			QString (onlyFileName (iF.toStdString ()).c_str ())).toStdString ());
		if (!isValidDir) result &= false;
		_iconFileTF -> setPixmap (QPixmap (isValidDir ? 
			":/VSWAdvancedEditor/Resources/Ok.png" : ":/VSWAdvancedEditor/Resources/Error.png"));
		if (isValidDir &&  defFile.exists ()) // Being valid, the implementation file already exists...
			_iconFileTF -> setPixmap (QPixmap (":/VSWAdvancedEditor/Resources/Warning.png"));
	}

	// The same with the resumen file...
	if (_implementationDirName -> dirName () != QString (__NULL_STRING__) && 
		_resumeFile -> fileName () != QString (__NULL_STRING__))
	{
		QString iF = _resumeFile -> fileName ();
		#ifdef __WINDOWSPLATFORM__
		iF.replace ("/","\\");
		#endif

		bool isValidDir = validateDir (_implementationDirName -> dirName ());
		Poco::File defFile = Poco::File ((_implementationDirName -> dirName () + QString (__PATH_SEPARATOR__) + 
			QString (onlyFileName (iF.toStdString ()).c_str ())).toStdString ());
		if (!isValidDir) result &= false;
		_resumeFileTF -> setPixmap (QPixmap (isValidDir ? 
			":/VSWAdvancedEditor/Resources/Ok.png" : ":/VSWAdvancedEditor/Resources/Error.png"));
		if (isValidDir &&  defFile.exists ()) // Being valid, the implementation file already exists...
			_resumeFileTF -> setPixmap (QPixmap (":/VSWAdvancedEditor/Resources/Warning.png"));
	}
		
	return (result);
}
Пример #3
0
void ExportData::addExternalFile(string const & format,
				 FileName const & sourceName)
{
	addExternalFile(format, sourceName, onlyFileName(sourceName.absFileName()));
}
Пример #4
0
string const doSubstitution(InsetExternalParams const & params,
			    Buffer const & buffer, string const & s,
			    bool use_latex_path,
			    bool external_in_tmpdir,
			    Substitute what)
{
	Buffer const * masterBuffer = buffer.masterBuffer();
	string const parentpath = external_in_tmpdir ?
		masterBuffer->temppath() :
		buffer.filePath();
	string const filename = external_in_tmpdir ?
		params.filename.mangledFileName() :
		params.filename.outputFileName(parentpath);
	string const basename = changeExtension(
			onlyFileName(filename), string());
	string const absname = makeAbsPath(filename, parentpath).absFileName();

	string result = s;
	if (what != ALL_BUT_PATHS) {
		string const filepath = onlyPath(filename);
		string const abspath = onlyPath(absname);
		string const masterpath = external_in_tmpdir ?
			masterBuffer->temppath() :
			masterBuffer->filePath();
		// FIXME UNICODE
		string relToMasterPath = onlyPath(
				to_utf8(makeRelPath(from_utf8(absname),
							     from_utf8(masterpath))));
		if (relToMasterPath == "./")
			relToMasterPath.clear();
		// FIXME UNICODE
		string relToParentPath = onlyPath(
				to_utf8(makeRelPath(from_utf8(absname),
							     from_utf8(parentpath))));
		if (relToParentPath == "./")
			relToParentPath.clear();

		result = subst_path(result, "$$FPath", filepath,
				    use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$AbsPath", abspath,
				    use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$RelPathMaster",
				    relToMasterPath, use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		result = subst_path(result, "$$RelPathParent",
				    relToParentPath, use_latex_path,
				    PROTECT_EXTENSION,
				    ESCAPE_DOTS);
		if (FileName::isAbsolute(filename)) {
			result = subst_path(result, "$$AbsOrRelPathMaster",
					    abspath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
			result = subst_path(result, "$$AbsOrRelPathParent",
					    abspath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
		} else {
			result = subst_path(result, "$$AbsOrRelPathMaster",
					    relToMasterPath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
			result = subst_path(result, "$$AbsOrRelPathParent",
					    relToParentPath, use_latex_path,
					    PROTECT_EXTENSION,
					    ESCAPE_DOTS);
		}
	}

	if (what == PATHS)
		return result;

	result = subst_path(result, "$$FName", filename, use_latex_path,
			    EXCLUDE_EXTENSION);
	result = subst_path(result, "$$Basename", basename, use_latex_path,
			    PROTECT_EXTENSION, ESCAPE_DOTS);
	result = subst_path(result, "$$Extension",
			'.' + getExtension(filename), use_latex_path);
	result = subst_path(result, "$$Tempname", params.tempname().absFileName(), use_latex_path);
	result = subst_path(result, "$$Sysdir",
				package().system_support().absFileName(), use_latex_path);

	// Handle the $$Contents(filename) syntax
	if (contains(result, "$$Contents(\"")) {
		// Since use_latex_path may be true we must extract the file
		// name from s instead of result and do the substitutions
		// again, this time with use_latex_path false.
		size_t const spos = s.find("$$Contents(\"");
		size_t const send = s.find("\")", spos);
		string const file_template = s.substr(spos + 12, send - (spos + 12));
		string const file = doSubstitution(params, buffer,
						   file_template, false,
						   external_in_tmpdir, what);
		string contents;

		FileName const absfile(
			makeAbsPath(file, masterBuffer->temppath()));
		if (absfile.isReadableFile())
			// FIXME UNICODE
			contents = to_utf8(absfile.fileContents("UTF-8"));

		size_t const pos = result.find("$$Contents(\"");
		size_t const end = result.find("\")", pos);
		result.replace(pos, end + 2, contents);
	}

	return result;
}