Bug 156732 - Would like to sync Dolphin's view with terminal location
Summary: Would like to sync Dolphin's view with terminal location
Status: RESOLVED FIXED
Alias: None
Product: dolphin
Classification: Applications
Component: panels: terminal (show other bugs)
Version: 16.12.2
Platform: Ubuntu Linux
: NOR wishlist
Target Milestone: ---
Assignee: Peter Penz
URL:
Keywords:
: 167211 190940 221341 273674 294839 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-01-26 18:45 UTC by David Benjamin
Modified: 2012-06-17 07:12 UTC (History)
9 users (show)

See Also:
Latest Commit:
Version Fixed In: 4.9.0


Attachments
A (sort of hacky) patch (2.88 KB, patch)
2008-01-26 19:02 UTC, David Benjamin
Details
Patch (still work in progress) (3.29 KB, patch)
2012-04-12 21:26 UTC, Frank Reininghaus
Details
Updated patch (8.60 KB, patch)
2012-04-14 20:17 UTC, Frank Reininghaus
Details

Note You need to log in before you can comment on or make changes to this bug.
Description David Benjamin 2008-01-26 18:45:38 UTC
Version:           1.0 (using KDE 4.0.0)
Installed from:    Ubuntu Packages
OS:                Linux

Currently, when Dolphin has a terminal open, it synchronizes the terminal's location with Dolphin's. It would be nice to do it the other way around as well.

Use case:
David is using zsh. He is browsing /usr/share/icons/FOO/scalable/categories. zsh has an awesome feature to type cd FOO BAR and replace FOO with BAR, with tab-completion on BAR. David wants to use this to browse those folders while using Dolphin to be able to preview things, etc.

Patch (sort of) attached below. (or will be, anyway ...is there any reason why Bugzilla doesn't let you attach on the first post?)
Comment 1 David Benjamin 2008-01-26 19:02:40 UTC
Created attachment 23298 [details]
A (sort of hacky) patch

A patch to do it. Sort of. :-) I don't know how to make cmake install stuff or
how to do paths cleanly, etc.

Also, is there a way to make TerminalInterface (or whatever) set an environment
variable? It might be better to make a folder with dolphin shell utils and add
that to $PATH, and then stuff in the mainwindow id into another environment
variable. Although, I'm not sure if their inheritability could cause oddness.

Incidentally, why does the Konsole KPart's implementation of
TerminalInterface::showShellInDir not follow the documentation... it doesn't
send "cd ..." if the shell is already running.
Comment 2 Robert Knight 2008-01-29 15:55:09 UTC
Depends on Bug #156919
Comment 3 Frank Reininghaus 2009-04-02 22:47:07 UTC
*** Bug 167211 has been marked as a duplicate of this bug. ***
Comment 4 Frank Reininghaus 2009-04-28 20:37:05 UTC
*** Bug 190940 has been marked as a duplicate of this bug. ***
Comment 5 Frank Reininghaus 2010-01-07 16:24:43 UTC
*** Bug 221341 has been marked as a duplicate of this bug. ***
Comment 6 Frank Reininghaus 2010-01-07 16:25:59 UTC
The reporter of bug 221341 suggested to watch /proc/$PID/cwd, where $PID is the process ID of the shell that belongs to the terminal panel.
Comment 7 Sebastian Dörner 2011-05-19 23:05:17 UTC
*** Bug 273674 has been marked as a duplicate of this bug. ***
Comment 8 Jekyll Wu 2012-02-26 05:38:27 UTC
*** Bug 294839 has been marked as a duplicate of this bug. ***
Comment 9 Jekyll Wu 2012-04-11 01:36:30 UTC
Now that bug 156919 has been implemented, it should be possible for dolphin to implement the synchronization in the other direction. Just listen to the currentDirectoryChanged(const QString& dir) signal emitted from konsolepart.
Comment 10 Peter Penz 2012-04-11 09:19:32 UTC
Thanks Jekyll for the update, I'll try to use the new API (hopefully I can do it until 4.9)
Comment 11 Frank Reininghaus 2012-04-12 21:26:05 UTC
Created attachment 70353 [details]
Patch (still work in progress)

