fix submenu scrollview adjustment

* auto-scroll when pointer is near the top or the bottom
* scroll with keyboard arrows

copy files-view extension
This commit is contained in:
abakkk 2020-08-06 22:10:12 +02:00
parent a1ce4aaf79
commit 075b080aaf
1 changed files with 26 additions and 5 deletions

31
menu.js
View File

@ -361,6 +361,7 @@ var DrawingMenu = new Lang.Class({
}); });
subItem.label.get_clutter_text().set_use_markup(true); subItem.label.get_clutter_text().set_use_markup(true);
getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment);
// change the display order of tools // change the display order of tools
if (obj == Area.ToolNames && i == Area.Tools.POLYGON) if (obj == Area.ToolNames && i == Area.Tools.POLYGON)
@ -392,6 +393,7 @@ var DrawingMenu = new Lang.Class({
}); });
// Foreground color markup is not displayed since 3.36, use style instead but the transparency is lost. // Foreground color markup is not displayed since 3.36, use style instead but the transparency is lost.
colorItem.label.set_style(`color:${this.area.colors[i].to_string().slice(0, 7)};`); colorItem.label.set_style(`color:${this.area.colors[i].to_string().slice(0, 7)};`);
getActor(colorItem).connect('key-focus-in', updateSubMenuAdjustment);
} }
return GLib.SOURCE_REMOVE; return GLib.SOURCE_REMOVE;
}); });
@ -417,6 +419,7 @@ var DrawingMenu = new Lang.Class({
}); });
if (FONT_FAMILY_STYLE) if (FONT_FAMILY_STYLE)
subItem.label.set_style(`font-family:${family}`); subItem.label.set_style(`font-family:${family}`);
getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment);
}); });
} }
item.menu.openOld(); item.menu.openOld();
@ -466,28 +469,29 @@ var DrawingMenu = new Lang.Class({
this.openDrawingSubMenu.removeAll(); this.openDrawingSubMenu.removeAll();
let jsons = Files.getJsons(); let jsons = Files.getJsons();
jsons.forEach(json => { jsons.forEach(json => {
let item = this.openDrawingSubMenu.addAction(`<i>${String(json)}</i>`, () => { let subItem = this.openDrawingSubMenu.addAction(`<i>${String(json)}</i>`, () => {
this.area.loadJson(json.name); this.area.loadJson(json.name);
this._updateDrawingNameMenuItem(); this._updateDrawingNameMenuItem();
this._updateSaveDrawingSubMenuItemSensitivity(); this._updateSaveDrawingSubMenuItemSensitivity();
}); });
item.label.get_clutter_text().set_use_markup(true); subItem.label.get_clutter_text().set_use_markup(true);
getActor(subItem).connect('key-focus-in', updateSubMenuAdjustment);
let expander = new St.Bin({ let expander = new St.Bin({
style_class: 'popup-menu-item-expander', style_class: 'popup-menu-item-expander',
x_expand: true, x_expand: true,
}); });
getActor(item).add_child(expander); getActor(subItem).add_child(expander);
let deleteButton = new St.Button({ style_class: 'draw-on-your-screen-menu-delete-button', let deleteButton = new St.Button({ style_class: 'draw-on-your-screen-menu-delete-button',
child: new St.Icon({ icon_name: 'edit-delete-symbolic', child: new St.Icon({ icon_name: 'edit-delete-symbolic',
style_class: 'popup-menu-icon', style_class: 'popup-menu-icon',
x_align: Clutter.ActorAlign.END }) }); x_align: Clutter.ActorAlign.END }) });
getActor(item).add_child(deleteButton); getActor(subItem).add_child(deleteButton);
deleteButton.connect('clicked', () => { deleteButton.connect('clicked', () => {
json.delete(); json.delete();
item.destroy(); subItem.destroy();
this.openDrawingSubMenuItem.setSensitive(!this.openDrawingSubMenu.isEmpty()); this.openDrawingSubMenuItem.setSensitive(!this.openDrawingSubMenu.isEmpty());
}); });
}); });
@ -547,6 +551,23 @@ var DrawingMenu = new Lang.Class({
} }
}); });
// based on ApplicationsButton.scrollToButton , https://gitlab.gnome.org/GNOME/gnome-shell-extensions/blob/master/extensions/apps-menu/extension.js
const updateSubMenuAdjustment = function(itemActor) {
let scrollView = itemActor.get_parent().get_parent();
let adjustment = scrollView.get_vscroll_bar().get_adjustment();
let scrollViewAlloc = scrollView.get_allocation_box();
let currentScrollValue = adjustment.get_value();
let height = scrollViewAlloc.y2 - scrollViewAlloc.y1;
let itemActorAlloc = itemActor.get_allocation_box();
let newScrollValue = currentScrollValue;
if (currentScrollValue > itemActorAlloc.y1 - 10)
newScrollValue = itemActorAlloc.y1 - 10;
if (height + currentScrollValue < itemActorAlloc.y2 + 10)
newScrollValue = itemActorAlloc.y2 - height + 10;
if (newScrollValue != currentScrollValue)
adjustment.set_value(newScrollValue);
};
// based on searchItem.js, https://github.com/leonardo-bartoli/gnome-shell-extension-Recents // based on searchItem.js, https://github.com/leonardo-bartoli/gnome-shell-extension-Recents
const DrawingMenuEntry = new Lang.Class({ const DrawingMenuEntry = new Lang.Class({
Name: 'DrawOnYourScreenDrawingMenuEntry', Name: 'DrawOnYourScreenDrawingMenuEntry',