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"
This commit is contained in:
Matthias Koefferlein 2023-05-03 00:22:34 +02:00
parent 34d147f1ce
commit 71487af411
5 changed files with 111 additions and 131 deletions

View File

@ -94,10 +94,7 @@
<item>
<widget class="QToolButton" name="newFolderButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;New folder&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>New folder</string>
</property>
<property name="text">
<string>...</string>
@ -121,10 +118,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="addButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;&quot;&gt;New&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>New</string>
</property>
<property name="text">
<string>...</string>
@ -141,10 +135,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="deleteButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px; font-size:10pt;&quot;&gt;Delete&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Delete</string>
</property>
<property name="text">
<string>...</string>
@ -161,10 +152,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="renameButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Rename&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Rename</string>
</property>
<property name="text">
<string>Rename</string>
@ -181,10 +169,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="importButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:10pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Import file&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Import file</string>
</property>
<property name="text">
<string>Import</string>
@ -208,7 +193,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="saveAllButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save all files (Ctrl+Shift+S)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Save all files (Ctrl+Shift+S)</string>
</property>
<property name="text">
<string>...</string>
@ -228,7 +213,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="saveButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Save current file (Ctrl+S)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Save current file (Ctrl+S)</string>
</property>
<property name="text">
<string>...</string>
@ -333,8 +318,8 @@ p, li { white-space: pre-wrap; }
<string>...</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/back_16.png</normaloff>:/back_16.png</iconset>
<iconset resource="../../icons/icons.qrc">
<normaloff>:/back_16px.png</normaloff>:/back_16px.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
@ -347,8 +332,8 @@ p, li { white-space: pre-wrap; }
<string>...</string>
</property>
<property name="icon">
<iconset>
<normaloff>:/forward_16.png</normaloff>:/forward_16.png</iconset>
<iconset resource="../../icons/icons.qrc">
<normaloff>:/forward_16px.png</normaloff>:/forward_16px.png</iconset>
</property>
<property name="autoRaise">
<bool>true</bool>
@ -365,10 +350,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="closeButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Close tab&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Close tab</string>
</property>
<property name="text">
<string>close</string>
@ -432,10 +414,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="stopButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Stop script&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Stop script</string>
</property>
<property name="text">
<string>...</string>
@ -452,10 +431,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="pauseButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Pause script (Ctrl+F5)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Pause script (Ctrl+F5)</string>
</property>
<property name="text">
<string>...</string>
@ -482,10 +458,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="breakpointButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Set breakpoint (F9)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Set breakpoint (F9)</string>
</property>
<property name="text">
<string>...</string>
@ -505,10 +478,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="clearBreakpointsButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Clear all breakpoints (Ctrl+Shift+F9)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Clear all breakpoints (Ctrl+Shift+F9)</string>
</property>
<property name="text">
<string>...</string>
@ -535,10 +505,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="singleStepButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Step into procedure (F11)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Step into procedure (F11)</string>
</property>
<property name="text">
<string>S</string>
@ -558,10 +525,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="nextStepButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Step over procedure or block (F10)&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Step over procedure or block (F10)</string>
</property>
<property name="text">
<string>N</string>
@ -588,10 +552,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="dbgOn">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Enable or disable debugging&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Enable or disable debugging</string>
</property>
<property name="text">
<string>DBG</string>
@ -618,10 +579,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="propertiesButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Edit properties of macro&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Edit properties of macro</string>
</property>
<property name="text">
<string>P</string>
@ -638,10 +596,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="setupButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Setup colors, formats, debugger&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Setup colors, formats, debugger</string>
</property>
<property name="text">
<string>prop</string>
@ -674,10 +629,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="findNextButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Find next&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Find next (Ctrl+F)</string>
</property>
<property name="text">
<string>N</string>
@ -687,7 +639,7 @@ p, li { white-space: pre-wrap; }
<normaloff>:/find_16px.png</normaloff>:/find_16px.png</iconset>
</property>
<property name="shortcut">
<string>F3</string>
<string>Ctrl+F</string>
</property>
<property name="autoRaise">
<bool>true</bool>
@ -709,10 +661,7 @@ p, li { white-space: pre-wrap; }
</size>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Show replace mode&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Show replace mode</string>
</property>
<property name="text">
<string>...</string>
@ -764,10 +713,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="replaceNextButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Replace and find next&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Replace and find next (Ctrl+R)</string>
</property>
<property name="text">
<string>RN</string>
@ -777,7 +723,7 @@ p, li { white-space: pre-wrap; }
<normaloff>:/replace_16px.png</normaloff>:/replace_16px.png</iconset>
</property>
<property name="shortcut">
<string/>
<string>Ctrl+R</string>
</property>
<property name="autoRaise">
<bool>true</bool>
@ -787,10 +733,7 @@ p, li { white-space: pre-wrap; }
<item>
<widget class="QToolButton" name="replaceAllButton">
<property name="toolTip">
<string>&lt;html&gt;&lt;head&gt;&lt;meta name=&quot;qrichtext&quot; content=&quot;1&quot; /&gt;&lt;style type=&quot;text/css&quot;&gt;
p, li { white-space: pre-wrap; }
&lt;/style&gt;&lt;/head&gt;&lt;body style=&quot; font-family:'Sans Serif'; font-size:9pt; font-weight:400; font-style:normal; text-decoration:none;&quot;&gt;
&lt;p style=&quot; margin-top:0px; margin-bottom:0px; margin-left:0px; margin-right:0px; -qt-block-indent:0; text-indent:0px;&quot;&gt;Replace all&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Replace all (Ctrl+Shift+R)</string>
</property>
<property name="text">
<string>All</string>
@ -799,6 +742,9 @@ p, li { white-space: pre-wrap; }
<iconset resource="../../icons/icons.qrc">
<normaloff>:/replace_all_16px.png</normaloff>:/replace_all_16px.png</iconset>
</property>
<property name="shortcut">
<string>Ctrl+Shift+R</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
@ -1497,14 +1443,6 @@ p, li { white-space: pre-wrap; }
<string>Case Sensitive</string>
</property>
</action>
<action name="actionSearchReplace">
<property name="text">
<string>Search &amp; Replace</string>
</property>
<property name="shortcut">
<string>Ctrl+F</string>
</property>
</action>
<action name="actionSaveAs">
<property name="text">
<string>Save As</string>

View File

@ -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 ();
}

View File

@ -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);

View File

@ -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 ()
{

View File

@ -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);
};