Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ExplorerCreateFile: open with app after creation. #66

Open
ewerybody opened this issue Feb 11, 2022 · 3 comments
Open

ExplorerCreateFile: open with app after creation. #66

ewerybody opened this issue Feb 11, 2022 · 3 comments

Comments

@ewerybody
Copy link
Owner

From @Cyberklabauter #60

  • Looking at your screenshot: I would like to have an option to open the created file with my preferred editor (accepting relative paths to it) immediatly.
    -> Like: Loop -> FileExist() -> run
    Would it be possible to add?

Possible 👍. But whats with the relative paths?
I'd add a path-field among the settings to pick an app to be run with the new file.
Or should it pick the default app for the file type?! 🤔

@Cyberklabauter
Copy link

It would be perfect to convert the picked path to a relativ path if possible.

Relative paths don't have a root dir and are relative to a2 / A_ScriptDir. Since you made a2 working as a portable application, it would be fantastic to do so with external sources as well. In general this would mean:

Let's say I have the following folders:

Case A

  1. Base Dir: D:\portableApplications\a2\ and
    Absolute Path: D:\portableApplications\notepad++\notepad++.exe

  2. the relative path to save would be: "..\notepad++\notepad++.exe"

=> If the root changes "D:" to "F:" running notepad++ would still work.

Case B

  1. Base Dir: D:\portableApplications\a2\ and
    Absolute Path: C:\portableApplications\notepad++\notepad++.exe

  2. The root differs: absolute path must be saved: "C:\portableApplications\notepad++\notepad++.exe"

=> If the root changes "C:" to "F:" running notepad++ would fail.


  1. Pick a a file or folder
  2. Check if the file/folder path can be expresed as a relative path
  3. Save path realtive or absolute (if relative is not possible)

Here are two functions you need:

`GetRelativePath(BaseDirectory, AbsolutePath, s="") {
; Author: Toralf
; From: https://www.autohotkey.com/board/topic/17922-func-relativepath-absolutepath/
len := InStr(BaseDirectory, s, "", InStr(BaseDirectory, s . s) + 2) ;get server or drive string length
If SubStr(BaseDirectory, 1, len ) <> SubStr(AbsolutePath, 1, len ) ;different server or drive
Return AbsolutePath ;return absolut path
BaseDirectory := SubStr(BaseDirectory, len + 1 ) ;remove server or drive from BaseDirectory
AbsolutePath := SubStr(AbsolutePath, len + 1 ) ;remove server or drive from AbsolutePath
If InStr(BaseDirectory, s, "", 0) = StrLen(BaseDirectory) ;remove last \ from BaseDirectory if any
StringTrimRight, BaseDirectory, BaseDirectory, 1
If InStr(AbsolutePath, s, "", 0) = StrLen(AbsolutePath) ;remove last \ from AbsolutePath if any
StringTrimRight, AbsolutePath, AbsolutePath, 1
Loop{
If !BaseDirectory ;when there is nothing didentical
Return s AbsolutePath ;return AbsolutePath in root
If InStr(AbsolutePath s, BaseDirectory s){ ;when parts of paths match
If !r ;no relative part yet
r = .%s% ;AbsolutePath is in the BaseDirectory
Return r . SubStr(AbsolutePath,StrLen(BaseDirectory) + 2) ;return relative path
}Else{ ;otherwise
r .= ".." s ;add relative part
BaseDirectory := SubStr(BaseDirectory, 1, InStr(BaseDirectory, s, "", 0) - 1) ;remove one folder from BaseDirectory
}
}
}

GetFullPathName(RelativePath) {
; Author: Lexikos
; from https://www.autohotkey.com/boards/viewtopic.php?p=289536&sid=eb3ee82330dba01de0d7d4556bc2f3f0#p289536
cc := DllCall("GetFullPathName", "str", RelativePath, "uint", 0, "ptr", 0, "ptr", 0, "uint")
VarSetCapacity(buf, cc*(A_IsUnicode?2:1))
DllCall("GetFullPathName", "str", RelativePath, "uint", cc, "str", buf, "ptr", 0, "uint")
return buf
}`

@ewerybody
Copy link
Owner Author

ewerybody commented Feb 11, 2022

AAhhh alright! ☝😅 Now I get what you mean. I just didn't know relative to what.

This would all be in the UI. So we don't need any AHK code for that. In Python there is os.path.relpath Voilà :D
Lets have:

  • a path field and
  • a checkbox to make the browsed paths a2 relative.

Additionally as this is a rather advanced feature anyway I'd say one should be able to just "write" any path into the field. This can nicely be configured in our path widgets already (for most cases, I'd keep users from hacking in anything and have them point to a dedicated location by browsing)

The ui could notify you if the path is invalid tho. But if things are breaking anyway in the AHK runtime. The user needs to fix their paths.

@Cyberklabauter
Copy link

Good solution! The UI seems to be quite powerful 😅.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants