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

feat: keyboard shortcut to export all bookmarks #25827

Open
wants to merge 11 commits into
base: master
Choose a base branch
from

Conversation

hamirmahal
Copy link

Resolves brave/brave-browser#41412

Allow users to create a keyboard shortcut that exports all bookmarks.

This is an action that some users, like myself, do very often. It would improve the user experience (UX) if there was a way to do this with one keyboard shortcut, as opposed to several, successive clicks.

Submitter Checklist:

  • I confirm that no security/privacy review is needed and no other type of reviews are needed, or that I have requested them
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Comment on lines 901 to 910
void ExportAllBookmarks(Browser* browser) {
auto* profile = browser->profile();
DCHECK(profile);
chrome::ExportBookmarks(profile, /*export_path=*/base::FilePath());
}

Copy link
Author

Choose a reason for hiding this comment

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

I'm trying to build locally to see if this approach is valid but

cd brave-browser/src/brave/ && npm run build -- Static && npm start Static

has been running for several hours and still hasn't finished.

Copy link
Contributor

@jonathansampson jonathansampson Oct 5, 2024

Choose a reason for hiding this comment

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

Unless I'm mistaken, you should see an early failure with this stating no member named 'ExportBookmarks' in namespace 'chrome'. Where did you see that method defined? You might find BookmarksFaviconFetcher to be helpful here; it contains a method ExportBookmarks which looks promising.

@hamirmahal hamirmahal force-pushed the feat/keyboard-shortcut-to-export-all-bookmarks branch from 2db2f06 to 3a5baf0 Compare October 6, 2024 18:01
@hamirmahal
Copy link
Author

Current behavior

Screencast.from.10-06-2024.10.58.15.AM.webm

@fallaciousreasoning
Copy link
Contributor

Nice work @hamirmahal! If you want to show a FilePicker this seems like a good place to start looking:

https://source.chromium.org/chromium/chromium/src/+/main:ui/shell_dialogs/select_file_dialog.h?q=symbol:%5Cbui::SelectFileDialog::Create%5Cb%20case:yes

(it sounds like you can pass nullptr as the second argument 😄)

@hamirmahal
Copy link
Author

Thanks, @fallaciousreasoning!

@hamirmahal hamirmahal marked this pull request as ready for review October 17, 2024 23:55
@hamirmahal hamirmahal requested a review from a team as a code owner October 17, 2024 23:55
@hamirmahal
Copy link
Author

Without this pull request

Screencast.from.10-17-2024.04.53.44.PM.webm

@hamirmahal
Copy link
Author

With this pull request

I recommend watching this at 2x speed.

Screencast.from.10-17-2024.03.54.15.PM.webm

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

This is looking great! Few more changes and I think I can kick off CI

browser/ui/browser_commands.cc Outdated Show resolved Hide resolved
browser/ui/browser_commands.cc Outdated Show resolved Hide resolved
browser/ui/browser_commands.cc Outdated Show resolved Hide resolved
browser/ui/browser_commands.cc Outdated Show resolved Hide resolved
raw_ptr<Profile> profile_;

public:
scoped_refptr<ui::SelectFileDialog> fileSelector;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Maybe pass this in as part of the constructor (or via a setter) and have this variable be private - Chromium doesn't allow public fields in classes

Suggested change
scoped_refptr<ui::SelectFileDialog> fileSelector;
scoped_refptr<ui::SelectFileDialog> file_selector_;

actually, can we remove this? I don't think we need to hold a reference to the file_selector

Copy link
Author

Choose a reason for hiding this comment

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

We can pass in file_selector_ as part of the constructor and have it be private.

I gave it several passes, and the way I had the code with file_selector_ removed entirely resulted in the file picker still appearing, but bookmarks not ultimately being saved to disk after confirming a path. But, I'm happy to give it another look if you have code suggestions.

}
void FileSelectionCanceled() override {
std::cout << "File selection for bookmarks export canceled" << std::endl;
delete this;
Copy link
Contributor

Choose a reason for hiding this comment

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

do we need to remove this as a listener to the FileSelectionDialog too?

Copy link
Author

Choose a reason for hiding this comment

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

I don't know if we need to remove it, but we can remove it without losing cancellation functionality, so I did.

browser/ui/browser_commands.cc Outdated Show resolved Hide resolved
@hamirmahal hamirmahal force-pushed the feat/keyboard-shortcut-to-export-all-bookmarks branch from dfa6a3f to adb2959 Compare October 18, 2024 21:41
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.

add keyboard shortcut for exporting all bookmarks
3 participants