forked from qt-creator/qt-creator
CodePaster: Allow for editing snippets.
Introduce separate plain text mode parallel to diff-chunk mode using a stacked widget with a QPlainTextEdit. Task-number: QTCREATORBUG-3859
This commit is contained in:
@@ -217,16 +217,18 @@ static inline void fixSpecialCharacters(QString &data)
|
|||||||
void CodepasterPlugin::post(QString data, const QString &mimeType)
|
void CodepasterPlugin::post(QString data, const QString &mimeType)
|
||||||
{
|
{
|
||||||
fixSpecialCharacters(data);
|
fixSpecialCharacters(data);
|
||||||
FileDataList lst = splitDiffToFiles(data.toLatin1());
|
|
||||||
QString username = m_settings->username;
|
const QString username = m_settings->username;
|
||||||
QString description;
|
|
||||||
QString comment;
|
|
||||||
QString protocolName;
|
|
||||||
|
|
||||||
PasteView view(m_protocols, mimeType, 0);
|
PasteView view(m_protocols, mimeType, 0);
|
||||||
view.setProtocol(m_settings->protocol);
|
view.setProtocol(m_settings->protocol);
|
||||||
|
|
||||||
view.show(username, description, comment, lst);
|
const FileDataList diffChunks = splitDiffToFiles(data.toLatin1());
|
||||||
|
if (diffChunks.isEmpty()) {
|
||||||
|
view.show(username, QString(), QString(), data);
|
||||||
|
} else {
|
||||||
|
view.show(username, QString(), QString(), diffChunks);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CodepasterPlugin::fetch()
|
void CodepasterPlugin::fetch()
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ PasteView::PasteView(const QList<Protocol *> protocols,
|
|||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
m_protocols(protocols),
|
m_protocols(protocols),
|
||||||
m_commentPlaceHolder(tr("<Comment>")),
|
m_commentPlaceHolder(tr("<Comment>")),
|
||||||
m_mimeType(mt)
|
m_mimeType(mt),
|
||||||
|
m_mode(DiffChunkMode)
|
||||||
{
|
{
|
||||||
m_ui.setupUi(this);
|
m_ui.setupUi(this);
|
||||||
|
|
||||||
@@ -95,6 +96,9 @@ QString PasteView::comment() const
|
|||||||
|
|
||||||
QByteArray PasteView::content() const
|
QByteArray PasteView::content() const
|
||||||
{
|
{
|
||||||
|
if (m_mode == PlainTextMode)
|
||||||
|
return m_ui.plainTextEdit->toPlainText().toUtf8();
|
||||||
|
|
||||||
QByteArray newContent;
|
QByteArray newContent;
|
||||||
for (int i = 0; i < m_ui.uiPatchList->count(); ++i) {
|
for (int i = 0; i < m_ui.uiPatchList->count(); ++i) {
|
||||||
QListWidgetItem *item = m_ui.uiPatchList->item(i);
|
QListWidgetItem *item = m_ui.uiPatchList->item(i);
|
||||||
@@ -121,28 +125,15 @@ void PasteView::protocolChanged(int p)
|
|||||||
m_ui.uiComment->setEnabled(caps & Protocol::PostCommentCapability);
|
m_ui.uiComment->setEnabled(caps & Protocol::PostCommentCapability);
|
||||||
}
|
}
|
||||||
|
|
||||||
int PasteView::show(const QString &user, const QString &description, const QString &comment,
|
void PasteView::setupDialog(const QString &user, const QString &description, const QString &comment)
|
||||||
const FileDataList &parts)
|
|
||||||
{
|
{
|
||||||
m_ui.uiUsername->setText(user);
|
m_ui.uiUsername->setText(user);
|
||||||
m_ui.uiDescription->setText(description);
|
m_ui.uiDescription->setText(description);
|
||||||
|
m_ui.uiComment->setPlainText(comment.isEmpty() ? m_commentPlaceHolder : comment);
|
||||||
|
}
|
||||||
|
|
||||||
if (comment.isEmpty())
|
int PasteView::showDialog()
|
||||||
m_ui.uiComment->setPlainText(m_commentPlaceHolder);
|
{
|
||||||
else
|
|
||||||
m_ui.uiComment->setPlainText(comment);
|
|
||||||
|
|
||||||
QByteArray content;
|
|
||||||
m_parts = parts;
|
|
||||||
m_ui.uiPatchList->clear();
|
|
||||||
foreach (const FileData &part, parts) {
|
|
||||||
QListWidgetItem *itm = new QListWidgetItem(part.filename, m_ui.uiPatchList);
|
|
||||||
itm->setCheckState(Qt::Checked);
|
|
||||||
itm->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
|
||||||
content += part.content;
|
|
||||||
}
|
|
||||||
m_ui.uiPatchView->setPlainText(content);
|
|
||||||
|
|
||||||
m_ui.uiDescription->setFocus();
|
m_ui.uiDescription->setFocus();
|
||||||
m_ui.uiDescription->selectAll();
|
m_ui.uiDescription->selectAll();
|
||||||
|
|
||||||
@@ -159,6 +150,37 @@ int PasteView::show(const QString &user, const QString &description, const QStri
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Show up with checkable list of diff chunks.
|
||||||
|
int PasteView::show(const QString &user, const QString &description,
|
||||||
|
const QString &comment, const FileDataList &parts)
|
||||||
|
{
|
||||||
|
setupDialog(user, description, comment);
|
||||||
|
m_ui.uiPatchList->clear();
|
||||||
|
m_parts = parts;
|
||||||
|
m_mode = DiffChunkMode;
|
||||||
|
QByteArray content;
|
||||||
|
foreach (const FileData &part, parts) {
|
||||||
|
QListWidgetItem *itm = new QListWidgetItem(part.filename, m_ui.uiPatchList);
|
||||||
|
itm->setCheckState(Qt::Checked);
|
||||||
|
itm->setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled);
|
||||||
|
content += part.content;
|
||||||
|
}
|
||||||
|
m_ui.stackedWidget->setCurrentIndex(0);
|
||||||
|
m_ui.uiPatchView->setPlainText(content);
|
||||||
|
return showDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show up with editable plain text.
|
||||||
|
int PasteView::show(const QString &user, const QString &description,
|
||||||
|
const QString &comment, const QString &content)
|
||||||
|
{
|
||||||
|
setupDialog(user, description, comment);
|
||||||
|
m_mode = PlainTextMode;
|
||||||
|
m_ui.stackedWidget->setCurrentIndex(1);
|
||||||
|
m_ui.plainTextEdit->setPlainText(content);
|
||||||
|
return showDialog();
|
||||||
|
}
|
||||||
|
|
||||||
void PasteView::accept()
|
void PasteView::accept()
|
||||||
{
|
{
|
||||||
const int index = m_ui.protocolBox->currentIndex();
|
const int index = m_ui.protocolBox->currentIndex();
|
||||||
@@ -170,8 +192,12 @@ void PasteView::accept()
|
|||||||
if (!Protocol::ensureConfiguration(protocol, this))
|
if (!Protocol::ensureConfiguration(protocol, this))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
const QByteArray data = content();
|
||||||
|
if (data.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
const Protocol::ContentType ct = Protocol::contentType(m_mimeType);
|
const Protocol::ContentType ct = Protocol::contentType(m_mimeType);
|
||||||
protocol->paste(content(), ct, user(), comment(), description());
|
protocol->paste(data, ct, user(), comment(), description());
|
||||||
// Store settings and close
|
// Store settings and close
|
||||||
QSettings *settings = Core::ICore::instance()->settings();
|
QSettings *settings = Core::ICore::instance()->settings();
|
||||||
settings->beginGroup(QLatin1String(groupC));
|
settings->beginGroup(QLatin1String(groupC));
|
||||||
|
|||||||
@@ -45,13 +45,25 @@ class PasteView : public QDialog
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum Mode
|
||||||
|
{
|
||||||
|
// Present a list of read-only diff chunks which the user can check for inclusion
|
||||||
|
DiffChunkMode,
|
||||||
|
// Present plain, editable text.
|
||||||
|
PlainTextMode
|
||||||
|
};
|
||||||
|
|
||||||
explicit PasteView(const QList<Protocol *> protocols,
|
explicit PasteView(const QList<Protocol *> protocols,
|
||||||
const QString &mimeType,
|
const QString &mimeType,
|
||||||
QWidget *parent);
|
QWidget *parent);
|
||||||
~PasteView();
|
~PasteView();
|
||||||
|
|
||||||
|
// Show up with checkable list of diff chunks.
|
||||||
int show(const QString &user, const QString &description, const QString &comment,
|
int show(const QString &user, const QString &description, const QString &comment,
|
||||||
const FileDataList &parts);
|
const FileDataList &parts);
|
||||||
|
// Show up with editable plain text.
|
||||||
|
int show(const QString &user, const QString &description, const QString &comment,
|
||||||
|
const QString &content);
|
||||||
|
|
||||||
void setProtocol(const QString &protocol);
|
void setProtocol(const QString &protocol);
|
||||||
|
|
||||||
@@ -68,12 +80,16 @@ private slots:
|
|||||||
void protocolChanged(int);
|
void protocolChanged(int);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void setupDialog(const QString &user, const QString &description, const QString &comment);
|
||||||
|
int showDialog();
|
||||||
|
|
||||||
const QList<Protocol *> m_protocols;
|
const QList<Protocol *> m_protocols;
|
||||||
const QString m_commentPlaceHolder;
|
const QString m_commentPlaceHolder;
|
||||||
const QString m_mimeType;
|
const QString m_mimeType;
|
||||||
|
|
||||||
Ui::ViewDialog m_ui;
|
Ui::ViewDialog m_ui;
|
||||||
FileDataList m_parts;
|
FileDataList m_parts;
|
||||||
|
Mode m_mode;
|
||||||
};
|
};
|
||||||
} // namespace CodePaster
|
} // namespace CodePaster
|
||||||
#endif // VIEW_H
|
#endif // VIEW_H
|
||||||
|
|||||||
@@ -6,18 +6,18 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>600</width>
|
<width>670</width>
|
||||||
<height>500</height>
|
<height>678</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>Send to Codepaster</string>
|
<string>Send to Codepaster</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="vboxLayout1">
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QFormLayout" name="formLayout">
|
<layout class="QFormLayout" name="formLayout">
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="label_3">
|
<widget class="QLabel" name="protocolLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Protocol:</string>
|
<string>Protocol:</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -27,7 +27,7 @@
|
|||||||
<widget class="QComboBox" name="protocolBox"/>
|
<widget class="QComboBox" name="protocolBox"/>
|
||||||
</item>
|
</item>
|
||||||
<item row="1" column="0">
|
<item row="1" column="0">
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="userLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Username:</string>
|
<string>&Username:</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -44,7 +44,7 @@
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="2" column="0">
|
<item row="2" column="0">
|
||||||
<widget class="QLabel" name="label_2">
|
<widget class="QLabel" name="descriptionLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>&Description:</string>
|
<string>&Description:</string>
|
||||||
</property>
|
</property>
|
||||||
@@ -89,68 +89,83 @@ p, li { white-space: pre-wrap; }
|
|||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox">
|
<widget class="QStackedWidget" name="stackedWidget">
|
||||||
<property name="sizePolicy">
|
<widget class="QWidget" name="diffChunkPage">
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<horstretch>0</horstretch>
|
<item>
|
||||||
<verstretch>0</verstretch>
|
<widget class="QGroupBox" name="groupBox">
|
||||||
</sizepolicy>
|
<property name="sizePolicy">
|
||||||
</property>
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
<property name="title">
|
<horstretch>0</horstretch>
|
||||||
<string>Parts to Send to Server</string>
|
<verstretch>0</verstretch>
|
||||||
</property>
|
</sizepolicy>
|
||||||
<property name="flat">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<layout class="QVBoxLayout">
|
|
||||||
<property name="spacing">
|
|
||||||
<number>2</number>
|
|
||||||
</property>
|
|
||||||
<property name="margin">
|
|
||||||
<number>0</number>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<widget class="QListWidget" name="uiPatchList">
|
|
||||||
<property name="sizePolicy">
|
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
|
||||||
<horstretch>0</horstretch>
|
|
||||||
<verstretch>1</verstretch>
|
|
||||||
</sizepolicy>
|
|
||||||
</property>
|
|
||||||
<property name="uniformItemSizes">
|
|
||||||
<bool>true</bool>
|
|
||||||
</property>
|
|
||||||
<item>
|
|
||||||
<property name="text">
|
|
||||||
<string>Patch 1</string>
|
|
||||||
</property>
|
</property>
|
||||||
</item>
|
<property name="title">
|
||||||
<item>
|
<string>Parts to Send to Server</string>
|
||||||
<property name="text">
|
|
||||||
<string>Patch 2</string>
|
|
||||||
</property>
|
</property>
|
||||||
</item>
|
<property name="flat">
|
||||||
</widget>
|
<bool>true</bool>
|
||||||
</item>
|
</property>
|
||||||
<item>
|
<layout class="QVBoxLayout">
|
||||||
<widget class="CodePaster::ColumnIndicatorTextEdit" name="uiPatchView">
|
<property name="spacing">
|
||||||
<property name="sizePolicy">
|
<number>2</number>
|
||||||
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
</property>
|
||||||
<horstretch>0</horstretch>
|
<property name="margin">
|
||||||
<verstretch>3</verstretch>
|
<number>0</number>
|
||||||
</sizepolicy>
|
</property>
|
||||||
</property>
|
<item>
|
||||||
<property name="font">
|
<widget class="QListWidget" name="uiPatchList">
|
||||||
<font>
|
<property name="sizePolicy">
|
||||||
<family>Courier New</family>
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
</font>
|
<horstretch>0</horstretch>
|
||||||
</property>
|
<verstretch>1</verstretch>
|
||||||
<property name="readOnly">
|
</sizepolicy>
|
||||||
<bool>true</bool>
|
</property>
|
||||||
</property>
|
<property name="uniformItemSizes">
|
||||||
</widget>
|
<bool>true</bool>
|
||||||
</item>
|
</property>
|
||||||
</layout>
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Patch 1</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Patch 2</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="CodePaster::ColumnIndicatorTextEdit" name="uiPatchView">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>3</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<family>Courier New</family>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<widget class="QWidget" name="plainTextPage">
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPlainTextEdit" name="plainTextEdit"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
|||||||
@@ -56,8 +56,7 @@ FileDataList splitDiffToFiles(const QByteArray &data)
|
|||||||
"\\n\\-\\-\\- ([^\\n\\r]*) [0-9\\-]* [0-9:\\.]*[^\\n\\r]*";
|
"\\n\\-\\-\\- ([^\\n\\r]*) [0-9\\-]* [0-9:\\.]*[^\\n\\r]*";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
ret.append(FileData("<not a diff>", data));
|
return FileDataList();
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int splitIndex = 0, previousSplit = -1;
|
int splitIndex = 0, previousSplit = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user