mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-27 16:39:29 -05:00
Improvements to WikiEditDialog
- Make Details togglable - Keep track of Modified state. - Add peg-markdown Renderer (disabled until I sort out support library). - Fix up Submit to submit correct text and handle Utf8 git-svn-id: http://svn.code.sf.net/p/retroshare/code/branches/v0.5-gxs-b1@5925 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
c955e3b5a4
commit
e1423919aa
@ -26,6 +26,12 @@
|
||||
|
||||
#include <iostream>
|
||||
|
||||
//#define USE_PEGMMD_RENDERER 1
|
||||
|
||||
#ifdef USE_PEGMMD_RENDERER
|
||||
#include "markdown_lib.h"
|
||||
#endif
|
||||
|
||||
|
||||
#define WIKIEDITDIALOG_GROUP 0x0001
|
||||
#define WIKIEDITDIALOG_PAGE 0x0002
|
||||
@ -43,14 +49,68 @@ WikiEditDialog::WikiEditDialog(QWidget *parent)
|
||||
connect(ui.pushButton_Submit, SIGNAL( clicked( void ) ), this, SLOT( submitEdit( void ) ) );
|
||||
connect(ui.pushButton_Preview, SIGNAL( clicked( void ) ), this, SLOT( previewToggle( void ) ) );
|
||||
connect(ui.pushButton_History, SIGNAL( clicked( void ) ), this, SLOT( historyToggle( void ) ) );
|
||||
connect(ui.toolButton_Show, SIGNAL( clicked( void ) ), this, SLOT( detailsToggle( void ) ) );
|
||||
connect(ui.toolButton_Hide, SIGNAL( clicked( void ) ), this, SLOT( detailsToggle( void ) ) );
|
||||
connect(ui.textEdit, SIGNAL( textChanged( void ) ), this, SLOT( textChanged( void ) ) );
|
||||
|
||||
mWikiQueue = new TokenQueue(rsWiki->getTokenService(), this);
|
||||
mRepublishMode = false;
|
||||
mPreviewMode = false;
|
||||
mPageLoading = false;
|
||||
mTextChanged = false;
|
||||
mCurrentText = "";
|
||||
|
||||
ui.groupBox_History->hide();
|
||||
detailsToggle();
|
||||
}
|
||||
|
||||
void WikiEditDialog::textChanged()
|
||||
{
|
||||
mTextChanged = true;
|
||||
ui.pushButton_Revert->setEnabled(true);
|
||||
ui.pushButton_Submit->setEnabled(true);
|
||||
ui.label_Status->setText("Modified");
|
||||
}
|
||||
|
||||
|
||||
void WikiEditDialog::textReset()
|
||||
{
|
||||
mTextChanged = false;
|
||||
ui.pushButton_Revert->setEnabled(false);
|
||||
ui.pushButton_Submit->setEnabled(false);
|
||||
ui.label_Status->setText("Original");
|
||||
}
|
||||
|
||||
|
||||
|
||||
void WikiEditDialog::detailsToggle()
|
||||
{
|
||||
std::cerr << "WikiEditDialog::detailsToggle()";
|
||||
std::cerr << std::endl;
|
||||
if (ui.toolButton_Hide->isHidden())
|
||||
{
|
||||
ui.toolButton_Hide->show();
|
||||
ui.toolButton_Show->hide();
|
||||
|
||||
ui.label_PrevVersion->show();
|
||||
ui.label_Group->show();
|
||||
ui.label_Tags->show();
|
||||
ui.lineEdit_PrevVersion->show();
|
||||
ui.lineEdit_Group->show();
|
||||
ui.lineEdit_Tags->show();
|
||||
}
|
||||
else
|
||||
{
|
||||
ui.toolButton_Hide->hide();
|
||||
ui.toolButton_Show->show();
|
||||
|
||||
ui.label_PrevVersion->hide();
|
||||
ui.label_Group->hide();
|
||||
ui.label_Tags->hide();
|
||||
ui.lineEdit_PrevVersion->hide();
|
||||
ui.lineEdit_Group->hide();
|
||||
ui.lineEdit_Tags->hide();
|
||||
}
|
||||
}
|
||||
|
||||
void WikiEditDialog::historyToggle()
|
||||
@ -101,10 +161,25 @@ void WikiEditDialog::redrawPage()
|
||||
|
||||
if (mPreviewMode)
|
||||
{
|
||||
#ifdef USE_PEGMMD_RENDERER
|
||||
/* render as HTML */
|
||||
QString renderedText = "RENDERED TEXT:\n";
|
||||
QByteArray byte_array = mCurrentText.toUtf8();
|
||||
|
||||
int extensions = 0;
|
||||
char *answer = markdown_to_string(byte_array.data(), extensions, HTML_FORMAT);
|
||||
|
||||
QString renderedText = QString::fromUtf8(answer);
|
||||
ui.textEdit->setHtml(renderedText);
|
||||
|
||||
// free answer.
|
||||
free(answer);
|
||||
#else
|
||||
/* render as HTML */
|
||||
QString renderedText = "IN (dummy) RENDERED TEXT MODE:\n";
|
||||
renderedText += mCurrentText;
|
||||
ui.textEdit->setPlainText(renderedText);
|
||||
#endif
|
||||
|
||||
|
||||
/* disable edit */
|
||||
ui.textEdit->setReadOnly(true);
|
||||
@ -143,6 +218,7 @@ void WikiEditDialog::setPreviousPage(RsWikiSnapshot &page)
|
||||
ui.lineEdit_PrevVersion->setText(QString::fromStdString(mWikiSnapshot.mMeta.mMsgId));
|
||||
mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str());
|
||||
redrawPage();
|
||||
textReset();
|
||||
}
|
||||
|
||||
|
||||
@ -163,6 +239,7 @@ void WikiEditDialog::setNewPage()
|
||||
ui.headerFrame->setHeaderText(tr("Create New Wiki Page"));
|
||||
setWindowTitle(tr("Create New Wiki Page"));
|
||||
|
||||
textReset();
|
||||
}
|
||||
|
||||
|
||||
@ -192,6 +269,7 @@ void WikiEditDialog::revertEdit()
|
||||
mCurrentText = QString::fromUtf8(mWikiSnapshot.mPage.c_str());
|
||||
}
|
||||
redrawPage();
|
||||
textReset();
|
||||
}
|
||||
|
||||
|
||||
@ -255,7 +333,18 @@ void WikiEditDialog::submitEdit()
|
||||
|
||||
|
||||
mWikiSnapshot.mMeta.mMsgName = ui.lineEdit_Page->text().toStdString();
|
||||
mWikiSnapshot.mPage = ui.textEdit->toPlainText().toStdString();
|
||||
|
||||
if (!mPreviewMode)
|
||||
{
|
||||
/* can just use the current text */
|
||||
mCurrentText = ui.textEdit->toPlainText();
|
||||
}
|
||||
|
||||
{
|
||||
// complicated way of preserving Utf8 text */
|
||||
QByteArray byte_array = mCurrentText.toUtf8();
|
||||
mWikiSnapshot.mPage = std::string(byte_array.data());
|
||||
}
|
||||
|
||||
std::cerr << "WikiEditDialog::submitEdit() PageTitle: " << mWikiSnapshot.mMeta.mMsgName;
|
||||
std::cerr << std::endl;
|
||||
|
@ -50,6 +50,9 @@ void revertEdit();
|
||||
void submitEdit();
|
||||
void previewToggle();
|
||||
void historyToggle();
|
||||
void detailsToggle();
|
||||
void textChanged();
|
||||
void textReset();
|
||||
|
||||
private:
|
||||
|
||||
@ -76,6 +79,7 @@ void loadEditTreeData(const uint32_t &token);
|
||||
bool mPageLoading;
|
||||
|
||||
bool mRepublishMode;
|
||||
bool mTextChanged;
|
||||
|
||||
QString mCurrentText;
|
||||
|
||||
|
@ -28,9 +28,6 @@
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<zorder>frame</zorder>
|
||||
<zorder>frame</zorder>
|
||||
<zorder>frame</zorder>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
@ -54,12 +51,6 @@
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<widget class="QGroupBox" name="groupBox_History">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="title">
|
||||
<string>Page Edit History</string>
|
||||
</property>
|
||||
@ -87,69 +78,139 @@
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Raised</enum>
|
||||
</property>
|
||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0,0">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_4" stretch="0,0,10,0">
|
||||
<item>
|
||||
<widget class="QGroupBox" name="groupBox">
|
||||
<property name="title">
|
||||
<string>Wiki Page</string>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_5">
|
||||
<property name="text">
|
||||
<string>Wiki Group:</string>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_Show">
|
||||
<property name="text">
|
||||
<string>\/</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeType">
|
||||
<enum>QSizePolicy::MinimumExpanding</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>10</width>
|
||||
<height>0</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QToolButton" name="toolButton_Hide">
|
||||
<property name="text">
|
||||
<string>/\</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QFrame" name="frame">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="MinimumExpanding">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="topMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>groupBox</cstring>
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_Group">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Page Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_Page">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>10</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Previous Version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_PrevVersion">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>10</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label_Group">
|
||||
<property name="text">
|
||||
<string>Wiki Group:</string>
|
||||
</property>
|
||||
<property name="buddy">
|
||||
<cstring>frame</cstring>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_Group">
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_Page">
|
||||
<property name="text">
|
||||
<string>Page Name:</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_Page">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>10</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<widget class="QLabel" name="label_PrevVersion">
|
||||
<property name="text">
|
||||
<string>Previous Version</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_PrevVersion">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>10</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="label_Tags">
|
||||
<property name="text">
|
||||
<string>Tags</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="1">
|
||||
<widget class="QLineEdit" name="lineEdit_Tags">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>10</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="readOnly">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||
@ -173,6 +234,13 @@
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="label_Status">
|
||||
<property name="text">
|
||||
<string>Status</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="pushButton_Preview">
|
||||
<property name="text">
|
||||
|
Loading…
Reference in New Issue
Block a user