New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow marking certain layouts as favourite #176
base: master
Are you sure you want to change the base?
Conversation
This commit allows the user to mark certain layouts as favourite for use with `new_window_with_favourite_layout` command, which, much like `new_window_with_current_layout`, opens a new window; the difference is that said marked layout is used as a base instead of the current one. If there are multiple layouts marked as favourite, only the first (per natural ordering in `saved_layouts`) is chosen.
2e48a3c
to
93fc6cc
Compare
class NewWindowWithFavouriteLayoutCommand(PaneCommand, WithSettings): | ||
"""Opens a new window using the favourite layout settings.""" | ||
|
||
def __init__(self, window): | ||
self.window = window | ||
super(NewWindowWithFavouriteLayoutCommand, self).__init__(window) | ||
|
||
def run(self): | ||
if not self.settings().has('saved_layouts'): | ||
return | ||
|
||
saved_layouts = self.settings().get('saved_layouts') | ||
favourite_layout = next( | ||
(layout for layout in saved_layouts if layout['favourite']), None) | ||
|
||
if favourite_layout: | ||
layout = { | ||
'cells': favourite_layout['cells'], | ||
'cols': favourite_layout['cols'], | ||
'rows': favourite_layout['rows'] | ||
} # type: sublime.Layout | ||
|
||
self.window.run_command("new_window") | ||
new_window = sublime.active_window() | ||
if new_window.is_valid(): | ||
new_window.set_layout(layout) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've introduced a concept of favorites but haven't added any documentation for the user on how to make or use those.
But anyway, I'm not sure this is the right approach. It feels unnecessarily complicated. If your issue is with the quick panel showing up unnecessarily then maybe we could just make it pick the saved layout automatically if there is just one.
Alternatively we could teach new_window_from_saved_layout
command to accept a nickname so that you could make your own command that opens a layout with specific name.
This commit allows the user to mark certain layouts as favourite for use with
new_window_with_favourite_layout
command, which, much likenew_window_with_current_layout
, opens a new window; the difference is that said marked layout is used as a base instead of the current one.If there are multiple layouts marked as favourite, only the first (per natural ordering in
saved_layouts
) is chosen.Why this PR? Most of the time I want to open a new window with the same layout as always. Yet, all I have is that single one - using
new_window_from_saved_layout
for that feels counterproductive. Furthermore, I can't use neither it nornew_window_with_current_layout
if I'm doing so from e.g. command line when no other windows exist. This is a partial remedy; I'd like to follow it up with a PR introducing a setting that would make Sublime automatically open windows using a certain layout. I haven't thought about the specifics yet - one idea is to use the marker introduced in this PR.