forked from qt-creator/qt-creator
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>
This commit is contained in:
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user