From kde-commits Mon Apr 15 15:44:26 2013 From: Juan Carlos Torres Date: Mon, 15 Apr 2013 15:44:26 +0000 To: kde-commits Subject: [konversation/1.5] /: Make manual auto-replace work in the paste editor Message-Id: <20130415154426.4EA2AA605E () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=136604067415746 Git commit 0e249dfb347a23fe7b2c576b6d991a50e2ad4564 by Juan Carlos Torres. Committed on 15/04/2013 at 17:39. Pushed by jucato into branch '1.5'. Make manual auto-replace work in the paste editor This patch makes the action to manually apply auto replace work also in the paste editor. The patch also puts the inline auto-replace method in a central location rather than duplicating code. M +2 -0 ChangeLog M +17 -0 src/application.cpp M +5 -0 src/application.h M +1 -12 src/viewer/ircinput.cpp M +23 -1 src/viewer/pasteeditor.cpp M +9 -0 src/viewer/pasteeditor.h M +4 -0 src/viewer/viewcontainer.cpp http://commits.kde.org/konversation/0e249dfb347a23fe7b2c576b6d991a50e2ad4564 diff --git a/ChangeLog b/ChangeLog index fe39315..b2c2437 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,8 @@ Changes since 1.5-rc1: channel starting with one # too few; this has been fixed. * Fixed auto-replace not being applied to messages that are sent from the Large Paste Warning dialog. +* Made the action to manually apply Auto Replace work in the Paste Editor + as well. = = Changes from 1.4 to 1.5-rc1: diff --git a/src/application.cpp b/src/application.cpp index 71e0f1f..7518183 100644 --- a/src/application.cpp +++ b/src/application.cpp @@ -39,6 +39,7 @@ #include #include #include +#include = #include #include @@ -48,6 +49,7 @@ #include #include #include +#include = = using namespace Konversation; @@ -1231,6 +1233,21 @@ QPair Application::doAutoreplace(const= QString& text, bool output, return QPair(line, cursorPos); } = +void Application::doInlineAutoreplace(KTextEdit* textEdit) +{ + QTextCursor cursor(textEdit->document()); + + cursor.beginEditBlock(); + const QPair& replace =3D Application::instance()->doAuto= replace(textEdit->toPlainText(), true, textEdit->textCursor().position()); + cursor.select(QTextCursor::Document); + cursor.insertText(replace.first); + cursor.setPosition(replace.second); + cursor.endEditBlock(); + + textEdit->setTextCursor(cursor); +} + + void Application::openUrl(const QString& url) { if (!Preferences::self()->useCustomBrowser() || url.startsWith(QLatin1= String("mailto:")) || url.startsWith(QLatin1String("amarok:"))) diff --git a/src/application.h b/src/application.h index b95bd7b..de84e5d 100644 --- a/src/application.h +++ b/src/application.h @@ -34,6 +34,8 @@ class Images; class ServerGroupSettings; class QStandardItemModel; = +class KTextEdit; + namespace Konversation { class DBus; @@ -117,6 +119,9 @@ class Application : public KUniqueApplication // auto replacement for input or output lines QPair doAutoreplace(const QString& text, bool output= , int cursorPos =3D -1); = + // inline auto replacement for input lines + void doInlineAutoreplace(KTextEdit* textEdit); + int newInstance(); = static void openUrl(const QString& url); diff --git a/src/viewer/ircinput.cpp b/src/viewer/ircinput.cpp index e99fb94..952426f 100644 --- a/src/viewer/ircinput.cpp +++ b/src/viewer/ircinput.cpp @@ -630,18 +630,7 @@ void IRCInput::setLastCompletion(const QString& comple= tion) = void IRCInput::doInlineAutoreplace() { - QTextCursor cursor(document()); - - cursor.beginEditBlock(); - - const QPair& rep =3D Application::instance()->doAutorepl= ace(toPlainText(), true, textCursor().position()); - cursor.select(QTextCursor::Document); - cursor.insertText(rep.first); - cursor.setPosition(rep.second); - - cursor.endEditBlock(); - - setTextCursor(cursor); + Application::instance()->doInlineAutoreplace(this); } = // Accessor methods diff --git a/src/viewer/pasteeditor.cpp b/src/viewer/pasteeditor.cpp index d2cf21f..2b620fd 100644 --- a/src/viewer/pasteeditor.cpp +++ b/src/viewer/pasteeditor.cpp @@ -15,16 +15,19 @@ = #include "pasteeditor.h" #include "preferences.h" +#include "application.h" = #include #include +#include = #include #include #include +#include = PasteEditor::PasteEditor(QWidget* parent) - : KDialog(parent), Ui::PasteEditor() + : KDialog(parent), Ui::PasteEditor(), m_autoReplaceActionWasEnabled(tr= ue), m_autoReplaceAction(0) { setCaption(i18n("Edit Multiline Paste")); setModal(true); @@ -42,6 +45,17 @@ PasteEditor::PasteEditor(QWidget* parent) m_textEditor->document()->setDefaultTextOption(options); m_textEditor->setFocus(); = + // Get auto_replace action, check enabled state and make the connection + m_autoReplaceAction =3D Application::instance()->getMainWindow()->acti= onCollection()->action("auto_replace"); + if (m_autoReplaceAction) + { + // Store action's original enabled state in ViewContainer + m_autoReplaceActionWasEnabled =3D m_autoReplaceAction->isEnabled(); + m_autoReplaceAction->setEnabled(true); + addAction(m_autoReplaceAction); + connect(m_autoReplaceAction, SIGNAL(triggered(bool)), this, SLOT(d= oInlineAutoreplace())); + } + connect(m_removeNewlinesButton, SIGNAL(clicked()), this, SLOT(removeNe= wlines())); connect(m_addQuotesButton, SIGNAL(clicked()), this, SLOT(addQuotationI= ndicators())); = @@ -51,6 +65,9 @@ PasteEditor::PasteEditor(QWidget* parent) PasteEditor::~PasteEditor() { Preferences::self()->setMultilineEditSize(size()); + // Restore action's original state in ViewContainer + if (m_autoReplaceAction) + m_autoReplaceAction->setEnabled(m_autoReplaceActionWasEnabled); } = void PasteEditor::addQuotationIndicators() @@ -121,4 +138,9 @@ QString PasteEditor::edit(QWidget* parent, const QStrin= g& text) return QString(); } = +void PasteEditor::doInlineAutoreplace() +{ + Application::instance()->doInlineAutoreplace(m_textEditor); +} + #include "pasteeditor.moc" diff --git a/src/viewer/pasteeditor.h b/src/viewer/pasteeditor.h index 8020a1d..ca103ec 100644 --- a/src/viewer/pasteeditor.h +++ b/src/viewer/pasteeditor.h @@ -20,6 +20,8 @@ = #include = +class QAction; + class PasteEditor : public KDialog, private Ui::PasteEditor { Q_OBJECT @@ -35,6 +37,13 @@ class PasteEditor : public KDialog, private Ui::PasteEdi= tor protected slots: void addQuotationIndicators(); void removeNewlines(); + + private slots: + void doInlineAutoreplace(); + + private: + bool m_autoReplaceActionWasEnabled; + QAction* m_autoReplaceAction; }; = #endif //KONVERSATION_PASTEEDITOR_H diff --git a/src/viewer/viewcontainer.cpp b/src/viewer/viewcontainer.cpp index ffa40ba..6b95066 100644 --- a/src/viewer/viewcontainer.cpp +++ b/src/viewer/viewcontainer.cpp @@ -2093,6 +2093,10 @@ void ViewContainer::doAutoReplace() if (!m_frontView) return; = + // Check for active window in case action was triggered from a modal d= ialog, like the Paste Editor + if (!m_window->isActiveWindow()) + return; + if (m_frontView->getInputBar()) m_frontView->getInputBar()->doInlineAutoreplace(); }