editorpage.cpp

来自「This a source insight software in Linux.」· C++ 代码 · 共 656 行 · 第 1/2 页

CPP
656
字号
 * Combines getSelection() and getWordUnderCursor() to return a suggested * text for queries. * The function first looks if any text is selected. If so, the selected text * is returned. Otherwise, the word under the cursor location is returned, if * one exists. * @return	Either the currently selected text, or the word under the cursor, *			or QString::null if both options fail */QString EditorPage::getSuggestedText(){	QString sText;		sText = getSelection();	if (sText == QString::null)		sText = getWordUnderCursor();		return sText;	}/** * Returns the contents of the requested line. * Truncates the leading and trailing white spaces. * @param	nLine	The line number * @return	The text of the requested line, if successful, QString::null *			otherwise */QString EditorPage::getLineContents(uint nLine){	KTextEditor::EditInterface* pEditIf;	QString sLine;	// Cannot accept line 0	if (nLine == 0)		return QString::null;		// Get a pointer to the edit interface	pEditIf = dynamic_cast<KTextEditor::EditInterface*>(m_pDoc);	if (!pEditIf)		return QString::null;	// Get the line on which the cursor is positioned	sLine = pEditIf->textLine(nLine - 1);	return sLine.stripWhiteSpace();}/** * Moves the editing caret to the beginning of a given line. * @param	nLine	The line number to move to */void EditorPage::slotGotoLine(uint nLine){	// Ensure there is an open document	if (!m_bOpen)		return;		// Set the cursor to the requested line	if (!setCursorPos(nLine))		return;	// Update Ctags view	m_pCtagsList->gotoLine(nLine);	// Set the focus to the selected line	m_pView->setFocus();}/** * Sets this editor as the current page, when the edited file's name is * selected in the "Window" menu. */void EditorPage::slotMenuSelect(){	m_pParentTab->setCurrentPage(m_pParentTab->indexOf(this));}/** * Displays a list of possible completions for the symbol currently under the * cursor. */void EditorPage::slotCompleteSymbol(){	m_pCompletion->slotComplete();}/** * Stores the sizes of the child widgets whenever they are changed. * This slot is connected to the resized() signal of the CtagsList child * widget. */void EditorPage::slotChildResized(){	SPLIT_SIZES si;	// Only store sizes when allowed to	if (!m_bSaveNewSizes) {		m_bSaveNewSizes = true;		return;	}			// Get the current widths of the child widgets	si = m_pSplit->sizes();	if (si.count() == 2)		Config().setEditorSizes(si);}/** * Sets the visibility status and sizes of the child widgets. * @param	bShowTagList	true to show the tag list, false otherwise * @param	si				The new sizes to use */void EditorPage::setLayout(bool bShowTagList, const SPLIT_SIZES& si){	// Make sure sizes are not stored during this process	m_bSaveNewSizes = false;		// Adjust the layout	m_pCtagsList->setShown(bShowTagList);	if (bShowTagList)		m_pSplit->setSizes(si);}/** * Returns the current position of the cursor. * @param	nLine	Holds the line on which the cursor is currently located * @param	nCol	Holds the column on which the cursor is currently located * @return	true if successful, false otherwise (cursor interface was not *			obtained) */bool EditorPage::getCursorPos(uint& nLine, uint& nCol){	KTextEditor::ViewCursorInterface* pCursorIf;		// Acquire the view cursor	pCursorIf = dynamic_cast<KTextEditor::ViewCursorInterface*>(m_pView);	if (pCursorIf == NULL)		return false;		// Get the cursor position (adjusted to 1-based counting)	pCursorIf->cursorPosition(&nLine, &nCol);	nLine++;	nCol++;		return true;}/** * Moves the cursor to a given position. * @param	nLine	The cursor's new line number * @param	nCol	The cursor's new column number * @return	true if successful, false otherwise (cursor interface was not *			obtained) */bool EditorPage::setCursorPos(uint nLine, uint nCol){	Kate::View* pKateView;	KTextEditor::ViewCursorInterface* pCursorIf;		// Cannot accept line 0	if (nLine == 0)		return false;		// Adjust to 0-based counting	nLine--;	nCol--;			// Acquire the view cursor	pCursorIf = dynamic_cast<KTextEditor::ViewCursorInterface*>(m_pView);	if (pCursorIf == NULL)		return false;		// NOTE: The following code is a fix to a bug in Kate, which wrongly	// calculates the column number in setCursorPosition.	pKateView = dynamic_cast<Kate::View*>(m_pView);	if (pKateView != NULL) {		KTextEditor::EditInterface* pEditIf;		const char* szLine;		uint nRealCol;		uint nTabAdjust;				// Get a pointer to the edit interface		pEditIf = dynamic_cast<KTextEditor::EditInterface*>(m_pDoc);		if (!pEditIf)			return false;				nRealCol = 0;				// Check for out of bound line numbers		if (nLine < pEditIf->numLines()) {			// Get the contents of the requested line			szLine = pEditIf->textLine(nLine).latin1();						// Check for empty line			if (szLine != NULL) {				// The number of columns which a tab character adds				nTabAdjust = pKateView->tabWidth() - 1;								// Calculate the real column, based on the tab width				for (; nRealCol < nCol && szLine[nRealCol] != 0; nRealCol++) {					if (szLine[nRealCol] == '\t')						nCol -= nTabAdjust;				}			}		}		else {			// Marker set beyond end of file, move to the last line			nLine = pEditIf->numLines() - 1;		}		// Set the cursor position		pCursorIf->setCursorPositionReal(nLine, nRealCol);	}	else {		// Non-Kate editors: set the cursor position normally		pCursorIf->setCursorPosition(nLine, nCol);	}		return true;}/** * Called when a document has completed loading. * Determines the file's properties and refreshes the tag list of the editor * window. * This slot is connected to the completed() signal of the document object. * The signal is emitted when a new file is opened, or when a modified file is * saved. */void EditorPage::slotFileOpened(){	QFileInfo fi(m_pDoc->url().path());		// Get file information	m_sName = fi.fileName();	m_bWritable = fi.isWritable();		// Set read/write or read-only mode	m_pDoc->setReadWrite(!Config().getReadOnlyMode() && m_bWritable);		// Refresh the tag list	m_pCtagsList->clear();	m_ctags.run(m_pDoc->url().path());	// Check if this is a modified file that has just been saved	if (m_bModified)		emit fileSaved(m_pDoc->url().path());		// Notify that the document has loaded	m_bOpen = true;	m_bModified = false;	emit fileOpened(this, m_pDoc->url().path());	// Set initial position of the cursor	m_nLine = 0;	slotCursorPosChange();		// This is no longer a new file	m_bNewFile = false;}/** * Marks a file as modified when the contents of the editor change. * This slot is conncted to the textChanged() signal of the Document object. * In addition to marking the file, this method also emits the modified() * signal. */void EditorPage::slotSetModified(){	// Only perform tasks if the file is not already marked	if (!m_bModified && m_pDoc->isModified()) {		m_bModified = true;		emit modified(this, m_bModified);	#if KDE_IS_VERSION(3,3,0)		Kate::DocumentExt* pKateDoc;			// If the editor is a Kate part, check whether it was modified on		// disk as well, and issue a warning if so		pKateDoc = dynamic_cast<Kate::DocumentExt*>(m_pDoc);		if (pKateDoc)			pKateDoc->slotModifiedOnDisk(dynamic_cast<Kate::View*>(m_pView));#endif	}		// Start/restart the auto-completion timer	m_pCompletion->slotAutoComplete();}/** * Marks a file as not modified if all undo levels have been applied. * This slot is conncted to the undoChanged() signal of the Document object. * In addition to marking the file, this method also emits the modified() * signal. */void EditorPage::slotUndoChanged(){	// Check if the file contents have been fully restored	if (m_bModified && !m_pDoc->isModified()) {		m_bModified = false;		emit modified(this, m_bModified);	}}/** * Handles changes in the cursor position. * Emits a signal with the new line and column numbers. */void EditorPage::slotCursorPosChange(){	uint nLine, nCol;		// Find the new line and column number, and emit the signal	if (!getCursorPos(nLine, nCol))		return;			emit cursorPosChanged(nLine, nCol);		// Select the relevant symbol in the tag list	if (Config().getAutoTagHl() && (m_nLine != nLine)) {		m_pCtagsList->gotoLine(nLine);		m_nLine = nLine;	}		// Abort code completion on cursor changes during the completion	// process	m_pCompletion->abort();}#include "editorpage.moc"

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?