Skip to content

Commit

Permalink
Merge 0ecb26c into 9ca4126
Browse files Browse the repository at this point in the history
  • Loading branch information
kaste committed Aug 5, 2019
2 parents 9ca4126 + 0ecb26c commit 27f136e
Show file tree
Hide file tree
Showing 18 changed files with 618 additions and 316 deletions.
2 changes: 1 addition & 1 deletion common/global_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def on_activated(self, view):
# status bar is handled by GsStatusBarEventListener
util.view.refresh_gitsavvy(view, refresh_status_bar=False)

def on_close(self, view):
def on_pre_close(self, view):
util.view.handle_closed_view(view)


Expand Down
28 changes: 22 additions & 6 deletions common/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
from ..core.settings import GitSavvySettings


if False:
from typing import Optional

interfaces = {}
edit_views = {}
subclasses = []
Expand Down Expand Up @@ -81,12 +84,13 @@ def __init__(self, repo_path=None, view=None):
self.render(nuke_cursors=False)
else:
self.create_view(repo_path)
sublime.set_timeout_async(self.on_new_dashboard, 0)
self.on_new_dashboard()

if hasattr(self, "tab_size"):
self.view.settings().set("tab_size", self.tab_size)

interfaces[self.view.id()] = self
self.on_create()

def create_view(self, repo_path):
window = sublime.active_window()
Expand Down Expand Up @@ -230,6 +234,18 @@ def on_new_dashboard(self):
"""
pass

def on_create(self):
"""
Hook template method called after creating the interface
"""
pass

def on_close(self):
"""
Hook template method called just before closing the view.
"""
pass


def partial(key):
def decorator(fn):
Expand Down Expand Up @@ -283,6 +299,7 @@ def register_listeners(InterfaceClass):


def get_interface(view_id):
# type: (sublime.ViewId) -> Optional[Interface]
return interfaces.get(view_id, None)


Expand All @@ -293,12 +310,11 @@ class GsInterfaceCloseCommand(TextCommand):
"""

def run(self, edit):
sublime.set_timeout_async(self.run_async, 0)

def run_async(self):
view_id = self.view.id()
if view_id in interfaces:
del interfaces[view_id]
interface = get_interface(view_id)
if interface:
interface.on_close()
sublime.set_timeout_async(lambda: interfaces.pop(view_id))


class GsInterfaceRefreshCommand(TextCommand):
Expand Down
29 changes: 16 additions & 13 deletions common/util/debug.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
import functools
import json
import pprint as _pprint

from contextlib import contextmanager
import threading

from ...core.settings import GitSavvySettings


# Preserve state of `enabled` during hot-reloads
try:
enabled
except NameError:
enabled = False

_log = []
enabled = False
ENCODING_NOT_UTF8 = "{} was sent as binaries and we dont know the encoding, not utf-8"


Expand All @@ -23,16 +28,6 @@ def stop_logging():
enabled = False


@contextmanager
def disable_logging():
global enabled
enabled = False
try:
yield
finally:
enabled = True


def get_log():
return json.dumps(_log, indent=2)

Expand All @@ -54,6 +49,14 @@ def make_log_message(_type, **kwargs):

def log_git(command, stdin, stdout, stderr, seconds):
""" Add git command details to debug log """
global enabled
if enabled:
print(' ({thread}) [{runtime:3.0f}ms] $ {cmd}'.format(
thread=threading.current_thread().name[0],
cmd=' '.join(['git'] + list(filter(None, command))),
runtime=seconds * 1000,
))

message = make_log_message(
'git', command=command, stdin=stdin, stdout=stdout, stderr=stderr,
seconds=seconds
Expand Down
1 change: 0 additions & 1 deletion core/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from .reflog import *
from .merge import*
from .changelog import *
from .status_bar import *
from .reset import *
from .remote import *
from .custom import *
Expand Down
92 changes: 0 additions & 92 deletions core/commands/status_bar.py

This file was deleted.

Loading

0 comments on commit 27f136e

Please sign in to comment.