Пример #1
0
/**
 * Saves the edited file.
 */
void EditorPage::save()
{
	if (m_pDoc->isModified()){
		// Avoid warning about modification on disk for this document
		KTextEditor::ModificationInterface *pModificationIf;

		pModificationIf = qobject_cast<KTextEditor::ModificationInterface *>(m_pDoc);
		if (pModificationIf)
			pModificationIf->setModifiedOnDiskWarning(false);

		m_pDoc->save();
	}
}
Пример #2
0
/**
 * Class constructor.
 * @param	pDoc	The document object associated with this page
 * @param	pMenu	A Cscope queries popup menu to use with the editor
 * @param	pParent	The parent widget
 * @param	szName	The widget's name
 */
EditorPage::EditorPage(KTextEditor::Document* pDoc, QMenu* pMenu,
	QTabWidget* pParent, const char* szName) : QWidget(pParent),
	m_pParentTab(pParent),
	m_pDoc(pDoc),
	m_bOpen(false),
	m_bNewFile(false),
	m_sName(""),
	m_bWritable(true), /* new documents are writable by default */
	m_bModified(false),
	m_nLine(0),
	m_bSaveNewSizes(false)
{
	Q_UNUSED(pMenu);
	setObjectName(szName);

	// Create code-completion objects (will be deleted by QObject destructor)
	m_pCompletion = new SymbolCompletion(this, this);

	// Set read-only mode, if required
	if (Config().getReadOnlyMode())
		m_pDoc->setReadWrite(false);

	// Turn on modifiedOnHdWarning on a per document base; this must be done BEFORE
	// creating the view ( see KateDocument::KateDocument )
	KTextEditor::ModificationInterface *pModificationIf;
	pModificationIf = qobject_cast<KTextEditor::ModificationInterface *>(m_pDoc);
	if (pModificationIf)
		pModificationIf->setModifiedOnDiskWarning(Config().getWarnModifiedOnDisk());

	// Create the child widgets
	m_pSplit = new QSplitter(this);
	m_pCtagsList = new CtagsList(m_pSplit);
	m_pView = m_pDoc->createView(m_pSplit);

	QHBoxLayout* pLayout = new QHBoxLayout;
	pLayout->addWidget(m_pSplit);
	QWidget::setLayout(pLayout);

	// Perform tasks only when the document has been loaded completely
	connect(m_pDoc, SIGNAL(completed()), this, SLOT(slotFileOpened()));

	// Be notified when the text in the editor changes
	connect(m_pDoc, SIGNAL(textChanged(KTextEditor::Document*)), this, SLOT(slotSetModified(KTextEditor::Document*)));
	connect(m_pDoc, SIGNAL(undoChanged()), this, SLOT(slotUndoChanged()));

	// Store the sizes of the child windows when the tag list is resized
	// (since it may imply a move of the splitter divider)
	connect(m_pCtagsList, SIGNAL(resized()), this, SLOT(slotChildResized()));

	// Go to a symbol's line if it is selected in the tag list
	connect(m_pCtagsList, SIGNAL(lineRequested(uint)), this,
		SLOT(slotGotoLine(uint)));

	// Add Ctag records to the tag list
	connect(&m_ctags, SIGNAL(dataReady(FrontendToken*)), m_pCtagsList,
		SLOT(slotDataReady(FrontendToken*)));

	// Monitor Ctags' operation
	connect(&m_ctags, SIGNAL(finished(uint)), m_pCtagsList, 
		SLOT(slotCtagsFinished(uint)));

	// Set the context menu
	m_pView->setContextMenu(pMenu);
	connect(m_pView, SIGNAL(cursorPositionChanged(KTextEditor::View *, const KTextEditor::Cursor&)),
		this, SLOT(slotCursorPosChange(KTextEditor::View *)));
}