summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libs/utils/basevalidatinglineedit.cpp8
-rw-r--r--src/libs/utils/basevalidatinglineedit.h1
-rw-r--r--src/libs/utils/filenamevalidatinglineedit.cpp24
-rw-r--r--src/libs/utils/filenamevalidatinglineedit.h10
-rw-r--r--src/libs/utils/filewizarddialog.cpp10
-rw-r--r--src/libs/utils/filewizarddialog.h3
-rw-r--r--src/libs/utils/filewizardpage.cpp11
-rw-r--r--src/libs/utils/filewizardpage.h3
-rw-r--r--src/plugins/coreplugin/basefilewizard.cpp11
-rw-r--r--src/plugins/coreplugin/basefilewizard.h16
-rw-r--r--src/plugins/coreplugin/dialogs/iwizard.h3
-rw-r--r--src/plugins/texteditor/texteditorplugin.cpp55
12 files changed, 97 insertions, 58 deletions
diff --git a/src/libs/utils/basevalidatinglineedit.cpp b/src/libs/utils/basevalidatinglineedit.cpp
index 375f4a7a32..e0ac86c71c 100644
--- a/src/libs/utils/basevalidatinglineedit.cpp
+++ b/src/libs/utils/basevalidatinglineedit.cpp
@@ -167,6 +167,9 @@ void BaseValidatingLineEdit::slotChanged(const QString &t)
emit validChanged();
}
}
+ bool block = blockSignals(true);
+ setText(fixInputString(t));
+ blockSignals(block);
}
void BaseValidatingLineEdit::slotReturnPressed()
@@ -180,4 +183,9 @@ void BaseValidatingLineEdit::triggerChanged()
slotChanged(text());
}
+QString BaseValidatingLineEdit::fixInputString(const QString &string)
+{
+ return string;
+}
+
} // namespace Utils
diff --git a/src/libs/utils/basevalidatinglineedit.h b/src/libs/utils/basevalidatinglineedit.h
index 1d9b591ff9..cbf8a00c9d 100644
--- a/src/libs/utils/basevalidatinglineedit.h
+++ b/src/libs/utils/basevalidatinglineedit.h
@@ -77,6 +77,7 @@ signals:
protected:
virtual bool validate(const QString &value, QString *errorMessage) const = 0;
+ virtual QString fixInputString(const QString &string);
protected slots:
// Custom behaviour can be added here. The base implementation must
diff --git a/src/libs/utils/filenamevalidatinglineedit.cpp b/src/libs/utils/filenamevalidatinglineedit.cpp
index bc37cfa4b6..4bbed5720f 100644
--- a/src/libs/utils/filenamevalidatinglineedit.cpp
+++ b/src/libs/utils/filenamevalidatinglineedit.cpp
@@ -68,7 +68,8 @@ static const QRegExp &windowsDeviceSubDirPattern()
// ----------- FileNameValidatingLineEdit
FileNameValidatingLineEdit::FileNameValidatingLineEdit(QWidget *parent) :
BaseValidatingLineEdit(parent),
- m_allowDirectories(false)
+ m_allowDirectories(false),
+ m_forceFirstCapitalLetter(false)
{
}
@@ -82,6 +83,16 @@ void FileNameValidatingLineEdit::setAllowDirectories(bool v)
m_allowDirectories = v;
}
+bool FileNameValidatingLineEdit::forceFirstCapitalLetter() const
+{
+ return m_forceFirstCapitalLetter;
+}
+
+void FileNameValidatingLineEdit::setForceFirstCapitalLetter(bool b)
+{
+ m_forceFirstCapitalLetter = b;
+}
+
/* Validate a file base name, check for forbidden characters/strings. */
#ifdef Q_OS_WIN
@@ -147,6 +158,17 @@ bool FileNameValidatingLineEdit::validate(const QString &value, QString *errorM
&& validateFileName(value, allowDirectories(), errorMessage);
}
+QString FileNameValidatingLineEdit::fixInputString(const QString &string)
+{
+ if (!forceFirstCapitalLetter())
+ return string;
+
+ QString fixedString = string;
+ if (!string.isEmpty() && string.at(0).isLower())
+ fixedString[0] = string.at(0).toUpper();
+
+ return fixedString;
+}
bool FileNameValidatingLineEdit::validateFileNameExtension(const QString &fileName,
const QStringList &requiredExtensions,
diff --git a/src/libs/utils/filenamevalidatinglineedit.h b/src/libs/utils/filenamevalidatinglineedit.h
index 582ebbf2e8..7e0e3e4cb3 100644
--- a/src/libs/utils/filenamevalidatinglineedit.h
+++ b/src/libs/utils/filenamevalidatinglineedit.h
@@ -42,6 +42,7 @@ class QTCREATOR_UTILS_EXPORT FileNameValidatingLineEdit : public BaseValidatingL
Q_OBJECT
Q_PROPERTY(bool allowDirectories READ allowDirectories WRITE setAllowDirectories)
Q_PROPERTY(QStringList requiredExtensions READ requiredExtensions WRITE setRequiredExtensions)
+ Q_PROPERTY(bool forceFirstCapitalLetter READ forceFirstCapitalLetter WRITE setForceFirstCapitalLetter)
public:
explicit FileNameValidatingLineEdit(QWidget *parent = 0);
@@ -62,6 +63,13 @@ public:
void setAllowDirectories(bool v);
/**
+ * Sets whether the first letter is forced to be a capital letter
+ * Default is off.
+ */
+ bool forceFirstCapitalLetter() const;
+ void setForceFirstCapitalLetter(bool b);
+
+ /**
* Sets a requred extension. If the extension is empty no extension is required.
* Default is empty.
*/
@@ -70,10 +78,12 @@ public:
protected:
virtual bool validate(const QString &value, QString *errorMessage) const;
+ virtual QString fixInputString(const QString &string);
private:
bool m_allowDirectories;
QStringList m_requiredExtensionList;
+ bool m_forceFirstCapitalLetter;
};
} // namespace Utils
diff --git a/src/libs/utils/filewizarddialog.cpp b/src/libs/utils/filewizarddialog.cpp
index 6cfe526acd..4167221e3c 100644
--- a/src/libs/utils/filewizarddialog.cpp
+++ b/src/libs/utils/filewizarddialog.cpp
@@ -75,6 +75,16 @@ QString FileWizardDialog::path() const
return m_filePage->path();
}
+bool FileWizardDialog::forceFirstCapitalLetterForFileName() const
+{
+ return m_filePage->forceFirstCapitalLetterForFileName();
+}
+
+void FileWizardDialog::setForceFirstCapitalLetterForFileName(bool b)
+{
+ m_filePage->setForceFirstCapitalLetterForFileName(b);
+}
+
void FileWizardDialog::setPath(const QString &path)
{
m_filePage->setPath(path);
diff --git a/src/libs/utils/filewizarddialog.h b/src/libs/utils/filewizarddialog.h
index 0e8ebaf649..5fd0fe6fb2 100644
--- a/src/libs/utils/filewizarddialog.h
+++ b/src/libs/utils/filewizarddialog.h
@@ -49,6 +49,9 @@ public:
QString fileName() const;
QString path() const;
+ bool forceFirstCapitalLetterForFileName() const;
+ void setForceFirstCapitalLetterForFileName(bool b);
+
public slots:
void setPath(const QString &path);
void setFileName(const QString &name);
diff --git a/src/libs/utils/filewizardpage.cpp b/src/libs/utils/filewizardpage.cpp
index 58fd73277d..dde0668a28 100644
--- a/src/libs/utils/filewizardpage.cpp
+++ b/src/libs/utils/filewizardpage.cpp
@@ -50,6 +50,7 @@ struct FileWizardPagePrivate
FileWizardPagePrivate();
Ui::WizardPage m_ui;
bool m_complete;
+ bool m_forceFirstCapitalLetter;
};
FileWizardPagePrivate::FileWizardPagePrivate() :
@@ -121,6 +122,16 @@ void FileWizardPage::setPathLabel(const QString &label)
d->m_ui.pathLabel->setText(label);
}
+bool FileWizardPage::forceFirstCapitalLetterForFileName() const
+{
+ return d->m_ui.nameLineEdit->forceFirstCapitalLetter();
+}
+
+void FileWizardPage::setForceFirstCapitalLetterForFileName(bool b)
+{
+ d->m_ui.nameLineEdit->setForceFirstCapitalLetter(b);
+}
+
void FileWizardPage::slotValidChanged()
{
const bool newComplete = d->m_ui.pathChooser->isValid() && d->m_ui.nameLineEdit->isValid();
diff --git a/src/libs/utils/filewizardpage.h b/src/libs/utils/filewizardpage.h
index e65ee0a01a..ed54c19330 100644
--- a/src/libs/utils/filewizardpage.h
+++ b/src/libs/utils/filewizardpage.h
@@ -59,6 +59,9 @@ public:
void setFileNameLabel(const QString &label);
void setPathLabel(const QString &label);
+ bool forceFirstCapitalLetterForFileName() const;
+ void setForceFirstCapitalLetterForFileName(bool b);
+
// Validate a base name entry field (potentially containing extension)
static bool validateBaseName(const QString &name, QString *errorMessage = 0);
diff --git a/src/plugins/coreplugin/basefilewizard.cpp b/src/plugins/coreplugin/basefilewizard.cpp
index b47ff946c6..3a3131b964 100644
--- a/src/plugins/coreplugin/basefilewizard.cpp
+++ b/src/plugins/coreplugin/basefilewizard.cpp
@@ -464,10 +464,17 @@ void BaseFileWizard::runWizard(const QString &path, QWidget *parent, const QStri
// Create dialog and run it. Ensure that the dialog is deleted when
// leaving the func, but not before the IFileWizardExtension::process
// has been called
+
+ WizardDialogParameters::DialogParameterFlags dialogParameterFlags;
+
+ if (flags().testFlag(ForceCapitalLetterForFileName))
+ dialogParameterFlags |= WizardDialogParameters::ForceCapitalLetterForFileName;
+
const QScopedPointer<QWizard> wizard(createWizardDialog(parent, WizardDialogParameters(path,
allExtensionPages,
platform,
- requiredFeatures())));
+ requiredFeatures(),
+ dialogParameterFlags)));
QTC_ASSERT(!wizard.isNull(), return);
GeneratedFiles files;
@@ -811,6 +818,8 @@ QWizard *StandardFileWizard::createWizardDialog(QWidget *parent,
const WizardDialogParameters &wizardDialogParameters) const
{
Utils::FileWizardDialog *standardWizardDialog = new Utils::FileWizardDialog(parent);
+ if (wizardDialogParameters.flags().testFlag(WizardDialogParameters::ForceCapitalLetterForFileName))
+ standardWizardDialog->setForceFirstCapitalLetterForFileName(true);
standardWizardDialog->setWindowTitle(tr("New %1").arg(displayName()));
setupWizard(standardWizardDialog);
standardWizardDialog->setPath(wizardDialogParameters.defaultPath());
diff --git a/src/plugins/coreplugin/basefilewizard.h b/src/plugins/coreplugin/basefilewizard.h
index 9701857fd1..181d801734 100644
--- a/src/plugins/coreplugin/basefilewizard.h
+++ b/src/plugins/coreplugin/basefilewizard.h
@@ -113,12 +113,19 @@ class CORE_EXPORT WizardDialogParameters
public:
typedef QList<QWizardPage *> WizardPageList;
+ enum DialogParameterEnum {
+ ForceCapitalLetterForFileName = 0x01
+ };
+ Q_DECLARE_FLAGS(DialogParameterFlags, DialogParameterEnum)
+
explicit WizardDialogParameters(const QString &defaultPath, const WizardPageList &extensionPages,
- const QString &platform, const Core::FeatureSet &requiredFeatures)
+ const QString &platform, const Core::FeatureSet &requiredFeatures,
+ DialogParameterFlags flags)
: m_defaultPath(defaultPath),
m_extensionPages(extensionPages),
m_selectedPlatform(platform),
- m_requiredFeatures(requiredFeatures) {}
+ m_requiredFeatures(requiredFeatures),
+ m_parameterFlags(flags) {}
QString defaultPath() const
{ return m_defaultPath; }
@@ -132,11 +139,15 @@ public:
Core::FeatureSet requiredFeatures() const
{ return m_requiredFeatures; }
+ DialogParameterFlags flags() const
+ { return m_parameterFlags; }
+
private:
QString m_defaultPath;
WizardPageList m_extensionPages;
QString m_selectedPlatform;
Core::FeatureSet m_requiredFeatures;
+ DialogParameterFlags m_parameterFlags;
};
class CORE_EXPORT BaseFileWizard : public IWizard
@@ -221,5 +232,6 @@ QList<WizardClass*> createMultipleBaseFileWizardInstances(const QList<BaseFileWi
} // namespace Core
Q_DECLARE_OPERATORS_FOR_FLAGS(Core::GeneratedFile::Attributes)
+Q_DECLARE_OPERATORS_FOR_FLAGS(Core::WizardDialogParameters::DialogParameterFlags)
#endif // BASEFILEWIZARD_H
diff --git a/src/plugins/coreplugin/dialogs/iwizard.h b/src/plugins/coreplugin/dialogs/iwizard.h
index 50383da148..0c6dde768f 100644
--- a/src/plugins/coreplugin/dialogs/iwizard.h
+++ b/src/plugins/coreplugin/dialogs/iwizard.h
@@ -56,7 +56,8 @@ public:
};
Q_DECLARE_FLAGS(WizardKinds, WizardKind)
enum WizardFlag {
- PlatformIndependent = 0x01
+ PlatformIndependent = 0x01,
+ ForceCapitalLetterForFileName = 0x02
};
Q_DECLARE_FLAGS(WizardFlags, WizardFlag)
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index fa3a3a70cc..d10a75d65f 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -65,8 +65,6 @@
#include <QtPlugin>
#include <QMainWindow>
#include <QShortcut>
-#include <QDir>
-#include <QTemporaryFile>
using namespace TextEditor;
using namespace TextEditor::Internal;
@@ -100,54 +98,6 @@ TextEditorPlugin *TextEditorPlugin::instance()
return m_instance;
}
-static const char wizardCategoryC[] = "U.General";
-
-static inline QString wizardDisplayCategory()
-{
- return TextEditorPlugin::tr("General");
-}
-
-// A wizard that quickly creates a scratch buffer
-// based on a temporary file without prompting for a path.
-class ScratchFileWizard : public Core::IWizard
-{
-public:
- virtual WizardKind kind() const { return FileWizard; }
- virtual QIcon icon() const { return QIcon(); }
- virtual QString description() const
- { return TextEditorPlugin::tr("Creates a scratch buffer using a temporary file."); }
- virtual QString displayName() const
- { return TextEditorPlugin::tr("Scratch Buffer"); }
- virtual QString id() const
- { return QLatin1String("Z.ScratchFile"); }
- virtual QString category() const
- { return QLatin1String(wizardCategoryC); }
- virtual QString displayCategory() const
- { return wizardDisplayCategory(); }
- virtual QString descriptionImage() const
- { return QString(); }
- virtual Core::FeatureSet requiredFeatures() const
- { return Core::FeatureSet(); }
- virtual WizardFlags flags() const
- { return Core::IWizard::PlatformIndependent; }
-
- virtual void runWizard(const QString &path, QWidget *parent, const QString &platform);
-};
-
-void ScratchFileWizard::runWizard(const QString &, QWidget *, const QString &)
-{
- QString tempPattern = QDir::tempPath();
- if (!tempPattern.endsWith(QLatin1Char('/')))
- tempPattern += QLatin1Char('/');
- tempPattern += QLatin1String("scratchXXXXXX.txt");
- QTemporaryFile file(tempPattern);
- file.setAutoRemove(false);
- QTC_ASSERT(file.open(), return; );
- file.close();
- Core::EditorManager *em = Core::EditorManager::instance();
- em->openEditor(file.fileName(), Core::Id(), Core::EditorManager::ModeSwitch);
-}
-
// ExtensionSystem::PluginInterface
bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
{
@@ -160,15 +110,14 @@ bool TextEditorPlugin::initialize(const QStringList &arguments, QString *errorMe
wizardParameters.setDescription(tr("Creates a text file. The default file extension is <tt>.txt</tt>. "
"You can specify a different extension as part of the filename."));
wizardParameters.setDisplayName(tr("Text File"));
- wizardParameters.setCategory(QLatin1String(wizardCategoryC));
- wizardParameters.setDisplayCategory(wizardDisplayCategory());
+ wizardParameters.setCategory(QLatin1String("U.General"));
+ wizardParameters.setDisplayCategory(tr("General"));
wizardParameters.setFlags(Core::IWizard::PlatformIndependent);
TextFileWizard *wizard = new TextFileWizard(QLatin1String(Constants::C_TEXTEDITOR_MIMETYPE_TEXT),
QLatin1String("text$"),
wizardParameters);
// Add text file wizard
addAutoReleasedObject(wizard);
- addAutoReleasedObject(new ScratchFileWizard);
m_settings = new TextEditorSettings(this);