Beispiel #1
0
void EditorTab::closeTab(int index)
{
    switch(tabType(index)) {

        case MM::codeTab:
        {
            Editor * ed = (Editor*)widget(index);
            if (ed->isModified()) {
                if (GetUserConfirmation("This file is being closed, but has unsaved changes. Do you want to save it?\n" + ed->GetFileName()))
                  saveFile(index);

            }
        }
            break;

        case MM::serialTab:
        {
            SerialMonitor * serial = (SerialMonitor*)widget(index);
            serial->ClosePort();
			QThread::msleep(200);
        }
            break;

    }

	// removeTab doesnt delete the widget
	QWidget * w = widget(index);
	this->removeTab(index);
#ifndef Q_OS_LINUX    
	delete w; // For some reason, this is causing a segfault on Linux. Data can't be freed for while :(
#endif
}
Beispiel #2
0
void Workspace::RemoveProject(QString projectName)
{

	Project * project = FindProject(projectName);
	if (project == NULL) {
		return;
	}

	if (GetUserConfirmation("Confirm deleting this whole project?\n\n" + projectName) == false) {
		return;
	}

	QString path = config.workspace + "/" + projectName;
	QDir(path).removeRecursively();

	if (QDir(path).exists()) {
		ErrorMessage("Could not remove the project files. Please delete them manually.");
		return;
	}

	for (int i=0; i < projects.size(); i++) {
		if (projects.at(i).name == projectName) {
			projects.erase(projects.begin() + i);
			break;
		}
	}

	if (projects.size() > 0) {
		SetCurrentProject(projects.at(0).name);
	}
	
	modified = true;
}
Beispiel #3
0
void EditorTab::closeTab(int index)
{
	if (tabType(index) == MM::codeTab) {
		Editor * editor = (Editor *)widget(index);
		if (editor->isModified()) {
			if (GetUserConfirmation("This file is being closed, but has unsaved changes. Do you want to save it?\n" + editor->GetFileName())) {
			/*QMessageBox::StandardButton reply;
			reply = QMessageBox::question(this, "File modified", "File was modified. Do you want to save it?\n" + editor->GetFileName(),
                                QMessageBox::Yes|QMessageBox::No);
			if (reply == QMessageBox::Yes) {*/
				saveFile(index);
			}
		}
	}
	
	// removeTab doesnt delete the widget
	QWidget * w = widget(index);
	this->removeTab(index);
	delete w;

	//delete widget(index);
   // cout << "Index to remove == "  << index << endl;
    //QWidget* tabItem = this->widget(index);
    // Removes the tab at position index from this stack of widgets.
    // The page widget itself is not deleted.
    //this->removeTab(index);
    //delete this->widget(index);
    //delete tabItem; //It does not work, still do not know why...
}
Beispiel #4
0
void Editor::focusInEvent ( QFocusEvent * event )
{
	QsciScintilla::focusInEvent(event);

	// Check if file was modified
	QFileInfo fInfo(file);
	if (fInfo.exists()) {
		QDateTime fileTime = fInfo.lastModified();
        QString s1 = lastModifiedTime.toString();
		QString s2 = fileTime.toString();
        if (lastModifiedTime < fileTime) {
			lastModifiedTime = QDateTime::currentDateTime();
			QString name = QFileInfo(file).fileName().toLower();
			if (name != "mariamole_auto_generated.h") {
				if (GetUserConfirmation("File was modified outside editor. Do you want to reload it?\n" +file) == false)  {
					return;
				}
			}
		
			QFile inFile(file);
			if (!inFile.open(QFile::ReadOnly)) {
				ErrorMessage(tr("Cannot read file %1:\n%2.").arg(file).arg(inFile.errorString()));			
				return;
			}
			QTextStream in(&inFile);
			QApplication::setOverrideCursor(Qt::WaitCursor);
			QString txt(in.readAll());
			setText(txt);				
			setModified(false);
			QApplication::restoreOverrideCursor();
        }
	} // file exists
}
Beispiel #5
0
void Workspace::RemoveFile(QString projectName, QString file, bool isExternal)
{
	Project * project = FindProject(projectName);
	if (project == NULL) {
		return;
	}

	QString msg;
	QString fullPath = GetFullFilePath(projectName, file);
	if (isExternal) {
		msg = "Confirm removing reference to this external file?\nThe file will NOT be deleted!\n\n"
			+ file;
	} else {
		msg = "Confirm deleting this file: \n\n" + fullPath;
	}
	
	if (GetUserConfirmation(msg) == false) {
		return;
	}

	int index = -1;
	for (int i=0; i < project->files.size(); i++) {
		if (isExternal) {
			if ( (project->files.at(i).type == ptExternal) && (project->files.at(i).name == file) ) {
				index = i;
				break;
			}
		} else {
			if ( (project->files.at(i).type == ptSource) && (project->files.at(i).name == file) ) {
				index = i;
				break;
			}
		}
	}

	if (index < 0 ) {
		ErrorMessage("Could not delete the file!\n");
		return;
	}

	if (isExternal == false) {
		bool ok = QFile(fullPath).remove();
		if (ok == false) {
			ErrorMessage("Error deleting the file!\n");
			return;
		}		
	}

	project->files.erase(project->files.begin() + index);
	modified = true;
}