Example #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
}
Example #2
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...
}
Example #3
0
void EditorTab::ConfigureAllTabs(void)
{
	for (int i=0; i < count(); i++) {
		if (tabType(i) == MM::codeTab) {
			Editor * editor = (Editor *)widget(i);
			editor->Configure();			
		}		
	}
}
Example #4
0
void EditorTab::FormatCode(void)
{
	if (currentIndex() < 0) {
		return;
	}
	
	if (tabType(currentIndex() == MM::codeTab)) {
		Editor * editor = (Editor *)widget(currentIndex());
		editor->CodeBeautifier();
	}
}
Example #5
0
bool EditorTab::saveAllFiles(void)
{
	bool ok = true;
	for (int i=0; i < count(); i++) {
		if (tabType(i) != MM::codeTab) {
			continue;
		}
		ok = ok && saveFile(i);		
	}

	return ok;
}
Example #6
0
void EditorTab::Search(QString text, bool caseSensitive, bool wholeWords)
{
	if (currentIndex() < 0) {
		return;
	}
	
	if (tabType(currentIndex() == MM::codeTab)) {
		Editor * editor = (Editor *)widget(currentIndex());
		if (editor->findFirst(text, false, caseSensitive, wholeWords, true, true, false) == false) {
			ErrorMessage("Text not found!");
		}
	}
}
Example #7
0
void EditorTab::EnableAllSerialPorts(bool enable)
{
	for (int i=0; i < count(); i++) {
		if (tabType(i) == MM::serialTab) {		
			SerialMonitor * serial = (SerialMonitor *)widget(i);
			if (enable) {
				serial->OpenPort();
			} else {
				serial->ClosePort();				
			}
		}
	}
}
Example #8
0
//check if all files are saved
bool EditorTab::allSaved(void)
{
    bool saved = true;

    for (int i = 0; i < count(); i++) {
        if (tabType(i) == MM::codeTab) {
            Editor * editor = (Editor *)widget(i);
            if(editor->isModified()) {
                saved = false;
                break; //if at least one file is not saved, why continue?
            }
        }
    }
    return saved;
}
Example #9
0
int EditorTab::portIndex(QString port)
// returns the tab index that holds the requested serila port
{
	for (int i=0;  i < count(); i++) {
        //QWidget * w = widget(i); //not used
		// Check if the widget is a code editor
		if (tabType(i) == MM::serialTab) {		
			SerialMonitor * monitor = (SerialMonitor *)(widget(i));
			if (monitor->GetPort() == port) {
				return i;
			}
		}		
	}

	return -1;
}
Example #10
0
int EditorTab::fileIndex(QString filename)
// returns the tab index that holds the requested file
// if no tab holds this file, returns -1
{
	for (int i=0;  i < count(); i++) {
		//QWidget * w = widget(i);
		// Check if the widget is a code editor
		if (tabType(i) == MM::codeTab) {		
			Editor * editor = (Editor *)(widget(i));
			if (editor->GetFileName() == filename) {
				return i;
			}
		}		
	}

	return -1;
}
Example #11
0
void EditorTab::EnableAllSerialPorts(bool enable)
{
	QString currentPort = "None";
	if (workspace.GetCurrentProject() != NULL) {
		currentPort = workspace.GetCurrentProject()->serialPort;
	}
	for (int i=0; i < count(); i++) {
		if (tabType(i) == MM::serialTab) {		
			SerialMonitor * serial = (SerialMonitor *)widget(i);
			if (enable) {
				serial->OpenPort();
				if (serial->GetPort() == currentPort) {
					setCurrentIndex(i);
				}
			} else {
				serial->ClosePort();				
			}
		}
	}
}