3 Copyright (c) 2010-2012 Jakob Leben
4 Copyright (c) 2012 Tim Blechmann
5 http://www.audiosynth.com
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "cmd_line.hpp"
23 #include "main_window.hpp"
24 #include "sc_symbol_references.hpp"
25 #include "../core/main.hpp"
26 #include "../core/settings/manager.hpp"
28 #include <QHBoxLayout>
34 QString
CmdLineEdit::symbolUnderCursor()
36 // TODO: select word under cursor
37 return selectedText();
40 bool CmdLineEdit::openDocumentation()
42 return Main::openDocumentation(symbolUnderCursor());
45 void CmdLineEdit::openDefinition()
47 return Main::openDefinition(symbolUnderCursor(), MainWindow::instance());
50 void CmdLineEdit::lookupReferences()
52 return Main::openReferences(symbolUnderCursor(), MainWindow::instance());
56 CmdLine::CmdLine( const QString
&text
, int maxHist
) :
58 maxHistory( qMax(1,maxHist
) )
60 QLabel
*lbl
= new QLabel(text
);
62 expr
= new CmdLineEdit
;
64 QHBoxLayout
*l
= new QHBoxLayout
;
65 l
->setContentsMargins(0,0,0,0);
70 expr
->installEventFilter( this );
73 applySettings( Main::settings() );
76 void CmdLine::applySettings( Settings::Manager
*settings
)
78 QFont codeFont
= settings
->codeFont();
79 expr
->setFont( codeFont
);
82 bool CmdLine::eventFilter( QObject
*, QEvent
*e
)
85 if( type
!= QEvent::KeyPress
) return false;
87 QKeyEvent
*ke
= static_cast<QKeyEvent
*>(e
);
94 if( expr
->text().isEmpty() ) return true;
96 emit
invoked( expr
->text(), false );
97 if( history
.count() == 0 || history
[0] != expr
->text() )
99 if( history
.count() >= maxHistory
) history
.removeAt( history
.count() - 1 );
100 history
.prepend( expr
->text() );
107 if( curHistory
< history
.count() - 1 ) {
108 expr
->blockSignals(true);
109 expr
->setText( history
[++curHistory
] );
110 expr
->blockSignals(false);
115 if( curHistory
> -1 ) {
117 expr
->blockSignals(true);
118 if( curHistory
== -1 ) expr
->clear();
119 else expr
->setText( history
[curHistory
] );
120 expr
->blockSignals(false);
124 default: return false;