added (Un)Comment to the musrgui
This commit is contained in:
parent
ac0fe26844
commit
fcc18e2ae4
@ -208,6 +208,11 @@ void PTextEdit::setupEditActions()
|
|||||||
connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
|
connect( a, SIGNAL( activated() ), this, SLOT( editPaste() ) );
|
||||||
a->addTo( tb );
|
a->addTo( tb );
|
||||||
a->addTo( menu );
|
a->addTo( menu );
|
||||||
|
menu->insertSeparator();
|
||||||
|
a = new QAction( tr( "(Un)Co&mment" ), CTRL + Key_M, this, "editComment" );
|
||||||
|
connect( a, SIGNAL( activated() ), this, SLOT( editComment() ) );
|
||||||
|
a->addTo( tb );
|
||||||
|
a->addTo( menu );
|
||||||
}
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
@ -631,6 +636,64 @@ void PTextEdit::editPaste()
|
|||||||
currentEditor()->paste();
|
currentEditor()->paste();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//----------------------------------------------------------------------------------------------------
|
||||||
|
/**
|
||||||
|
* <p>
|
||||||
|
*/
|
||||||
|
void PTextEdit::editComment()
|
||||||
|
{
|
||||||
|
if ( !currentEditor() )
|
||||||
|
return;
|
||||||
|
|
||||||
|
QString str;
|
||||||
|
if (currentEditor()->hasSelectedText()) { // selected text present
|
||||||
|
int paraFrom, paraTo;
|
||||||
|
int indexFrom, indexTo;
|
||||||
|
// get selection
|
||||||
|
currentEditor()->getSelection(¶From, &indexFrom, ¶To, &indexTo);
|
||||||
|
// check that indexFrom == 0, if not change the selection accordingly
|
||||||
|
if (indexFrom != 0) {
|
||||||
|
indexFrom = 0;
|
||||||
|
currentEditor()->setSelection(paraFrom, indexFrom, paraTo, indexTo);
|
||||||
|
}
|
||||||
|
// check that indexTo == end of line of paraTo
|
||||||
|
if (indexTo != (int)currentEditor()->text(paraTo).length()) {
|
||||||
|
indexTo = currentEditor()->text(paraTo).length();
|
||||||
|
currentEditor()->setSelection(paraFrom, indexFrom, paraTo, indexTo);
|
||||||
|
}
|
||||||
|
// get selection text
|
||||||
|
str = currentEditor()->selectedText();
|
||||||
|
// check line by line if (un)comment is needed
|
||||||
|
QStringList strList = QStringList::split("\n", str);
|
||||||
|
for (QStringList::Iterator it = strList.begin(); it != strList.end(); ++it) {
|
||||||
|
if ((*it).stripWhiteSpace().startsWith("#")) { // comment -> uncomment it
|
||||||
|
(*it).remove(0,1);
|
||||||
|
(*it) = (*it).stripWhiteSpace();
|
||||||
|
} else { // no comment -> comment it
|
||||||
|
(*it).prepend("# ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
str = strList.join("\n");
|
||||||
|
currentEditor()->insert(str);
|
||||||
|
} else { // no text selected
|
||||||
|
int para, index;
|
||||||
|
currentEditor()->getCursorPosition(¶, &index);
|
||||||
|
// get current text line
|
||||||
|
str = currentEditor()->text(para);
|
||||||
|
// check if it is a comment line or not
|
||||||
|
if (str.stripWhiteSpace().startsWith("#")) { // comment -> uncomment it
|
||||||
|
str.remove(0,1);
|
||||||
|
str = str.stripWhiteSpace();
|
||||||
|
} else { // no comment -> comment it
|
||||||
|
str.prepend("# ");
|
||||||
|
}
|
||||||
|
// select current line
|
||||||
|
currentEditor()->setSelection(para, 0, para, currentEditor()->text(para).length());
|
||||||
|
// insert altered text
|
||||||
|
currentEditor()->insert(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//----------------------------------------------------------------------------------------------------
|
//----------------------------------------------------------------------------------------------------
|
||||||
/**
|
/**
|
||||||
* <p>
|
* <p>
|
||||||
|
@ -76,6 +76,7 @@ private slots:
|
|||||||
void editCut();
|
void editCut();
|
||||||
void editCopy();
|
void editCopy();
|
||||||
void editPaste();
|
void editPaste();
|
||||||
|
void editComment();
|
||||||
|
|
||||||
void textFamily( const QString &f );
|
void textFamily( const QString &f );
|
||||||
void textSize( const QString &p );
|
void textSize( const QString &p );
|
||||||
|
Loading…
x
Reference in New Issue
Block a user