[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [konversation/1.5] /: Make manual auto-replace work in the paste editor
From: Juan Carlos Torres <carlosdgtorres () gmail ! com>
Date: 2013-04-15 15:44:26
Message-ID: 20130415154426.4EA2AA605E () git ! kde ! org
[Download RAW message or body]
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 <QWaitCondition>
#include <QStandardItemModel>
#include <QFileInfo>
+#include <QTextCursor>
#include <KRun>
#include <KCmdLineArgs>
@@ -48,6 +49,7 @@
#include <KCharMacroExpander>
#include <kwallet.h>
#include <solid/networking.h>
+#include <KTextEdit>
using namespace Konversation;
@@ -1231,6 +1233,21 @@ QPair<QString, int> Application::doAutoreplace(const QString& \
text, bool output, return QPair<QString, int>(line, cursorPos);
}
+void Application::doInlineAutoreplace(KTextEdit* textEdit)
+{
+ QTextCursor cursor(textEdit->document());
+
+ cursor.beginEditBlock();
+ const QPair<QString, int>& replace = \
Application::instance()->doAutoreplace(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(QLatin1String("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<QString, int> doAutoreplace(const QString& text, bool output, int \
cursorPos = -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& completion)
void IRCInput::doInlineAutoreplace()
{
- QTextCursor cursor(document());
-
- cursor.beginEditBlock();
-
- const QPair<QString, int>& rep = \
Application::instance()->doAutoreplace(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 <KPushButton>
#include <KLocale>
+#include <KActionCollection>
#include <QTextCursor>
#include <QTextOption>
#include <QPointer>
+#include <QAction>
PasteEditor::PasteEditor(QWidget* parent)
- : KDialog(parent), Ui::PasteEditor()
+ : KDialog(parent), Ui::PasteEditor(), m_autoReplaceActionWasEnabled(true), \
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 = \
Application::instance()->getMainWindow()->actionCollection()->action("auto_replace"); \
+ if (m_autoReplaceAction) + {
+ // Store action's original enabled state in ViewContainer
+ m_autoReplaceActionWasEnabled = m_autoReplaceAction->isEnabled();
+ m_autoReplaceAction->setEnabled(true);
+ addAction(m_autoReplaceAction);
+ connect(m_autoReplaceAction, SIGNAL(triggered(bool)), this, \
SLOT(doInlineAutoreplace())); + }
+
connect(m_removeNewlinesButton, SIGNAL(clicked()), this, \
SLOT(removeNewlines()));
connect(m_addQuotesButton, SIGNAL(clicked()), this, \
SLOT(addQuotationIndicators()));
@@ -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 QString& 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 <KDialog>
+class QAction;
+
class PasteEditor : public KDialog, private Ui::PasteEditor
{
Q_OBJECT
@@ -35,6 +37,13 @@ class PasteEditor : public KDialog, private Ui::PasteEditor
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 dialog, \
like the Paste Editor + if (!m_window->isActiveWindow())
+ return;
+
if (m_frontView->getInputBar())
m_frontView->getInputBar()->doInlineAutoreplace();
}
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic