Skip to content

Commit

Permalink
feat: allow export all bookmarks keyboard shortcut
Browse files Browse the repository at this point in the history
  • Loading branch information
hamirmahal committed Oct 6, 2024
1 parent 94ec4f5 commit 3a5baf0
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/brave_command_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@

// Bookmark commands.
#define IDC_TOGGLE_ALL_BOOKMARKS_BUTTON_VISIBILITY 56300
#define IDC_EXPORT_ALL_BOOKMARKS 56312

#define IDC_COMMANDER 56301

Expand Down
4 changes: 4 additions & 0 deletions browser/ui/brave_browser_command_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ void BraveBrowserCommandController::InitBraveCommandState() {
UpdateCommandsForPin();

UpdateCommandEnabled(IDC_TOGGLE_ALL_BOOKMARKS_BUTTON_VISIBILITY, true);
UpdateCommandEnabled(IDC_EXPORT_ALL_BOOKMARKS, true);

if (browser_->is_type_normal()) {
// Delete these when upstream enables by default.
Expand Down Expand Up @@ -656,6 +657,9 @@ bool BraveBrowserCommandController::ExecuteBraveCommandWithDisposition(
case IDC_TOGGLE_ALL_BOOKMARKS_BUTTON_VISIBILITY:
brave::ToggleAllBookmarksButtonVisibility(base::to_address(browser_));
break;
case IDC_EXPORT_ALL_BOOKMARKS:
brave::ExportAllBookmarks(&*browser_);
break;
case IDC_COMMANDER:
#if BUILDFLAG(ENABLE_COMMANDER)
brave::ToggleCommander(base::to_address(browser_));
Expand Down
10 changes: 10 additions & 0 deletions browser/ui/browser_commands.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "brave/components/speedreader/common/buildflags/buildflags.h"
#include "brave/components/tor/buildflags/buildflags.h"
#include "brave/components/url_sanitizer/browser/url_sanitizer_service.h"
#include "chrome/browser/bookmarks/bookmark_html_writer.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
Expand Down Expand Up @@ -898,6 +899,15 @@ void ScrollTabToBottom(Browser* browser) {
contents->ScrollToBottomOfDocument();
}

void ExportAllBookmarks(Browser* browser) {
Profile* profile = browser->profile();
// @TODO: Get the path from the user, like we do when the user clicks the export bookmarks button manually.
base::FilePath path("/home/hamir/Downloads/Brave browser bookmarks.html");
BookmarksExportObserver* observer = nullptr;

bookmark_html_writer::WriteBookmarks(profile, path, observer);
}

void ToggleAllBookmarksButtonVisibility(Browser* browser) {
auto* prefs = browser->profile()->GetPrefs();
prefs->SetBoolean(
Expand Down
1 change: 1 addition & 0 deletions browser/ui/browser_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ void UnmuteAllTabs(Browser* browser);
void ScrollTabToTop(Browser* browser);
void ScrollTabToBottom(Browser* browser);

void ExportAllBookmarks(Browser* browser);
void ToggleAllBookmarksButtonVisibility(Browser* browser);

// In case |tab| is not provided, the active tab will be used.
Expand Down
3 changes: 3 additions & 0 deletions components/resources/commands.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,9 @@
<message name="IDS_IDC_BRAVE_BOOKMARK_BAR_NEVER">
Hide bookmark bar
</message>
<message name="IDS_IDC_EXPORT_ALL_BOOKMARKS">
Export all bookmarks
</message>
<message name="IDS_IDC_TOGGLE_ALL_BOOKMARKS_BUTTON_VISIBILITY">
Toggle All bookmarks button visibility
</message>
Expand Down

0 comments on commit 3a5baf0

Please sign in to comment.