Пример #1
0
int FrostEdit::tabWidgetContains(TabWidget* wid, Document* doc) {
	for(int i = 0; i < wid->count(); i++) {
		TextEdit* edit = toTextEdit(wid->widget(i));
		if(edit == nullptr)
			continue;
		if(toDocument(edit->document()) == doc) {
			return i;
		}
	}
	return -1;
}
Пример #2
0
int FrostEdit::openEditors(Document* doc) {
	int open = 0;
	for(TabWidgetFrame* tab: mTabWidgetFrames) {
		for(int i = 0; i < tab->tabWidget()->count(); i++) {
			TextEdit* edit = toTextEdit(tab->tabWidget()->widget(i));
			if(edit != NULL && edit->document() == doc)
				open++;
		}
	}
	return open;
}
Пример #3
0
void FrostEdit::currentTabPageChanged(int id) {
	if(id == -1) {
		disableActions();
		return;
	}
	QWidget* wid = mCurrentTabWidget->widget(id);
	if(wid == nullptr) {
		disableActions();
		return;
	}
	TextEdit* e = toTextEdit(wid);
	if(e != nullptr &&  e->document() != getActiveDocument())
		emit documentChanged(toDocument(e->document()));
	//if there's no editor, let's disable some buttons.
	if(e == nullptr) {
		disableActions();
	} else { //there was editor, enable them
		enableActions();
	}
}
Пример #4
0
void FrostEdit::updateTabHeader(Document* doc, bool b) {
	for(TabWidgetFrame* tab: mTabWidgetFrames) {
		for(int i = 0; i < tab->tabWidget()->count(); i++) {
			TextEdit* edit = toTextEdit(tab->tabWidget()->widget(i));
			if(edit != nullptr && edit->document() == doc) {
				tab->tabWidget()->setTabText(i, doc->getDynamicName());
				changeTitle(tab->tabWidget(), i);
			}
		}
	}
}
Пример #5
0
void FrostEdit::on_actionSave_triggered() {
	TextEdit* e = toTextEdit(mCurrentTabWidget->currentWidget());
	Document* doc = toDocument(e->document());
	if(doc->getFileInfo().isFile()) {
		mDocumentWatcher->removePath(doc->getFullPath());
		doc->save();
		mDocumentWatcher->addPath(doc->getFullPath());
	} else {
		QString prevPath = doc->getFullPath();
		on_actionSave_As_triggered();
		if(mCompiledFile == prevPath)
			mCompiledFile = doc->getFullPath();
	}
	updateTabHeader(doc, doc->isModified());
}
Пример #6
0
void FrostEdit::on_actionSave_As_triggered() {
	QString file = QFileDialog::getSaveFileName(this, "Save as", "", "FrostBasic code files (*.frb);;CoolBasic code files (*.cb);;Text files (.txt);;All files (*.*)");
	if(!file.isEmpty()) {
		TextEdit* e = toTextEdit(mCurrentTabWidget->currentWidget());
		Document* doc = toDocument(e->document());
		mDocumentWatcher->removePath(doc->getFullPath());

		for(TabWidgetFrame* tab: mTabWidgetFrames) {
			tab->removeComboBoxItem(doc->getFullPath());
			tab->addComboBoxItem(file);
		}

		doc->saveAs(file);
		mDocumentWatcher->addPath(file);
		updateTabHeader(doc, doc->isModified());
		doc->getItem()->update();
	}
}
Пример #7
0
void FrostEdit::updateDocumentSelection(TabWidget* wid, int sel) {
	if(wid->count() == 0)
		return;
	if(!wid->count())
		return;

	TextEdit* e = toTextEdit(wid->widget(sel));
	if(e == NULL)
		return;
	Document* doc = toDocument(e->document());
	TabWidgetFrame* parentWidget = toTabWidgetFrame(wid->parentWidget());
	parentWidget->setCurrentItem(doc->getFullPath());
	if(doc->isActualFile())
		mFileSystemTreeView->setCurrentIndex(mFileSystemModel->index(doc->getFullPath()));

	doc->getItem()->setSelected(true);

}
Пример #8
0
void FrostEdit::addEditor(QListWidgetItem* item) {
	DocumentItem* docitem = static_cast<DocumentItem*>(item);
	Document* doc = docitem->getDocument();
	for(int i = 0; i < mCurrentTabWidget->count(); i++) {
		TextEdit* edit = toTextEdit(mCurrentTabWidget->widget(i));
		if(toDocument(edit->document()) == doc) {
			mCurrentTabWidget->setCurrentIndex(i);
			return;
		}
	}

	TextEdit* edit = new TextEdit(mCurrentTabWidget, doc);
	edit->setFindReplaceInstance(mFindReplace);
	edit->setFont(mFont);
	mSyntaxStyle.applyToTextEdit(edit);
	mCurrentTabWidget->addTab(edit, doc->getDynamicName());
	mCurrentTabWidget->setCurrentIndex(mCurrentTabWidget->count()-1);
}
Пример #9
0
void FrostEdit::closeTab(TabWidget* wid, int id) {
	qDebug() << wid  <<  id;
	TextEdit* e = toTextEdit(wid->widget(id));
	Document* doc = toDocument(e->document());

	int editors = openEditors(doc);
	qDebug() << "Open in editors: " << editors;
	int ans = -1;
	if(editors == 1) {
		ans = documentSafeClose(doc);
		if(ans == 0 || ans == 1) {
			wid->removeTab(id);
			delete e;
			removeDocument(doc);
			return;
		}
	}
	wid->removeTab(id);

}
Пример #10
0
void FrostEdit::removeDocument(Document* doc) {

	for(TabWidgetFrame* tab: mTabWidgetFrames) {
		tab->removeComboBoxItem(doc->getFullPath());
		for(int i = 0; i < tab->tabWidget()->count(); i++) {
			TextEdit* edit = toTextEdit(tab->tabWidget()->widget(i));
			if(edit->document() == doc) {
				tab->tabWidget()->removeTab(i);
				delete edit;
			}
		}
	}

	mOpenDocuments.remove(doc->getFullPath());
	mDocumentWatcher->removePath(doc->getFullPath());
	disconnect(doc, &Document::textChanged, this, &FrostEdit::updateTabHeader);
	disconnect(doc, &Document::exterminate, this, &FrostEdit::removeDocument);
	delete doc;
	doc = nullptr;
}
Пример #11
0
TextEdit* MainWindow::CreateTextEdit()
{
	TextEdit* child = new TextEdit;
	++m_countOfFiles;
	//mdiArea->addSubWindow(child);
	/*if(tabWidget->count() == 1)
	{
		tabWidget->insertTab(0, child, "new file");
	}
	else
	{
		tabWidget->addTab(child, tr("new file %1").arg(tabWidget->count()+1));
	}*/

	connect( child, SIGNAL(copyAvailable(bool)), actionCut, SLOT(setEnabled(bool)));
	connect( child, SIGNAL(copyAvailable(bool)), actionCopy, SLOT(setEnabled(bool)));

	connect( child->document(), SIGNAL(undoAvailable(bool)), actionUndo, SLOT(setEnabled(bool)) );
	connect( child->document(), SIGNAL(redoAvailable(bool)), actionRecover, SLOT(setEnabled(bool)) );

	return child;
}
Пример #12
0
Document* FrostEdit::getActiveDocument() {
	TextEdit* edit = toTextEdit(mCurrentTabWidget->currentWidget());
	if(edit == nullptr)
		return nullptr;
	return toDocument(edit->document());
}