Ejemplo n.º 1
0
bool DocumentEditor::saveFile(const QString &fileName_) {
	//remove old path from watcher
	_watcher.removePath(_fullPath);

	QFile file(fileName_);
	if (!file.open(QFile::WriteOnly)) {
		QMessageBox::warning(this, PACKAGE_NAME,
							 tr("Cannot save file %1:\n%2.")
							 .arg(fileName_)
							 .arg(file.errorString()));

		//re add the old path to the watcher
		if(!_fullPath.isEmpty())
			_watcher.addPath(_fullPath);
		return false;
	}

	QTextCodec* codec = QTextCodec::codecForName(_codec.toUtf8());
	if(codec == 0) {
		QMessageBox::critical(this, PACKAGE_NAME,
							  tr("Cannot save file %1:\nUnsupported charset %2 !!")
							  .arg(fileName_).arg(_codec));
		//re add the old path to the watcher
		if(!_fullPath.isEmpty())
			_watcher.addPath(_fullPath);
		return false;
	}

	QApplication::setOverrideCursor(Qt::WaitCursor);
	//file.resize(0);
	//file.write(codec->fromUnicode(text()));

	// check if strip spaces
	if(_trimOnSave == true)
		trimTrailingSpaces();

	// check if add new line to the end
	if (_addNewLineOnSave == true) {
		if (!isLineEmpty(lines() - 1)) {
			append(getEol());
		}
	}

	QTextStream out(&file);
	out.setCodec(codec);
	out.setGenerateByteOrderMark(needBOM());
	out << text();
	out.flush();

	_fullPath = fileName_;
	setModified(false);
	_isNew = false;

	QApplication::restoreOverrideCursor();

	//add it to the watcher
	_watcher.addPath(_fullPath);
	_notified = false;
	return true;
}
Ejemplo n.º 2
0
void MainWindow::initMenuEdit() {
	//connect menu "Edit" Action
	connect(actionCut, SIGNAL(triggered()), _documentManager, SLOT(cut()));
	connect(actionCopy, SIGNAL(triggered()), _documentManager, SLOT(copy()));
	connect(actionPaste, SIGNAL(triggered()), _documentManager, SLOT(paste()));
	connect(actionUndo, SIGNAL(triggered()), _documentManager, SLOT(undo()));
	connect(actionRedo, SIGNAL(triggered()), _documentManager, SLOT(redo()));
	connect(actionSelectAll, SIGNAL(triggered()), _documentManager, SLOT(selectAll()));

	connect(actionIndent, SIGNAL(triggered()), this, SLOT(increaseIndentation()));
	connect(actionUnindent, SIGNAL(triggered()), this, SLOT(decreaseIndentation()));
	connect(actionAutoIndentation, SIGNAL(toggled(bool)), _documentManager, SLOT(setAutoIndentation(bool)));
	connect(actionIndentationGuides, SIGNAL(toggled(bool)), _documentManager, SLOT(showIndentationGuides(bool)));

	connect(actionTabsToSpaces, SIGNAL(triggered()), _documentManager, SLOT(tabsToSpaces()));
	connect(actionSpacesToTabs, SIGNAL(triggered()), _documentManager, SLOT(spacesToTabs()));
	connect(actionTrimTrailingSpaces, SIGNAL(triggered()), _documentManager, SLOT(trimTrailingSpaces()));
	connect(actionCompressSpaces, SIGNAL(triggered()), _documentManager, SLOT(compressSpaces()));

	connect(actionUpperCase, SIGNAL(triggered()), _documentManager, SLOT(convertSelectedTextToUpperCase()));
	connect(actionLowerCase, SIGNAL(triggered()), _documentManager, SLOT(convertSelectedTextToLowerCase()));
	connect(actionDuplicateLine, SIGNAL(triggered()), _documentManager, SLOT(duplicateCurrentLine()));
	connect(actionCopyLine, SIGNAL(triggered()), _documentManager, SLOT(copyCurrentLine()));
	connect(actionCutLine, SIGNAL(triggered()), _documentManager, SLOT(cutCurrentLine()));
	connect(actionDeleteLine, SIGNAL(triggered()), _documentManager, SLOT(deleteCurrentLine()));
	connect(actionMoveLineUp, SIGNAL(triggered()), _documentManager, SLOT(moveCurrentLineUp()));
	connect(actionMoveLineDown, SIGNAL(triggered()), _documentManager, SLOT(moveCurrentLineDown()));
	connect(actionDeleteWord, SIGNAL(triggered()), _documentManager, SLOT(deleteCurrentWord()));

	connect(actionGotoLine, SIGNAL(triggered()), this, SLOT(gotoLine()));

	connect(actionReadOnly, SIGNAL(triggered(bool)), _documentManager, SLOT(setReadOnly(bool)));
	connect(actionReindentFile, SIGNAL(triggered()), _documentManager, SLOT(reindentDocument()));
	connect(actionReindentOpenFiles, SIGNAL(triggered()), _documentManager, SLOT(reindentOpenDocuments()));

	connect(actionToggleComment, SIGNAL(triggered()), _documentManager, SLOT(toggleComment()));
	connect(actionToggleBlockComment, SIGNAL(triggered()), _documentManager, SLOT(toggleBlockComment()));

	connect(actionSwitchSrc, SIGNAL(triggered()), _documentManager, SLOT(switchDocumentSrc()));
	connect(actionSwitchFile, SIGNAL(triggered()), _documentManager, SLOT(switchFile()));
	connect(actionSwitchSymbol, SIGNAL(triggered()), this, SLOT(switchSymbol()));

	connect(menuEdit, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEditMenu()));
	connect(menuIndentation, SIGNAL(aboutToShow()), this, SLOT(aboutToShowEditIndentationMenu()));
}
Ejemplo n.º 3
0
status SampleVisionFile::readInit(AFfilesetup)
{
	m_fh->seek(0, File::SeekFromBeginning);

	char magic[kSMPMagicLength];
	if (m_fh->read(magic, kSMPMagicLength) != (ssize_t) kSMPMagicLength)
		return AF_FAIL;
	if (strncmp(magic, kSMPMagic, kSMPMagicLength) != 0)
		return AF_FAIL;

	char version[kSMPVersionLength];
	if (m_fh->read(version, kSMPVersionLength) != (ssize_t) kSMPVersionLength)
		return AF_FAIL;
	if (strncmp(version, kSMPVersion, kSMPVersionLength) != 0)
		return AF_FAIL;

	Track *track = allocateTrack();

	char name[kSMPNameLength + 1];
	m_fh->read(name, kSMPNameLength);
	name[kSMPNameLength] = '\0';
	trimTrailingSpaces(name);
	if (strlen(name) > 0)
		addMiscellaneous(AF_MISC_NAME, name);

	char comment[kSMPCommentLength + 1];
	m_fh->read(comment, kSMPCommentLength);
	comment[kSMPCommentLength] = '\0';
	trimTrailingSpaces(comment);
	if (strlen(comment) > 0)
		addMiscellaneous(AF_MISC_COMMENT, comment);

	uint32_t frameCount;
	readU32(&frameCount);
	track->totalfframes = frameCount;
	track->fpos_first_frame = m_fh->tell();
	track->data_size = 2 * frameCount;

	m_fh->seek(track->data_size, File::SeekFromCurrent);

	uint16_t reserved;
	readU16(&reserved);

	parseLoops();
	parseMarkers();

	uint8_t midiNote;
	uint32_t sampleRate;
	uint32_t smpteOffset;
	uint32_t cycleLength;

	readU8(&midiNote);
	readU32(&sampleRate);
	readU32(&smpteOffset);
	readU32(&cycleLength);

	track->f.byteOrder = AF_BYTEORDER_LITTLEENDIAN;
	track->f.sampleRate = sampleRate;
	track->f.channelCount = 1;
	track->f.compressionType = AF_COMPRESSION_NONE;
	track->f.framesPerPacket = 1;
	_af_set_sample_format(&track->f, AF_SAMPFMT_TWOSCOMP, 16);
	track->f.computeBytesPerPacketPCM();

	return AF_SUCCEED;
}