Skip to content

#303 Open File in Folder #304

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

spipau
Copy link
Contributor

@spipau spipau commented Jun 8, 2025

  • Add function "open file in folder" to context menu for unstaged, staged and committed files
  • Add File extension function to open a folder

Tested only with Ubuntu LTS 24.04.2, GNOME 46.0

spipau added 2 commits June 8, 2025 22:30
- Add function to context menu for unstaged, staged and commited files
- Add File extention function to open a folder
Copy link
Owner

@JetpackDuba JetpackDuba left a comment

Choose a reason for hiding this comment

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

Thanks for your MR! I've added a few comments to fix some issues before merging it.


add(
ContextMenuElement.ContextTextEntry(
label = "Open file in folder",
Copy link
Owner

Choose a reason for hiding this comment

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

Use string resources for any new strings (The old ones are still being migrated)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was delighted to see that localization already started. I tried to use the resources but as this in a non composable context, I cannot simply access the resources. How should I do this? Hand down the Strings into the context menu?

Copy link
Owner

@JetpackDuba JetpackDuba Jul 5, 2025

Choose a reason for hiding this comment

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

Correct, it's a bit tricky out of the box. I've pushed some changes in the main branch to add proper support. If you rebase it, you will also see some examples as I extracted the rest of strings in that context menu.

- Use printError instead of println
- Revert formatting of Status.kt
- Change RefreshType to NONE
@spipau
Copy link
Contributor Author

spipau commented Jun 29, 2025

@JetpackDuba while working on the improvements, I realized that the changes do not actually open the repository folder, but the development folder of the project. The DiffEntry.parentDirectoryPath does not provide the full path of the repository. I could not find on how to the path of the repository, could you please point me in the right direction?

Copy link
Owner

@JetpackDuba JetpackDuba left a comment

Choose a reason for hiding this comment

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

The DiffEntry.parentDirectoryPath does not provide the full path of the repository. I could not find on how to the path of the repository, could you please point me in the right direction?

When running an operation from any of the view models, you have access to the git object of that repository. From that object you can get the File instance pointing to the repository:

fun example() = tabState.runOperation(
        refreshType = RefreshType.NONE,
    ) { git ->  
        val repositoryFile = git.repository.workTree
        // TODO Do something with the repository file
    }

fun openFileInFolder(folderPath: String?) = tabState.runOperation(
refreshType = RefreshType.NONE,
) {
folderPath?.let { File(it).openFileInFolder() }
Copy link
Owner

Choose a reason for hiding this comment

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

I think I forgot to mention it last time: Use a regular if statement instead of let, it's more readable when checking nullability of parameters


add(
ContextMenuElement.ContextTextEntry(
label = "Open file in folder",
Copy link
Owner

@JetpackDuba JetpackDuba Jul 5, 2025

Choose a reason for hiding this comment

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

Correct, it's a bit tricky out of the box. I've pushed some changes in the main branch to add proper support. If you rebase it, you will also see some examples as I extracted the rest of strings in that context menu.

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

Successfully merging this pull request may close these issues.

2 participants