Source Code (Use browser search to find items of interest.)
Class Index
kdevelop'CEditWidget (./kdevelop/kdevelop/ceditwidget.h:32)
class CEditWidget : public KWrite {
Q_OBJECT
public: // Constructor and destructor
CEditWidget(QWidget* parent=0,const char* name=0);
CEditWidget(QWidget* parent,const char* name,KWriteDoc* doc,CEditWidgetPrivate* data,QPopupMenu* shared_pop);
~CEditWidget();
public: // Public methods to set attribute values
/** Set the filename.
* @param filename The new filename.
*/
void setName(QString filename) { KWrite::setFileName(filename); }
/** Make the edit view get the input focus. */
void setFocus();
/** Discard old text without warning and set new text
* @param text The new text.
*/
void setText(QString &text) { KWrite::setText(text); }
/** Sets the modification status of the document. */
void toggleModified(bool mod) { KWrite::setModified(mod); }
public: // File related method
/** Loads the file given in name into the editor.
* @param filename Name of the file to load.
* @param mode Current not used.
* @return The line at which the file got loaded.
*/
int loadFile(QString filename, int mode);
/** Save the editbuffer to the current file. */
void doSave();
/** Save the editbuffer to a file with the supplied filename.
* @param filename Name of the file to save the buffer to.
*/
// Requires a little thought about last_modified
// void doSave(QString filename) { KWrite::writeFile(filename); }
bool modifiedOnDisk();
/**
* Returns whether this editor is editing the given file. It is important
* _not_ to decide this by comparing file names, but the inode/device no.
*/
bool isEditing(const QString &filename);
public: // Cursor placement methods
/** Goto the start of the line that contains the specified position.
* @param pos Position to go to
* @param text The editwidget text.
*/
void gotoPos(int pos, QString text);
/** Presents a "Goto Line" dialog to the user. */
void gotoLine() { KWrite::gotoLine(); }
public: // Selection related methods
/** Copies the marked text into the clipboard. */
void copyText() { KWrite::copy(); }
/** Deselects all text. */
void deselectAll() { KWrite::deselectAll(); }
public: // Search and replace methods
/** Presents a search dialog to the user. */
void search() { KWrite::find(); }
/** Repeats the last search or replace operation.
* On replace, the user is prompted even if the "Prompt On Replace"
* option was off.
*/
void searchAgain() { KWrite::findAgain(); }
/** Presents a replace dialog to the user. */
void replace() { KWrite::replace(); }
public: // Queries
/** Return the popupmenu.
* @return Pointer to the current popupmenu.
*/
QPopupMenu* popup() { return pop; };
/** Gets the marked text as string.
* @return The marked text as a string.
*/
QString markedText() { return KWrite::markedText(); }
/** Get the current filename.
* @return The current filename.
*/
QString getName();
/** Gets the complete document content as string.
* @return A string containing the whole document.
*/
QString text() { return KWrite::text(); }
/** Returns the number of lines in the text.
* @return Number of lines in the text.
*/
uint lines() { return (uint) numLines();}//(text().contains('\n', false)); }
public slots:
void spellcheck();
void spellcheck2(KSpell*);
void slotGrepText();
public: // Method to manipulate the buffer
/** Delete an interval of lines.
* @param startAt Line to start deleting at.
* @param endAt Line to stop deleting at.
*/
void deleteInterval( uint startAt, uint endAt );
/** Insert the string at the supplied line.
* @param toInsert Text to insert.
* @param atLine Line to start inserting the text.
*/
void insertAtLine( const char *toInsert, uint atLine );
/** Append a text at the end of the file.
* @param toAdd Text to append.
*/
void append( const char *toAdd );
protected: // Protected attributes
/** Current popupmenu., is shared in different view because of the connects */
QPopupMenu* pop;
/** Current searchtext. */
QString searchtext;
protected: // Protected methods
virtual void enterEvent ( QEvent * e);
virtual void mousePressEvent(QMouseEvent* event);
/** Get the startposition in the buffer of a line
* @param buf Buffer to search in.
* @param aLine Linenumber to find position to.
* @return The 0-based bufferposition or -1 if not found.
*/
int getLinePos( const char *buf, uint aLine );
protected slots:
void slotLookUp();
signals:
void lookUp(QString text);
void grepText(QString text);
void bufferMenu(const QPoint&);
public:
KSpell *kspell;
KSpellConfig *ksc;
int spell_offset;
CEditWidgetPrivate *d; // this date is shared with the second/third view.
};
kdevelop'CEditWidget::CEditWidget() (./kdevelop/kdevelop/ceditwidget.cpp:63)
CEditWidget::CEditWidget(QWidget* parent,const char* name)
: KWrite(new KWriteDoc(&hlManager),parent,name)
{
setFocusProxy (kWriteView);
pop = new QPopupMenu();
// pop->insertItem(i18n("Open: "),this,SLOT(open()),0,6);
pop->insertItem(BarIcon("undo"),i18n("Undo"),this,SLOT(undo()),0,ID_EDIT_UNDO);
pop->insertItem(BarIcon("redo"),i18n("Redo"),this,SLOT(redo()),0,ID_EDIT_REDO);
pop->insertSeparator();
pop->insertItem(BarIcon("cut"),i18n("Cut"),this,SLOT(cut()),0,ID_EDIT_CUT);
pop->insertItem(BarIcon("copy"),i18n("Copy"),this,SLOT(copy()),0,ID_EDIT_COPY);
pop->insertItem(BarIcon("paste"),i18n("Paste"),this,SLOT(paste()),0,ID_EDIT_PASTE);
pop->setItemEnabled(ID_EDIT_CUT,false);
pop->setItemEnabled(ID_EDIT_COPY,false);
pop->setItemEnabled(ID_EDIT_PASTE,false);
pop->insertSeparator();
pop->insertItem(BarIcon("grep"),"",this,SLOT(slotGrepText()),0,ID_EDIT_SEARCH_IN_FILES);
pop->insertItem(BarIcon("lookup"),"",this,SLOT(slotLookUp()),0,ID_HELP_SEARCH_TEXT);
bookmarks.setAutoDelete(true);
d = new CEditWidgetPrivate();
}
kdevelop'CEditWidget::CEditWidget() (./kdevelop/kdevelop/ceditwidget.cpp:89)
CEditWidget::CEditWidget(QWidget* parent,const char* name,KWriteDoc* doc,CEditWidgetPrivate* data,QPopupMenu* shared_pop)
: KWrite(doc,parent,name)
{
setFocusProxy (kWriteView);
bookmarks.setAutoDelete(true);
d = data;
pop = shared_pop;
}
/*-------------------------------------- CEditWidget::~CEditWidget()
* ~CEditWidget()
* Destructor.
*
* Parameters:
* -
* Returns:
* -
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::~CEditWidget() (./kdevelop/kdevelop/ceditwidget.cpp:107)
CEditWidget::~CEditWidget() {
// delete doc();
// delete d;
}
/*********************************************************************
* *
* PUBLIC METHODS *
* *
********************************************************************/
/*--------------------------------------------- CEditWidget::getName()
* getName()
* Get the current filename.
*
* Parameters:
* -
* Returns:
* QString The current filename.
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::getName() (./kdevelop/kdevelop/ceditwidget.cpp:127)
QString CEditWidget::getName(){
//return filename;
QString s(KWrite::fileName());
if (s.isNull()) s = "";
return s;//QString(KWrite::fileName());
}
/*--------------------------------------------- CEditWidget::loadFile()
* loadFile()
* Loads the file given in name into the editor.
*
* Parameters:
* filename Name of the file to load.
* mode Current not used.
*
* Returns:
* int The line at which the file got loaded.
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::loadFile() (./kdevelop/kdevelop/ceditwidget.cpp:145)
int CEditWidget::loadFile(QString filename, int) {
struct stat buf;
KWrite::loadFile(filename);
::stat(filename, &buf);
d->ino = buf.st_ino;
d->dev = buf.st_dev;
d->mtime = buf.st_mtime;
return 0;
}
kdevelop'CEditWidget::doSave() (./kdevelop/kdevelop/ceditwidget.cpp:155)
void CEditWidget::doSave() {
struct stat buf;
KWrite::save();
::stat(KWrite::fileName(), &buf);
d->mtime = buf.st_mtime;
}
kdevelop'CEditWidget::modifiedOnDisk() (./kdevelop/kdevelop/ceditwidget.cpp:162)
bool CEditWidget::modifiedOnDisk() {
struct stat buf;
::stat(KWrite::fileName(), &buf);
return buf.st_mtime != d->mtime;
}
kdevelop'CEditWidget::isEditing() (./kdevelop/kdevelop/ceditwidget.cpp:168)
bool CEditWidget::isEditing(const QString &filename)
{
struct stat buf;
::stat(filename, &buf);
return (buf.st_dev == d->dev) && (buf.st_ino == d->ino);
}
/*------------------------------------------- CEditWidget::setFocus()
* setFocus()
* Make the edit view get the input focus.
*
* Parameters:
* -
* Returns:
* -
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::setFocus() (./kdevelop/kdevelop/ceditwidget.cpp:185)
void CEditWidget::setFocus(){
cerr << "CEditWidget::setFocus()\n";
// KWrite::setFocus();
// kWriteView->setFocus();
}
/*--------------------------------------------- CEditWidget::gotoPos()
* gotoPos()
* Goto the start of the line that contains the specified position.
*
* Parameters:
* pos Position to go to
* text The editwidget text.
*
* Returns:
* -
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::gotoPos() (./kdevelop/kdevelop/ceditwidget.cpp:202)
void CEditWidget::gotoPos(int pos,QString text_str){
// cerr << endl << "POS: " << pos;
// calculate the line
QString last_textpart = text_str.right(text_str.length()+1-pos); // the second part of the next,after the pos
int line = text_str.contains("\n") - last_textpart.contains("\n");
// cerr << endl << "LINE:" << line;
setCursorPosition(line,0);
setFocus();
}
kdevelop'CEditWidget::spellcheck() (./kdevelop/kdevelop/ceditwidget.cpp:213)
void CEditWidget::spellcheck(){
kspell= new KSpell (this, "KDevelop: Spellcheck", this,
SLOT (spellcheck2 (KSpell *)));
}
kdevelop'CEditWidget::spellcheck2() (./kdevelop/kdevelop/ceditwidget.cpp:218)
void CEditWidget::spellcheck2(KSpell *){
// setReadOnly (TRUE);
/* connect (kspell, SIGNAL (misspelling (char *, QStrList *, unsigned)),
this, SLOT (misspelling (char *, QStrList *, unsigned)));
connect (kspell, SIGNAL (corrected (char *,
char *, unsigned)),
this, SLOT (corrected (char *,
char *, unsigned)));
connect (kspell, SIGNAL (progress (unsigned int)),
this, SIGNAL (spellcheck_progress (unsigned int)) );
connect (kspell, SIGNAL (done(char *)),
this, SLOT (spellResult (char *)));
kspell->setProgressResolution (2);
*/
kspell->check (text().data());
}
/*------------------------------------- CEditWidget::deleteInterval()
* deleteInterval()
* Delete an interval of lines.
*
* Parameters:
* startAt Line to start deleting at.
* endAt Line to end deleting at.
*
* Returns:
* -
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::deleteInterval() (./kdevelop/kdevelop/ceditwidget.cpp:252)
void CEditWidget::deleteInterval( uint startAt, uint endAt )
{
assert( startAt >= endAt );
int startPos=0;
int endPos=0;
QString txt;
// Fetch the text.
txt = text();
// Find start position.
startPos = getLinePos( txt, startAt );
// We find the end of the line by increasing the linecounter and
// subtracting by one to make pos point at the last \n character.
endPos = getLinePos( txt, endAt + 1 );
endPos--;
// Remove the interval.
txt.remove( startPos, endPos - startPos );
// Update the editwidget with the new text.
setText( txt );
// Set the buffer as modified.
toggleModified( true );
}
/*------------------------------------- CEditWidget::deleteInterval()
* deleteInterval()
* Insert the string at the given line.
*
* Parameters:
* toInsert Text to insert.
* atLine Line to start inserting the text.
*
* Returns:
* -
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::insertAtLine() (./kdevelop/kdevelop/ceditwidget.cpp:292)
void CEditWidget::insertAtLine( const char *toInsert, uint atLine )
{
assert( toInsert != NULL );
int pos=0;
QString txt;
// Fetch the text.
txt = text();
// Find the position to insert at.
pos = getLinePos( txt, atLine );
// Insert the new text.
txt.insert( pos, toInsert );
// Update the editwidget with the new text.
setText( txt );
// Set the buffer as modified.
toggleModified( true );
}
/*---------------------------------------------- CEditWidget::append()
* append()
* Append a text at the end of the file.
*
* Parameters:
* toAdd Text to append.
*
* Returns:
* -
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::append() (./kdevelop/kdevelop/ceditwidget.cpp:325)
void CEditWidget::append( const char *toAdd )
{
QString txt;
txt = text();
txt.append( toAdd );
setText( txt );
}
/*********************************************************************
* *
* PROTECTED METHODS *
* *
********************************************************************/
/*------------------------------------------ CEditWidget::getLinePos()
* getLinePos()
* Get the startposition in the buffer of a line
*
* Parameters:
* buf Buffer to search in.
* aLine Linenumber to find position to.
*
* Returns:
* int The 0-based bufferposition or -1 if not found.
*-----------------------------------------------------------------*/
kdevelop'CEditWidget::getLinePos() (./kdevelop/kdevelop/ceditwidget.cpp:351)
int CEditWidget::getLinePos( const char *buf, uint aLine )
{
uint line=0;
int pos=0;
while( line < aLine )
{
pos++;
if( buf[ pos ] == '\n' )
line++;
}
// Pos currently points at the last \n, that's why we add 1.
return pos + 1;
}
kdevelop'CEditWidget::enterEvent() (./kdevelop/kdevelop/ceditwidget.cpp:367)
void CEditWidget::enterEvent ( QEvent * e){
KWrite::enterEvent(e);
// setFocus();
}
kdevelop'CEditWidget::mousePressEvent() (./kdevelop/kdevelop/ceditwidget.cpp:372)
void CEditWidget::mousePressEvent(QMouseEvent* event){
if(event->button() == RightButton){
if(event->state() & ControlButton) {
emit bufferMenu(this->mapToGlobal(event->pos()));
return;
}
int state;
int pos;
state = undoState();
//undo
if(state & 1){
pop->setItemEnabled(ID_EDIT_UNDO,true);
}
else{
pop->setItemEnabled(ID_EDIT_UNDO,false);
}
//redo
if(state & 2){
pop->setItemEnabled(ID_EDIT_REDO,true);
}
else{
pop->setItemEnabled(ID_EDIT_REDO,false);
}
QString str = markedText();
if(!str.isEmpty()){
pop->setItemEnabled(ID_EDIT_CUT,true);
pop->setItemEnabled(ID_EDIT_COPY,true);
}
else{
pop->setItemEnabled(ID_EDIT_CUT,false);
pop->setItemEnabled(ID_EDIT_COPY,false);
}
QClipboard *cb = kapp->clipboard();
QString text=cb->text();
if(text.isEmpty())
pop->setItemEnabled(ID_EDIT_PASTE,false);
else
pop->setItemEnabled(ID_EDIT_PASTE,true);
if(str == ""){
str = word(event->x(),event->y());
}
searchtext = str;
str.replace(QRegExp("^\n"), "");
pos=str.find("\n");
if (pos>-1)
str=str.left(pos);
if(str.length() > 20 ){
str = str.left(20) + "...";
}
pop->setItemEnabled(ID_HELP_SEARCH_TEXT, !str.isEmpty());
pop->setItemEnabled(ID_EDIT_SEARCH_IN_FILES, !str.isEmpty());
pop->changeItem(BarIcon("grep"),i18n("grep: ") + str,ID_EDIT_SEARCH_IN_FILES); // the grep entry
pop->changeItem(BarIcon("lookup"),i18n("look up: ") + str,ID_HELP_SEARCH_TEXT); // the lookup entry
pop->popup(this->mapToGlobal(event->pos()));
}
setFocus();
}
/*********************************************************************
* *
* SLOTS *
* *
********************************************************************/
kdevelop'CEditWidget::slotLookUp() (./kdevelop/kdevelop/ceditwidget.cpp:448)
void CEditWidget::slotLookUp(){
emit lookUp(searchtext);
}
kdevelop'CEditWidget::slotGrepText() (./kdevelop/kdevelop/ceditwidget.cpp:451)
void CEditWidget::slotGrepText(){
emit grepText(searchtext);
}