Beispiel #1
0
def close_view(view: sublime.View, *, force: bool = False) -> None:
    """Close the given view, discarding unsaved changes if `force` is ``True``.

    If the view is invalid (e.g. already closed), do nothing.

    :raise ValueError: if the view has unsaved changes and `force` is not ``True``.
    :raise ValueError: if the view is not closed for any other reason.
    """
    unsaved = view.is_dirty() and not view.is_scratch()

    if unsaved:
        if not force:
            raise ValueError('The view has unsaved changes.')

        with _temporarily_scratch_unsaved_views([view]):
            closed = view.close()
    else:
        closed = view.close()

    if not closed:
        raise ValueError('The view could not be closed.')
Beispiel #2
0
def close_view(view: sublime.View, *, force: bool = False) -> None:
    """Close the given view, discarding unsaved changes if `force` is ``True``.

    If the view is invalid (e.g. already closed), do nothing.

    :raise ValueError: if the view has unsaved changes and `force` is not ``True``.
    :raise ValueError: if the view is not closed for any other reason.
    """
    if view.is_dirty() and not view.is_scratch():
        if force:
            view.set_scratch(True)
        else:
            raise ValueError('The view has unsaved changes.')

    if not view.close():
        raise ValueError('The view could not be closed.')