screenshot: Use GLib.BookmarkFile to save recent screenshots
Avoid the GTK dependency, and use the common GLib API to store screenshots in recent files. While at it, give it a better exec hint than the implicit "gnome-shell %u" GTK added for us, nobody seems to pay attention to that, but if they ever did it's better to provide sensible information. Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2656>
This commit is contained in:
parent
1f7e03ab5e
commit
b89d90eb80
@ -1,7 +1,7 @@
|
|||||||
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
// -*- mode: js; js-indent-level: 4; indent-tabs-mode: nil -*-
|
||||||
/* exported ScreenshotService, ScreenshotUI, showScreenshotUI, captureScreenshot */
|
/* exported ScreenshotService, ScreenshotUI, showScreenshotUI, captureScreenshot */
|
||||||
|
|
||||||
const { Clutter, Cogl, Gio, GObject, GLib, Graphene, Gtk, Meta, Shell, St } = imports.gi;
|
const {Clutter, Cogl, Gio, GObject, GLib, Graphene, Meta, Shell, St} = imports.gi;
|
||||||
|
|
||||||
const GrabHelper = imports.ui.grabHelper;
|
const GrabHelper = imports.ui.grabHelper;
|
||||||
const Layout = imports.ui.layout;
|
const Layout = imports.ui.layout;
|
||||||
@ -2060,6 +2060,33 @@ function _storeScreenshot(bytes, pixbuf) {
|
|||||||
yield `-${i}`;
|
yield `-${i}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a record of a screenshot file in the recently used files list.
|
||||||
|
*
|
||||||
|
* @param {Gio.File} screenshotFile - The screenshot file.
|
||||||
|
*/
|
||||||
|
function saveRecentFile(screenshotFile) {
|
||||||
|
const recentFile =
|
||||||
|
GLib.build_filenamev([GLib.get_user_data_dir(), 'recently-used.xbel']);
|
||||||
|
const uri = screenshotFile.get_uri();
|
||||||
|
const bookmarks = new GLib.BookmarksFile();
|
||||||
|
try {
|
||||||
|
bookmarks.load_from_file(recentFile);
|
||||||
|
} catch (e) {
|
||||||
|
if (!e.matches(GLib.BookmarkFileError.FILE_NOT_FOUND)) {
|
||||||
|
log(`Could not open recent file ${uri}: ${e.message}`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
bookmarks.add_application(uri, GLib.get_prgname(), 'gio open %u');
|
||||||
|
bookmarks.to_file(recentFile);
|
||||||
|
} catch (e) {
|
||||||
|
log(`Could not save recent file ${uri}: ${e.message}`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const lockdownSettings =
|
const lockdownSettings =
|
||||||
new Gio.Settings({ schema_id: 'org.gnome.desktop.lockdown' });
|
new Gio.Settings({ schema_id: 'org.gnome.desktop.lockdown' });
|
||||||
const disableSaveToDisk =
|
const disableSaveToDisk =
|
||||||
@ -2102,7 +2129,7 @@ function _storeScreenshot(bytes, pixbuf) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Add it to recent files.
|
// Add it to recent files.
|
||||||
Gtk.RecentManager.get_default().add_item(file.get_uri());
|
saveRecentFile(file);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a St.ImageContent icon for the notification. We want
|
// Create a St.ImageContent icon for the notification. We want
|
||||||
|
Loading…
Reference in New Issue
Block a user