<table><tr><td style="">pino added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D22199">View Revision</a></tr></table><br /><div><div><p>In addition to the assumption done about a path being a local file: what if the selection contains more than one path/URL?</p></div></div><br /><div><strong>INLINE COMMENTS</strong><div><div style="margin: 6px 0 12px 0;"><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125160">View Inline</a><span style="color: #4b4d51; font-weight: bold;">kateopenselectionplugin.desktop:6-7</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);">Name=Open Selection
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);">Name[en_GB]=Open Selection
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);">Name[fr]=Ouvrir la sélection
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);">Comment=Opens the selected path
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Please do not add translations manually, there is a KDE-wide system to handle them.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125161">View Inline</a><span style="color: #4b4d51; font-weight: bold;">kateopenselectionplugin.desktop:9</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);">Comment=Opens the selected path
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">ditto</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125154">View Inline</a><span style="color: #4b4d51; font-weight: bold;">plugin_kateopenselection.cpp:47</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span class="n">K_PLUGIN_FACTORY_WITH_JSON</span><span class="p">(</span><span class="n">KateOpenSelectionFactory</span><span class="p">,</span><span style="color: #766510">"kateopenselectionplugin.json"</span><span class="p">,</span> <span class="n">registerPlugin</span><span style="color: #aa2211"><</span><span class="n">PluginKateOpenSelection</span><span style="color: #aa2211">></span><span class="p">();)</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><span style="color: #74777d">//K_EXPORT_PLUGIN(KateOpenSelectionFactory(KAboutData("kateopenselection","kateopenselection",ki18n("Open Selection"), "0.1", ki18n("Open selection for a source file"), KAboutData::License_LGPL_V2)) )</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">I guess there is no need for commented code in new code.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125149">View Inline</a><span style="color: #4b4d51; font-weight: bold;">yurchor</span> wrote in <span style="color: #4b4d51; font-weight: bold;">plugin_kateopenselection.cpp:59</span></div>
<div style="margin: 8px 0; padding: 0 12px; color: #74777D;"><p style="padding: 0; margin: 8px;">This seems to be a non-standard way to define a menu item. The other items are just verbs "Open", "Save, not "Opens" or "Saves".</p></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">In addition to what Yuri said:a better action text, more in line with our HIG [1] is IMHO "Open Selected Path".<br />
"Opens the selected path" can be a good tooltip or whatsthis text.</p>
<p style="padding: 0; margin: 8px;">[1] <a href="https://hig.kde.org/style/writing/index.html" class="remarkup-link" target="_blank" rel="noreferrer">https://hig.kde.org/style/writing/index.html</a></p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125157">View Inline</a><span style="color: #4b4d51; font-weight: bold;">plugin_kateopenselection.cpp:100</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">selection</span><span class="p">.</span><span class="n">endsWith</span><span class="p">(</span><span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'\n'</span><span class="p">)))</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="n">selection</span> <span style="color: #aa2211">=</span> <span class="n">selection</span><span class="p">.</span><span class="n">left</span><span class="p">(</span><span class="n">selection</span><span class="p">.</span><span class="n">size</span><span class="p">()</span> <span style="color: #aa2211">-</span><span style="color: #601200">1</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span class="p">}</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;"><tt style="background: #ebebeb; font-size: 13px;">selection.chop(1)</tt> is easier. Even better, directly trim the string to remove all whitespaces at the beginning and at the end.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125155">View Inline</a><span style="color: #4b4d51; font-weight: bold;">plugin_kateopenselection.cpp:114</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #74777d">// Stop at first white space or quote (for path with space, user should select the text)</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">while</span><span class="p">(</span><span class="n">start</span> <span style="color: #aa2211">></span> <span style="color: #601200">0</span> <span style="color: #aa2211">&&</span> <span class="p">(</span><span class="n">c</span> <span style="color: #aa2211">=</span> <span class="n">line</span><span class="p">.</span><span class="n">at</span><span class="p">(</span><span class="n">start</span><span style="color: #aa2211">-</span><span style="color: #601200">1</span><span class="p">))</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">' '</span><span class="p">)</span> <span style="color: #aa2211">&&</span> <span class="n">c</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'\t'</span><span class="p">)</span> <span style="color: #aa2211">&&</span> <span class="n">c</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'"'</span><span class="p">)</span> <span style="color: #aa2211">&&</span> <span class="n">c</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'\''</span><span class="p">))</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa2211">--</span><span class="n">start</span><span class="p">;</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">This condition (and the same below for <tt style="background: #ebebeb; font-size: 13px;">end</tt>) is hard to read, as it mixes checks and an assignment mid-way.<br />
A suggestion to make it simpler, and also avoid the duplicated checks is to put the character checks in a small helper:</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="c++" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);"><span style="color: #aa4000">static</span> <span style="color: #aa4000">bool</span> <span style="color: #004012">isValidChar</span><span class="p">(</span><span class="n">QChar</span> <span class="n">c</span><span class="p">)</span>
<span class="p">{</span>
<span style="color: #aa4000">return</span> <span class="n">c</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">' '</span><span class="p">)</span> <span style="color: #aa2211">&&</span> <span class="n">c</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'\t'</span><span class="p">)</span> <span style="color: #aa2211">&&</span> <span class="n">c</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'"'</span><span class="p">)</span> <span style="color: #aa2211">&&</span> <span class="n">c</span> <span style="color: #aa2211">!=</span> <span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'\''</span><span class="p">);</span>
<span class="p">}</span></pre></div>
<p style="padding: 0; margin: 8px;">and thus using it:</p>
<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="c++" data-sigil="remarkup-code-block"><pre class="remarkup-code" style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; padding: 12px; margin: 0; background: rgba(71, 87, 120, 0.08);"><span style="color: #aa4000">while</span> <span class="p">(</span><span class="n">start</span> <span style="color: #aa2211">></span> <span style="color: #601200">0</span> <span style="color: #aa2211">&&</span> <span class="n">isValidChar</span><span class="p">(</span><span class="n">line</span><span class="p">.</span><span class="n">at</span><span class="p">(</span><span class="n">start</span> <span style="color: #aa2211">-</span> <span style="color: #601200">1</span><span class="p">))</span></pre></div>
<p style="padding: 0; margin: 8px;">Way more readable IMHO.</p>
<p style="padding: 0; margin: 8px;">Also, most probably other characters can be excluded from what is a file path -- for example word boundaries, newlines, etc. Check the QChar API documentation to see whether there are character classes that can help here.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125156">View Inline</a><span style="color: #4b4d51; font-weight: bold;">plugin_kateopenselection.cpp:134</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #74777d">// Open the file</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #aa2211">!</span><span class="n">selection</span><span class="p">.</span><span class="n">isEmpty</span><span class="p">()</span> <span style="color: #aa2211">&&</span> <span style="color: #aa2211">!</span><span class="n">selection</span><span class="p">.</span><span class="n">contains</span><span class="p">(</span><span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'\n'</span><span class="p">)))</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">const</span> <span class="n">QUrl</span> <span class="n">url</span> <span style="color: #aa2211">=</span> <span class="n">QUrl</span><span style="color: #aa2211">::</span><span class="n">fromLocalFile</span><span class="p">(</span><span class="n">selection</span><span class="p">);</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Excluding the newline in the code above (see my <tt style="background: #ebebeb; font-size: 13px;">isValidChar()</tt> suggestion) can avoid the need to check for newline here.</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125158">View Inline</a><span style="color: #4b4d51; font-weight: bold;">plugin_kateopenselection.cpp:135</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span style="color: #aa2211">!</span><span class="n">selection</span><span class="p">.</span><span class="n">isEmpty</span><span class="p">()</span> <span style="color: #aa2211">&&</span> <span style="color: #aa2211">!</span><span class="n">selection</span><span class="p">.</span><span class="n">contains</span><span class="p">(</span><span class="n">QLatin1Char</span><span class="p">(</span><span style="color: #766510">'\n'</span><span class="p">)))</span> <span class="p">{</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">const</span> <span class="n">QUrl</span> <span class="n">url</span> <span style="color: #aa2211">=</span> <span class="n">QUrl</span><span style="color: #aa2211">::</span><span class="n">fromLocalFile</span><span class="p">(</span><span class="n">selection</span><span class="p">);</span>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <span style="color: #aa4000">if</span> <span class="p">(</span><span class="n">fileExists</span><span class="p">(</span><span class="n">url</span><span class="p">))</span> <span class="p">{</span>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">This assumes the string is a local file -- what if under the cursor there is a remote URL?</p></div></div><br /><div style="border: 1px solid #C7CCD9; border-radius: 3px;"><div style="padding: 0; background: #F7F7F7; border-color: #e3e4e8; border-style: solid; border-width: 0 0 1px 0; margin: 0;"><div style="color: #74777d; background: #eff2f4; padding: 6px 8px; overflow: hidden;"><a style="float: right; text-decoration: none;" href="https://phabricator.kde.org/D22199#inline-125159">View Inline</a><span style="color: #4b4d51; font-weight: bold;">ui.rc:3</span></div>
<div style="font: 11px/15px "Menlo", "Consolas", "Monaco", monospace; white-space: pre-wrap; clear: both; padding: 4px 0; margin: 0;"><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><!DOCTYPE kpartgui>
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"><gui name="kateopenselection" library="libkateopenselectionplugin" version="5" translationDomain="kateopenselection">
</div><div style="padding: 0 8px; margin: 0 4px; background: rgba(151, 234, 151, .6);"> <MenuBar>
</div></div></div>
<div style="margin: 8px 0; padding: 0 12px;"><p style="padding: 0; margin: 8px;">Since it is a new plugin, I'd start with version=1.</p></div></div></div></div></div><br /><div><strong>REPOSITORY</strong><div><div>R40 Kate</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D22199">https://phabricator.kde.org/D22199</a></div></div><br /><div><strong>To: </strong>nononux<br /><strong>Cc: </strong>pino, yurchor, kwrite-devel, kde-doc-english, gennad, fbampaloukas, domson, michaelh, ngraham, demsking, skadinna, cullmann, sars, dhaumann<br /></div>