r22883 by jghali - Some refactoring for ScripterCore
scribus-commit
scribus-commit at lists.scribus.net
Mon Mar 11 11:33:55 UTC 2019
Author: jghali
Date: Mon Mar 11 11:33:54 2019
New Revision: 22883
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22883
Log:
Some refactoring for ScripterCore
Modified:
trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22883&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.cpp Mon Mar 11 11:33:54 2019
@@ -43,33 +43,33 @@
ScripterCore::ScripterCore(QWidget* parent)
{
- menuMgr = nullptr;
-
- pcon = new PythonConsole(parent);
- scrScripterActions.clear();
- scrRecentScriptActions.clear();
+ m_menuMgr = nullptr;
+
+ m_pyConsole = new PythonConsole(parent);
+ m_scripterActions.clear();
+ m_recentScriptActions.clear();
returnString = "init";
- scrScripterActions.insert("scripterExecuteScript", new ScrAction(QObject::tr("&Execute Script..."), QKeySequence(), this));
- scrScripterActions.insert("scripterShowConsole", new ScrAction(QObject::tr("Show &Console"), QKeySequence(), this));
- scrScripterActions.insert("scripterAboutScript", new ScrAction(QObject::tr("&About Script..."), QKeySequence(), this));
-
- scrScripterActions["scripterExecuteScript"]->setMenuRole(QAction::NoRole);
- scrScripterActions["scripterShowConsole"]->setMenuRole(QAction::NoRole);
- scrScripterActions["scripterAboutScript"]->setMenuRole(QAction::NoRole);
-
- scrScripterActions["scripterShowConsole"]->setToggleAction(true);
- scrScripterActions["scripterShowConsole"]->setChecked(false);
-
- QObject::connect( scrScripterActions["scripterExecuteScript"], SIGNAL(triggered()) , this, SLOT(runScriptDialog()) );
- QObject::connect( scrScripterActions["scripterShowConsole"], SIGNAL(toggled(bool)) , this, SLOT(slotInteractiveScript(bool)) );
- QObject::connect( scrScripterActions["scripterAboutScript"], SIGNAL(triggered()) , this, SLOT(aboutScript()) );
-
- SavedRecentScripts.clear();
- ReadPlugPrefs();
-
- QObject::connect(pcon, SIGNAL(runCommand()), this, SLOT(slotExecute()));
- QObject::connect(pcon, SIGNAL(paletteShown(bool)), this, SLOT(slotInteractiveScript(bool)));
+ m_scripterActions.insert("scripterExecuteScript", new ScrAction(QObject::tr("&Execute Script..."), QKeySequence(), this));
+ m_scripterActions.insert("scripterShowConsole", new ScrAction(QObject::tr("Show &Console"), QKeySequence(), this));
+ m_scripterActions.insert("scripterAboutScript", new ScrAction(QObject::tr("&About Script..."), QKeySequence(), this));
+
+ m_scripterActions["scripterExecuteScript"]->setMenuRole(QAction::NoRole);
+ m_scripterActions["scripterShowConsole"]->setMenuRole(QAction::NoRole);
+ m_scripterActions["scripterAboutScript"]->setMenuRole(QAction::NoRole);
+
+ m_scripterActions["scripterShowConsole"]->setToggleAction(true);
+ m_scripterActions["scripterShowConsole"]->setChecked(false);
+
+ QObject::connect( m_scripterActions["scripterExecuteScript"], SIGNAL(triggered()) , this, SLOT(runScriptDialog()) );
+ QObject::connect( m_scripterActions["scripterShowConsole"], SIGNAL(toggled(bool)) , this, SLOT(slotInteractiveScript(bool)) );
+ QObject::connect( m_scripterActions["scripterAboutScript"], SIGNAL(triggered()) , this, SLOT(aboutScript()) );
+
+ m_savedRecentScripts.clear();
+ readPlugPrefs();
+
+ QObject::connect(m_pyConsole, SIGNAL(runCommand()), this, SLOT(slotExecute()));
+ QObject::connect(m_pyConsole, SIGNAL(paletteShown(bool)), this, SLOT(slotInteractiveScript(bool)));
QObject::connect(ScQApp, SIGNAL(appStarted()) , this, SLOT(runStartupScript()) );
QObject::connect(ScQApp, SIGNAL(appStarted()) , this, SLOT(slotRunPythonScript()) );
@@ -77,48 +77,48 @@
ScripterCore::~ScripterCore()
{
- SavePlugPrefs();
- delete pcon;
+ savePlugPrefs();
+ delete m_pyConsole;
}
void ScripterCore::addToMainWindowMenu(ScribusMainWindow *mw)
{
- menuMgr = mw->scrMenuMgr;
- menuMgr->createMenu("Scripter", QObject::tr("&Script"));
- menuMgr->createMenu("ScribusScripts", QObject::tr("&Scribus Scripts"), "Scripter");
- menuMgr->addMenuItemString("ScribusScripts", "Scripter");
- menuMgr->addMenuItemString("scripterExecuteScript", "Scripter");
- menuMgr->createMenu("RecentScripts", QObject::tr("&Recent Scripts"), "Scripter", false, true);
- menuMgr->addMenuItemString("RecentScripts", "Scripter");
- menuMgr->addMenuItemString("scripterExecuteScript", "Scripter");
- menuMgr->addMenuItemString("SEPARATOR", "Scripter");
- menuMgr->addMenuItemString("scripterShowConsole", "Scripter");
- menuMgr->addMenuItemString("scripterAboutScript", "Scripter");
+ m_menuMgr = mw->scrMenuMgr;
+ m_menuMgr->createMenu("Scripter", QObject::tr("&Script"));
+ m_menuMgr->createMenu("ScribusScripts", QObject::tr("&Scribus Scripts"), "Scripter");
+ m_menuMgr->addMenuItemString("ScribusScripts", "Scripter");
+ m_menuMgr->addMenuItemString("scripterExecuteScript", "Scripter");
+ m_menuMgr->createMenu("RecentScripts", QObject::tr("&Recent Scripts"), "Scripter", false, true);
+ m_menuMgr->addMenuItemString("RecentScripts", "Scripter");
+ m_menuMgr->addMenuItemString("scripterExecuteScript", "Scripter");
+ m_menuMgr->addMenuItemString("SEPARATOR", "Scripter");
+ m_menuMgr->addMenuItemString("scripterShowConsole", "Scripter");
+ m_menuMgr->addMenuItemString("scripterAboutScript", "Scripter");
buildScribusScriptsMenu();
- menuMgr->addMenuStringToMenuBarBefore("Scripter","Windows");
- menuMgr->addMenuItemStringstoMenuBar("Scripter", scrScripterActions);
- RecentScripts = SavedRecentScripts;
+ m_menuMgr->addMenuStringToMenuBarBefore("Scripter","Windows");
+ m_menuMgr->addMenuItemStringstoMenuBar("Scripter", m_scripterActions);
+ m_recentScripts = m_savedRecentScripts;
rebuildRecentScriptsMenu();
}
void ScripterCore::enableMainWindowMenu()
{
- if (!menuMgr)
- return;
- menuMgr->setMenuEnabled("ScribusScripts", true);
- menuMgr->setMenuEnabled("RecentScripts", true);
- scrScripterActions["scripterExecuteScript"]->setEnabled(true);
+ if (!m_menuMgr)
+ return;
+ m_menuMgr->setMenuEnabled("ScribusScripts", true);
+ m_menuMgr->setMenuEnabled("RecentScripts", true);
+ m_scripterActions["scripterExecuteScript"]->setEnabled(true);
}
void ScripterCore::disableMainWindowMenu()
{
- if (!menuMgr)
- return;
- menuMgr->setMenuEnabled("ScribusScripts", false);
- menuMgr->setMenuEnabled("RecentScripts", false);
- scrScripterActions["scripterExecuteScript"]->setEnabled(false);
+ if (!m_menuMgr)
+ return;
+ m_menuMgr->setMenuEnabled("ScribusScripts", false);
+ m_menuMgr->setMenuEnabled("RecentScripts", false);
+ m_scripterActions["scripterExecuteScript"]->setEnabled(false);
}
void ScripterCore::buildScribusScriptsMenu()
@@ -133,52 +133,52 @@
{
QFileInfo fs(ds[dc]);
QString strippedName=fs.baseName();
- scrScripterActions.insert(strippedName, new ScrAction( ScrAction::RecentScript, strippedName, QKeySequence(), this, strippedName));
- connect( scrScripterActions[strippedName], SIGNAL(triggeredData(QString)), this, SLOT(StdScript(QString)) );
- menuMgr->addMenuItemString(strippedName, "ScribusScripts");
+ m_scripterActions.insert(strippedName, new ScrAction( ScrAction::RecentScript, strippedName, QKeySequence(), this, strippedName));
+ connect( m_scripterActions[strippedName], SIGNAL(triggeredData(QString)), this, SLOT(StdScript(QString)) );
+ m_menuMgr->addMenuItemString(strippedName, "ScribusScripts");
}
}
}
void ScripterCore::rebuildRecentScriptsMenu()
{
- menuMgr->clearMenuStrings("RecentScripts");
- scrRecentScriptActions.clear();
- uint max = qMin(PrefsManager::instance()->appPrefs.uiPrefs.recentDocCount, RecentScripts.count());
+ m_menuMgr->clearMenuStrings("RecentScripts");
+ m_recentScriptActions.clear();
+ uint max = qMin(PrefsManager::instance()->appPrefs.uiPrefs.recentDocCount, m_recentScripts.count());
for (uint m = 0; m < max; ++m)
{
- QString strippedName=RecentScripts[m];
+ QString strippedName=m_recentScripts[m];
strippedName.remove(QDir::separator());
- scrRecentScriptActions.insert(strippedName, new ScrAction( ScrAction::RecentScript, RecentScripts[m], QKeySequence(), this, RecentScripts[m]));
- connect( scrRecentScriptActions[strippedName], SIGNAL(triggeredData(QString)), this, SLOT(RecentScript(QString)) );
- menuMgr->addMenuItemString(strippedName, "RecentScripts");
- }
- menuMgr->addMenuItemStringstoRememberedMenu("RecentScripts", scrRecentScriptActions);
-}
-
-void ScripterCore::FinishScriptRun()
-{
- ScribusMainWindow* ScMW=ScCore->primaryMainWindow();
- if (ScMW->HaveDoc)
- {
- ScMW->propertiesPalette->setDoc(ScMW->doc);
- ScMW->textPalette->setDoc(ScMW->doc);
- ScMW->marksManager->setDoc(ScMW->doc);
- ScMW->nsEditor->setDoc(ScMW->doc);
- ScMW->layerPalette->setDoc(ScMW->doc);
- ScMW->outlinePalette->setDoc(ScMW->doc);
- ScMW->outlinePalette->BuildTree();
- ScMW->pagePalette->setView(ScMW->view);
- ScMW->pagePalette->Rebuild();
- ScMW->doc->RePos = false;
- if (ScMW->doc->m_Selection->count() != 0)
- ScMW->doc->m_Selection->itemAt(0)->emitAllToGUI();
- ScMW->HaveNewSel();
- ScMW->view->DrawNew();
- //CB Really only need (want?) this for new docs, but we need it after a call to ScMW doFileNew.
- //We don't want it in cmddoc calls as itll interact with the GUI before a script may be finished.
- ScMW->HaveNewDoc();
- }
+ m_recentScriptActions.insert(strippedName, new ScrAction( ScrAction::RecentScript, m_recentScripts[m], QKeySequence(), this, m_recentScripts[m]));
+ connect( m_recentScriptActions[strippedName], SIGNAL(triggeredData(QString)), this, SLOT(RecentScript(QString)) );
+ m_menuMgr->addMenuItemString(strippedName, "RecentScripts");
+ }
+ m_menuMgr->addMenuItemStringstoRememberedMenu("RecentScripts", m_recentScriptActions);
+}
+
+void ScripterCore::finishScriptRun()
+{
+ ScribusMainWindow* mainWin = ScCore->primaryMainWindow();
+ if (!mainWin->HaveDoc)
+ return;
+
+ mainWin->propertiesPalette->setDoc(mainWin->doc);
+ mainWin->textPalette->setDoc(mainWin->doc);
+ mainWin->marksManager->setDoc(mainWin->doc);
+ mainWin->nsEditor->setDoc(mainWin->doc);
+ mainWin->layerPalette->setDoc(mainWin->doc);
+ mainWin->outlinePalette->setDoc(mainWin->doc);
+ mainWin->outlinePalette->BuildTree();
+ mainWin->pagePalette->setView(mainWin->view);
+ mainWin->pagePalette->Rebuild();
+ mainWin->doc->RePos = false;
+ if (mainWin->doc->m_Selection->count() != 0)
+ mainWin->doc->m_Selection->itemAt(0)->emitAllToGUI();
+ mainWin->HaveNewSel();
+ mainWin->view->DrawNew();
+ //CB Really only need (want?) this for new docs, but we need it after a call to ScMW doFileNew.
+ //We don't want it in cmddoc calls as itll interact with the GUI before a script may be finished.
+ mainWin->HaveNewDoc();
}
void ScripterCore::runScriptDialog()
@@ -190,16 +190,16 @@
fileName = dia.selectedFile();
slotRunScriptFile(fileName, dia.extensionRequested());
- if (RecentScripts.indexOf(fileName) == -1)
- RecentScripts.prepend(fileName);
+ if (m_recentScripts.indexOf(fileName) == -1)
+ m_recentScripts.prepend(fileName);
else
{
- RecentScripts.removeAll(fileName);
- RecentScripts.prepend(fileName);
+ m_recentScripts.removeAll(fileName);
+ m_recentScripts.prepend(fileName);
}
rebuildRecentScriptsMenu();
}
- FinishScriptRun();
+ finishScriptRun();
}
void ScripterCore::StdScript(const QString& basefilename)
@@ -212,7 +212,7 @@
if (!fd.exists())
return;
slotRunScriptFile(fn);
- FinishScriptRun();
+ finishScriptRun();
}
void ScripterCore::RecentScript(const QString& fn)
@@ -220,12 +220,12 @@
QFileInfo fd(fn);
if (!fd.exists())
{
- RecentScripts.removeAll(fn);
+ m_recentScripts.removeAll(fn);
rebuildRecentScriptsMenu();
return;
}
slotRunScriptFile(fn);
- FinishScriptRun();
+ finishScriptRun();
}
void ScripterCore::slotRunScriptFile(const QString& fileName, bool inMainInterpreter)
@@ -382,7 +382,7 @@
if (!ScQApp->pythonScript.isNull())
{
slotRunScriptFile(ScQApp->pythonScript, ScQApp->pythonScriptArgs, true);
- FinishScriptRun();
+ finishScriptRun();
}
}
@@ -464,24 +464,24 @@
void ScripterCore::slotInteractiveScript(bool visible)
{
- QObject::disconnect( scrScripterActions["scripterShowConsole"], SIGNAL(toggled(bool)) , this, SLOT(slotInteractiveScript(bool)) );
-
- scrScripterActions["scripterShowConsole"]->setChecked(visible);
- pcon->setFonts();
- pcon->setVisible(visible);
-
- QObject::connect( scrScripterActions["scripterShowConsole"], SIGNAL(toggled(bool)) , this, SLOT(slotInteractiveScript(bool)) );
+ QObject::disconnect( m_scripterActions["scripterShowConsole"], SIGNAL(toggled(bool)) , this, SLOT(slotInteractiveScript(bool)) );
+
+ m_scripterActions["scripterShowConsole"]->setChecked(visible);
+ m_pyConsole->setFonts();
+ m_pyConsole->setVisible(visible);
+
+ QObject::connect( m_scripterActions["scripterShowConsole"], SIGNAL(toggled(bool)) , this, SLOT(slotInteractiveScript(bool)) );
}
void ScripterCore::slotExecute()
{
- slotRunScript(pcon->command());
- pcon->outputEdit->append(returnString);
- pcon->commandEdit->ensureCursorVisible();
- FinishScriptRun();
-}
-
-void ScripterCore::ReadPlugPrefs()
+ slotRunScript(m_pyConsole->command());
+ m_pyConsole->outputEdit->append(returnString);
+ m_pyConsole->commandEdit->ensureCursorVisible();
+ finishScriptRun();
+}
+
+void ScripterCore::readPlugPrefs()
{
PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("scriptplugin");
if (!prefs)
@@ -499,7 +499,7 @@
for (int i = 0; i < prefRecentScripts->getRowCount(); i++)
{
QString rs(prefRecentScripts->get(i,0));
- SavedRecentScripts.append(rs);
+ m_savedRecentScripts.append(rs);
}
// then get more general preferences
m_enableExtPython = prefs->getBool("extensionscripts",false);
@@ -508,7 +508,7 @@
// and have the console window set up its position
}
-void ScripterCore::SavePlugPrefs()
+void ScripterCore::savePlugPrefs()
{
PrefsContext* prefs = PrefsManager::instance()->prefsFile->getPluginContext("scriptplugin");
if (!prefs)
@@ -522,9 +522,9 @@
qDebug("scriptplugin: Unable to get recent scripts");
return;
}
- for (int i = 0; i < RecentScripts.count(); i++)
- {
- prefRecentScripts->set(i, 0, RecentScripts[i]);
+ for (int i = 0; i < m_recentScripts.count(); i++)
+ {
+ prefRecentScripts->set(i, 0, m_recentScripts[i]);
}
// then save more general preferences
prefs->set("extensionscripts", m_enableExtPython);
@@ -585,13 +585,13 @@
void ScripterCore::languageChange()
{
- scrScripterActions["scripterExecuteScript"]->setText(QObject::tr("&Execute Script..."));
- scrScripterActions["scripterShowConsole"]->setText(QObject::tr("Show &Console"));
- scrScripterActions["scripterAboutScript"]->setText(QObject::tr("&About Script..."));
-
- menuMgr->setText("Scripter", QObject::tr("&Script"));
- menuMgr->setText("ScribusScripts", QObject::tr("&Scribus Scripts"));
- menuMgr->setText("RecentScripts", QObject::tr("&Recent Scripts"));
+ m_scripterActions["scripterExecuteScript"]->setText(QObject::tr("&Execute Script..."));
+ m_scripterActions["scripterShowConsole"]->setText(QObject::tr("Show &Console"));
+ m_scripterActions["scripterAboutScript"]->setText(QObject::tr("&About Script..."));
+
+ m_menuMgr->setText("Scripter", QObject::tr("&Script"));
+ m_menuMgr->setText("ScribusScripts", QObject::tr("&Scribus Scripts"));
+ m_menuMgr->setText("RecentScripts", QObject::tr("&Recent Scripts"));
}
bool ScripterCore::setupMainInterpreter()
@@ -632,7 +632,7 @@
void ScripterCore::updateSyntaxHighlighter()
{
- pcon->updateSyntaxHighlighter();
+ m_pyConsole->updateSyntaxHighlighter();
}
const QString & ScripterCore::startupScript() const
Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22883&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptercore.h Mon Mar 11 11:33:54 2019
@@ -65,9 +65,9 @@
protected:
// Private helper functions
- void FinishScriptRun();
- void ReadPlugPrefs();
- void SavePlugPrefs();
+ void finishScriptRun();
+ void readPlugPrefs();
+ void savePlugPrefs();
void rebuildRecentScriptsMenu();
void buildScribusScriptsMenu();
//void buildRecentScriptsMenu();
@@ -75,12 +75,12 @@
//Internal members
//! \brief Reference to the "IDE" widget
- PythonConsole *pcon;
- QStringList SavedRecentScripts;
- QStringList RecentScripts;
- MenuManager *menuMgr;
- QMap<QString, QPointer<ScrAction> > scrScripterActions;
- QMap<QString, QPointer<ScrAction> > scrRecentScriptActions;
+ PythonConsole *m_pyConsole;
+ MenuManager *m_menuMgr;
+ QStringList m_savedRecentScripts;
+ QStringList m_recentScripts;
+ QMap<QString, QPointer<ScrAction> > m_scripterActions;
+ QMap<QString, QPointer<ScrAction> > m_recentScriptActions;
// Preferences
/** \brief pref: Enable access to main interpreter and 'extension scripts' */
More information about the scribus-commit
mailing list