<table><tr><td style="">wsdfhjxc 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/D11352">View Revision</a></tr></table><br /><div><div><p>Unfortunately, comparing by <tt style="background: #ebebeb; font-size: 13px;">item.text</tt> with a non-US language enabled makes the result worse than on previous screenshot (especially the order of items within the <tt style="background: #ebebeb; font-size: 13px;">Hardware</tt> group is very odd). To get it consistent regardless of system's language setting it might be better to compare by <tt style="background: #ebebeb; font-size: 13px;">item.itemId</tt>. Although <tt style="background: #ebebeb; font-size: 13px;">StatusNotifierItem</tt> may have it undefined initially, it can be fixed with a timer hack and waiting till a proper <tt style="background: #ebebeb; font-size: 13px;">Id</tt> is available, then updating the <tt style="background: #ebebeb; font-size: 13px;">itemId</tt> property and calling <tt style="background: #ebebeb; font-size: 13px;">updateItemVisibility()</tt> function.</p>

<p>Modifying the comparing function to look at <tt style="background: #ebebeb; font-size: 13px;">item.itemId</tt> instead of <tt style="background: #ebebeb; font-size: 13px;">item.text</tt> makes the result no better than it was originally. However, if compared strings are slightly altered in a specific way, the result might be better (something like a seed to get the most satisfying pattern). For example:</p>

<div class="remarkup-code-block" style="margin: 12px 0;" data-code-lang="qml" 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">function</span> <span style="color: #004012">compareItems</span><span class="p">(</span><span style="color: #004012">a</span><span class="p">,</span> <span style="color: #004012">b</span><span class="p">)</span> <span class="p">{</span>
    <span style="color: #aa4000">var</span> <span style="color: #004012">categoryDiff</span> <span style="color: #aa2211">=</span> <span style="color: #004012">indexForItemCategory</span><span class="p">(</span><span style="color: #004012">a</span><span class="p">)</span> <span style="color: #aa2211">-</span> <span style="color: #004012">indexForItemCategory</span><span class="p">(</span><span style="color: #004012">b</span><span class="p">)</span>
    <span style="color: #aa4000">var</span> <span style="color: #004012">altA</span> <span style="color: #aa2211">=</span> <span style="color: #004012">a</span><span class="p">.</span><span style="color: #004012">itemId</span> <span style="color: #aa2211">?</span> <span style="color: #004012">a</span><span class="p">.</span><span style="color: #004012">itemId</span><span class="p">.</span><span style="color: #004012">replace</span><span class="p">(</span><span style="color: #766510">"org.kde."</span><span class="p">,</span> <span style="color: #766510">""</span><span class="p">).</span><span style="color: #004012">replace</span><span class="p">(</span><span style="color: #766510">"plasma."</span><span class="p">,</span> <span style="color: #766510">""</span><span class="p">)</span> <span style="color: #aa2211">:</span> <span style="color: #766510">""</span>
    <span style="color: #aa4000">var</span> <span style="color: #004012">altB</span> <span style="color: #aa2211">=</span> <span style="color: #004012">b</span><span class="p">.</span><span style="color: #004012">itemId</span> <span style="color: #aa2211">?</span> <span style="color: #004012">b</span><span class="p">.</span><span style="color: #004012">itemId</span><span class="p">.</span><span style="color: #004012">replace</span><span class="p">(</span><span style="color: #766510">"org.kde."</span><span class="p">,</span> <span style="color: #766510">""</span><span class="p">).</span><span style="color: #004012">replace</span><span class="p">(</span><span style="color: #766510">"plasma."</span><span class="p">,</span> <span style="color: #766510">""</span><span class="p">)</span> <span style="color: #aa2211">:</span> <span style="color: #766510">""</span>
    <span style="color: #004012">altA</span> <span style="color: #aa2211">=</span> <span style="color: #004012">altA</span><span class="p">.</span><span style="color: #004012">substring</span><span class="p">(</span><span style="color: #004012">altA</span><span class="p">.</span><span style="color: #004012">length</span> <span style="color: #aa2211">/</span> <span style="color: #601200">2</span><span class="p">,</span> <span style="color: #004012">altA</span><span class="p">.</span><span style="color: #004012">length</span><span class="p">)</span>        
    <span style="color: #004012">altB</span> <span style="color: #aa2211">=</span> <span style="color: #004012">altB</span><span class="p">.</span><span style="color: #004012">substring</span><span class="p">(</span><span style="color: #004012">altB</span><span class="p">.</span><span style="color: #004012">length</span> <span style="color: #aa2211">/</span> <span style="color: #601200">2</span><span class="p">,</span> <span style="color: #004012">altB</span><span class="p">.</span><span style="color: #004012">length</span><span class="p">)</span>
    <span style="color: #aa4000">return</span> <span style="color: #004012">categoryDiff</span> <span style="color: #aa2211">!=</span> <span style="color: #601200">0</span> <span style="color: #aa2211">?</span> <span style="color: #aa4000">categoryDiff :</span> <span style="color: #004012">altA</span><span class="p">.</span><span style="color: #004012">localeCompare</span><span class="p">(</span><span style="color: #004012">altB</span><span class="p">)</span>
<span class="p">}</span></pre></div>

<p>Screenshot below presents the item ordering result after this modification, which is consistent regardless of system's language setting and which looks nicer in my opinion.<br />
<a href="https://phabricator.kde.org/F5759917" style="background-color: #e7e7e7;
          border-color: #e7e7e7;
          border-radius: 3px;
          padding: 0 4px;
          font-weight: bold;
          color: black;text-decoration: none;">F5759917: Items.png</a></p>

<p>I don't really have any other ideas on further improvements, so forgive me if you find this one utterly stupid, I promise there will bo no more of them :)</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R120 Plasma Workspace</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D11352">https://phabricator.kde.org/D11352</a></div></div><br /><div><strong>To: </strong>Pitel<br /><strong>Cc: </strong>wsdfhjxc, mart, plasma-devel, ZrenBot, lesliezhai, ali-mohamed, jensreuterberg, abetts, sebas, apol<br /></div>