@Jekyll: nice work :-)

This patch is a first step toward making use of the new konsole API. Some remarks about it:

1. I think it's necessary to keep track of the current directory of the konsole part to prevent sending an unneeded "cd" to the terminal after a currentDirectoryChanged(QString) signal is received and the URL is changed -> added a new member m_konsolePartCurrentDirectory.

2. When the terminal's current directory changes and the view's URL is updated accordingly, the terminal loses focus at the moment. I think that this is very distracting -> needs more work.

3. Sometimes, there is a noticeable delay between the "cd" command which is entered in the terminal and the update of the view's URL. I have the feeling that this delay originates inside the terminal, i.e., that the currentDirectoryChanged(QString) signal is not emitted right after the "cd" command has been entered, but a little while later.
Comment 12 Peter Penz 2012-04-12 22:49:32 UTC
Thanks Frank! Regarding point 2 (focus): I'd say don't lets touch the focus-handling in the class DolphinView - grabbing the focus when changing a directory is usually the preferred behavior and a good default. Probably introducing a kind of slot DolphinMainWindow::slotTerminalDirectoryChange() (naming?) might make sense: Here we can call changeUrl() and return the focus to the terminal-panel afterwards. This is just a suggestion, probably you have a better idea.
Comment 13 Jonas 2012-04-13 09:24:02 UTC
Great to hear that this is going to be implemented.

With respect to the question about focus: like Frank, I would prefer that the focus stays in the terminal if I change the directory via 'cd' in the terminal. This would allow to use dolphin as a kind of terminal replacement with the folder view as graphical upgrade.
Comment 14 Jekyll Wu 2012-04-13 23:39:47 UTC
@Frank:

Thanks for your work!

The delay is mentioned in the konsolepart commit[1]. That is also true for standalone Konsole .  Currently Konsole gets process information through polling /proc periodically and when needed (after keyboard event). For the concern of efficiency and load, the polling does not start immediately after each keystroke. A hardcoded 1000ms oneshot timer is used to start the polling later. If the user feedback suggests that delay is a show stopper for this new dolphin feature, I think it should be OK to decrase that 1000ms to a smaller value. But it is unlikely to be immediate.

As for the focus problem, I think that depends upon how (most) users take advantage of this new synchronization. 

   * some users think using "cd /some/path/" in the shell is the more efficient way than using mouse to enter into the needed folder, and they want to use dolphin to operate files after entering into that folder. So changing focus should make sense for them.  For them, they are using "dolphin + shell"

   * some users realize they can now use dolphin as an previewer or helper for their favorite ncurses filemanagers, like mc, vifm, and ranger. Most of time they want to do their work in the ncurses filemanagers running in the terminal panel. So chaning focus would totally defeat that possiblily. For them, they are using "mc/ranger + dolphin"

[1] http://commits.kde.org/konsole/675dbcb2fe777b22044510579321148989d29cfb
Comment 15 Frank Reininghaus 2012-04-14 07:09:05 UTC
(In reply to comment #14)
> The delay is mentioned in the konsolepart commit[1]. 

I must have missed that in the commit message. Thanks for the detailed explanation! Just a quick idea: maybe one could reduce the 1000ms if the key pressed is "Enter"?

> As for the focus problem, I think that depends upon how (most) users take
> advantage of this new synchronization. 

It's also important to consider how any changes can break existing use patterns. I sometimes use the Terminal Panel to run some quick commands in the current folder, then realise I have to do something else in a subfolder, so I enter "cd subfolder" and run some more commands. In this situation, it would be unwanted to change focus.

I understand that changing focus may make sense in some use cases, but it would be a behaviour change that is likely to frustrate users who got used to the terminal *not* losing focus after a "cd" command. I'm pretty sure that I'm not the only one ;-)
Comment 16 Frank Reininghaus 2012-04-14 09:27:06 UTC
(In reply to comment #12)
> Thanks Frank! Regarding point 2 (focus): I'd say don't lets touch the
> focus-handling in the class DolphinView - grabbing the focus when changing a
> directory is usually the preferred behavior and a good default. Probably
> introducing a kind of slot DolphinMainWindow::slotTerminalDirectoryChange()
> (naming?) might make sense: Here we can call changeUrl() and return the
> focus to the terminal-panel afterwards.

I tried that:

void DolphinMainWindow::slotTerminalDirectoryChanged(const KUrl& url)
{
    QWidget* focusWidget = QApplication::focusWidget();
    changeUrl(url);
    if (focusWidget) {
        focusWidget->setFocus();
    }
}

This does not work because DolphinViewContainer requests the focus asynchronously when the URL navigator's url changes, see DolphinViewContainer::slotUrlNavigatorLocationChanged(const KUrl& url).

The cleanest solution I can see at the moment is to add a function like DolphinViewContainer::doNotRequestFocusAfterNextUrlChange(), which could be called by DolphinMainWindow::slotTerminalDirectoryChanged(). An alternative could be that DolphinViewContainer tries to find out which widget has the focus and does not change focus if a parent of that widget is a TerminalPanel (using parent->metaObject()->className()), but this seems a bit more hackish to me.
Comment 17 Peter Penz 2012-04-14 10:14:23 UTC
> The cleanest solution I can see at the moment is to add a function like 
> DolphinViewContainer::doNotRequestFocusAfterNextUrlChange(), which
> could be called by DolphinMainWindow::slotTerminalDirectoryChanged().
> An alternative could be that DolphinViewContainer tries to find out which
> widget has the focus and does not change focus if a parent of that widget is a
> TerminalPanel (using parent->metaObject()->className()), but this seems
> a bit more hackish to me.

Hm... As you say checking the class-name inside DolphinViewContainer is a hack, let us ignore this ;-) In opposite to having a temporary state change due to an interface like DolphinViewContainer::doNotRequestFocusAfterNextUrlChange(), what do you think about adding something explicit like:
  /**
   * If \a grab is set to true, the container automatically grabs the focus
   * as soon as the URL has been changed. Per default the grabbing
   * of the focus is enabled.
   */
  void DolphinViewContainer:: setAutoGrabFocus(bool grab);
  bool DolphinViewContainer::autoGrabFocus() const;

DolphinMainWindow (which is aware about the terminal-panel + container) takes care to disable the autograbbing in case if the Terminal has the focus. Personally I'd prefer this interface in comparison to such internal state-changes like doNotRequestFocusAfterNextUrlChange(), which depends on triggering another action to get back the old behavior.

BTW: Generally I agree that we should not change the focus. We did not change the focus when synchronizing the terminal with the view and I think we should not change the focus too when synchronizing the view with the terminal. Of course as Jekyll said there might be usecases where such an automatic focus-change might be fine, but my gut feeling believes that these are corner-cases...
Comment 18 Jekyll Wu 2012-04-14 13:55:22 UTC
I myself prefer not changing focus, because I'm really interested with using "ranger + dolphin" . That is what is in my mind when I decide to add that konsolepart signal :)

My point is this new synchronization itself introduces behavior change, and some users might feel uncomfortable with it.

