Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5231: Move clipboard handling to separate module to prevent crashes …
…at shutdown due to memory allocation/deallocation problems.
- Loading branch information
1 parent
239df58
commit 6ec1bd3
Showing
12 changed files
with
148 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "imodule.h" | ||
|
||
namespace radiant | ||
{ | ||
|
||
/** | ||
* Interface to DarkRadiant's clipboard which is able to | ||
* store and retrieve a string from and to the system clipboard. | ||
* Access it through the GlobalClipboard() function. | ||
* | ||
* This module might not be present in all configurations | ||
* so its advisable to check for its presence first. | ||
*/ | ||
class IClipboard : | ||
public RegisterableModule | ||
{ | ||
public: | ||
virtual ~IClipboard() {} | ||
|
||
/// Return the contents of the clipboard as a string | ||
virtual std::string getString() = 0; | ||
|
||
/// Copy the given string to the system clipboard | ||
virtual void setString(const std::string& str) = 0; | ||
}; | ||
|
||
} | ||
|
||
const char* const MODULE_CLIPBOARD("Clipboard"); | ||
|
||
inline radiant::IClipboard& GlobalClipboard() | ||
{ | ||
// Cache the reference locally | ||
static radiant::IClipboard& _instance( | ||
*std::static_pointer_cast<radiant::IClipboard>( | ||
module::GlobalModuleRegistry().getModule(MODULE_CLIPBOARD) | ||
) | ||
); | ||
return _instance; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#include "ClipboardModule.h" | ||
|
||
#include "itextstream.h" | ||
#include <wx/clipbrd.h> | ||
|
||
#include "module/StaticModule.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
std::string ClipboardModule::getString() | ||
{ | ||
std::string returnValue; | ||
|
||
if (wxTheClipboard->Open()) | ||
{ | ||
if (wxTheClipboard->IsSupported(wxDF_TEXT)) | ||
{ | ||
wxTextDataObject data; | ||
wxTheClipboard->GetData(data); | ||
returnValue = data.GetText().ToStdString(); | ||
} | ||
|
||
wxTheClipboard->Close(); | ||
} | ||
|
||
return returnValue; | ||
} | ||
|
||
void ClipboardModule::setString(const std::string& str) | ||
{ | ||
if (wxTheClipboard->Open()) | ||
{ | ||
// This data objects are held by the clipboard, so do not delete them in the app. | ||
wxTheClipboard->SetData(new wxTextDataObject(str)); | ||
wxTheClipboard->Close(); | ||
} | ||
} | ||
|
||
const std::string& ClipboardModule::getName() const | ||
{ | ||
static std::string _name(MODULE_CLIPBOARD); | ||
return _name; | ||
} | ||
|
||
const StringSet& ClipboardModule::getDependencies() const | ||
{ | ||
static StringSet _dependencies; | ||
return _dependencies; | ||
} | ||
|
||
void ClipboardModule::initialiseModule(const ApplicationContext& ctx) | ||
{ | ||
rMessage() << getName() << "::initialiseModule called." << std::endl; | ||
} | ||
|
||
module::StaticModule<ClipboardModule> clipboardModule; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#pragma once | ||
|
||
#include "iclipboard.h" | ||
|
||
namespace ui | ||
{ | ||
|
||
class ClipboardModule : | ||
public radiant::IClipboard | ||
{ | ||
public: | ||
std::string getString() override; | ||
void setString(const std::string& str) override; | ||
|
||
const std::string& getName() const override; | ||
const StringSet& getDependencies() const override; | ||
void initialiseModule(const ApplicationContext& ctx) override; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters