Skip to content

Conversation

stefnotch
Copy link

@stefnotch stefnotch commented Jul 14, 2022

Fix #26

I already implemented this, so I figured I'd carefully open a pull request with the feature. I'd love some feedback :)

And upgrade to .net 5
@stefnotch
Copy link
Author

Okay, the failing pipeline is absolutely my fault, as I attempted to upgrade to .NET 5 without changing the pipeline scripts.

So either I downgrade back, or a lovely maintainer takes a look at how to upgrade the pipeline.

@jjw24
Copy link
Owner

jjw24 commented Jul 15, 2022

I am currently afk on my mobile, will take a look later :)

@jjw24 jjw24 requested a review from taooceros July 15, 2022 10:21
@jjw24 jjw24 added the enhancement New feature or request label Jul 15, 2022
Copy link
Author

@stefnotch stefnotch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make reviewing slightly easier, I'll point out some important changes

@@ -148,11 +151,18 @@ private ProcessArguments GetProcessArguments(Command c, IEnumerable<string> term
}

var workingDir = c.WorkingDirectory;
if (workingDir == "{explorer}")
Copy link
Author

@stefnotch stefnotch Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working directory can be set to {explorer}, which will trigger the new behavior where it tries to get the path of the topmost file explorer window.

public static List<string> GetOpenExplorerPaths()
{
var results = new List<string>();
if (OperatingSystem.IsWindows())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just saw this, is this referring to OS type? Flow is windows only so not sure if this check is necessary.

{
class ExplorerPathsService
{
public static List<string> GetOpenExplorerPaths()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This uses the "Shell" to iterate over all file explorer windows and read the file paths and HWNDs from them.
Then it uses "Win32" stuff to iterate over all open windows (sorted by how close to the user they are), and read the HWNDs from there.

Finally, it combines that info to return a sorted list of open file explorer windows. This means that GetOpenExplorerPaths().First() will always return the topmost open file explorer.

<OutputType>Library</OutputType>
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<Nullable>enable</Nullable>
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also enabled the nullable references stuff, which makes it a lot easier to spot potential null pointer exceptions at compile time.

@taooceros
Copy link
Collaborator

Lgtm. Shall we also implement similar thing in flow? I remember @Garulf has shared a similar idea about pasting the first explorer path to flow.

@jjw24
Copy link
Owner

jjw24 commented Jul 15, 2022

Lgtm. Shall we also implement similar thing in flow? I remember @Garulf has shared a similar idea about pasting the first explorer path to flow.

Was about to ask you same thing if we want to expose this via the flow API instead?

@stefnotch
Copy link
Author

Lgtm. Shall we also implement similar thing in flow? I remember @Garulf has shared a similar idea about pasting the first explorer path to flow.

Oh, that'd be a lovely API to have in Flow. I personally use this for

  • Starting VSCode with the open directory
  • Starting a HTTP file server with the open directory

and have thought about things like

  • Find a file in the current directory. Heck, if combined with ripgrep, it would put the Windows file searching to shame if used on code-bases.
  • git init with the current directory or git status

Copy link
Collaborator

@taooceros taooceros left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also could you resolve the null safety check since we have enabled it? To mark all property that allows null as nullable and create a constructor for all other properties.

var result = fullResults.Find(v => v.HWND == hwnd);
if(result != null)
{
result.ZIndex = zIndex;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we set the result.ZIndex to zIndex? To put the window up to front?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that's used for sorting the windows correctly.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why do we want to sort out the windows?
Shouldn't we pick the window with the largest zindex?

Copy link
Author

@stefnotch stefnotch Jul 15, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My thought process was that it might make sense to be able to get other open file explorer paths. But honestly, I'm not sure if that would ever be useful.

(See https://github.com/Flow-Launcher/Flow.Launcher/pull/1018/files#r922377206 )

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I messed up with the logic. So the EnumWindow Call will enumerate with the ZIndex order?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you plan to make usage of the ZIndex? But I think it would be a bit hard to do so lol. Maybe adding multiple results instead of only the first one, but order them based on the zindex? BTW, you can order the results with the Score property for Result class.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I slightly tweaked the code, let me know if it's easier to understand now

@taooceros
Copy link
Collaborator

Flow-Launcher/Flow.Launcher#907
Maybe we can add a similar feature for explorer plugin as well.

@taooceros
Copy link
Collaborator

Flow-Launcher/Flow.Launcher#1018

And for this one, do you have any clues about a better implementation?

@stefnotch
Copy link
Author

@taooceros I did my best to fix the null warnings, however there were quite a few places where I ended up placing a !, since I wouldn't know how to do it without big refactors.

@stefnotch
Copy link
Author

stefnotch commented Jul 15, 2022

Flow-Launcher/Flow.Launcher#1018

And for this one, do you have any clues about a better implementation?

Alrighty, I took a look at it and left some comments there.

@@ -21,9 +21,9 @@ public void LoadCommands()
RunnerConfiguration.Commands.Select( c => new CommandViewModel( c ) ) );
}

public ObservableCollection<CommandViewModel> Commands { get; set; }
public ObservableCollection<CommandViewModel>? Commands { get; set; }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe refactor a bit to make this not nullable. The viewmodel is not intended to have null Commands.

@taooceros
Copy link
Collaborator

@taooceros I did my best to fix the null warnings, however there were quite a few places where I ended up placing a !, since I wouldn't know how to do it without big refactors.

Thanks it looks great. I think when you ends up placing a !, maybe just suppress the nullity check with null!, or otherwise use a ? instead.

@taooceros
Copy link
Collaborator

btw do you mind fixing the UI overflow? Thanks
image

@taooceros
Copy link
Collaborator

btw maybe it would be even useful if we can put this as part of the parameter? I think it would be fairly easy to just use a replace (though you may need to consider a bit about the escaping). I wonder whether it is possible to use the ArgumentList api instead of the current one so that we don't need to worry about the escaping.

@stefnotch
Copy link
Author

@taooceros Okay, I modified the null checks. I didn't fix the XAML stuff, since that's way out of my depth. (I don't understand how it works.)

@stefnotch
Copy link
Author

btw maybe it would be even useful if we can put this as part of the parameter? I think it would be fairly easy to just use a replace (though you may need to consider a bit about the escaping). I wonder whether it is possible to use the ArgumentList api instead of the current one so that we don't need to worry about the escaping.

Yeah, probably would be useful. I think that could be done in a future pull request?

@taooceros
Copy link
Collaborator

@taooceros Okay, I modified the null checks. I didn't fix the XAML stuff, since that's way out of my depth. (I don't understand how it works.)

No problem, I will fix that part.

@taooceros
Copy link
Collaborator

Done, do you want to include the multiple explorer path or leave it in the future?

@stefnotch
Copy link
Author

@taooceros Let's leave it for the future

@jjw24
Copy link
Owner

jjw24 commented Jul 23, 2022

This is ready to roll?

@stefnotch
Copy link
Author

From my side: Yes, I've been using it for a week now without issues and it's pretty sweet.

There is Flow-Launcher/Flow.Launcher#1275 for getting a part of the functionality into Flow itself, but that's a separate story.

@taooceros
Copy link
Collaborator

taooceros commented Jul 23, 2022

Ah sorry I was supposed to approve it earlier but I forget

taooceros
taooceros previously approved these changes Jul 23, 2022
@taooceros
Copy link
Collaborator

Oh there's one more thing that needs to be done (I always forget). Update the version in plugin.json.

taooceros
taooceros previously approved these changes Jul 25, 2022
@jjw24 jjw24 merged commit 953b73b into jjw24:master Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use open file explorer directory
3 participants