From f6281d694a11cf5d5f1f2b7c4a9fde5fe96010e5 Mon Sep 17 00:00:00 2001 From: Ianos Gnatiuc Date: Wed, 5 Oct 2005 20:35:22 +0000 Subject: [PATCH] ToggleCase on selected text --- docs/notework.txt | 2 + golded3/geedit.cpp | 136 +++++++++++++++++++++++++++++++++++++++++++++ golded3/geedit.h | 3 + 3 files changed, 141 insertions(+) diff --git a/docs/notework.txt b/docs/notework.txt index 445e3f6..3bdaecc 100644 --- a/docs/notework.txt +++ b/docs/notework.txt @@ -10,6 +10,8 @@ ______________________________________________________________________ Notes for GoldED+ 1.1.5, /snapshot/ ______________________________________________________________________ ++ EditToggleCase, EditToUpper and EditToLower keys will work on selected text. + + Added MenuNextArea (yes/no/unread) config file token that set default for cursor on "Goto Next Area?" menu. diff --git a/golded3/geedit.cpp b/golded3/geedit.cpp index d1dfe66..77b7f51 100644 --- a/golded3/geedit.cpp +++ b/golded3/geedit.cpp @@ -2025,6 +2025,133 @@ void IEclass::ToggleCase() { } +// ------------------------------------------------------------------ + +void IEclass::ToggleCaseChar(gkey key, + std::string::iterator it, + Line *ln, int n) +{ + int oldchar = *it; + int newchar = *it; + + switch (key) + { + case KK_EditToLower: + newchar = tolower(*it); + break; + + case KK_EditToUpper: + newchar = toupper(*it); + break; + + case KK_EditToggleCase: + if (toupper(*it) == oldchar) + newchar = tolower(*it); + else + newchar = toupper(*it); + break; + } + + if (newchar != oldchar) + { + currline = ln; pcol = col = n; getthisrow(currline); prow = thisrow; + Undo->PushItem(EDIT_UNDO_OVR_CHAR); + *it = newchar; + } +} + + +// ------------------------------------------------------------------ + +void IEclass::ToggleCaseBlock(gkey key) +{ + GFTRK("EditToggleCaseBlock"); + + // Find the anchor, if any + Line* _anchor = findanchor(); + + // Did we find the anchor? + if (_anchor) + { + Line* oldline = currline; + int oldcol = col; + + Line* _firstline = currline; + Line* _lastline = currline; + int firstcol = col, lastcol = col; + + // Search below to find the anchor line + while (_lastline->next and (_lastline != _anchor)) + _lastline = _lastline->next; + + // Was the anchor line above or on the current line? + if (_lastline != _anchor) + { + // The last copy line is the current line + _lastline = currline; + + // Search above to find the anchor line + while (_firstline->prev and (_firstline != _anchor)) + _firstline = _firstline->prev; + firstcol = blockcol; + } + else + { + if (currline != _anchor or blockcol > col) + lastcol = blockcol; + else + firstcol = blockcol; + } + + // The _firstline and _lastline pointers + // are now pointing where they should + + int n; + Line* ln = _firstline; + std::string::iterator it1, it2; + + if (ln == _lastline) + { + it1 = ln->txt.begin() + firstcol; + it2 = ln->txt.begin() + lastcol; + for (n = firstcol; it1 < it2; it1++, n++) + ToggleCaseChar(key, it1, ln, n); + } + else + { + it1 = ln->txt.begin() + firstcol; + it2 = ln->txt.end(); + for (n = firstcol; it1 < it2; it1++, n++) + ToggleCaseChar(key, it1, ln, n); + + for (ln = ln->next; ln != _lastline; ln = ln->next) + { + it1 = ln->txt.begin(); + it2 = ln->txt.end(); + for (n = 0; it1 < it2; it1++, n++) + ToggleCaseChar(key, it1, ln, n); + } + + it1 = ln->txt.begin(); + it2 = ln->txt.begin() + lastcol; + for (n = 0; it1 < it2; it1++, n++) + ToggleCaseChar(key, it1, ln, n); + } + + currline = oldline; + pcol = col = oldcol; + getthisrow(currline); + prow = thisrow; + } + + // Refresh display + Line* _topline = findtopline(); + refresh(_topline, minrow); + + GFTRK(NULL); +} + + // ------------------------------------------------------------------ void IEclass::SCodeChange(gkey key) @@ -2242,6 +2369,15 @@ int IEclass::handlekey(gkey __key) { goto noselecting; break; + case KK_EditToLower: + case KK_EditToUpper: + case KK_EditToggleCase: + if (!selecting) goto noselecting; + + ToggleCaseBlock(__key); + undo_ready = NO; + return rc; + default: rc = PlayMacro(__key, KT_E); if(rc == true) diff --git a/golded3/geedit.h b/golded3/geedit.h index 22dcf6f..7ecf072 100644 --- a/golded3/geedit.h +++ b/golded3/geedit.h @@ -399,6 +399,7 @@ public: void SpellCheck (); void Tab (); void ToggleCase (); + void ToggleCaseBlock(gkey key); void SCodeChange(gkey key); void ToggleInsert (); void ToLower (); @@ -406,6 +407,8 @@ public: void UnDelete (bool before=true); void ZapQuoteBelow (); +private: + void ToggleCaseChar(gkey key, std::string::iterator it, Line *ln, int n); // ---------------------------------------------------------------- };