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 "../core/main.hpp"
25 #include "../core/settings/manager.hpp"
27 #include <QHBoxLayout>
33 QString
CmdLineEdit::symbolUnderCursor()
35 // TODO: select word under cursor
36 return selectedText();
39 bool CmdLineEdit::openDocumentation()
41 return Main::openDocumentation(symbolUnderCursor());
44 void CmdLineEdit::openDefinition()
46 return Main::openDefinition(symbolUnderCursor(), MainWindow::instance());
49 void CmdLineEdit::findReferences()
51 return Main::findReferences(symbolUnderCursor(), MainWindow::instance());
55 CmdLine::CmdLine( const QString
&text
, int maxHist
) :
57 maxHistory( qMax(1,maxHist
) )
59 QLabel
*lbl
= new QLabel(text
);
61 expr
= new CmdLineEdit
;
63 QHBoxLayout
*l
= new QHBoxLayout
;
64 l
->setContentsMargins(0,0,0,0);
69 expr
->installEventFilter( this );
72 applySettings( Main::settings() );
75 void CmdLine::applySettings( Settings::Manager
*settings
)
77 QFont codeFont
= settings
->codeFont();
78 expr
->setFont( codeFont
);
81 bool CmdLine::eventFilter( QObject
*, QEvent
*e
)
84 if( type
!= QEvent::KeyPress
) return false;
86 QKeyEvent
*ke
= static_cast<QKeyEvent
*>(e
);
93 if( expr
->text().isEmpty() ) return true;
95 emit
invoked( expr
->text(), false );
96 if( history
.count() == 0 || history
[0] != expr
->text() )
98 if( history
.count() >= maxHistory
) history
.removeAt( history
.count() - 1 );
99 history
.prepend( expr
->text() );
106 if( curHistory
< history
.count() - 1 ) {
107 expr
->blockSignals(true);
108 expr
->setText( history
[++curHistory
] );
109 expr
->blockSignals(false);
114 if( curHistory
> -1 ) {
116 expr
->blockSignals(true);
117 if( curHistory
== -1 ) expr
->clear();
118 else expr
->setText( history
[curHistory
] );
119 expr
->blockSignals(false);
123 default: return false;