int main(int argc, char **argv) { if (argc != 3){ g_print ("Usage: formatXml inputfile outputfile\n\n"); return -1; } xmlKeepBlanksDefault(0); formatFile (argv [1], argv [2]); return 0; }
void ClangFormat::formatSelectedText() { const TextEditor::TextEditorWidget *widget = TextEditor::TextEditorWidget::currentTextEditorWidget(); if (!widget) return; const QTextCursor tc = widget->textCursor(); if (tc.hasSelection()) { const int offset = tc.selectionStart(); const int length = tc.selectionEnd() - offset; m_beautifierPlugin->formatCurrentFile(command(offset, length)); } else if (m_settings->formatEntireFileFallback()) { formatFile(); } }
void ClangFormat::formatSelectedText() { TextEditor::BaseTextEditor *editor = qobject_cast<TextEditor::BaseTextEditor *>(Core::EditorManager::currentEditor()); if (!editor) return; QTextCursor tc = editor->editorWidget()->textCursor(); if (tc.hasSelection()) { const int offset = tc.selectionStart(); const int length = tc.selectionEnd() - offset; BeautifierPlugin::formatCurrentFile(command(offset, length)); } else if (m_settings->formatEntireFileFallback()) { formatFile(); } }
bool Uncrustify::initialize() { Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::Uncrustify::MENU_ID); menu->menu()->setTitle(QLatin1String(Constants::Uncrustify::DISPLAY_NAME)); m_formatFile = new QAction(BeautifierPlugin::msgFormatCurrentFile(), this); Core::Command *cmd = Core::ActionManager::registerAction(m_formatFile, Constants::Uncrustify::ACTION_FORMATFILE, Core::Context(Core::Constants::C_GLOBAL)); menu->addAction(cmd); connect(m_formatFile, SIGNAL(triggered()), this, SLOT(formatFile())); Core::ActionManager::actionContainer(Constants::MENU_ID)->addMenu(menu); return true; }
// Запись форматов, разделенных символом перевода строки void MainWindow::saveFormats(QString text) { QFile formatFile(formatFileName); bool result=formatFile.open(QIODevice::WriteOnly | QIODevice::Text); if(!result) { QMessageBox msgBox; msgBox.setText("Невозможно сохранить файл настроек."); msgBox.exec(); formatFile.close(); return; } formatFile.write(text.toUtf8()); formatFile.close(); }
// Загрузка форматов из файла void MainWindow::readFormats() { formats.clear(); QFile formatFile(formatFileName); bool result=formatFile.open(QIODevice::ReadOnly | QIODevice::Text); if(!result) { QMessageBox msgBox; msgBox.setText("Список форматов пуст. Воспользуйтесь настройкой чтобы добавить форматы."); msgBox.exec(); formatFile.close(); return; } // Заполняется список форматов while(!formatFile.atEnd()) { QByteArray line = formatFile.readLine(); QString format=QString(line); if(format.trimmed().length()>0) formats << format.trimmed(); } // Выпадающий список на экране заполняется считанными форматами ui->currentDataFormatComboBox->clear(); ui->currentDataFormatComboBox->addItems(formats); formatFile.close(); }
bool ClangFormat::initialize() { Core::ActionContainer *menu = Core::ActionManager::createMenu(Constants::ClangFormat::MENU_ID); menu->menu()->setTitle(QLatin1String("ClangFormat")); m_formatFile = new QAction(tr("Format Current File"), this); Core::Command *cmd = Core::ActionManager::registerAction(m_formatFile, Constants::ClangFormat::ACTION_FORMATFILE, Core::Context(Core::Constants::C_GLOBAL)); menu->addAction(cmd); connect(m_formatFile, SIGNAL(triggered()), this, SLOT(formatFile())); m_formatRange = new QAction(tr("Format Selected Text"), this); cmd = Core::ActionManager::registerAction(m_formatRange, Constants::ClangFormat::ACTION_FORMATSELECTED, Core::Context(Core::Constants::C_GLOBAL)); menu->addAction(cmd); connect(m_formatRange, SIGNAL(triggered()), this, SLOT(formatSelectedText())); Core::ActionManager::actionContainer(Constants::MENU_ID)->addMenu(menu); return true; }
bool EQStr::load(const QString& fileName) { // clear out any existing contents m_messageStrings.clear(); // create a QFile on the file QFile formatFile(fileName); // open the file read only if (!formatFile.open(IO_ReadOnly)) { seqWarn("EQStr: Failed to open '%s'", fileName.latin1()); return false; } // allocate a QCString large enough to hold the entire file QCString textData(formatFile.size() + 1); // read in the entire file formatFile.readBlock(textData.data(), textData.size()); // construct a regex to deal with either style line termination QRegExp lineTerm("[\r\n]{1,2}"); // split the data into lines at the line termination QStringList lines = QStringList::split(lineTerm, QString::fromUtf8(textData), false); // start iterating over the lines QStringList::Iterator it = lines.begin(); // first is the magic id string QString magicString = (*it++); int spc; uint32_t formatId; QString formatString; uint32_t maxFormatId = 0; // next skip over the count, etc... it++; // now iterate over the format lines for (; it != lines.end(); ++it) { // find the beginning space spc = (*it).find(' '); // convert the beginnign of the string to a ULong formatId = (*it).left(spc).toULong(); if (formatId > maxFormatId) maxFormatId = formatId; // insert the format string into the dictionary. m_messageStrings.insert(formatId, new QString((*it).mid(spc+1))); } // note that strings are loaded m_loaded = true; seqInfo("Loaded %d message strings from '%s' maxFormat=%d", m_messageStrings.count(), fileName.latin1(), maxFormatId); return true; }
void IssueDetailsGenerator::writeHistory( HtmlWriter* writer, const IssueEntity& issue, HtmlText::Flags flags ) { Qt::SortOrder order = Qt::AscendingOrder; if ( dataManager->preferenceOrSetting( "history_order" ) == "desc" ) order = Qt::DescendingOrder; QList<ChangeEntity> changes; if ( m_history == AllHistory ) changes = issue.changes( order ); else if ( m_history == OnlyComments ) changes = issue.comments( order ); else if ( m_history == OnlyFiles ) changes = issue.files( order ); else if ( m_history == CommentsAndFiles ) changes = issue.commentsAndFiles( order ); QList<HtmlText> list; int lastUserId = 0; QDateTime lastDate; for ( int i = 0; i < changes.count(); i++ ) { const ChangeEntity& change = changes.at( i ); if ( change.type() == ValueChanged && change.attributeId() == 0 ) continue; if ( change.type() <= ValueChanged && list.count() > 0 ) { if ( change.createdUserId() == lastUserId && lastDate.secsTo( change.createdDate() ) < 180 ) { list.append( formatChange( change, flags ) ); continue; } } if ( list.count() > 0 ) { writer->writeBulletList( list ); writer->endHistoryItem(); list.clear(); } switch ( change.type() ) { case IssueCreated: case IssueRenamed: case ValueChanged: lastUserId = change.createdUserId(); lastDate = change.createdDate(); writer->beginHistoryItem(); writer->writeBlock( formatStamp( change ), HtmlWriter::Header4Block ); list.append( formatChange( change, flags ) ); break; case CommentAdded: writer->beginHistoryItem(); writer->writeBlock( changeLinks( change, flags ), HtmlWriter::HistoryInfoBlock ); writer->writeBlock( formatStamp( change ), HtmlWriter::Header4Block ); writer->writeBlock( commentText( change.comment(), flags ), HtmlWriter::CommentBlock ); writer->endHistoryItem(); m_commentsCount++; break; case FileAdded: writer->beginHistoryItem(); writer->writeBlock( changeLinks( change, flags ), HtmlWriter::HistoryInfoBlock ); writer->writeBlock( formatStamp( change ), HtmlWriter::Header4Block ); writer->writeBlock( formatFile( change.file(), flags ), HtmlWriter::AttachmentBlock ); writer->endHistoryItem(); m_filesCount++; break; case IssueMoved: writer->beginHistoryItem(); writer->writeBlock( formatStamp( change ), HtmlWriter::Header4Block ); writer->writeBulletList( QList<HtmlText>() << formatChange( change, flags ) ); writer->endHistoryItem(); break; } } if ( list.count() > 0 ) { writer->writeBulletList( list ); writer->endHistoryItem(); } if ( changes.count() == 0 ) { if ( m_history == OnlyComments ) writer->writeBlock( tr( "There are no comments." ), HtmlWriter::NoItemsBlock ); else if ( m_history == OnlyFiles ) writer->writeBlock( tr( "There are no attachments." ), HtmlWriter::NoItemsBlock ); else if ( m_history == CommentsAndFiles ) writer->writeBlock( tr( "There are no comments or attachments." ), HtmlWriter::NoItemsBlock ); } }
void main( int argc, char **argv ) { FILE *fp; int ch; int width = DEF_LINE_LEN; int offset = 0; int regexp = 0; argv = ExpandEnv( &argc, argv ); while( 1 ) { ch = GetOpt( &argc, argv, "Xcjnl:p:", usageMsg ); if( ch == -1 ) { break; } switch( ch ) { case 'c': f_mode |= FMT_CENTRE; break; case 'j': f_mode |= FMT_JUSTIFY; break; case 'n': f_mode |= FMT_NOSPACE; break; case 'l': width = atoi( OptArg ); break; case 'p': offset = atoi( OptArg ); break; case 'X': regexp = 1; break; } } if( width <= 0 ) { Die( "fmt: invalid line length\n" ); } if( offset < 0 ) { Die( "fmt: invalid page offset\n" ); } argv = ExpandArgv( &argc, argv, regexp ); argv++; if( *argv == NULL ) { formatFile( stdin, width, offset ); } else { while( *argv != NULL ) { fp = fopen( *argv, "r" ); if( fp == NULL ) { fprintf( stderr, "fmt: cannot open input file \"%s\"\n", *argv ); } else { if( argc > 2 ) { fprintf( stdout, "%s:\n", *argv ); } formatFile( fp, width, offset ); fclose( fp ); } argv++; } } free( w_buff ); // free the word space exit( EXIT_SUCCESS ); }