summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-03-16 16:07:33 +0100
committerFriedemann Kleint <Friedemann.Kleint@nokia.com>2012-03-26 15:44:05 +0200
commitd86b2abc0bc71f8748356c1a0eb7eb7c60226873 (patch)
treee211ed4ab2b2463d7f8f890b7405e9a1adbb1fc4
parentecbadbce2468b9ae56726481e8e1cc0cfe16c0dc (diff)
downloadqt-creator-d86b2abc0bc71f8748356c1a0eb7eb7c60226873.tar.gz
Add a scratch file wizard.
Add a wizard that quickly creates a text file without prompting for a path, useful for shuffling clipboard pastes around, for examples when collecting stack traces, etc and posting them to a code paster. Acked-by: Eike Ziller <eike.ziller@nokia.com> Change-Id: I9fa6375a961cfcfef28a79b71ee4e046e57f0ec7 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@nokia.com>
-rw-r--r--src/plugins/texteditor/texteditorplugin.cpp55
1 files changed, 53 insertions, 2 deletions
diff --git a/src/plugins/texteditor/texteditorplugin.cpp b/src/plugins/texteditor/texteditorplugin.cpp
index d10a75d65f..fa3a3a70cc 100644
--- a/src/plugins/texteditor/texteditorplugin.cpp
+++ b/src/plugins/texteditor/texteditorplugin.cpp
@@ -65,6 +65,8 @@
#include <QtPlugin>
#include <QMainWindow>
#include <QShortcut>
+#include <QDir>
+#include <QTemporaryFile>
using namespace TextEditor;
using namespace TextEditor::Internal;
@@ -98,6 +100,54 @@ 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)
{
@@ -110,14 +160,15 @@ 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("U.General"));
- wizardParameters.setDisplayCategory(tr("General"));
+ wizardParameters.setCategory(QLatin1String(wizardCategoryC));
+ wizardParameters.setDisplayCategory(wizardDisplayCategory());
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);