Codebase list gnome-shell-extension-desktop-icons / 4fd2b5c
general: add new files top to bottom, left to right Until now, each new file was added to the free place nearest to the top-left corner. This means that the icons are added radially. This patch changes this behaviour by filling the desktop top to bottom, then left to right. This is a more natural way of doing it. It also tries in more desktops than the original. A possible enhacenment is to do it right to left when the selected language is RTL. Fixes https://gitlab.gnome.org/World/ShellExtensions/desktop-icons/issues/95 Sergio Costas authored 5 years ago Carlos Soriano committed 5 years ago
2 changed file(s) with 20 addition(s) and 10 deletion(s). Raw diff Collapse all Expand all
5858 var StoredCoordinates = {
5959 PRESERVE: 0,
6060 OVERWRITE:1,
61 ASSIGN:2,
6162 };
6263
6364 class Placeholder extends St.Bin {
371372 this.actor._desktopBackgroundManager.ignoreRelease();
372373 }
373374
374 _addFileItemTo(fileItem, column, row, overwriteCoordinates) {
375 _addFileItemTo(fileItem, column, row, coordinatesAction) {
375376 let placeholder = this.layout.get_child_at(column, row);
376377 placeholder.child = fileItem.actor;
377378 this._fileItems.push(fileItem);
385386 * Also store the new possition if it has been moved by the user,
386387 * and not triggered by a screen change.
387388 */
388 if ((fileItem.savedCoordinates == null) || (overwriteCoordinates == StoredCoordinates.OVERWRITE)) {
389 if ((fileItem.savedCoordinates == null) || (coordinatesAction == StoredCoordinates.OVERWRITE)) {
389390 let [fileX, fileY] = placeholder.get_transformed_position();
390391 fileItem.savedCoordinates = [Math.round(fileX), Math.round(fileY)];
391392 }
392393 }
393394
394 addFileItemCloseTo(fileItem, x, y, overwriteCoordinates) {
395 let [column, row] = this._getEmptyPlaceClosestTo(x, y);
396 this._addFileItemTo(fileItem, column, row, overwriteCoordinates);
397 }
398
399 _getEmptyPlaceClosestTo(x, y) {
395 addFileItemCloseTo(fileItem, x, y, coordinatesAction) {
396 let [column, row] = this._getEmptyPlaceClosestTo(x, y, coordinatesAction);
397 this._addFileItemTo(fileItem, column, row, coordinatesAction);
398 }
399
400 _getEmptyPlaceClosestTo(x, y, coordinatesAction) {
400401 let maxColumns = this._getMaxColumns();
401402 let maxRows = this._getMaxRows();
402403
421422 continue;
422423
423424 let [proposedX, proposedY] = placeholder.get_transformed_position();
425 if (coordinatesAction == StoredCoordinates.ASSIGN)
426 return [column, row];
424427 let distance = DesktopIconsUtil.distanceBetweenPoints(proposedX, proposedY, x, y);
425428 if (distance < minDistance) {
426429 found = true;
588588 }
589589
590590 _addFileItemCloseTo(item) {
591 let [x, y] = (item.savedCoordinates == null) ? [0, 0] : item.savedCoordinates;
591 let coordinates;
592 let x = 0;
593 let y = 0;
594 let coordinatesAction = DesktopGrid.StoredCoordinates.ASSIGN;
595 if (item.savedCoordinates != null) {
596 [x, y] = item.savedCoordinates;
597 coordinatesAction = DesktopGrid.StoredCoordinates.PRESERVE;
598 }
592599 let monitorIndex = findMonitorIndexForPos(x, y);
593600 let desktopGrid = this._desktopGrids[monitorIndex];
594601 try {
595 desktopGrid.addFileItemCloseTo(item, x, y, DesktopGrid.StoredCoordinates.PRESERVE);
602 desktopGrid.addFileItemCloseTo(item, x, y, coordinatesAction);
596603 } catch (e) {
597604 log(`Error adding children to desktop: ${e.message}`);
598605 }