From d5bebda6af437be44fd2caebbc948153e9c715e2 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sun, 24 Nov 2024 18:31:19 +0100 Subject: [PATCH] Formatting key-bindings and menu visibility in klayoutrc differently (one entry per line), so they are easier to edit --- src/laybasic/laybasic/layAbstractMenu.cc | 52 +++++++++++++++------- src/laybasic/laybasic/layLayoutViewBase.cc | 3 ++ 2 files changed, 39 insertions(+), 16 deletions(-) diff --git a/src/laybasic/laybasic/layAbstractMenu.cc b/src/laybasic/laybasic/layAbstractMenu.cc index bac75edbd..44de01ab0 100644 --- a/src/laybasic/laybasic/layAbstractMenu.cc +++ b/src/laybasic/laybasic/layAbstractMenu.cc @@ -76,15 +76,16 @@ std::vector > unpack_key_binding (const std::string &packed) { tl::Extractor ex (packed.c_str ()); + ex.test(";"); // backward compatibiliy std::vector > key_bindings; while (! ex.at_end ()) { - ex.test(";"); key_bindings.push_back (std::make_pair (std::string (), std::string ())); ex.read_word_or_quoted (key_bindings.back ().first); ex.test(":"); ex.read_word_or_quoted (key_bindings.back ().second); + ex.test(";"); } return key_bindings; @@ -93,17 +94,26 @@ unpack_key_binding (const std::string &packed) std::string pack_key_binding (const std::vector > &unpacked) { - std::string packed; + std::string packed = "\n"; + bool first = true; - for (std::vector >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) { - if (! packed.empty ()) { - packed += ";"; + // for easier editing we separate the entries into non-empty and empty ones and put each of them on a new line + for (int pass = 0; pass < 2; ++pass) { + for (std::vector >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) { + if ((pass == 0) == p->second.empty ()) { + continue; + } + if (! first) { + packed += ";\n"; + } + first = false; + packed += tl::to_word_or_quoted_string (p->first); + packed += ":"; + packed += tl::to_word_or_quoted_string (p->second); } - packed += tl::to_word_or_quoted_string (p->first); - packed += ":"; - packed += tl::to_word_or_quoted_string (p->second); } + packed += "\n"; return packed; } @@ -111,15 +121,16 @@ std::vector > unpack_menu_items_hidden (const std::string &packed) { tl::Extractor ex (packed.c_str ()); + ex.test(";"); // backward compatibiliy std::vector > hidden; while (! ex.at_end ()) { - ex.test(";"); hidden.push_back (std::make_pair (std::string (), false)); ex.read_word_or_quoted (hidden.back ().first); ex.test(":"); ex.read (hidden.back ().second); + ex.test(";"); } return hidden; @@ -128,17 +139,26 @@ unpack_menu_items_hidden (const std::string &packed) std::string pack_menu_items_hidden (const std::vector > &unpacked) { - std::string packed; + std::string packed = "\n"; + bool first = true; - for (std::vector >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) { - if (! packed.empty ()) { - packed += ";"; + // for easier editing we separate the entries into true and false ones and put each of them on a new line + for (int pass = 0; pass < 2; ++pass) { + for (std::vector >::const_iterator p = unpacked.begin (); p != unpacked.end (); ++p) { + if ((pass == 0) != p->second) { + continue; + } + if (! first) { + packed += ";\n"; + } + first = false; + packed += tl::to_word_or_quoted_string (p->first); + packed += ":"; + packed += tl::to_string (p->second); } - packed += tl::to_word_or_quoted_string (p->first); - packed += ":"; - packed += tl::to_string (p->second); } + packed += "\n"; return packed; } diff --git a/src/laybasic/laybasic/layLayoutViewBase.cc b/src/laybasic/laybasic/layLayoutViewBase.cc index 6d6f9ab11..a5341edb2 100644 --- a/src/laybasic/laybasic/layLayoutViewBase.cc +++ b/src/laybasic/laybasic/layLayoutViewBase.cc @@ -3986,6 +3986,9 @@ LayoutViewBase::redraw () void LayoutViewBase::transform (const db::DCplxTrans &tr) { + // NOTE: we call "finish_edits" rather than "cancel_edits" because + // "move by" while "duplicate interactive" relies on keeping the + // pasted shapes from the previous transaction. So we must not roll back. finish_edits (); lay::Editables::transform (tr); }