Commit 163335bb authored by Robert Knight's avatar Robert Knight

Make 'Search History' menu item into a toggle which hides or shows the search...

Make 'Search History' menu item into a toggle which hides or shows the search bar when toggled.  Search bar doesn't actually do anything yet.

svn path=/branches/work/konsole-split-view/; revision=637905
parent 57e03c56
......@@ -23,6 +23,7 @@
#include <QLabel>
#include <QLineEdit>
#include <QProgressBar>
#include <QShowEvent>
#include <QToolButton>
// KDE
......@@ -41,7 +42,7 @@ IncrementalSearchBar::IncrementalSearchBar(Features features , QWidget* parent)
, _searchEdit(0)
, _continueLabel(0)
{
QHBoxLayout* layout = new QHBoxLayout(parent);
QHBoxLayout* layout = new QHBoxLayout(this);
QToolButton* close = new QToolButton(this);
close->setAutoRaise(true);
......@@ -142,6 +143,12 @@ bool IncrementalSearchBar::matchRegExp()
return _matchRegExp;
}
void IncrementalSearchBar::showEvent(QShowEvent* event)
{
//TODO - Check if this is the correct reason value to use here
_searchEdit->setFocus( Qt::ActiveWindowFocusReason );
}
void IncrementalSearchBar::setFoundMatch( bool match )
{
//FIXME - Hard coded colour used here - is there a better alternative?
......
......@@ -23,6 +23,7 @@
// Qt
#include <QWidget>
class QLabel;
class QLineEdit;
class QProgressBar;
......@@ -147,6 +148,9 @@ signals:
/** Emitted when the close button is clicked */
void closeClicked();
protected:
virtual void showEvent( QShowEvent* event );
private:
bool _foundMatch;
bool _matchCase;
......
......@@ -17,6 +17,9 @@
02110-1301 USA.
*/
// Qt
#include <QVBoxLayout>
// KDE
#include <KAction>
#include <KActionCollection>
......@@ -30,6 +33,7 @@
#include <KXMLGUIFactory>
// Konsole
#include "IncrementalSearchBar.h"
#include "KonsoleApp.h"
#include "KonsoleBookmarkHandler.h"
#include "KonsoleMainWindow.h"
......@@ -45,10 +49,8 @@ KonsoleMainWindow::KonsoleMainWindow()
// to prevent the menu bar and main widget borders touching (which looks very ugly) in styles
// where the menu bar has a lower border
setContentsMargins(0,2,0,0);
// create main window widgets
setupWidgets();
// create actions for menus
setupActions();
......@@ -57,15 +59,24 @@ KonsoleMainWindow::KonsoleMainWindow()
_viewManager = new ViewManager(this);
connect( _viewManager , SIGNAL(empty()) , this , SLOT(close()) );
// create main window widgets
setupWidgets();
// create menus
createGUI();
}
ViewManager* KonsoleMainWindow::viewManager()
ViewManager* KonsoleMainWindow::viewManager() const
{
return _viewManager;
}
IncrementalSearchBar* KonsoleMainWindow::searchBar() const
{
return _searchBar;
}
void KonsoleMainWindow::setupActions()
{
KActionCollection* collection = actionCollection();
......@@ -155,8 +166,20 @@ void KonsoleMainWindow::mergeWindows()
void KonsoleMainWindow::setupWidgets()
{
QWidget* widget = new QWidget(this);
QVBoxLayout* layout = new QVBoxLayout();
_searchBar = new IncrementalSearchBar( IncrementalSearchBar::AllFeatures , this);
_searchBar->setVisible(false);
layout->addWidget( _viewManager->widget() );
layout->addWidget( _searchBar );
layout->setMargin(0);
layout->setSpacing(0);
widget->setLayout(layout);
setCentralWidget(widget);
}
#include "KonsoleMainWindow.moc"
......@@ -22,6 +22,7 @@
#include <KMainWindow>
class IncrementalSearchBar;
class ViewSplitter;
class ViewManager;
class SessionList;
......@@ -52,7 +53,13 @@ class KonsoleMainWindow : public KMainWindow
* Returns the view manager associated with this window. The view manager can be used to
* create new views on particular session objects inside this window.
*/
ViewManager* viewManager();
ViewManager* viewManager() const;
/**
* Returns the search bar.
* TODO - More documentation
*/
IncrementalSearchBar* searchBar() const;
/** Sets the list of sessions to be displayed in the File menu */
void setSessionList(SessionList* list);
......@@ -93,6 +100,7 @@ class KonsoleMainWindow : public KMainWindow
private:
ViewManager* _viewManager;
KonsoleBookmarkHandler* _bookmarkHandler;
IncrementalSearchBar* _searchBar;
};
#endif // KONSOLEMAINWINDOW_H
......@@ -11,6 +11,7 @@
// Konsole
#include "Filter.h"
#include "IncrementalSearchBar.h"
#include "TESession.h"
#include "TEWidget.h"
#include "SessionController.h"
......@@ -37,6 +38,8 @@ SessionController::SessionController(TESession* session , TEWidget* view, QObjec
, _session(session)
, _view(view)
, _previousState(-1)
, _viewUrlFilter(0)
, _historyToggleAction(0)
{
// handle user interface related to session (menus etc.)
setXMLFile("sessionui.rc");
......@@ -101,6 +104,22 @@ bool SessionController::eventFilter(QObject* watched , QEvent* event)
return false;
}
void SessionController::setSearchBar(IncrementalSearchBar* searchBar)
{
if ( _searchBar )
{
disconnect( this , 0 , _searchBar , 0 );
}
_searchBar = searchBar;
connect( _searchBar , SIGNAL(closeClicked()) , this , SLOT(searchClosed()) );
}
IncrementalSearchBar* SessionController::searchBar() const
{
return _searchBar;
}
void SessionController::setupActions()
{
QAction* action = 0;
......@@ -143,10 +162,9 @@ void SessionController::setupActions()
connect( action , SIGNAL(toggled(bool)) , this , SLOT(monitorSilence(bool)) );
// History
action = collection->addAction("search-history");
action->setIcon( KIcon("find") );
action->setText( i18n("Search History") );
connect( action , SIGNAL(triggered()) , this , SLOT(searchHistory()) );
_historyToggleAction = new KToggleAction(i18n("Search History"),this);
action = collection->addAction("search-history" , _historyToggleAction);
connect( action , SIGNAL(toggled(bool)) , this , SLOT(searchHistory(bool)) );
action = collection->addAction("find-next");
action->setIcon( KIcon("next") );
......@@ -240,8 +258,17 @@ void SessionController::clearAndReset()
emulation->reset();
emulation->clearSelection();
}
void SessionController::searchHistory()
void SessionController::searchClosed()
{
_historyToggleAction->setChecked(false);
_view->setFocus( Qt::ActiveWindowFocusReason );
}
void SessionController::searchHistory(bool showSearchBar)
{
if ( _searchBar )
{
_searchBar->setVisible(showSearchBar);
}
}
void SessionController::findNextInHistory()
{
......
......@@ -16,9 +16,11 @@
#include "ViewProperties.h"
class QAction;
class KToggleAction;
class KUrl;
class TESession;
class TEWidget;
class IncrementalSearchBar;
class UrlFilter;
// SaveHistoryTask
......@@ -62,6 +64,16 @@ public:
/** Returns the view associated with this controller */
TEWidget* view() { return _view; }
/**
* Sets the widget used for searches through the session's history.
* The widget will be shown when the user clicks on the "Search History" menu action.
*/
void setSearchBar( IncrementalSearchBar* searchBar );
/**
* see setSearchBar()
*/
IncrementalSearchBar* searchBar() const;
// reimplemented
virtual KUrl url() const;
......@@ -90,7 +102,8 @@ private slots:
void paste();
void clear();
void clearAndReset();
void searchHistory();
void searchHistory(bool showSearchBar);
void searchClosed();
void findNextInHistory();
void findPreviousInHistory();
void saveHistory();
......@@ -113,12 +126,15 @@ private:
KIcon _sessionIcon;
QString _sessionIconName;
int _previousState;
UrlFilter* _viewUrlFilter;
KToggleAction* _historyToggleAction;
static KIcon _activityIcon;
static KIcon _silenceIcon;
QPointer<IncrementalSearchBar> _searchBar;
};
/**
......@@ -285,6 +301,7 @@ private:
int _lastLineFetched;
TerminalCharacterDecoder* _decoder;
QRegExp _regExp;
};
#endif //SESSIONCONTROLLER_H
......@@ -49,8 +49,6 @@ ViewManager::ViewManager(KonsoleMainWindow* mainWindow)
// create main view area
_viewSplitter = new ViewSplitter(_mainWindow);
_mainWindow->setCentralWidget(_viewSplitter);
// emit a signal when all of the views held by this view manager are destroyed
connect( _viewSplitter , SIGNAL(allContainersEmpty()) , this , SIGNAL(empty()) );
......@@ -61,6 +59,11 @@ ViewManager::~ViewManager()
{
}
QWidget* ViewManager::widget() const
{
return _viewSplitter;
}
void ViewManager::setupActions()
{
KActionCollection* collection = _mainWindow->actionCollection();
......@@ -197,11 +200,15 @@ void ViewManager::viewFocused( SessionController* controller )
connect( _mainWindow->bookmarkHandler() , SIGNAL(openUrl(const KUrl&)) , controller ,
SLOT(openUrl(const KUrl&)) );
// associated main window's search bar with session
controller->setSearchBar( _mainWindow->searchBar() );
// update the caption of the main window to match that of the focused session
connect( controller , SIGNAL(titleChanged(ViewProperties*)),
this , SLOT(activeViewTitleChanged(ViewProperties*)) );
//kDebug() << "Plugged actions for " << controller->session()->displayTitle() << endl;
}
}
......
......@@ -80,6 +80,8 @@ public:
*/
void merge(ViewManager* manager);
QWidget* widget() const;
signals:
/** Emitted when the last view is removed from the view manager */
void empty();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment