Merge branch 'danfis-session-save-only-active-window'
This commit is contained in:
commit
f1ecb21d3d
@ -34,6 +34,7 @@ Added
|
|||||||
- New `qute:history` URL and `:history` command to show the browsing history.
|
- New `qute:history` URL and `:history` command to show the browsing history.
|
||||||
- Open tabs are now auto-saved on each successful load and restored in case of a crash.
|
- Open tabs are now auto-saved on each successful load and restored in case of a crash.
|
||||||
- `:jseval` now has a `--file` flag so you can pass a javascript file
|
- `:jseval` now has a `--file` flag so you can pass a javascript file
|
||||||
|
- `:session-save` now has a `--only-active-window` flag to only save the active window.
|
||||||
|
|
||||||
Changed
|
Changed
|
||||||
~~~~~~~
|
~~~~~~~
|
||||||
|
@ -195,6 +195,7 @@ Contributors, sorted by the number of commits in descending order:
|
|||||||
* error800
|
* error800
|
||||||
* Michael Hoang
|
* Michael Hoang
|
||||||
* Liam BEGUIN
|
* Liam BEGUIN
|
||||||
|
* Daniel Fiser
|
||||||
* skinnay
|
* skinnay
|
||||||
* Zach-Button
|
* Zach-Button
|
||||||
* Samuel Walladge
|
* Samuel Walladge
|
||||||
|
@ -741,7 +741,8 @@ Load a session.
|
|||||||
|
|
||||||
[[session-save]]
|
[[session-save]]
|
||||||
=== session-save
|
=== session-save
|
||||||
Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] ['name']+
|
Syntax: +:session-save [*--current*] [*--quiet*] [*--force*] [*--only-active-window*]
|
||||||
|
['name']+
|
||||||
|
|
||||||
Save a session.
|
Save a session.
|
||||||
|
|
||||||
@ -753,6 +754,7 @@ Save a session.
|
|||||||
* +*-c*+, +*--current*+: Save the current session instead of the default.
|
* +*-c*+, +*--current*+: Save the current session instead of the default.
|
||||||
* +*-q*+, +*--quiet*+: Don't show confirmation message.
|
* +*-q*+, +*--quiet*+: Don't show confirmation message.
|
||||||
* +*-f*+, +*--force*+: Force saving internal sessions (starting with an underline).
|
* +*-f*+, +*--force*+: Force saving internal sessions (starting with an underline).
|
||||||
|
* +*-o*+, +*--only-active-window*+: Saves only tabs of the currently active window.
|
||||||
|
|
||||||
[[set]]
|
[[set]]
|
||||||
=== set
|
=== set
|
||||||
|
@ -213,10 +213,15 @@ class SessionManager(QObject):
|
|||||||
data['history'].append(item_data)
|
data['history'].append(item_data)
|
||||||
return data
|
return data
|
||||||
|
|
||||||
def _save_all(self):
|
def _save_all(self, *, only_window=None):
|
||||||
"""Get a dict with data for all windows/tabs."""
|
"""Get a dict with data for all windows/tabs."""
|
||||||
data = {'windows': []}
|
data = {'windows': []}
|
||||||
for win_id in objreg.window_registry:
|
if only_window is not None:
|
||||||
|
winlist = [only_window]
|
||||||
|
else:
|
||||||
|
winlist = objreg.window_registry
|
||||||
|
|
||||||
|
for win_id in winlist:
|
||||||
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
tabbed_browser = objreg.get('tabbed-browser', scope='window',
|
||||||
window=win_id)
|
window=win_id)
|
||||||
main_window = objreg.get('main-window', scope='window',
|
main_window = objreg.get('main-window', scope='window',
|
||||||
@ -254,7 +259,8 @@ class SessionManager(QObject):
|
|||||||
name = 'default'
|
name = 'default'
|
||||||
return name
|
return name
|
||||||
|
|
||||||
def save(self, name, last_window=False, load_next_time=False):
|
def save(self, name, last_window=False, load_next_time=False,
|
||||||
|
only_window=None):
|
||||||
"""Save a named session.
|
"""Save a named session.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -263,6 +269,7 @@ class SessionManager(QObject):
|
|||||||
last_window: If set, saves the saved self._last_window_session
|
last_window: If set, saves the saved self._last_window_session
|
||||||
instead of the currently open state.
|
instead of the currently open state.
|
||||||
load_next_time: If set, prepares this session to be load next time.
|
load_next_time: If set, prepares this session to be load next time.
|
||||||
|
only_window: If set, only tabs in the specified window is saved.
|
||||||
|
|
||||||
Return:
|
Return:
|
||||||
The name of the saved session.
|
The name of the saved session.
|
||||||
@ -277,7 +284,7 @@ class SessionManager(QObject):
|
|||||||
log.sessions.error("last_window_session is None while saving!")
|
log.sessions.error("last_window_session is None while saving!")
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
data = self._save_all()
|
data = self._save_all(only_window=only_window)
|
||||||
log.sessions.vdebug("Saving data: {}".format(data))
|
log.sessions.vdebug("Saving data: {}".format(data))
|
||||||
try:
|
try:
|
||||||
with qtutils.savefile_open(path) as f:
|
with qtutils.savefile_open(path) as f:
|
||||||
@ -435,8 +442,9 @@ class SessionManager(QObject):
|
|||||||
|
|
||||||
@cmdutils.register(name=['session-save', 'w'], instance='session-manager')
|
@cmdutils.register(name=['session-save', 'w'], instance='session-manager')
|
||||||
@cmdutils.argument('name', completion=usertypes.Completion.sessions)
|
@cmdutils.argument('name', completion=usertypes.Completion.sessions)
|
||||||
|
@cmdutils.argument('win_id', win_id=True)
|
||||||
def session_save(self, name: str=default, current=False, quiet=False,
|
def session_save(self, name: str=default, current=False, quiet=False,
|
||||||
force=False):
|
force=False, only_active_window=False, win_id=None):
|
||||||
"""Save a session.
|
"""Save a session.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
@ -445,6 +453,7 @@ class SessionManager(QObject):
|
|||||||
current: Save the current session instead of the default.
|
current: Save the current session instead of the default.
|
||||||
quiet: Don't show confirmation message.
|
quiet: Don't show confirmation message.
|
||||||
force: Force saving internal sessions (starting with an underline).
|
force: Force saving internal sessions (starting with an underline).
|
||||||
|
only_active_window: Saves only tabs of the currently active window.
|
||||||
"""
|
"""
|
||||||
if (name is not default and
|
if (name is not default and
|
||||||
name.startswith('_') and # pylint: disable=no-member
|
name.startswith('_') and # pylint: disable=no-member
|
||||||
@ -457,6 +466,9 @@ class SessionManager(QObject):
|
|||||||
name = self._current
|
name = self._current
|
||||||
assert not name.startswith('_')
|
assert not name.startswith('_')
|
||||||
try:
|
try:
|
||||||
|
if only_active_window:
|
||||||
|
name = self.save(name, only_window=win_id)
|
||||||
|
else:
|
||||||
name = self.save(name)
|
name = self.save(name)
|
||||||
except SessionError as e:
|
except SessionError as e:
|
||||||
raise cmdexc.CommandError("Error while saving session: {}"
|
raise cmdexc.CommandError("Error while saving session: {}"
|
||||||
|
@ -278,6 +278,31 @@ Feature: Saving and loading sessions
|
|||||||
Then "Saved session quiet_session." should not be logged
|
Then "Saved session quiet_session." should not be logged
|
||||||
And the session quiet_session should exist
|
And the session quiet_session should exist
|
||||||
|
|
||||||
|
Scenario: Saving session with --only-active-window
|
||||||
|
When I open data/numbers/1.txt
|
||||||
|
And I open data/numbers/2.txt in a new tab
|
||||||
|
And I open data/numbers/3.txt in a new window
|
||||||
|
And I open data/numbers/4.txt in a new tab
|
||||||
|
And I open data/numbers/5.txt in a new tab
|
||||||
|
And I run :session-save --only-active-window window_session_name
|
||||||
|
And I run :window-only
|
||||||
|
And I run :tab-only
|
||||||
|
And I run :session-load window_session_name
|
||||||
|
Then the session should look like:
|
||||||
|
windows:
|
||||||
|
- tabs:
|
||||||
|
- history:
|
||||||
|
- active: true
|
||||||
|
url: http://localhost:*/data/numbers/5.txt
|
||||||
|
- tabs:
|
||||||
|
- history:
|
||||||
|
- url: http://localhost:*/data/numbers/3.txt
|
||||||
|
- history:
|
||||||
|
- url: http://localhost:*/data/numbers/4.txt
|
||||||
|
- history:
|
||||||
|
- active: true
|
||||||
|
url: http://localhost:*/data/numbers/5.txt
|
||||||
|
|
||||||
# :session-delete
|
# :session-delete
|
||||||
|
|
||||||
Scenario: Deleting a directory
|
Scenario: Deleting a directory
|
||||||
|
Loading…
Reference in New Issue
Block a user