[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: branches/kdevelop/3.4/parts/astyle
From: Megan Webb <kdeveloper.megan () gmail ! com>
Date: 2006-12-11 7:00:44
Message-ID: 1165820444.129554.24547.nullmailer () svn ! kde ! org
[Download RAW message or body]
SVN commit 612387 by webb:
Make all format options follow project/global defaults.
M +33 -21 astyle_part.cpp
M +5 -5 astyle_part.h
M +46 -22 astyle_widget.cpp
M +3 -3 astyle_widget.h
--- branches/kdevelop/3.4/parts/astyle/astyle_part.cpp #612386:612387
@@ -72,9 +72,8 @@
loadGlobal();
//use the globals first, project level will override later..
m_project=m_global;
+ m_projectExtensions = m_globalExtensions;
- QString defaultExt="*.cpp *.h,*.c *.h,*.cxx *.hxx,*.c++ *.h++,*.cc *.hh,*.C \
*.H,*.diff ,*.inl,*.java,*.moc,*.patch,*.tlh,*.xpm";
- setExtensions(defaultExt);
// maybe there is a file open already
activePartChanged( partController()->activePart() );
@@ -86,8 +85,8 @@
KConfig *config = kapp->config();
config->setGroup("AStyle");
QString options = \
config->readEntry("Options","BlockBreak=0,BlockBreakAll=0,BlockIfElse=0,Brackets=Break \
,BracketsCloseHeaders=0,FStyle=UserDefined,Fill=Tabs,FillCount=4,FillEmptyLines=0,Fill \
Force=0,IndentBlocks=0,IndentBrackets=0,IndentCases=0,IndentClasses=1,IndentLabels=1,I \
ndentNamespaces=1,IndentPreprocessors=0,IndentSwitches=1,KeepBlocks=1,KeepStatements=1 \
,MaxStatement=40,MinConditional=-1,PadOperators=0,PadParenthesesIn=1,PadParenthesesOut=1,PadParenthesesUn=1,");
+ m_globalExtensions=QStringList::split(",",config->readEntry("Extensions","*.cpp \
*.h,*.c *.h,*.cxx *.hxx,*.c++ *.h++,*.cc *.hh,*.C \
*.H,*.diff,*.inl,*.java,*.moc,*.patch,*.tlh,*.xpm"));
-
QStringList pairs = QStringList::split( ",", options);
QStringList::Iterator it;
for ( it = pairs.begin(); it != pairs.end(); ++it ) {
@@ -95,6 +94,7 @@
m_global[bits[0]] = bits[1];
}
+
// for (QMap<QString, QVariant>::iterator iter = m_global.begin();iter != \
m_global.end();iter++) // {
// kdDebug(9009) << "load: " <<iter.key() << "="<< iter.data() << \
endl; @@ -120,6 +120,7 @@
KConfig *config = kapp->config();
config->setGroup("AStyle");
config->writeEntry("Options",options);
+ config->writeEntry("Extensions",m_globalExtensions.join(","));
config->sync();
// for (QMap<QString, QVariant>::iterator iter = m_global.begin();iter != \
m_global.end();iter++) @@ -254,24 +255,33 @@
}
}
-QString AStylePart::getExtensions(){
- QString values = m_displayExtensions.join("\n");
- kdDebug(9009) << "getExtensions " << values<<endl;
+QString AStylePart::getGlobalExtensions(){
+ QString values = m_globalExtensions.join("\n");
return values.stripWhiteSpace();
}
+QString AStylePart::getProjectExtensions(){
+ QString values = m_projectExtensions.join("\n");
+ return values.stripWhiteSpace();
+}
+
/**
* Extensions from the widget passed in.
* We preserve the order, so common extensions will
* end up at the top
* @param ext
*/
-void AStylePart::setExtensions ( QString ext )
+void AStylePart::setExtensions ( QString ext, bool global )
{
kdDebug(9009) << "setExtensions " << ext<<endl;
+ if ( global){
+ m_globalExtensions.clear();
+ m_globalExtensions=QStringList::split ( QRegExp("\n"), ext );
+ }
+ else{
m_searchExtensions.clear();
- m_displayExtensions.clear();
- m_displayExtensions = QStringList::split ( QRegExp("\n"), ext );
+ m_projectExtensions.clear();
+ m_projectExtensions = QStringList::split ( QRegExp("\n"), ext );
QStringList bits = QStringList::split(QRegExp("\\s+"),ext);
for ( QStringList::Iterator iter = bits.begin(); iter != bits.end(); iter++ )
{
@@ -291,6 +301,7 @@
m_searchExtensions.insert(ending, ending);
}
}
+ }
}
void AStylePart::activePartChanged ( KParts::Part *part )
@@ -405,6 +416,7 @@
{
m_project = m_global;
m_project["FStyle"] = "GLOBAL";
+ m_projectExtensions=m_globalExtensions;
}
else
{
@@ -412,13 +424,14 @@
{
m_project[iter.key()] = \
style.attribute(iter.key(),iter.data().toString()); }
+
+ QDomElement exten = el->namedItem("Extensions").toElement();
+ QString ext = exten.attribute("ext").simplifyWhiteSpace();
+ if ( ext.isEmpty()){
+ ext="*.cpp *.h,*.c *.h,*.cxx *.hxx,*.c++ *.h++,*.cc *.hh,*.C *.H,*.diff \
,*.inl,*.java,*.moc,*.patch,*.tlh,*.xpm"; + }
+ setExtensions(ext.replace(QChar(','), QChar('\n')),false);
}
- QDomElement exten = el->namedItem("Extensions").toElement();
- QString ext = exten.attribute("ext").simplifyWhiteSpace();
- if ( ext.isEmpty()){
- ext="*.cpp *.h,*.c *.h,*.cxx *.hxx,*.c++ *.h++,*.cc *.hh,*.C *.H,*.diff \
,*.inl,*.java,*.moc,*.patch,*.tlh,*.xpm";
- }
- setExtensions(ext.replace(QChar(','), QChar('\n')));
}
@@ -436,17 +449,16 @@
{
style.setAttribute(iter.key(),iter.data().toString());
}
+ QDomElement exten = domDoc.createElement ( "Extensions" );
+ exten.setAttribute ( "ext", m_projectExtensions.join(",").simplifyWhiteSpace() );
+ el->appendChild(exten);
}
- QDomElement exten = domDoc.createElement ( "Extensions" );
- exten.setAttribute ( "ext", m_displayExtensions.join(",").simplifyWhiteSpace() );
-
el->appendChild(style);
- el->appendChild(exten);
}
void AStylePart::formatFilesSelect(){
m_urls.clear();
- QStringList filenames = KFileDialog::getOpenFileNames ( QString::null, \
getExtensions(),0,"Select files to format" ); + QStringList filenames = \
KFileDialog::getOpenFileNames ( QString::null, getProjectExtensions(),0,"Select \
files to format" );
for(QStringList::Iterator it = filenames.begin(); it != filenames.end();it++){
m_urls << *it;
@@ -513,7 +525,7 @@
}
if ( processed != 0 )
{
- KMessageBox::information ( 0, i18n ( "Processed %1 files ending with extensions \
%2" ).arg ( processed ).arg(getExtensions().stripWhiteSpace()) ); \
+ KMessageBox::information ( 0, i18n ( "Processed %1 files ending with extensions \
%2" ).arg ( processed ).arg(getProjectExtensions().stripWhiteSpace()) ); }
m_urls.clear();
--- branches/kdevelop/3.4/parts/astyle/astyle_part.h #612386:612387
@@ -33,8 +33,9 @@
virtual QString formatSource(const QString text);
QString indentString() const;
void saveGlobal();
- void setExtensions(QString ext);
- QString getExtensions();
+ void setExtensions(QString ext, bool global);
+ QString getProjectExtensions();
+ QString getGlobalExtensions();
void restorePartialProjectSession(const QDomElement * el);
void savePartialProjectSession(QDomElement * el);
@@ -65,11 +66,10 @@
// the configurable options.
QMap<QString, QVariant> m_project;
QMap<QString, QVariant> m_global;
+ QStringList m_projectExtensions;
+ QStringList m_globalExtensions;
QMap<QString, QString> m_searchExtensions;
- QStringList m_displayExtensions;
KURL::List m_urls;
-
-
};
--- branches/kdevelop/3.4/parts/astyle/astyle_widget.cpp #612386:612387
@@ -14,7 +14,7 @@
AStyleWidget::AStyleWidget(AStylePart * part, bool global, QWidget *parent, const \
char *name)
- : AStyleConfig(parent, name), m_part(part), isGlobal(global)
+ : AStyleConfig(parent, name), m_part(part), isGlobalWidget(global)
{
// which style changed - disable the other pages.
connect(StyleGroup, SIGNAL(clicked(int)), this, SLOT(styleChanged()));
@@ -54,22 +54,13 @@
QMap<QString, QVariant> option;
- if ( isGlobal){
- Style_Global->setEnabled(false);
+ if ( isGlobalWidget){
Style_Global->hide();
- GeneralExtension->hide();
- FrameFilesFormat->hide();
option = m_part->getGlobalOptions();
}
else{
- Style_Global->setEnabled(true);
Style_Global->show();
- GeneralExtension->show();
- FrameFilesFormat->show();
option = m_part->getProjectOptions();
- QString ext = m_part->getExtensions();
- if ( !ext.isEmpty())
- GeneralExtension->setText(m_part->getExtensions());
}
// style
@@ -84,6 +75,26 @@
if (s == "GLOBAL") id = 6;
StyleGroup->setButton(id);
+ if ( isGlobalWidget ){
+ GeneralExtension->setText(m_part->getGlobalExtensions());
+ GeneralExtension->setEnabled(true);
+ globalOptions=true;
+ }
+ else{
+ if ( id == 6){
+ GeneralExtension->setText(m_part->getGlobalExtensions());
+ GeneralExtension->setEnabled(false);
+ globalOptions=true;
+ }
+ else{
+ GeneralExtension->setText(m_part->getProjectExtensions());
+ GeneralExtension->setEnabled(true);
+ globalOptions=false;
+ }
+ }
+
+ m_lastExt=GeneralExtension->text();
+
if (s == "UserDefined" || s =="GLOBAL" )
{
int wsCount = option["FillCount"].toInt();
@@ -162,12 +173,13 @@
void AStyleWidget::accept()
{
QMap<QString, QVariant>* m_option;
- if ( isGlobal){
+ if ( isGlobalWidget){
m_option = &(m_part->getGlobalOptions());
+ m_part->setExtensions(GeneralExtension->text(),true);
}
else{
m_option = &(m_part->getProjectOptions());
- m_part->setExtensions(GeneralExtension->text());
+ m_part->setExtensions(GeneralExtension->text(),false);
}
@@ -251,7 +263,7 @@
(*m_option)["KeepBlocks"] = Keep_Blocks->isChecked();
}
- if ( isGlobal){
+ if ( isGlobalWidget){
QMap<QString, QVariant>& project = m_part->getProjectOptions();
if ( project["FStyle"] == "GLOBAL"){
project = m_part->getGlobalOptions();
@@ -267,7 +279,6 @@
}
-
/**
* Change the sample formatting text depending on what tab is selected.
*
@@ -275,8 +286,7 @@
*/
void AStyleWidget::styleChanged( )
{
-
- // diable the tabs for predefined sample
+ // disable the tabs for predefined sample
// only user define id==0, enables the other tabs
ConfigTabs->setTabEnabled(tab_2, Style_UserDefined->isChecked());
ConfigTabs->setTabEnabled(tab_3, Style_UserDefined->isChecked());
@@ -284,7 +294,6 @@
int id = ConfigTabs->currentPageIndex();
-
StyleExample->clear();
QString bracketSample = "namespace foospace {\n\tint Foo(){\n\tif \
(isBar)\n{\nbar(); \n\treturn 1; } else \nreturn 0;}}\n\nvoid test(){\n\tif \
(isFoo){\n\tbar();\n} else\n{\n\tbar();\n}\n}\n"; @@ -295,8 +304,6 @@
QString styleSample = "\t//Tabs & Brackets\nnamespace foo{\n" + bracketSample + \
"}\n\t// Indentation\n" + indentSample + "\t// Formatting\n" + formattingSample;
-
-
switch(id){
case 1:
StyleExample->setText( m_part->formatSource( bracketSample, \
this,m_part->getProjectOptions() ) ); @@ -309,14 +316,31 @@
break;
default:
{
- if ( Style_Global->isChecked())
- StyleExample->setText( m_part->formatSource( styleSample, 0, \
m_part->getGlobalOptions()) ); + if ( Style_Global->isChecked() ){
+ StyleExample->setText( m_part->formatSource( styleSample, 0, \
m_part->getGlobalOptions()) ); + }
else
{
StyleExample->setText( m_part->formatSource( styleSample, this, \
m_part->getProjectOptions() ) ); }
}
}
+
+ if ( Style_Global->isChecked()){
+ if ( !globalOptions){
+ m_lastExt = GeneralExtension->text();
+ GeneralExtension->setEnabled ( false );
+ GeneralExtension->setText ( m_part->getGlobalExtensions() );
+ globalOptions=!globalOptions;
+ }
+ }
+ else{
+ if ( globalOptions){
+ GeneralExtension->setEnabled ( true );
+ GeneralExtension->setText ( m_lastExt );
+ globalOptions=!globalOptions;
+ }
+ }
}
#include "astyle_widget.moc"
--- branches/kdevelop/3.4/parts/astyle/astyle_widget.h #612386:612387
@@ -23,13 +23,13 @@
private slots:
-
void styleChanged();
private:
-
AStylePart * m_part;
- bool isGlobal;
+ bool isGlobalWidget;
+ QString m_lastExt;
+ bool globalOptions;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic