Skip to content

Commit

Permalink
Implement Application::copyToClipboard for iOS
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Jul 23, 2019
1 parent b6d2285 commit fc036f2
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/docs/reference/foundation/application.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ namespace bdn {
Opens the given URL in a suitable external application. Web URLs will be opened in the system's standard web browser. Application-specific URLs will open in the respective application.
* **virtual void copyToClipboard(const String &str)**
Copies the given string to the clipboard.
## Resources
* **virtual String uriToBundledFileUri(const String &uri)**
Expand Down
1 change: 1 addition & 0 deletions framework/foundation/include/bdn/Application.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ namespace bdn
public:
virtual void openURL(const String &url) = 0;
virtual String uriToBundledFileUri(const String &uri) { return uri; }
virtual void copyToClipboard(const String &str) = 0;

protected:
virtual void platformSpecificInit() {}
Expand Down
2 changes: 2 additions & 0 deletions framework/foundation/include/bdn/GenericApplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ namespace bdn

void openURL(const String &url) override {}

void copyToClipboard(const String &str) override {}

protected:
virtual bool shouldExit() const
{
Expand Down
2 changes: 2 additions & 0 deletions framework/ui/platforms/ios/include/bdn/ios/UIApplication.hh
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ namespace bdn::ui::ios

String uriToBundledFileUri(const String &uri) override;

void copyToClipboard(const String &str) override;

public:
bool _applicationWillFinishLaunching(NSDictionary *launchOptions);
bool _applicationDidFinishLaunching(NSDictionary *launchOptions);
Expand Down
6 changes: 6 additions & 0 deletions framework/ui/platforms/ios/src/UIApplication.mm
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ - (void)applicationWillTerminate:(UIApplication *)application
return "file:///" + result;
}

void UIApplication::copyToClipboard(const String &str)
{
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
pasteboard.string = [NSString stringWithUTF8String:str.c_str()];
}

bool UIApplication::_applicationWillFinishLaunching(NSDictionary *launchOptions)
{
bdn::platformEntryWrapper(
Expand Down

0 comments on commit fc036f2

Please sign in to comment.