Home » Developing U++ » UppHub » Simple app-wide "macros"
Simple app-wide "macros" [message #13110] |
Wed, 12 December 2007 17:35  |
 |
mirek
Messages: 14257 Registered: November 2005
|
Ultimate Member |
|
|
I was asked by application user to provide some means to insert often repeated texts ("e.g. if I press F4, I want xyz to be inserted here).
This simple module allows you do define selection as macro using Ctrl+F1-10 a insert using F1-10, in EditField, DocEdit, LineEdit, RichEdit:
static WString s_macro[10];
bool MacroKeyHook(Ctrl *ctrl, dword key, int count)
{
if(key >= K_CTRL_F1 && key <= K_CTRL_F10) {
WString& txt = s_macro[key - K_CTRL_F1];
int l, h;
if(EditField *e = dynamic_cast<EditField *>(ctrl))
if(e->GetSelection(l, h)) {
txt = e->GetText().Mid(l, h - l);
return true;
}
if(TextCtrl *e = dynamic_cast<TextCtrl *>(ctrl))
if(e->GetSelection(l, h)) {
txt = e->GetW(l, h - l);
return true;
}
if(RichEdit *e = dynamic_cast<RichEdit *>(ctrl)) {
txt = e->GetSelection().GetPlainText();
return true;
}
}
if(key >= K_F1 && key <= K_F10) {
WString txt = s_macro[key - K_F1];
if(EditField *e = dynamic_cast<EditField *>(ctrl)) {
e->Insert(txt);
return true;
}
if(TextCtrl *e = dynamic_cast<TextCtrl *>(ctrl)) {
e->Paste(txt);
return true;
}
if(RichEdit *e = dynamic_cast<RichEdit *>(ctrl)) {
e->PasteText(AsRichText(txt, e->GetFormatInfo()));
return true;
}
}
return false;
}
void SerializeTextMacros(Stream& s)
{
int version = 0;
s / version;
for(int i = 0; i < 10; i++)
s % s_macro[i];
}
INITBLOCK {
Ctrl::InstallKeyHook(MacroKeyHook);
}
|
|
|
Re: Simple app-wide "macros" [message #30214 is a reply to message #13110] |
Thu, 16 December 2010 00:07  |
alendar
Messages: 47 Registered: January 2010 Location: Idaho, USA
|
Member |
|
|
Thanks, Mirek!
The snippet below was really helpful.
PasteText(AsRichText(txt, GetFormatInfo()));
I'll also try adding the entire logic to use for capturing text macros.
cd7651feeb698f6ac6cec1f6deda5e5b
|
|
|
Goto Forum:
Current Time: Sun May 11 19:50:19 CEST 2025
Total time taken to generate the page: 0.00375 seconds
|