There is another minor problem with the current patch:  after hiding the terminal panel with F4, dolphin automatically sends "cd /"  into the shell, which makes terminal panel emit that directory changing signal later,  and finally dolphin shows the "/" folder. I guess that "cd /" is to make sure the shell does not stands in the way of unplugging removable media.  I would suggest disconnecting that signal after terminal panel is hidden and connecting it when the terminal panel is shown again later.
Comment 19 Frank Reininghaus 2012-04-14 16:52:18 UTC
(In reply to comment #18)
> My point is this new synchronization itself introduces behavior change, and
> some users might feel uncomfortable with it.

You're right of course, any behaviour change may turn out to be unwanted for some users. But I can't see any way to prevent this here. IMHO, the benefit of syncing the view's URL with the terminal is much larger than the risk of a large number of users not liking it. And those users still have the possibility to work in an external Konsole by pressing Shift+F4.

> There is another minor problem with the current patch:  after hiding the
> terminal panel with F4, dolphin automatically sends "cd /"  into the shell,
> which makes terminal panel emit that directory changing signal later,  and
> finally dolphin shows the "/" folder. I guess that "cd /" is to make sure
> the shell does not stands in the way of unplugging removable media.  I would
> suggest disconnecting that signal after terminal panel is hidden and
> connecting it when the terminal panel is shown again later.

Thanks, I had already noticed that when playing around with it. I'll work on that.
Comment 20 Frank Reininghaus 2012-04-14 20:17:41 UTC
Created attachment 70382 [details]
Updated patch

(In reply to comment #17)
> Hm... As you say checking the class-name inside DolphinViewContainer is a
> hack, let us ignore this ;-) 

I fully agree ;-) My new patch builds upon the DolphinViewContainer changes suggested by Peter and the connect/disconnect approach proposed by Jekyll. Note that I added a pointer to the Konsole part to TerminalPanel to make it possible to connect to/disconnect from the part's signal at any time. Casting from m_terminal is not possible via qobject_cast because m_terminal is not a QObject (a dynamic_cast would be possible, however).

I have not found any situation where it doesn't work as it should, but many eyes make bugs shallow ;-)

A (sort of off-topic) question that I asked myself when working on this: Does anyone remember why the "hide terminal" situation is handled in a slot (which has to be connected by DolphinMainWindow) rather than reimplementing hideEvent() and ignoring (i.e., forwarding) spontaneous events? That would be more symmetric to the showEvent() situation and also slightly reduce the complexity of DolphinMainWindow.
Comment 21 Jekyll Wu 2012-04-18 21:44:59 UTC
(In reply to comment #20)
> Created attachment 70382 [details]
> Updated patch

I have used the patched dolphon for a few days. No problems observed so far.
Comment 22 Frank Reininghaus 2012-04-26 06:43:00 UTC
Git commit b53f7c6c19dda3cd1f11b9cb4c2aca84aa806fd1 by Frank Reininghaus.
Committed on 26/04/2012 at 08:31.
Pushed by freininghaus into branch 'master'.

Update the view when changing the directory using 'cd' in the terminal

Thanks to Jekyll Wu for helping to implement this feature!
FIXED-IN: 4.9.0

M  +8    -0    dolphin/src/dolphinmainwindow.cpp
M  +7    -0    dolphin/src/dolphinmainwindow.h
M  +13   -3    dolphin/src/dolphinviewcontainer.cpp
M  +9    -0    dolphin/src/dolphinviewcontainer.h
M  +34   -6    dolphin/src/panels/terminal/terminalpanel.cpp
M  +12   -0    dolphin/src/panels/terminal/terminalpanel.h

http://commits.kde.org/kde-baseapps/b53f7c6c19dda3cd1f11b9cb4c2aca84aa806fd1
Comment 23 2012-06-17 05:04:56 UTC
I never thought that was a feature, i thought it was a bug, i was even going ot create a bug report about this, but then i was told that this was in fact some dolphin feature, so i asked if was possible to disable this and i also was told that atm that does not exist.

So i gently ask to dolphin developers to create a way to disable dolphin from follow konsole "movements", its rather annoying to have symlinks in out home dir and each time i click on them im automatically redirected to the original location , and there i go again move the mouse to go back to my home dir.
Comment 24 Frank Reininghaus 2012-06-17 07:12:09 UTC
(In reply to comment #23)
> its rather annoying to have symlinks in out
> home dir and each time i click on them im automatically redirected to the
> original location , and there i go again move the mouse to go back to my
> home dir.

Of course this is a bug. I've created a new bug report about this (bug 302037). The right solution is to fix this bug, not to work around it by disabling the feature.