void EditorTab::onEditorTextChanged(void) { int index = currentIndex(); Editor * editor = (Editor *)widget(index); setTabText(index, "*" + QFileInfo(editor->GetFileName()).fileName()); emit codeChanged(); }
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; }
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 }
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... }