[KDirOperator] Add follow new directories options
ClosedPublic

Authored by daandemeyer on Thu, Aug 22, 8:57 AM.

Details

Summary

Currently, KDirOperator always calls setUrl on newly created directories.

This revision adds new option to configure this behaviour:
followNewDirectories and followSelectedDirectories

When using KDirOperator in tree mode as an embedded project view widget, we don't want to change the listed directory when creating new directories.

Diff Detail

Repository
R241 KIO
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
daandemeyer created this revision.Thu, Aug 22, 8:57 AM
Restricted Application added a project: Frameworks. · View Herald TranscriptThu, Aug 22, 8:57 AM
Restricted Application added a subscriber: kde-frameworks-devel. · View Herald Transcript
daandemeyer requested review of this revision.Thu, Aug 22, 8:57 AM

+1, but you need to add @since 5.62 to the new public functions.

  • Address comment
  • Apply option when selecting directories as well
  • Rename to followDirectories

followDirectories() seems somewhat ambiguous to me. How about the old one, or else, openNewlyCreatedDirectories()?

daandemeyer added a comment.EditedThu, Aug 22, 5:26 PM

I changed the option to apply to directories that are double clicked as well. Previously, double clicking a directory would also change the listed url which now depends on whether the option is enabled. Since it applies to both new and existing directories, followDirectories seemed more apt. I'm open to other name suggestions but your suggestions seem to only consider the new directory case (perhaps you missed the added behaviour in the latest revision?).

I changed the option to apply to directories that are double clicked as well. Previously, double clicking a directory would also change the listed url which now depends on whether the option is enabled. Since it applies to both new and existing directories, followDirectories seemed more apt. I'm open to other name suggestions but your suggestions seem to only consider the new directory case (perhaps you missed the added behaviour in the latest revision?).

I did miss the behavior change. What's the use case for that? If you double-click on a directory but the URL doesn't actually change, that seems like it would be pretty confusing when the URL is user-visible. Does your use case involve an implementation where the URL isn't user-visible?

daandemeyer added a comment.EditedThu, Aug 22, 6:06 PM

Now, with followDirectories set to false, directories simply expand on double click which is what I wanted to achieve. The general behaviour I want to get with this change is to have a project tree view where the root folder stays fixed.

What happens when this is set but the view isn't an expandable tree view?

daandemeyer added a comment.EditedThu, Aug 22, 8:44 PM

That is something I hadn't considered yet. Would it be acceptable to only apply this option when the KDirOperator is configured as a tree view?

I could also go the hard way and wrap QTreeView myself but that would be unfortunate as KDirOperator almost does exactly what I need in a few lines of code which would not be the case when implementing this myself.

Any suggestions on how to proceed?

EDIT: We could still apply it generally in the case of creating new directories but only apply it to the tree view in the case of selecting an existing directory.

When selecting directories, only disable following directories if a tree view is used (normal or detail).

Remove extra unnecessary '&'

Hmm, I think this makes more sense now. Frameworks people, what say ye?

What I still miss in the description is what problem is solved? A bug? A nice feature? Where will this be used? To me as someone not using KDirOperator every day this is rather unclear.

src/filewidgets/kdiroperator.h
507

The API documentation is missing the default value.

Added default value to documentation.

The use case is showing a project tree view in an application where we want the root of the KDirOperator to stay fixed. The initial motivation for this change was replicating the File Explorer from Visual Studio Code (text editor) where one opens a folder and the file explorer stays fixed at that specific folder until another folder is opened. KDirOperator almost fit this use case except when creating new directories or selecting existing directories, that directory would be made the top level directory in the KDirOperator. When the new option is enabled, the top level directory stays the same when selecting directories or creating new directories which makes KDirOperator behave more like the File Explorer in Visual Studio Code.

Of course, this functionality can be generally used by applications that want to provide a fixed project view (or workspace) in their UI.

This sounds like two different options to me. Sure, right now, for this use case, you need to toggle them both together, but then one day some application will want to follow dirs in treeviews, just not when creating directories, or vice versa.

Split followDirectories option into followNewDirectories and followSelectedDirectories options. followSelectedDirectories only applies to tree views. Let me know if you want the option name to include that information.

dfaure accepted this revision.Sat, Aug 24, 12:59 PM
This revision is now accepted and ready to land.Sat, Aug 24, 12:59 PM
ngraham accepted this revision.Sat, Aug 24, 2:31 PM
ngraham retitled this revision from KDirOperator: Add follow new directories option to [KDirOperator] Add follow new directories options.Sat, Aug 24, 3:00 PM
ngraham edited the summary of this revision. (Show Details)
This revision was automatically updated to reflect the committed changes.

Thanks for the explanation. Such details could also be mentioned in the class description as a separate \section. The explanation in the review request will be lost at some point, since we unlikely will stay on phabricator forever.