#include "PyViewer_ViewWindow.h"
-#include "PyEditor_Editor.h"
+#include "PyEditor_Widget.h"
#include "PyEditor_SettingsDlg.h"
#include "SUIT_Session.h"
#include "QtxActionToolMgr.h"
#include <QApplication>
+#include <QCloseEvent>
#include <QFileDialog>
#include <QMessageBox>
#include <QTextStream>
+#include <QVBoxLayout>
/*!
\class PyViewer_ViewWindow
PyViewer_ViewWindow::PyViewer_ViewWindow( SUIT_Desktop* desktop ) :
SUIT_ViewWindow( desktop )
{
- // Create editor and set it as a central widget.
- myTextEditor = new PyEditor_Editor( this );
- setCentralWidget( myTextEditor );
+ // Create central widget.
+ myEditor = new PyEditor_Widget( this );
+ setCentralWidget( myEditor );
// Create actions.
SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
action->setShortcut( QKeySequence::Save );
connect( action, SIGNAL( triggered( bool ) ), this, SLOT( onSave() ) );
action->setEnabled( false );
- connect( myTextEditor->document(), SIGNAL( modificationChanged( bool ) ),
+ connect( myEditor, SIGNAL( modificationChanged( bool ) ),
action, SLOT( setEnabled( bool ) ) );
toolMgr()->registerAction( action, SaveId );
tr( "ACT_UNDO" ), 0, this );
action->setStatusTip( tr( "DSC_UNDO" ) );
action->setShortcut( QKeySequence::Undo );
- connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( undo() ) );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( undo() ) );
action->setEnabled( false );
- connect( myTextEditor->document(), SIGNAL( undoAvailable( bool ) ),
+ connect( myEditor, SIGNAL( undoAvailable( bool ) ),
action, SLOT( setEnabled( bool ) ) );
toolMgr()->registerAction( action, UndoId );
tr( "ACT_REDO" ), 0, this );
action->setStatusTip( tr( "DSC_REDO" ) );
action->setShortcut( QKeySequence::Redo );
- connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( redo() ) );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( redo() ) );
action->setEnabled( false );
- connect( myTextEditor->document(), SIGNAL( redoAvailable( bool ) ),
+ connect( myEditor, SIGNAL( redoAvailable( bool ) ),
action, SLOT( setEnabled( bool ) ) );
toolMgr()->registerAction( action, RedoId );
tr( "ACT_CUT" ), 0, this );
action->setStatusTip( tr( "DSC_CUT" ) );
action->setShortcut( QKeySequence::Cut );
- connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( cut() ) );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( cut() ) );
action->setEnabled( false );
- connect( myTextEditor, SIGNAL( copyAvailable( bool ) ),
+ connect( myEditor, SIGNAL( copyAvailable( bool ) ),
action, SLOT( setEnabled( bool ) ) );
toolMgr()->registerAction( action, CutId );
tr( "ACT_COPY" ), 0, this );
action->setStatusTip( tr( "DSC_COPY" ) );
action->setShortcut( QKeySequence::Copy );
- connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( copy() ) );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( copy() ) );
action->setEnabled( false );
- connect( myTextEditor, SIGNAL( copyAvailable( bool ) ),
+ connect( myEditor, SIGNAL( copyAvailable( bool ) ),
action, SLOT( setEnabled( bool ) ) );
toolMgr()->registerAction( action, CopyId );
tr( "ACT_PASTE" ), 0, this );
action->setStatusTip( tr( "DSC_PASTE" ) );
action->setShortcut( QKeySequence::Paste );
- connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( paste() ) );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( paste() ) );
toolMgr()->registerAction( action, PasteId );
// . Delete
tr( "ACT_DELETE" ), 0, this );
action->setStatusTip( tr( "DSC_DELETE" ) );
action->setShortcut( QKeySequence::Delete );
- connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( deleteSelected() ) );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( deleteSelected() ) );
action->setEnabled( false );
- connect( myTextEditor, SIGNAL( copyAvailable( bool ) ),
+ connect( myEditor, SIGNAL( copyAvailable( bool ) ),
action, SLOT( setEnabled( bool ) ) );
toolMgr()->registerAction( action, DeleteId );
tr( "ACT_SELECT_ALL" ), 0, this );
action->setStatusTip( tr( "DSC_SELECT_ALL" ) );
action->setShortcut( QKeySequence::SelectAll );
- connect( action, SIGNAL( triggered( bool ) ), myTextEditor, SLOT( selectAll() ) );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( selectAll() ) );
toolMgr()->registerAction( action, SelectAllId );
+ // . Find
+ action = new QtxAction( tr( "TTP_FIND" ),
+ resMgr->loadPixmap( "PyViewer", tr( "ICON_FIND" ) ),
+ tr( "ACT_FIND" ), 0, this );
+ action->setStatusTip( tr( "DSC_FIND" ) );
+ action->setShortcut( QKeySequence::Find );
+ action->setShortcutContext( Qt::WidgetShortcut );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( find() ) );
+ toolMgr()->registerAction( action, FindId );
+
+ // . Replace
+ action = new QtxAction( tr( "TTP_REPLACE" ),
+ resMgr->loadPixmap( "PyViewer", tr( "ICON_REPLACE" ) ),
+ tr( "ACT_REPLACE" ), 0, this );
+ action->setStatusTip( tr( "DSC_REPLACE" ) );
+ action->setShortcuts( QList<QKeySequence>() << QKeySequence( "Ctrl+H" ) << QKeySequence( QKeySequence::Replace ) );
+ action->setShortcutContext( Qt::WidgetShortcut );
+ connect( action, SIGNAL( triggered( bool ) ), myEditor, SLOT( replace() ) );
+ toolMgr()->registerAction( action, ReplaceId );
+
// . Preferences
action = new QtxAction( tr( "TTP_PREFERENCES" ),
resMgr->loadPixmap( "PyViewer", tr( "ICON_PREFERENCES" ) ),
toolMgr()->append( DeleteId, idTB );
toolMgr()->append( SelectAllId, idTB );
toolMgr()->append( toolMgr()->separator(), idTB );
+ toolMgr()->append( FindId, idTB );
+ toolMgr()->append( ReplaceId, idTB );
+ toolMgr()->append( toolMgr()->separator(), idTB );
toolMgr()->append( PreferencesId, idTB );
toolMgr()->append( toolMgr()->separator(), idTB );
toolMgr()->append( HelpId, idTB );
{
if ( whetherSave() )
{
- myTextEditor->clear();
+ myEditor->clear();
setCurrentFile( QString() );
}
}
*/
void PyViewer_ViewWindow::onPreferences()
{
- PyEditor_SettingsDlg dlg( myTextEditor, true, this );
+ PyEditor_SettingsDlg dlg( myEditor->editor(), true, this );
connect( &dlg, SIGNAL( help() ), this, SLOT( onHelp() ) );
dlg.exec();
}
void PyViewer_ViewWindow::setCurrentFile( const QString& filePath )
{
myURL = filePath;
- myTextEditor->document()->setModified( false );
+ myEditor->setModified( false );
}
/*!
*/
bool PyViewer_ViewWindow::whetherSave()
{
- if ( myTextEditor->document()->isModified() )
+ if ( myEditor->isModified() )
{
QMessageBox::StandardButton answer = QMessageBox::warning( this,
tr( "NAME_PYEDITOR" ),
QTextStream anInput( &aFile );
QApplication::setOverrideCursor( Qt::WaitCursor );
- myTextEditor->setPlainText( anInput.readAll() );
+ myEditor->setText( anInput.readAll() );
QApplication::restoreOverrideCursor();
setCurrentFile( filePath );
QTextStream anOutput( &aFile );
QApplication::setOverrideCursor( Qt::WaitCursor );
- anOutput << myTextEditor->toPlainText();
+ anOutput << myEditor->text();
QApplication::restoreOverrideCursor();
setCurrentFile( filePath );
{
SUIT_Application* app = SUIT_Session::session()->activeApplication();
if ( app ) {
- QString page = "python_viewer_page.html";
+ QString page = "python_viewer.html";
if ( qobject_cast<QWidget*>( sender() ) )
- page += "#custom_python_preferences";
+ page += "#custom-python-preferences";
app->onHelpContextModule( "GUI", page );
}
}