screenshot-ui: Extract _saveScreenshot()

For simpler handling of screenshot/screencast.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/1954>
This commit is contained in:
Ivan Molodetskikh 2021-08-17 10:54:05 +03:00 committed by Marge Bot
parent 4e93d35037
commit 77eeaf6dbe

View File

@ -1523,16 +1523,21 @@ class ScreenshotUI extends St.Widget {
} }
_onCaptureButtonClicked() { _onCaptureButtonClicked() {
this._saveScreenshot();
// TODO: screencasting.
this.close();
}
_saveScreenshot() {
global.display.get_sound_player().play_from_theme( global.display.get_sound_player().play_from_theme(
'screen-capture', _('Screenshot taken'), null); 'screen-capture', _('Screenshot taken'), null);
if (this._selectionButton.checked || this._screenButton.checked) { if (this._selectionButton.checked || this._screenButton.checked) {
const content = this._stageScreenshot.get_content(); const content = this._stageScreenshot.get_content();
if (!content) { if (!content)
// Failed to capture the screenshot for some reason. return; // Failed to capture the screenshot for some reason.
this.close();
return;
}
const texture = content.get_texture(); const texture = content.get_texture();
const stream = Gio.MemoryOutputStream.new_resizable(); const stream = Gio.MemoryOutputStream.new_resizable();
@ -1572,10 +1577,8 @@ class ScreenshotUI extends St.Widget {
return; return;
const content = window.windowContent; const content = window.windowContent;
if (!content) { if (!content)
this.close();
return; return;
}
const texture = content.get_texture(); const texture = content.get_texture();
const stream = Gio.MemoryOutputStream.new_resizable(); const stream = Gio.MemoryOutputStream.new_resizable();
@ -1606,8 +1609,6 @@ class ScreenshotUI extends St.Widget {
logError(err, 'Error capturing screenshot'); logError(err, 'Error capturing screenshot');
}); });
} }
this.close();
} }
vfunc_key_press_event(event) { vfunc_key_press_event(event) {