File indexing completed on 2024-05-19 12:55:55
0001 /******************************************************************************************* 0002 Copyright (C) 2003 by Jeroen Wijnhout (Jeroen.Wijnhout@kdemail.net) 0003 (C) 2007 by Holger Danielsson (holger.danielsson@versanet.de) 0004 (C) 2013-2016 by Michel Ludwig (michel.ludwig@kdemail.net) 0005 (C) 2015 by Andreas Cord-Landwehr (cordlandwehr@kde.org) 0006 ********************************************************************************************/ 0007 0008 /*************************************************************************** 0009 * * 0010 * This program is free software; you can redistribute it and/or modify * 0011 * it under the terms of the GNU General Public License as published by * 0012 * the Free Software Foundation; either version 2 of the License, or * 0013 * (at your option) any later version. * 0014 * * 0015 ***************************************************************************/ 0016 0017 // 2007-02-15 (dani) 0018 // - cosmetic changes 0019 // - use of groupboxes to prepare further extensions 0020 0021 // 2007-03-12 (dani) 0022 // - use KileDocument::Extensions 0023 // - allowed extensions are always defined as list, f.e.: .tex .ltx .latex 0024 0025 #include "dialogs/projectdialogs.h" 0026 0027 #include <QDialogButtonBox> 0028 #include <QFileInfo> 0029 #include <QGridLayout> 0030 #include <QGroupBox> 0031 #include <QLabel> 0032 #include <QList> 0033 #include <QPushButton> 0034 #include <QRegExp> 0035 #include <QValidator> 0036 #include <QVBoxLayout> 0037 #include <QFormLayout> 0038 0039 #include <KComboBox> 0040 #include <KLocalizedString> 0041 #include <KMessageBox> 0042 #include <KUrlCompletion> 0043 #include <KConfigGroup> 0044 0045 #include "kiledebug.h" 0046 #include "kileproject.h" 0047 #include "kiletoolmanager.h" 0048 #include "documentinfo.h" 0049 #include "kileconfig.h" 0050 #include "kileextensions.h" 0051 #include "templates.h" 0052 0053 KileProjectDialogBase::KileProjectDialogBase(const QString &caption, KileDocument::Extensions *extensions, QWidget *parent, const char *name) 0054 : QDialog(parent) 0055 , m_extmanager(extensions) 0056 , m_project(Q_NULLPTR) 0057 , m_projectGroup(new QGroupBox(i18n("Project"), this)) 0058 , m_extensionGroup(new QGroupBox(i18n("Extensions"), this)) 0059 { 0060 setWindowTitle(caption); 0061 setModal(true); 0062 setObjectName(name); 0063 0064 const QString whatsthisName = i18n("Insert a short descriptive name of your project here."); 0065 const QString whatsthisExt = i18n("Insert a list (separated by spaces) of file extensions which should be treated also as files of the corresponding type in this project."); 0066 0067 m_title = new QLineEdit(m_projectGroup); 0068 m_title->setWhatsThis(whatsthisName); 0069 QLabel *projectTitleLabel = new QLabel(i18n("Project &title:"), m_projectGroup); 0070 projectTitleLabel->setBuddy(m_title); 0071 projectTitleLabel->setWhatsThis(whatsthisName); 0072 0073 // project settings groupbox 0074 QFormLayout *projectGoupLayout= new QFormLayout(m_projectGroup); 0075 projectGoupLayout->setAlignment(Qt::AlignTop); 0076 m_projectGroup->setLayout(projectGoupLayout); 0077 projectGoupLayout->addRow(projectTitleLabel, m_title); 0078 0079 m_projectFolder = new KUrlRequester(m_projectGroup); 0080 m_projectFolder->setMode(KFile::Directory | KFile::LocalOnly); 0081 0082 QLabel *projectFolderLabel = new QLabel(i18n("Project &folder:"), m_projectGroup); 0083 projectFolderLabel->setBuddy(m_projectFolder); 0084 const QString whatsthisPath = i18n("Insert the path to your project here."); 0085 m_projectFolder->setWhatsThis(whatsthisPath); 0086 projectGoupLayout->addRow(projectFolderLabel, m_projectFolder); 0087 0088 // combo box for default graphics extension 0089 m_defaultGraphicsExtensionCombo = new QComboBox(this); 0090 KileDocument::Extensions extManager; 0091 QStringList imageExtensions = extManager.images().split(' '); 0092 foreach (const QString &extension, imageExtensions) { 0093 const QString extName = extension.mid(1); // all characters right of "." 0094 m_defaultGraphicsExtensionCombo->addItem(extension, extName); 0095 } 0096 m_defaultGraphicsExtensionCombo->addItem(i18n("(use global settings)"),""); 0097 const QString whatsThisTextDefaultGraphicsExtension = i18n("Default graphic extension to open when none specified by file name."); 0098 m_defaultGraphicsExtensionCombo->setWhatsThis(whatsThisTextDefaultGraphicsExtension); 0099 0100 // extension settings groupbox 0101 m_userFileExtensions = new QLineEdit(this); 0102 m_userFileExtensions->setWhatsThis(whatsthisExt); 0103 QRegExp reg("[\\. a-zA-Z0-9]+"); 0104 QRegExpValidator *extValidator = new QRegExpValidator(reg, m_extensionGroup); 0105 m_userFileExtensions->setValidator(extValidator); 0106 0107 m_defaultLatexFileExtensionsCombo = new KComboBox(false, this); 0108 m_defaultLatexFileExtensionsCombo->addItem(i18n("Source Files")); 0109 m_defaultLatexFileExtensionsCombo->addItem(i18n("Package Files")); 0110 m_defaultLatexFileExtensionsCombo->addItem(i18n("Image Files")); 0111 m_defaultLatexFileExtensionsCombo->addItem(i18n("Bibliography Files")); 0112 m_defaultLatexFileExtensions = new QLabel(QString(), this); 0113 m_defaultLatexFileExtensionsCombo->setWhatsThis(whatsthisExt); 0114 0115 QFormLayout *extensionGroupLayout = new QFormLayout(m_extensionGroup); 0116 m_extensionGroup->setLayout(extensionGroupLayout); 0117 extensionGroupLayout->setAlignment(Qt::AlignTop); 0118 extensionGroupLayout->addRow(new QLabel(i18n("Default Graphics Extension:"), this), m_defaultGraphicsExtensionCombo); 0119 extensionGroupLayout->addRow(m_defaultLatexFileExtensionsCombo, m_userFileExtensions); 0120 extensionGroupLayout->addRow(new QLabel(i18n("Predefined:"), this), m_defaultLatexFileExtensions); 0121 0122 fillProjectDefaults(); 0123 0124 QWidget::setTabOrder(m_title, m_projectFolder); 0125 QWidget::setTabOrder(m_defaultGraphicsExtensionCombo, m_defaultLatexFileExtensionsCombo); 0126 QWidget::setTabOrder(m_defaultLatexFileExtensionsCombo, m_defaultLatexFileExtensions); 0127 } 0128 0129 KileProjectDialogBase::~KileProjectDialogBase() 0130 { 0131 } 0132 0133 void KileProjectDialogBase::onExtensionsIndexChanged(int index) 0134 { 0135 m_userFileExtensions->setText(m_val_extensions[index]); 0136 m_defaultLatexFileExtensions->setText(m_val_standardExtensions[index]); 0137 } 0138 0139 void KileProjectDialogBase::onExtensionsTextEdited(const QString &text) 0140 { 0141 m_val_extensions[m_defaultLatexFileExtensionsCombo->currentIndex()] = text; 0142 } 0143 0144 bool KileProjectDialogBase::acceptUserExtensions() 0145 { 0146 QRegExp reg("\\.\\w+"); 0147 0148 for (int i = KileProjectItem::Source; i < KileProjectItem::Other; ++i) { 0149 m_val_extensions[i-1] = m_val_extensions[i-1].trimmed(); 0150 if (! m_val_extensions[i-1].isEmpty()) { 0151 // some tiny extension checks 0152 QStringList::ConstIterator it; 0153 QStringList list = m_val_extensions[i-1].split(' '); 0154 for (it = list.constBegin(); it != list.constEnd(); ++it) { 0155 if (! reg.exactMatch(*it)) { 0156 KMessageBox::error(this, i18n("Error in extension '%1':\nAll user-defined extensions should look like '.xyz'", *it), i18n("Invalid extension")); 0157 return false; 0158 } 0159 } 0160 } 0161 } 0162 0163 return true; 0164 } 0165 0166 void KileProjectDialogBase::setExtensions(KileProjectItem::Type type, const QString & ext) 0167 { 0168 if (m_defaultLatexFileExtensionsCombo->currentIndex() == type - 1) { 0169 m_userFileExtensions->setText(ext); 0170 } 0171 else { 0172 m_val_extensions[type-1] = ext; 0173 } 0174 } 0175 0176 void KileProjectDialogBase::setProject(KileProject *project, bool override) 0177 { 0178 m_project = project; 0179 0180 if ((!override) || (project == 0)) { 0181 return; 0182 } 0183 0184 for (int i = KileProjectItem::Source; i < KileProjectItem::Other; ++i) { 0185 m_val_extensions[i - 1] = project->extensions((KileProjectItem::Type) i); 0186 } 0187 0188 m_title->setText(m_project->name()); 0189 m_userFileExtensions->setText(m_val_extensions[0]); 0190 m_defaultLatexFileExtensions->setText(m_val_standardExtensions[0]); 0191 0192 m_defaultGraphicsExtensionCombo->setCurrentIndex(m_defaultGraphicsExtensionCombo->findData(project->defaultGraphicExt())); 0193 } 0194 0195 KileProject* KileProjectDialogBase::project() 0196 { 0197 return m_project; 0198 } 0199 0200 void KileProjectDialogBase::fillProjectDefaults() 0201 { 0202 m_val_extensions[0].clear(); 0203 m_val_extensions[1].clear(); 0204 m_val_extensions[2].clear(); 0205 m_val_extensions[3].clear(); 0206 //m_val_extensions[4] = OTHER_EXTENSIONS; 0207 0208 m_val_standardExtensions[0] = m_extmanager->latexDocuments(); 0209 m_val_standardExtensions[1] = m_extmanager->latexPackages(); 0210 m_val_standardExtensions[2] = m_extmanager->images(); 0211 m_val_standardExtensions[3] = m_extmanager->bibtex(); 0212 0213 m_userFileExtensions->setText(m_val_extensions[0]); 0214 m_defaultLatexFileExtensions->setText(m_val_standardExtensions[0]); 0215 0216 m_defaultGraphicsExtensionCombo->setCurrentIndex(0); 0217 } 0218 0219 /* 0220 * KileNewProjectDialog 0221 */ 0222 KileNewProjectDialog::KileNewProjectDialog(KileTemplate::Manager *templateManager, KileDocument::Extensions *extensions, QWidget* parent, const char* name) 0223 : KileProjectDialogBase(i18n("Create New Project"), extensions, parent, name) 0224 , m_templateManager(templateManager) 0225 { 0226 QVBoxLayout *mainLayout = new QVBoxLayout; 0227 setLayout(mainLayout); 0228 0229 // properties groupbox 0230 mainLayout->addWidget(m_projectGroup); 0231 0232 // second groupbox 0233 QGroupBox *fileGroup = new QGroupBox(i18n("File"), this); 0234 mainLayout->addWidget(fileGroup); 0235 QGridLayout *fileGrid = new QGridLayout(); 0236 fileGroup->setLayout(fileGrid); 0237 m_createNewFileCheckbox = new QCheckBox(i18n("Create a new file and add it to this project"), fileGroup); 0238 m_createNewFileCheckbox->setChecked(true); 0239 m_filenameLabel = new QLabel(i18n("File&name (relative to where the project file is):"), fileGroup); 0240 m_file = new QLineEdit(fileGroup); 0241 m_filenameLabel->setBuddy(m_file); 0242 m_templateIconView = new TemplateIconView(fileGroup); 0243 m_templateIconView->setTemplateManager(m_templateManager); 0244 m_templateManager->scanForTemplates(); 0245 m_templateIconView->fillWithTemplates(KileDocument::LaTeX); 0246 m_createNewFileCheckbox->setWhatsThis(i18n("If you want Kile to create a new file and add it to the project, then check this option and select a template from the list that will appear below.")); 0247 0248 fileGrid->addWidget(m_createNewFileCheckbox, 0, 0, 1, 2); 0249 fileGrid->addWidget(m_filenameLabel, 1, 0); 0250 fileGrid->addWidget(m_file, 1, 1); 0251 fileGrid->addWidget(m_templateIconView, 2, 0, 1, 2); 0252 fileGrid->setColumnStretch(1, 1); 0253 connect(m_createNewFileCheckbox, SIGNAL(clicked()), this, SLOT(clickedCreateNewFileCb())); 0254 0255 // add to layout 0256 mainLayout->addWidget(m_projectGroup); 0257 mainLayout->addWidget(fileGroup); 0258 mainLayout->addWidget(m_extensionGroup); 0259 mainLayout->addStretch(); 0260 0261 fillProjectDefaults(); 0262 0263 // add buttons 0264 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 0265 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0266 okButton->setDefault(true); 0267 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0268 okButton->setDefault(true); 0269 connect(okButton, &QPushButton::clicked, this, &KileNewProjectDialog::handleOKButtonClicked); 0270 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0271 0272 connect(m_defaultLatexFileExtensionsCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), 0273 this, &KileNewProjectDialog::onExtensionsIndexChanged); 0274 connect(m_userFileExtensions, &QLineEdit::textEdited, this, &KileNewProjectDialog::onExtensionsTextEdited); 0275 0276 mainLayout->addWidget(buttonBox); 0277 0278 QWidget::setTabOrder(m_projectFolder, m_createNewFileCheckbox); 0279 0280 QWidget::setTabOrder(m_createNewFileCheckbox, m_file); 0281 QWidget::setTabOrder(m_file, m_templateIconView); 0282 QWidget::setTabOrder(m_templateIconView, m_defaultGraphicsExtensionCombo); 0283 0284 QWidget::setTabOrder(m_defaultGraphicsExtensionCombo, buttonBox); 0285 } 0286 0287 KileNewProjectDialog::~KileNewProjectDialog() 0288 {} 0289 0290 KileProject * KileNewProjectDialog::project() 0291 { 0292 if (!m_project) { 0293 m_project = new KileProject(projectTitle(), m_projectFileWithPath, m_extmanager); 0294 0295 KileProjectItem::Type type; 0296 for (int i = KileProjectItem::Source; i < KileProjectItem::Other; ++i) { 0297 type = (KileProjectItem::Type) i; 0298 m_project->setExtensions(type, extensions(type)); 0299 } 0300 0301 m_project->setDefaultGraphicExt( 0302 m_defaultGraphicsExtensionCombo->itemData(m_defaultGraphicsExtensionCombo->currentIndex()).toString()); 0303 0304 m_project->buildProjectTree(); 0305 } 0306 0307 return m_project; 0308 } 0309 0310 void KileNewProjectDialog::clickedCreateNewFileCb() 0311 { 0312 if (m_createNewFileCheckbox->isChecked()) { 0313 m_file->show(); 0314 m_filenameLabel->show(); 0315 m_templateIconView->show(); 0316 } 0317 else { 0318 m_file->hide(); 0319 m_filenameLabel->hide(); 0320 m_templateIconView->hide(); 0321 } 0322 } 0323 0324 QString KileNewProjectDialog::cleanProjectFile() 0325 { 0326 return projectTitle().toLower().trimmed().remove(QRegExp("\\s*")) + ".kilepr"; 0327 } 0328 0329 void KileNewProjectDialog::handleOKButtonClicked() 0330 { 0331 if (!acceptUserExtensions()) { 0332 return; 0333 } 0334 0335 if (projectTitle().trimmed().isEmpty()) { 0336 if (KMessageBox::warningTwoActions(this, i18n("You have not entered a project name. If you decide to proceed, the project name will be set to \"Untitled\".\n" 0337 "Do you want to create the project nevertheless?"), i18n("No Project Name Given"), 0338 KStandardGuiItem::ok(), KStandardGuiItem::cancel() 0339 ) == KMessageBox::PrimaryAction) { 0340 m_title->setText(i18n("Untitled")); 0341 } 0342 else { 0343 return; 0344 } 0345 } 0346 0347 const QString dirString = folder().trimmed(); 0348 const QString fileString = file().trimmed(); 0349 0350 if (dirString.isEmpty()) { 0351 KMessageBox::error(this, i18n("Please enter the folder where the project file should be saved to."), i18n("Empty Location")); 0352 return; 0353 } 0354 0355 if (!QDir::isAbsolutePath(dirString)) { 0356 KMessageBox::error(this, i18n("Please enter an absolute path to the project folder."), i18n("Invalid Location")); 0357 return; 0358 } 0359 0360 if (createNewFile() && fileString.isEmpty()) { 0361 KMessageBox::error(this, i18n("Please enter a filename for the file that should be added to this project."), i18n("No File Name Given")); 0362 return; 0363 } 0364 0365 const QString cleanProjectFileName = cleanProjectFile(); 0366 const QDir projectDir(dirString); 0367 const QString projectFilePath = projectDir.filePath(cleanProjectFileName); 0368 const QDir guiFileDir = KileProject::getPathForPrivateKileDirectory(projectFilePath); 0369 0370 testDirectoryIsUsable(projectDir); 0371 testDirectoryIsUsable(guiFileDir); 0372 0373 if (QFileInfo::exists(projectFilePath)) { // this can only happen when the project dir existed already 0374 KMessageBox::error(this, i18n("The project file exists already. Please choose another name."), i18n("Project File Already Exists")); 0375 return; 0376 } 0377 0378 const QString guiProjectFilePath = KileProject::getPathForGUISettingsProjectFile(projectFilePath); 0379 if (QFileInfo::exists(guiProjectFilePath)) { // this can only happen when the project dir existed already 0380 KMessageBox::error(this, i18n("The GUI settings file exists already. Please choose another project name."), i18n("Project File Already Exists")); 0381 return; 0382 } 0383 0384 if (createNewFile()) { 0385 //check for validity of name first, then check for existence (fixed by tbraun) 0386 QUrl fileURL; 0387 fileURL = fileURL.adjusted(QUrl::RemoveFilename); 0388 fileURL.setPath(fileURL.path() + file()); 0389 QUrl validURL = KileDocument::Info::makeValidTeXURL(fileURL, this, m_extmanager->isTexFile(fileURL), true); 0390 if(validURL != fileURL) { 0391 m_file->setText(validURL.fileName()); 0392 } 0393 0394 if(QFileInfo::exists(projectDir.filePath(fileString))) { 0395 if (KMessageBox::warningTwoActions(this, i18n("The file \"%1\" already exists, overwrite it?", fileString), i18n("File Already Exists"), 0396 KStandardGuiItem::overwrite(), KStandardGuiItem::cancel()) == KMessageBox::SecondaryAction) { 0397 return; 0398 } 0399 } 0400 } 0401 0402 m_projectFileWithPath = QUrl::fromLocalFile(projectFilePath); 0403 accept(); 0404 } 0405 0406 void KileNewProjectDialog::fillProjectDefaults() 0407 { 0408 m_projectFolder->lineEdit()->setText(QDir::cleanPath(KileConfig::defaultProjectLocation())); 0409 m_createNewFileCheckbox->setChecked(true); 0410 KileProjectDialogBase::fillProjectDefaults(); 0411 } 0412 0413 TemplateItem* KileNewProjectDialog::getSelection() const 0414 { 0415 return static_cast<TemplateItem*>(m_templateIconView->currentItem()); 0416 } 0417 0418 /* 0419 * KileProjectOptionsDialog 0420 */ 0421 KileProjectOptionsDialog::KileProjectOptionsDialog(KileProject *project, KileDocument::Extensions *extensions, QWidget *parent, const char * name) 0422 : KileProjectDialogBase(i18n("Project Options"), extensions, parent, name) 0423 , m_toolDefaultString(i18n("(use global setting)")) 0424 { 0425 QVBoxLayout *mainLayout = new QVBoxLayout; 0426 setLayout(mainLayout); 0427 0428 // properties groupbox 0429 mainLayout->addWidget(m_projectGroup); 0430 0431 // third groupbox 0432 QGroupBox *group3 = new QGroupBox(i18n("Properties"), this); 0433 mainLayout->addWidget(group3); 0434 QGridLayout *grid3 = new QGridLayout(); 0435 grid3->setAlignment(Qt::AlignTop); 0436 group3->setLayout(grid3); 0437 0438 const QString whatsthisMaster = i18n("Select the default master document. Leave empty for auto detection."); 0439 0440 m_selectMasterDocumentCombo = new KComboBox(false, group3); 0441 m_selectMasterDocumentCombo->setObjectName("master"); 0442 //m_selectMasterDocumentCombo->setDisabled(true); 0443 QLabel *lb1 = new QLabel(i18n("&Master document:"), group3); 0444 lb1->setBuddy(m_selectMasterDocumentCombo); 0445 lb1->setMinimumWidth(m_defaultLatexFileExtensionsCombo->sizeHint().width()); 0446 m_selectMasterDocumentCombo->setWhatsThis(whatsthisMaster); 0447 lb1->setWhatsThis(whatsthisMaster); 0448 0449 m_selectMasterDocumentCombo->addItem(i18n("(auto-detect)")); 0450 QList<KileProjectItem*> rootItemList = project->rootItems(); 0451 int index = 0; 0452 for (QList<KileProjectItem*>::iterator it = rootItemList.begin(); it != rootItemList.end(); ++it) { 0453 if ((*it)->type() == KileProjectItem::Source) { 0454 m_selectMasterDocumentCombo->addItem((*it)->url().fileName()); 0455 ++index; 0456 if ((*it)->url().path() == project->masterDocument()) { 0457 m_selectMasterDocumentCombo->setCurrentIndex(index); 0458 } 0459 } 0460 } 0461 0462 if (project->masterDocument().isEmpty()) { 0463 m_selectMasterDocumentCombo->setCurrentIndex(0); 0464 } 0465 0466 QLabel *quickbuildLabel = new QLabel(i18n("&QuickBuild configuration:"), group3); 0467 m_QuickBuildCheckbox = new KComboBox(group3); 0468 quickbuildLabel->setBuddy(m_QuickBuildCheckbox); 0469 m_QuickBuildCheckbox->addItem(m_toolDefaultString); 0470 m_QuickBuildCheckbox->addItems(KileTool::configNames("QuickBuild", KSharedConfig::openConfig().data())); 0471 QString itemToSelect = project->quickBuildConfig().length() > 0 ? project->quickBuildConfig() : m_toolDefaultString; 0472 int selectIndex = m_QuickBuildCheckbox->findText(itemToSelect); 0473 if(selectIndex >= 0) { 0474 m_QuickBuildCheckbox->setCurrentIndex(selectIndex); 0475 } 0476 else { 0477 m_QuickBuildCheckbox->addItem(itemToSelect); 0478 } 0479 0480 //don't put this after the call to toggleMakeIndex 0481 setProject(project, true); 0482 m_projectFolder->setUrl(project->baseURL()); 0483 m_projectFolder->setEnabled(false); 0484 0485 m_ckMakeIndex = new QCheckBox(i18n("&MakeIndex options"), group3); 0486 connect(m_ckMakeIndex, SIGNAL(toggled(bool)), this, SLOT(toggleMakeIndex(bool))); 0487 m_leMakeIndex = new QLineEdit(group3); 0488 m_ckMakeIndex->setChecked(project->useMakeIndexOptions()); 0489 toggleMakeIndex(m_ckMakeIndex->isChecked()); 0490 0491 grid3->addWidget(lb1, 0, 0); 0492 grid3->addWidget(m_selectMasterDocumentCombo, 0, 1); 0493 grid3->addWidget(quickbuildLabel, 1, 0); 0494 grid3->addWidget(m_QuickBuildCheckbox, 1, 1); 0495 grid3->addWidget(m_ckMakeIndex, 2, 0); 0496 grid3->addWidget(m_leMakeIndex, 2, 1, 1, 2); 0497 grid3->setColumnStretch(2, 1); 0498 0499 // add to layout 0500 mainLayout->addWidget(m_projectGroup); 0501 mainLayout->addWidget(m_extensionGroup); 0502 mainLayout->addWidget(group3); 0503 mainLayout->addStretch(); 0504 0505 // add buttons 0506 QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok|QDialogButtonBox::Cancel); 0507 QPushButton *okButton = buttonBox->button(QDialogButtonBox::Ok); 0508 okButton->setDefault(true); 0509 okButton->setShortcut(Qt::CTRL | Qt::Key_Return); 0510 okButton->setDefault(true); 0511 connect(buttonBox, &QDialogButtonBox::accepted, this, &QDialog::accept); 0512 connect(buttonBox, &QDialogButtonBox::rejected, this, &QDialog::reject); 0513 connect(this, &QDialog::accepted, this, &KileProjectOptionsDialog::onAccepted); 0514 0515 connect(m_defaultLatexFileExtensionsCombo, static_cast<void (QComboBox::*)(int)>(&QComboBox::currentIndexChanged), 0516 this, &KileProjectOptionsDialog::onExtensionsIndexChanged); 0517 connect(m_userFileExtensions, &QLineEdit::textChanged, this, &KileProjectOptionsDialog::onExtensionsTextEdited); 0518 0519 mainLayout->addWidget(buttonBox); 0520 0521 QWidget::setTabOrder(m_projectFolder, m_defaultGraphicsExtensionCombo); 0522 QWidget::setTabOrder(m_defaultLatexFileExtensions, m_selectMasterDocumentCombo); 0523 0524 QWidget::setTabOrder(m_selectMasterDocumentCombo, m_QuickBuildCheckbox); 0525 QWidget::setTabOrder(m_QuickBuildCheckbox, m_ckMakeIndex); 0526 QWidget::setTabOrder(m_ckMakeIndex, m_leMakeIndex); 0527 0528 QWidget::setTabOrder(m_leMakeIndex, buttonBox); 0529 } 0530 0531 KileProjectOptionsDialog::~KileProjectOptionsDialog() 0532 { 0533 } 0534 0535 void KileProjectOptionsDialog::toggleMakeIndex(bool on) 0536 { 0537 KILE_DEBUG_MAIN << "TOGGLED!" << Qt::endl; 0538 m_leMakeIndex->setEnabled(on); 0539 m_project->setUseMakeIndexOptions(on); 0540 m_project->writeUseMakeIndexOptions(); 0541 m_project->readMakeIndexOptions(); 0542 m_leMakeIndex->setText(m_project->makeIndexOptions()); 0543 } 0544 0545 void KileProjectOptionsDialog::onAccepted() 0546 { 0547 if(!acceptUserExtensions()) { 0548 return; 0549 } 0550 0551 this->m_project->setName(m_title->text()); 0552 0553 QList<KileProjectItem*> rootItemList = m_project->rootItems(); 0554 for (QList<KileProjectItem*>::iterator it = rootItemList.begin(); it != rootItemList.end(); ++it) { 0555 if ((*it)->url().fileName() == m_selectMasterDocumentCombo->currentText()) { 0556 m_project->setMasterDocument((*it)->url().toLocalFile()); 0557 } 0558 } 0559 if (m_selectMasterDocumentCombo->currentIndex() == 0) { 0560 m_project->setMasterDocument(QString()); 0561 } 0562 0563 m_val_extensions[m_defaultLatexFileExtensionsCombo->currentIndex()] = m_userFileExtensions->text(); 0564 0565 for (int i = KileProjectItem::Source; i < KileProjectItem::Other; ++i) { 0566 m_project->setExtensions((KileProjectItem::Type) i, m_val_extensions[i-1]); 0567 } 0568 0569 if (m_QuickBuildCheckbox->currentText() == m_toolDefaultString) { 0570 m_project->setQuickBuildConfig(""); 0571 } 0572 else { 0573 m_project->setQuickBuildConfig(m_QuickBuildCheckbox->currentText()); 0574 } 0575 0576 m_project->setUseMakeIndexOptions(m_ckMakeIndex->isChecked()); 0577 if (m_project->useMakeIndexOptions()) { 0578 m_project->setMakeIndexOptions(m_leMakeIndex->text()); 0579 } 0580 0581 m_project->setDefaultGraphicExt( 0582 m_defaultGraphicsExtensionCombo->itemData(m_defaultGraphicsExtensionCombo->currentIndex()).toString()); 0583 0584 m_project->save(); 0585 } 0586 0587 bool KileNewProjectDialog::testDirectoryIsUsable(const QString& path) 0588 { 0589 return testDirectoryIsUsable(QDir(path)); 0590 } 0591 0592 bool KileNewProjectDialog::testDirectoryIsUsable(const QDir& dir) 0593 { 0594 if (!dir.exists()) { 0595 dir.mkpath(dir.absolutePath()); 0596 } 0597 0598 if (!dir.exists()) { 0599 KMessageBox::error(this, i18n("<p>Could not create the project folder \"\n%1\"</p>." 0600 "<p>Please check whether you have write permissions.</p>", dir.path())); 0601 return false; 0602 } 0603 0604 QFileInfo fi(dir.absolutePath()); 0605 if (!fi.isDir() || !fi.isWritable()) { 0606 KMessageBox::error(this, i18n("<p>The project folder \"(%1)\" is not writable.</p>" 0607 "<p>Please check the permissions of the project folder.</p>", dir.path())); 0608 return false; 0609 } 0610 return true; 0611 }