示例#1
0
bool MainWindow::memoryOpen(const QByteArray& ba, const QString& assocPath)
{
	QFileInfo fileInfo(assocPath);

	if(!fileInfo.isFile() || !fileInfo.isReadable()) return false;

	for(int i = 0; i < ui_tabWidget->count(); ++i) {
		SourceFile* sourceFile = dynamic_cast<SourceFile*>(ui_tabWidget->widget(i));
		if(sourceFile && sourceFile->associatedFile() == assocPath) {
			ui_tabWidget->setCurrentIndex(i);
			on_ui_tabWidget_currentChanged(i);
			return true;
		}
	}
	
	/* Attempt to open the selected file */
	SourceFile *sourceFile = new SourceFile(this);
	if(!sourceFile->memoryOpen(ba, assocPath)) {
		MessageDialog::showError(this, "simple_error", QStringList() <<
			tr("Could not open ") + sourceFile->associatedFileName() <<
			tr("Unable to open file from memory."));
		delete sourceFile;
		return false;
	}	

	addTab(sourceFile);
	
	UiEventManager::ref().sendEvent(UI_EVENT_OPEN_FILE);

	hideProjectDock();

	return true;
}
示例#2
0
void MainWindow::projectClicked(const QModelIndex& index)
{
	Project* project = m_projectsModel.indexToProject(index);
	qDebug() << "Type" << m_projectsModel.indexType(index);
	if(m_projectsModel.indexType(index) == ProjectsModel::ProjectType) {
		for(int i = 0; i < ui_tabWidget->count(); ++i) {
			ProjectSettingsTab* tab = dynamic_cast<ProjectSettingsTab*>(ui_tabWidget->widget(i));
			if(tab && tab->associatedProject() == project) {
				ui_tabWidget->setCurrentIndex(i);
				on_ui_tabWidget_currentChanged(i);
				return;
			}
		}
	
		ProjectSettingsTab* tab = new ProjectSettingsTab(project, this);
		addTab(tab);
	} else if(m_projectsModel.indexType(index) == ProjectsModel::FileType) {
		qDebug() << "File!!";
		const TinyNode* node = m_projectsModel.indexToNode(index);
		const QString& file = QString::fromStdString(node->path());
		if(!project) return;

		SourceFile* sourceFile = new SourceFile(this);
		for(int i = 0; i < ui_tabWidget->count(); ++i) {
			SourceFile* sourceFile = dynamic_cast<SourceFile*>(ui_tabWidget->widget(i));
			if(sourceFile && sourceFile->associatedFile() == file) {
				ui_tabWidget->setCurrentIndex(i);
				on_ui_tabWidget_currentChanged(i);
				return;
			}
		}

		if(!sourceFile->openProjectFile(project, node)) {
			delete sourceFile;
			return;
		}
		Log::ref().debug(QString("Opened %1 for editing").arg(node->name()));
		addTab(sourceFile);
	}
}
示例#3
0
bool MainWindow::openFile(const QString& file)
{
	QFileInfo fileInfo(file);

	if(!fileInfo.isFile() || !fileInfo.isReadable()) return false;

	for(int i = 0;i < ui_tabWidget->count();i++) {
		SourceFile* sourceFile = dynamic_cast<SourceFile*>(ui_tabWidget->widget(i));
		if(sourceFile && sourceFile->associatedFile() == file) {
			ui_tabWidget->setCurrentIndex(i);
			on_ui_tabWidget_currentChanged(i);
			return true;
		}
	}
	
	/* Attempt to open the selected file */
	SourceFile *sourceFile = new SourceFile(this);
	if(!sourceFile->fileOpen(file)) {
		MessageDialog::showError(this, "simple_error", QStringList() <<
			tr("Could not open ") + sourceFile->associatedFileName() <<
			tr("Unable to open file for reading."));
		delete sourceFile;
		return false;
	}

	QSettings settings;
	QStringList current = settings.value(RECENTS).toStringList().mid(0, 5);
	current.push_front(fileInfo.absoluteFilePath());
	current.removeDuplicates();
	settings.setValue(RECENTS, current);
	
	addTab(sourceFile);
	
	UiEventManager::ref().sendEvent(UI_EVENT_OPEN_FILE);

	return true;
}