// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com)
//
+#include "PyEditor_Widget.h"
#include "PyEditor_Window.h"
#include "PyEditor_StdSettings.h"
QCommandLineParser parser;
parser.setApplicationDescription( QApplication::translate( "PyEditor", "PROGRAM_DESCRIPTION" ) );
parser.addHelpOption();
+ QCommandLineOption gotoOption( QStringList() << "l" << "line",
+ QApplication::translate( "PyEditor", "Set initial line number." ),
+ "line" );
+ parser.addOption( gotoOption );
parser.addPositionalArgument( QApplication::translate( "PyEditor", "FILE_PARAM_NAME" ),
QApplication::translate( "PyEditor", "FILE_PARAM_DESCRIPTION" ) );
window.resize( 650, 700 );
window.show();
- if ( args.count() > 0 )
+ if ( args.count() > 0 ) {
window.loadFile( args[0], false );
+
+ if ( parser.isSet( gotoOption ) ) {
+ bool ok;
+ int line = parser.value( gotoOption ).toInt( &ok );
+ if ( ok )
+ window.editor()->setCurrentLine( line );
+ }
+ }
return app.exec();
}
#include <QMenu>
#include <QPainter>
#include <QTextBlock>
+#include <QScrollBar>
#include <iostream>
{
return myStdKeywords;
}
+
+/*!
+ \brief Move cursor to the given line.
+ \note Line count starts from 1.
+ \param line Line number.
+*/
+void PyEditor_Editor::setCurrentLine( int line )
+{
+ QTextCursor cursor( document()->findBlockByLineNumber( line - 1 ) );
+ setTextCursor( cursor );
+ ensureCursorVisible();
+}
void setSettings( const PyEditor_Settings& );
const PyEditor_Settings& settings() const;
+
QString text() const;
QStringList keywords() const;
void deleteSelected();
void append( const QString& );
void setText( const QString& text );
+ void setCurrentLine( int );
protected:
virtual void keyPressEvent( QKeyEvent* );
myTabSpaceVisible( true ),
myTabSize( 4 ),
myFont( "Courier", 10 ),
- myCompletionPolicy( PyEditor_Editor::Always )
+ myCompletionPolicy( PyEditor_Editor::None )
{
}
{
return myEditor->settings();
}
+
+/*!
+ \brief Move editor's cursor to the given line.
+ \note Line count starts from 1.
+ \param line Line number.
+*/
+void PyEditor_Widget::setCurrentLine( int line )
+{
+ myEditor->setCurrentLine( line );
+}
void setText( const QString& );
+ void setCurrentLine( int );
+
signals:
void modificationChanged( bool );
void undoAvailable( bool );
return true;
}
+
+/*!
+ Get editor.
+ \return Editor widget.
+*/
+PyEditor_Widget* PyEditor_Window::editor()
+{
+ return myEditor;
+}
+
/*!
Slot, called when user clicks "Help" button in "Preferences" dialog box.
*/
void loadFile( const QString&, bool = true );
bool saveFile( const QString&, bool = true );
+
+ PyEditor_Widget* editor();
protected:
virtual void closeEvent( QCloseEvent* );
void deleteSelected();
void append( const QString& );
void setText( const QString& text );
+ void setCurrentLine( int );
protected:
virtual void keyPressEvent( QKeyEvent* );
void setText( const QString& );
+ void setCurrentLine( int );
+
signals:
void modificationChanged( bool );
void undoAvailable( bool );