From 71487af4119dbaff08699b54870fcb06db325b38 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Wed, 3 May 2023 00:22:34 +0200 Subject: [PATCH] Some fixes for macro editor - added missing icons for back/forward - trying to improve behavior or find, search&replace - fixed tool tips of buttons - Ctrl-R, Ctrl+Shift+R for replace and "replace all" --- src/lay/lay/MacroEditorDialog.ui | 122 +++++++--------------------- src/lay/lay/layMacroEditorDialog.cc | 23 ++---- src/lay/lay/layMacroEditorDialog.h | 1 - src/lay/lay/layMacroEditorPage.cc | 94 +++++++++++++++------ src/lay/lay/layMacroEditorPage.h | 2 + 5 files changed, 111 insertions(+), 131 deletions(-) diff --git a/src/lay/lay/MacroEditorDialog.ui b/src/lay/lay/MacroEditorDialog.ui index 95b142033..80f62e53c 100644 --- a/src/lay/lay/MacroEditorDialog.ui +++ b/src/lay/lay/MacroEditorDialog.ui @@ -94,10 +94,7 @@ - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">New folder</p></body></html> + New folder ... @@ -121,10 +118,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;">New</p></body></html> + New ... @@ -141,10 +135,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;">Delete</p></body></html> + Delete ... @@ -161,10 +152,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Rename</p></body></html> + Rename Rename @@ -181,10 +169,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Import file</p></body></html> + Import file Import @@ -208,7 +193,7 @@ p, li { white-space: pre-wrap; } - <html><head/><body><p>Save all files (Ctrl+Shift+S)</p></body></html> + Save all files (Ctrl+Shift+S) ... @@ -228,7 +213,7 @@ p, li { white-space: pre-wrap; } - <html><head/><body><p>Save current file (Ctrl+S)</p></body></html> + Save current file (Ctrl+S) ... @@ -333,8 +318,8 @@ p, li { white-space: pre-wrap; } ... - - :/back_16.png:/back_16.png + + :/back_16px.png:/back_16px.png true @@ -347,8 +332,8 @@ p, li { white-space: pre-wrap; } ... - - :/forward_16.png:/forward_16.png + + :/forward_16px.png:/forward_16px.png true @@ -365,10 +350,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Close tab</p></body></html> + Close tab close @@ -432,10 +414,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Stop script</p></body></html> + Stop script ... @@ -452,10 +431,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Pause script (Ctrl+F5)</p></body></html> + Pause script (Ctrl+F5) ... @@ -482,10 +458,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Set breakpoint (F9)</p></body></html> + Set breakpoint (F9) ... @@ -505,10 +478,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Clear all breakpoints (Ctrl+Shift+F9)</p></body></html> + Clear all breakpoints (Ctrl+Shift+F9) ... @@ -535,10 +505,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Step into procedure (F11)</p></body></html> + Step into procedure (F11) S @@ -558,10 +525,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Step over procedure or block (F10)</p></body></html> + Step over procedure or block (F10) N @@ -588,10 +552,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Enable or disable debugging</p></body></html> + Enable or disable debugging DBG @@ -618,10 +579,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Edit properties of macro</p></body></html> + Edit properties of macro P @@ -638,10 +596,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Setup colors, formats, debugger</p></body></html> + Setup colors, formats, debugger prop @@ -674,10 +629,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Find next</p></body></html> + Find next (Ctrl+F) N @@ -687,7 +639,7 @@ p, li { white-space: pre-wrap; } :/find_16px.png:/find_16px.png - F3 + Ctrl+F true @@ -709,10 +661,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Show replace mode</p></body></html> + Show replace mode ... @@ -764,10 +713,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Replace and find next</p></body></html> + Replace and find next (Ctrl+R) RN @@ -777,7 +723,7 @@ p, li { white-space: pre-wrap; } :/replace_16px.png:/replace_16px.png - + Ctrl+R true @@ -787,10 +733,7 @@ p, li { white-space: pre-wrap; } - <html><head><meta name="qrichtext" content="1" /><style type="text/css"> -p, li { white-space: pre-wrap; } -</style></head><body style=" font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;"> -<p style=" margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;">Replace all</p></body></html> + Replace all (Ctrl+Shift+R) All @@ -799,6 +742,9 @@ p, li { white-space: pre-wrap; } :/replace_all_16px.png:/replace_all_16px.png + + Ctrl+Shift+R + true @@ -1497,14 +1443,6 @@ p, li { white-space: pre-wrap; } Case Sensitive - - - Search & Replace - - - Ctrl+F - - Save As diff --git a/src/lay/lay/layMacroEditorDialog.cc b/src/lay/lay/layMacroEditorDialog.cc index 4924798da..3266b7c60 100644 --- a/src/lay/lay/layMacroEditorDialog.cc +++ b/src/lay/lay/layMacroEditorDialog.cc @@ -386,9 +386,6 @@ MacroEditorDialog::MacroEditorDialog (lay::Dispatcher *pr, lym::MacroCollection connect (actionUseRegularExpressions, SIGNAL (triggered ()), this, SLOT (search_editing ())); connect (actionCaseSensitive, SIGNAL (triggered ()), this, SLOT (search_editing ())); - addAction (actionSearchReplace); - connect (actionSearchReplace, SIGNAL (triggered ()), this, SLOT (search_replace ())); - searchEditBox->set_clear_button_enabled (true); searchEditBox->set_options_button_enabled (true); searchEditBox->set_options_menu (m); @@ -1974,7 +1971,7 @@ MacroEditorDialog::find_next_button_clicked () apply_search (true); page->find_next (); - if (sender () != searchEditBox && sender () != replaceText) { + if (! searchEditBox->hasFocus () && ! replaceText->hasFocus ()) { set_editor_focus (); } } @@ -1989,7 +1986,7 @@ MacroEditorDialog::find_prev_button_clicked () apply_search (true); page->find_prev (); - if (sender () != searchEditBox && sender () != replaceText) { + if (! searchEditBox->hasFocus () && ! replaceText->hasFocus ()) { set_editor_focus (); } } @@ -2004,7 +2001,7 @@ MacroEditorDialog::replace_next_button_clicked () apply_search (true); page->replace_and_find_next (replaceText->text ()); - if (sender () != replaceText) { + if (! searchEditBox->hasFocus () && ! replaceText->hasFocus ()) { set_editor_focus (); } } @@ -2034,12 +2031,6 @@ MacroEditorDialog::search_requested (const QString &s) search_editing (); } -void -MacroEditorDialog::search_replace () -{ - searchEditBox->setFocus (Qt::TabFocusReason); -} - void MacroEditorDialog::search_editing () { @@ -2050,7 +2041,9 @@ MacroEditorDialog::search_editing () apply_search (); page->find_reset (); // search from the initial position - page->find_next (); + if (! page->has_multi_block_selection ()) { + page->find_next (); + } } void @@ -2083,7 +2076,9 @@ MacroEditorDialog::do_search_edited () apply_search (); page->find_reset (); // search from the initial position - page->find_next (); + if (! page->has_multi_block_selection ()) { + page->find_next (); + } set_editor_focus (); } diff --git a/src/lay/lay/layMacroEditorDialog.h b/src/lay/lay/layMacroEditorDialog.h index 7461f2a2c..54d9428df 100644 --- a/src/lay/lay/layMacroEditorDialog.h +++ b/src/lay/lay/layMacroEditorDialog.h @@ -245,7 +245,6 @@ protected slots: void file_changed (const QString &path); void file_removed (const QString &path); void clear_log (); - void search_replace (); void apply_search () { apply_search (false); diff --git a/src/lay/lay/layMacroEditorPage.cc b/src/lay/lay/layMacroEditorPage.cc index 1bb507820..93b85b986 100644 --- a/src/lay/lay/layMacroEditorPage.cc +++ b/src/lay/lay/layMacroEditorPage.cc @@ -1196,63 +1196,96 @@ MacroEditorPage::replace_and_find_next (const QString &replace) return; } - QTextCursor c = mp_text->textCursor (); - if (c.hasSelection ()) { - QTextBlock b = c.block (); - int o = std::max (0, c.position () - b.position ()); - if (m_current_search.indexIn (b.text (), o) == o) { - c.insertText (interpolate_string (replace, m_current_search)); - } - } - + replace_in_selection (replace, true); find_next (); } -void +void MacroEditorPage::replace_all (const QString &replace) { if (! mp_macro || mp_macro->is_readonly ()) { return; } + replace_in_selection (replace, false); +} + +void +MacroEditorPage::replace_in_selection (const QString &replace, bool first) +{ const QTextDocument *doc = mp_text->document (); QTextBlock bs = doc->begin (), be = doc->end (); + int ps = 0; + int pe = be.length (); QTextCursor c = mp_text->textCursor (); if (c.hasSelection ()) { - QTextBlock s = mp_text->document ()->findBlock (mp_text->textCursor ().selectionStart ()); - QTextBlock e = mp_text->document ()->findBlock (mp_text->textCursor ().selectionEnd ()); - if (e != s) { - bs = s; - be = e; - } + + ps = mp_text->textCursor ().selectionStart (); + pe = mp_text->textCursor ().selectionEnd (); + + bs = mp_text->document ()->findBlock (ps); + be = mp_text->document ()->findBlock (pe); + ps -= bs.position (); + pe -= be.position (); + + } else if (first) { + + // don't replace first entry without selection + return; + } c.beginEditBlock (); - for (QTextBlock b = bs; b != be; b = b.next()) { + bool done = false; + + for (QTextBlock b = bs; ; b = b.next()) { int o = 0; - while (true) { + while (!done) { + + bool substitute = false; int i = m_current_search.indexIn (b.text (), o); if (i < 0) { break; + } else if (b == bs && i < ps) { + // ignore + } else if (b == be && i >= pe) { + // ignore + done = true; } else if (m_current_search.matchedLength () == 0) { break; // avoid an infinite loop + } else { + substitute = true; } - QString r = interpolate_string (replace, m_current_search); + if (substitute) { - c.setPosition (i + b.position () + m_current_search.matchedLength ()); - c.setPosition (i + b.position (), QTextCursor::KeepAnchor); - c.insertText (r); + QString r = interpolate_string (replace, m_current_search); - o = i + r.size (); + c.setPosition (i + b.position () + m_current_search.matchedLength ()); + c.setPosition (i + b.position (), QTextCursor::KeepAnchor); + c.insertText (r); - } + o = i + r.size (); + + done = first; + + } else { + + o = i + m_current_search.matchedLength (); + + } + + } + + if (b == be || done) { + break; + } } @@ -1381,6 +1414,19 @@ MacroEditorPage::current_pos () const return mp_text->textCursor ().position () - mp_text->textCursor ().block ().position (); } +bool +MacroEditorPage::has_multi_block_selection () const +{ + QTextCursor c = mp_text->textCursor (); + if (c.selectionStart () != c.selectionEnd ()) { + QTextBlock s = mp_text->document ()->findBlock (c.selectionStart ()); + QTextBlock e = mp_text->document ()->findBlock (c.selectionEnd ()); + return e != s; + } else { + return false; + } +} + bool MacroEditorPage::tab_key_pressed () { diff --git a/src/lay/lay/layMacroEditorPage.h b/src/lay/lay/layMacroEditorPage.h index 960a13538..a689aefe5 100644 --- a/src/lay/lay/layMacroEditorPage.h +++ b/src/lay/lay/layMacroEditorPage.h @@ -246,6 +246,7 @@ public: int current_line () const; int current_pos () const; + bool has_multi_block_selection () const; void set_debugging_on (bool debugging_on); @@ -313,6 +314,7 @@ private: void fill_completer_list (); void complete (); QTextCursor get_completer_cursor (int &pos0, int &pos); + void replace_in_selection (const QString &replace, bool first); bool eventFilter (QObject *watched, QEvent *event); };