Home » U++ TheIDE » U++ TheIDE: CodeEditor, Assist++, Topic++ » CodeEditor: CopyWord; SwapChars [FEATURE REQUEST][ADDED]
CodeEditor: CopyWord; SwapChars [FEATURE REQUEST][ADDED] [message #2592] |
Tue, 18 April 2006 13:50  |
gprentice
Messages: 260 Registered: November 2005 Location: New Zealand
|
Experienced Member |
|
|
Hi
I've written CopyWord and SwapChars for CodeEditor coz these are things I use a lot. They seem to work (including when hard tabs are involved) - I tested them a little bit ... - but only on Win XP. Hopefully Mirek could consider adding them to CodeEditor.cpp, if he has time and wants to ... but if not, that's ok.
It took me longer than the ESC macro versions I wrote a while ago coz there isn't a nice help file of how to do everything like there is for ESC. Surprisingly, TheIDE is sometimes better at navigating UPP source than slickedit! (it's great to have Alt left, Alt right in TheIDE).
I don't know what the clipboard stuff is doing - I just copied the Copy() function. I notice that copying something in TheIDE results in four copies going to the clipboard because I have another editor (EditPlus) that allows me to monitor the clipboard and all copied stuff turns up 4 times in EditPlus
Graeme
void CodeEditor::CopyWord() {
int p = GetCursor();
if(iscid(GetChar(p)) || (p > 0 && iscid(GetChar(--p))))
{
int e = GetLength();
int f = p;
while(--p >= 0 && iscid(GetChar(p)));
++p;
while(++f < e && iscid(GetChar(f)));
WString txt = GetW(p, f - p);
WriteClipboardUnicodeText(txt);
WriteClipboardText(txt.ToString(), false);
}
}
void CodeEditor::SwapChars() {
int i = GetLine(cursor);
int j = GetPos(i);
if (j < cursor && (cursor-j) < line[i].GetLength())
{
int p = cursor;
WString txt(GetChar(p-1),1);
Remove(p-1,1);
Insert(p, txt, true);
PlaceCaret(p);
}
}
[Updated on: Tue, 02 May 2006 04:26] by Moderator Report message to a moderator
|
|
|
|
Re: CopyWord; SwapChars [message #2741 is a reply to message #2734] |
Sun, 23 April 2006 20:40   |
gprentice
Messages: 260 Registered: November 2005 Location: New Zealand
|
Experienced Member |
|
|
luzr wrote on Mon, 24 April 2006 00:57 | Thanks. Just curious - how do you activate those functions? (hotkeys?)
As for 4 pieces on clipboard, that is quite believable - we are putting Unicode and "system page" versions, Win32 then automagically creates other formats from them.
Mirek
|
Oops, looks like I forgot
if(IsReadOnly()) return;
at the start of SwapChars.
I guess SwapChars would be better in LineEdit class anyway, since it's not C++ specific.
Nope, I have it hard coded in CodeEditor::Key at present. I didn't go to the trouble of hotkeys as I wasn't sure if this code would make it into upp sources. Of course I'd definitely like a hotkey option for it but I see that involves quite a few changes. I don't blame you for being reluctant to let people modify sources, especially CodeEditor - I don't think I even really want to. I was hoping it would be an easy thing to copy in from the code I posted.
Ideally, maybe something like an "Others" item on the Edit menu which would give sub-menu of Swap chars, copy word, move line up/down, upper case, lower case ...
Otherwise, I guess it could go in Ide::Key - I'm wondering why that uses editor (an AssistEditor) and not editor2 (CodeEditor) ??
BTW - if save file checked isreadonly() before writing, it would provide a mechanism for avoiding changing a file - currently if you make a change to a file, there's no way to prevent it going to disk other than Ctrl Z/undo. (just a thought)
Graeme
|
|
|
|
Re: CopyWord; SwapChars [message #2743 is a reply to message #2742] |
Sun, 23 April 2006 23:16   |
gprentice
Messages: 260 Registered: November 2005 Location: New Zealand
|
Experienced Member |
|
|
luzr wrote on Mon, 24 April 2006 07:36 | Well, if I am about to add it, I would need to know actual keys 
Mirek
|
Um, well, if it's hard coded, I'd probably vote for not adding it and I'll try and do it through Esc, but otherwise ...
In visual studio (and other editors too I think), Ctrl T is transpose chars, shift alt T is line transpose and ctrl shift T is word transpose, but Ctrl T is taken so I'd suggest Ctrl shift T for SwapChars (and I'll swap them over through IDE setup dialog). (I guess the function could be renamed TransposeChars too.)
For copy word, in Slickedit it's Ctrl K by default (VS doesn't seem to have it), so that would be my choice, but I guess Ctrl shift C is a possibility.
Suppose I wrote the code for Esc macros to have copy/paste - would you consider adding it
Graeme
|
|
|
|
|
|
|
Goto Forum:
Current Time: Fri May 09 11:20:55 CEST 2025
Total time taken to generate the page: 0.00933 seconds
|