menu->addAction( myActions[ClearId] );
menu->addSeparator();
menu->addAction( myActions[SelectAllId] );
+ menu->addSeparator();
+ menu->addAction( myActions[DumpCommandsId] );
Qtx::simplifySeparators( menu );
myActions[PasteId]->setVisible( flags & PasteId );
myActions[ClearId]->setVisible( flags & ClearId );
myActions[SelectAllId]->setVisible( flags & SelectAllId );
+ myActions[DumpCommandsId]->setVisible( flags & DumpCommandsId );
}
/*!
ret = ret | ( myActions[PasteId]->isVisible() ? PasteId : 0 );
ret = ret | ( myActions[ClearId]->isVisible() ? ClearId : 0 );
ret = ret | ( myActions[SelectAllId]->isVisible() ? SelectAllId : 0 );
+ ret = ret | ( myActions[DumpCommandsId]->isVisible() ? DumpCommandsId : 0 );
return ret;
}
a->setStatusTip( tr( "EDIT_SELECTALL_CMD" ) );
connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( selectAll() ) );
myActions.insert( SelectAllId, a );
+
+ a = new QAction( tr( "EDIT_DUMPCOMMANDS_CMD" ), this );
+ a->setStatusTip( tr( "EDIT_DUMPCOMMANDS_CMD" ) );
+ connect( a, SIGNAL( triggered( bool ) ), myEditor, SLOT( dump() ) );
+ myActions.insert( DumpCommandsId, a );
}
/*!
//! Context popup menu actions flags
enum
{
- CopyId = 0x01, //!< "Copy" menu action
- PasteId = 0x02, //!< "Paste" menu action
- ClearId = 0x04, //!< "Clear" menu action
- SelectAllId = 0x08, //!< "Select All" menu action
- All = CopyId | PasteId | ClearId | SelectAllId //!< all menu actions
+ CopyId = 0x01, //!< "Copy" menu action
+ PasteId = 0x02, //!< "Paste" menu action
+ ClearId = 0x04, //!< "Clear" menu action
+ SelectAllId = 0x08, //!< "Select All" menu action
+ DumpCommandsId = 0x16, //!< "DumpCommands" menu action
+ All = CopyId | PasteId | ClearId | SelectAllId | DumpCommandsId //!< all menu actions
};
public:
#include <PyInterp_Dispatcher.h>
#include <SUIT_Tools.h>
+#include <SUIT_FileDlg.h>
+#include <SUIT_MessageBox.h>
+#include <SUIT_FileValidator.h>
#include <QApplication>
#include <QClipboard>
#include <QTextBlock>
#include <QTextCursor>
#include <QTextDocument>
+#include <QTextStream>
static QString READY_PROMPT = ">>> ";
static QString DOTS_PROMPT = "... ";
#define PRINT_EVENT 65432
+
+class DumpCommandsFileValidator : public SUIT_FileValidator
+{
+ public:
+ DumpCommandsFileValidator( QWidget* parent = 0 ) : SUIT_FileValidator ( parent ) {};
+ virtual ~DumpCommandsFileValidator() {};
+ virtual bool canSave( const QString& file, bool permissions );
+};
+
+bool DumpCommandsFileValidator::canSave(const QString& file, bool permissions)
+{
+ QFileInfo fi( file );
+ if ( !QRegExp( "[A-Za-z_][A-Za-z0-9_]*" ).exactMatch( fi.completeBaseName() ) ) {
+ SUIT_MessageBox::critical( parent(),
+ QObject::tr("WRN_WARNING"),
+ QObject::tr("WRN_FILE_NAME_BAD") );
+ return false;
+ }
+ return SUIT_FileValidator::canSave( file, permissions);
+}
+
/*!
\class ExecCommand
\brief Python command execution request.
myPrompt = READY_PROMPT;
addText( myPrompt );
}
+
+/*!
+ \brief "Dump commands" operation.
+ */
+void PyConsole_Editor::dump()
+{
+ QStringList aFilters;
+ aFilters.append( tr( "PYTHON_FILES_FILTER" ) );
+
+ QString fileName = SUIT_FileDlg::getFileName( this, QString(),
+ aFilters, tr( "TOT_DUMP_PYCOMMANDS" ),
+ false, true, new DumpCommandsFileValidator( this ) );
+ if ( fileName != "" ) {
+ QFile file( fileName );
+ if ( !file.open( QFile::WriteOnly ) )
+ return;
+
+ QTextStream out (&file);
+
+ for( int i=0; i<myHistory.count(); i++ ) {
+ out<<myHistory[i]<<endl;
+ }
+ file.close();
+ }
+}
void clear();
void handleReturn();
void onPyInterpChanged( PyConsole_Interp* );
+ void dump();
private:
PyConsole_Interp* myInterp; //!< python interpreter
- QString myCommandBuffer; //!< python comman buffer
+ QString myCommandBuffer; //!< python command buffer
QString myCurrentCommand; //!< currently being printed command
QString myPrompt; //!< current command line prompt
int myCmdInHistory; //!< current history command index
<source>EDIT_SELECTALL_CMD</source>
<translation>Select &All</translation>
</message>
+ <message>
+ <source>EDIT_DUMPCOMMANDS_CMD</source>
+ <translation>D&ump commands</translation>
+ </message>
+</context>
+
+<context>
+ <name>PyConsole_Editor</name>
+ <message>
+ <source>TOT_DUMP_PYCOMMANDS</source>
+ <translation>Dump commands</translation>
+ </message>
+ <message>
+ <source>PYTHON_FILES_FILTER</source>
+ <translation>PYTHON Files (*.py)</translation>
+ </message>
</context>
</TS>