Commit 942ecb74 authored by Robert Knight's avatar Robert Knight

Make new sessions start in the same directory as the previously active...

Make new sessions start in the same directory as the previously active session.  Does not apply when creating a new tab from a specific profile.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=670566
parent 3f1f8cac
......@@ -78,10 +78,10 @@ MainWindow* Application::newMainWindow()
MainWindow* window = new MainWindow();
window->setSessionList( new ProfileList(true,window) );
connect( window , SIGNAL(newSessionRequest(const QString&,ViewManager*)),
this , SLOT(createSession(const QString&,ViewManager*)));
connect( window , SIGNAL(newWindowRequest(const QString&)),
this , SLOT(createWindow(const QString&)) );
connect( window , SIGNAL(newSessionRequest(const QString&,const QString&,ViewManager*)),
this , SLOT(createSession(const QString&,const QString&,ViewManager*)));
connect( window , SIGNAL(newWindowRequest(const QString&,const QString&)),
this , SLOT(createWindow(const QString&,const QString&)) );
connect( window->viewManager() , SIGNAL(viewDetached(Session*)) , this , SLOT(detachView(Session*)) );
return window;
......@@ -118,7 +118,7 @@ int Application::newInstance()
window->setDefaultProfile(key);
}
createSession( window->defaultProfile() , window->viewManager() );
createSession( window->defaultProfile() , QString() , window->viewManager() );
// if the background-mode argument is supplied, start the background session
// ( or bring to the front if it already exists )
......@@ -184,18 +184,21 @@ void Application::detachView(Session* session)
window->show();
}
void Application::createWindow(const QString& key)
void Application::createWindow(const QString& key , const QString& directory)
{
MainWindow* window = newMainWindow();
window->setDefaultProfile(key);
createSession(key,window->viewManager());
createSession(key,directory,window->viewManager());
window->show();
}
void Application::createSession(const QString& key , ViewManager* view)
void Application::createSession(const QString& key , const QString& directory , ViewManager* view)
{
Session* session = SessionManager::instance()->createSession(key);
if (!directory.isEmpty())
session->setInitialWorkingDirectory(directory);
// create view before starting the session process so that the session doesn't suffer
// a change in terminal size right after the session starts. some applications such as GNU Screen
// and Midnight Commander don't like this happening
......
......@@ -69,8 +69,8 @@ public:
static Application* self();
private slots:
void createSession(const QString& key, ViewManager* view);
void createWindow(const QString& key);
void createSession(const QString& key, const QString& directory , ViewManager* view);
void createWindow(const QString& key , const QString& directory);
void detachView(Session* session);
void toggleBackgroundInstance();
......
......@@ -239,14 +239,22 @@ void MainWindow::sessionListChanged(const QList<QAction*>& actions)
plugActionList("favorite-profiles",actions);
}
QString MainWindow::activeSessionDir() const
{
if ( _pluggedController )
return _pluggedController->currentDir();
else
return QString();
}
void MainWindow::newTab()
{
emit newSessionRequest( _defaultProfile , _viewManager);
emit newSessionRequest( _defaultProfile , activeSessionDir() , _viewManager);
}
void MainWindow::newWindow()
{
emit newWindowRequest( _defaultProfile );
emit newWindowRequest( _defaultProfile , activeSessionDir() );
}
void MainWindow::showShortcutsDialog()
......@@ -257,7 +265,7 @@ void MainWindow::showShortcutsDialog()
void MainWindow::newFromProfile(const QString& key)
{
emit newSessionRequest(key,_viewManager);
emit newSessionRequest(key,QString(),_viewManager);
}
void MainWindow::showManageProfilesDialog()
{
......@@ -269,7 +277,7 @@ void MainWindow::showRemoteConnectionDialog()
{
RemoteConnectionDialog dialog(this);
if ( dialog.exec() == QDialog::Accepted )
emit newSessionRequest(dialog.sessionKey(),_viewManager);
emit newSessionRequest(dialog.sessionKey(),QString(),_viewManager);
}
void MainWindow::setupWidgets()
......
......@@ -100,9 +100,13 @@ class MainWindow : public KXmlGuiWindow
* Emitted by the main window to request the creation of a new session.
*
* @param key The key for the profile to use to create the new session.
* @param directory Initial working directory for the new session or empty
* if the default working directory associated with the profile should be used.
* @param view The view manager owned by this main window
*/
void newSessionRequest(const QString& key , ViewManager* view);
void newSessionRequest(const QString& key ,
const QString& directory,
ViewManager* view);
/**
* Emitted by the main window to request the creation of a
......@@ -110,8 +114,12 @@ class MainWindow : public KXmlGuiWindow
*
* @param key The key for the profile to use to create the
* first session in the new window.
* @param directory Initial working directory for the new window or empty
* if the default working directory associated with the profile should
* be used.
*/
void newWindowRequest(const QString& key);
void newWindowRequest(const QString& key,
const QString& directory);
private slots:
void newTab();
......@@ -129,6 +137,7 @@ class MainWindow : public KXmlGuiWindow
private:
void setupActions();
void setupWidgets();
QString activeSessionDir() const;
private:
ViewManager* _viewManager;
......
......@@ -192,6 +192,20 @@ void SessionController::snapshot()
_session->setTitle(Session::DisplayedTitleRole,_session->title(Session::NameRole));
}
QString SessionController::currentDir() const
{
ProcessInfo* info = ProcessInfo::newInstance(_session->processId());
info->update();
bool ok = false;
QString path = info->currentDir(&ok);
if ( ok )
return path;
else
return QString();
}
KUrl SessionController::url() const
{
ProcessInfo* info = ProcessInfo::newInstance(_session->processId());
......
......@@ -111,6 +111,7 @@ public:
// reimplemented
virtual KUrl url() const;
virtual QString currentDir() const;
// Reimplemented to watch for events happening to the view
virtual bool eventFilter(QObject* watched , QEvent* event);
......
......@@ -33,7 +33,10 @@ KUrl ViewProperties::url() const
{
return KUrl();
}
QString ViewProperties::currentDir() const
{
return QString();
}
void ViewProperties::fireActivity()
{
emit activity(this);
......
......@@ -55,6 +55,14 @@ public:
*/
virtual KUrl url() const;
/**
* Returns the current directory associated with a view.
* This may be the same as url()
*
* The default implementation returns an empty string.
*/
virtual QString currentDir() const;
/**
* A unique identifier representing the data displayed by the view associated with this
* ViewProperties instance.
......
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