Skip to content

Commit

Permalink
Added Copy Clean URL item
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Jul 19, 2022
1 parent a89df68 commit 42b61a3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/brave_command_ids.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#define IDC_APP_MENU_IPFS_OPEN_FILES 56037
#define IDC_APP_MENU_IPFS_UPDATE_IPNS 56038
#define IDC_CONTENT_CONTEXT_FORCE_PASTE 56039
#define IDC_CONTENT_CONTEXT_COPYCLEANLINKLOCATION 56040

#define IDC_CONTENT_CONTEXT_IMPORT_IPNS_KEYS_START 56100
#define IDC_CONTENT_CONTEXT_IMPORT_IPNS_KEYS_END 56199
Expand Down
4 changes: 3 additions & 1 deletion app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -908,7 +908,9 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_IMPORTED_FROM_BOOKMARK_FOLDER" desc="Name for bookmark panel folder imported from another browser">
Imported from <ph name="BROWSER_NAME">$1<ex>Chrome</ex></ph>.
</message>

<message name="IDS_CONTENT_CONTEXT_COPYCLEANLINKLOCATION" desc="The name of the context menu item to copy clean address location">
Copy clean link address
</message>
<!--Add new items to the appropriate sections above -->
</messages>
</release>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ bool BraveRenderViewContextMenu::IsCommandIdEnabled(int id) const {
// IsPasteAndMatchStyleEnabled checks internally, but IsPasteEnabled
// allows non text types
return IsPasteAndMatchStyleEnabled();
case IDC_CONTENT_CONTEXT_COPYCLEANLINKLOCATION:
return params_.unfiltered_link_url.is_valid();
#if BUILDFLAG(ENABLE_IPFS)
case IDC_CONTENT_CONTEXT_IMPORT_IPFS:
case IDC_CONTENT_CONTEXT_IMPORT_IPFS_PAGE:
Expand Down Expand Up @@ -221,8 +223,18 @@ void BraveRenderViewContextMenu::ExecuteIPFSCommand(int id, int event_flags) {
}
#endif

void BraveRenderViewContextMenu::WriteCleanURLToClipboard(const GURL& url) {
GURL::Replacements replacements;
replacements.SetPathStr(url.path_piece());
WriteURLToClipboard(url.GetWithEmptyPath().ReplaceComponents(replacements));
}

void BraveRenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
switch (id) {
case IDC_CONTENT_CONTEXT_COPYCLEANLINKLOCATION:
WriteCleanURLToClipboard(params_.unfiltered_link_url);
break;

case IDC_CONTENT_CONTEXT_FORCE_PASTE: {
std::u16string result;
ui::Clipboard::GetForCurrentThread()->ReadText(
Expand Down Expand Up @@ -370,6 +382,16 @@ void BraveRenderViewContextMenu::BuildIPFSMenu() {
}
#endif

void BraveRenderViewContextMenu::AddCleanCopyLinkItem() {
int index =
menu_model_.GetIndexOfCommandId(IDC_CONTENT_CONTEXT_COPYLINKLOCATION);
if (index != -1) {
menu_model_.InsertItemWithStringIdAt(
index + 1, IDC_CONTENT_CONTEXT_COPYCLEANLINKLOCATION,
IDS_CONTENT_CONTEXT_COPYCLEANLINKLOCATION);
}
}

void BraveRenderViewContextMenu::InitMenu() {
RenderViewContextMenu_Chromium::InitMenu();

Expand Down Expand Up @@ -405,6 +427,7 @@ void BraveRenderViewContextMenu::InitMenu() {
#if BUILDFLAG(ENABLE_IPFS)
BuildIPFSMenu();
#endif
AddCleanCopyLinkItem();

#if BUILDFLAG(ENABLE_BRAVE_TRANSLATE_GO)
const bool remove_translate =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class BraveRenderViewContextMenu : public RenderViewContextMenu_Chromium {
static void AddSpellCheckServiceItem(ui::SimpleMenuModel* menu,
bool is_checked);
void AddAccessibilityLabelsServiceItem(bool is_checked) override;
void AddCleanCopyLinkItem();
void WriteCleanURLToClipboard(const GURL& url);

private:
// RenderViewContextMenuBase:
Expand Down

0 comments on commit 42b61a3

Please sign in to comment.