Skip to content

Commit

Permalink
add force paste option to context menu
Browse files Browse the repository at this point in the history
  • Loading branch information
bridiver committed Apr 26, 2022
1 parent cb752c3 commit 8497a60
Show file tree
Hide file tree
Showing 3 changed files with 28 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 @@ -48,6 +48,7 @@
#define IDC_APP_MENU_IPFS_SHARE_LOCAL_FOLDER 56036
#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_IMPORT_IPNS_KEYS_START 56100
#define IDC_CONTENT_CONTEXT_IMPORT_IPNS_KEYS_END 56199
Expand Down
3 changes: 3 additions & 0 deletions app/brave_generated_resources.grd
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ Or change later at <ph name="SETTINGS_EXTENIONS_LINK">$2<ex>brave://settings/ext
<message name="IDS_LOCATION_BAR_ONION_AVAILABLE_TOOLTIP_TEXT" desc="The tooltip text for onion available button.">
Open using .onion address
</message>
<message name="IDS_CONTENT_CONTEXT_FORCE_PASTE" desc="The name of the context menu item to paste without triggering onpaste handleres">
Force Paste
</message>
<message name="IDS_CONTENT_CONTEXT_IMPORT_IPFS" desc="The name of the IPFS context menu item for renderer">
Import to IPFS
</message>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,11 @@ BraveRenderViewContextMenu::BraveRenderViewContextMenu(

bool BraveRenderViewContextMenu::IsCommandIdEnabled(int id) const {
switch (id) {
case IDC_CONTENT_CONTEXT_FORCE_PASTE:
// only enable if there is plain text data to paste - this is what
// IsPasteAndMatchStyleEnabled checks internally, but IsPasteEnabled
// allows non text types
return IsPasteAndMatchStyleEnabled();
#if BUILDFLAG(ENABLE_IPFS)
case IDC_CONTENT_CONTEXT_IMPORT_IPFS:
case IDC_CONTENT_CONTEXT_IMPORT_IPFS_PAGE:
Expand Down Expand Up @@ -218,6 +223,14 @@ void BraveRenderViewContextMenu::ExecuteIPFSCommand(int id, int event_flags) {

void BraveRenderViewContextMenu::ExecuteCommand(int id, int event_flags) {
switch (id) {
case IDC_CONTENT_CONTEXT_FORCE_PASTE: {
std::u16string result;
ui::Clipboard::GetForCurrentThread()->ReadText(
ui::ClipboardBuffer::kCopyPaste,
CreateDataEndpoint(/*notify_if_restricted=*/true).get(), &result);
// Replace works just like Paste, but it doesn't trigger onpaste handlers
source_web_contents_->Replace(result);
}; break;
#if BUILDFLAG(ENABLE_IPFS)
case IDC_CONTENT_CONTEXT_IMPORT_IPFS_PAGE:
case IDC_CONTENT_CONTEXT_IMPORT_IMAGE_IPFS:
Expand Down Expand Up @@ -356,7 +369,18 @@ void BraveRenderViewContextMenu::InitMenu() {
RenderViewContextMenu_Chromium::InitMenu();

int index = -1;

index = menu_model_.GetIndexOfCommandId(
IDC_CONTENT_CONTEXT_PASTE_AND_MATCH_STYLE);
if (index != -1) {
menu_model_.InsertItemWithStringIdAt(
index + 1,
IDC_CONTENT_CONTEXT_FORCE_PASTE,
IDS_CONTENT_CONTEXT_FORCE_PASTE);
}

#if BUILDFLAG(ENABLE_TOR)
index = -1;
// Add Open Link with Tor
if (!TorProfileServiceFactory::IsTorDisabled() &&
!params_.link_url.is_empty()) {
Expand Down

0 comments on commit 8497a60

Please sign in to comment.