<commit_before>import time
import weakref

import gtk

from snaked.core.shortcuts import ContextShortcutActivator, register_shortcut
import snaked.core.manager
import snaked.core.editor

tab_bar_pos_mapping = {
    'top': gtk.POS_TOP,
    'bottom': gtk.POS_BOTTOM,
    'left': gtk.POS_LEFT,
    'right': gtk.POS_RIGHT
}

class TabbedEditorManager(snaked.core.manager.EditorManager):
    def __init__(self, session):
        super(TabbedEditorManager, self).__init__(session)

        self.last_switch_time = None
        self.panels = weakref.WeakKeyDictionary()

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect('delete-event', self.on_delete_event)
        self.window.connect('window-state-event', self.on_state_event)

        self.window.set_property('default-width', 800)
        self.window.set_property('default-height', 500)

        self.activator = ContextShortcutActivator(self.window, self.get_context)

        self.main_pane = gtk.VPaned()
        self.main_pane_position_set = False
        self.window.add(self.main_pane)

        self.note = gtk.Notebook()
        self.note.set_show_border(False)
        self.note.set_show_tabs(self.snaked_conf['SHOW_TABS'])
        self.note.set_scrollable(True)
        self.note.set_property('tab-hborder', 10)
        self.note.set_property('homogeneous', False)
        self.note.connect_after('switch-page', self.on_switch_page)
        self.note.connect('page_removed', self.on_page_removed)
        self.note.connect('page_reordered', self.on_page_reordered)
        self.note.props.tab_pos = tab_bar_pos_mapping.get(
        self.snaked_conf['TAB_BAR_PLACEMENT'], gtk.POS_TOP)
        self.main_pane.add1(self.note)

        register_shortcut('toggle-tabs-visibility', '<alt>F11', 'Window', 'Toggles tabs visibility')
        register_shortcut('next-editor', '<alt>Right', 'Window', 'Switches to next editor')
        register_shortcut('prev-editor', '<alt>Left', 'Window', 'Switches to previous editor')
        register_shortcut('next-editor-alt', '<ctrl>Page_Down', 'Window', 'Switches to next editor')
        register_shortcut('prev-editor-alt', '<ctrl>Page_Up', 'Window', 'Switches to previous editor')
        register_shortcut('move-tab-left', '<shift><ctrl>Page_Up', 'Window', 'Move tab to the left')
        register_shortcut('move-tab-right', '<shift><ctrl>Page_Down', 'Window', 'Move tab to the right')

        register_shortcut('fullscreen', 'F11', 'Window', 'Toggles fullscreen mode')

        register_shortcut('toggle-console', '<alt>grave', 'Window', 'Toggles console')
        register_shortcut('send-to-console', '<alt>Return', 'Window',
            'Send selection or buffer to console')

        if self.snaked_conf['RESTORE_POSITION'] and 'LAST_POSITION' in self.snaked_conf:
            pos, size = self.snaked_conf['LAST_POSITION']
            self.window.move(*pos)
            self.window.resize(*size)

        self.window.show_all()

        if self.snaked_conf['FULLSCREEN']:
            self.window.fullscreen()

    def get_context(self):
        widget = self.note.get_nth_page(self.note.get_current_page())
        for e in self.editors:
            if e.widget is widget:
                return (e,)

        return (None,)

    def manage_editor(self, editor):
        label = gtk.Label('Unknown')
        self.note.append_page(editor.widget, label)
        self.note.set_tab_reorderable(editor.widget, True)
        self.focus_editor(editor)
        editor.view.grab_focus()

    def focus_editor(self, editor):
        idx = self.note.page_num(editor.widget)
        self.note.set_current_page(idx)

    def update_top_level_title(self):
        idx = self.note.get_current_page()
        if idx < 0:
            return

        editor = self.get_context()[0]
        if editor:
            title = editor.get_window_title.emit()

        if not title:
            title = self.note.get_tab_label_text(self.note.get_nth_page(idx))

        if title is not None:
            self.window.set_title(title)

    def set_editor_title(self, editor, title):
        self.note.set_tab_label_text(editor.widget, title)
        if self.note.get_current_page() == self.note.page_num(editor.widget):
            self.update_top_level_title()

    def on_delete_event(self, *args):
        self.quit(self.get_context()[0])

    def on_state_event(self, widget, event):
        state = event.new_window_stat
        if state & gtk.gdk.WINDOW_STATE_MAXIMIZED or state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
            self.window.set_border_width(0)
        else:<commit_msg>Hiding border in fullscreen and maximized state<commit_after>import time
import weakref

import gtk

from snaked.core.shortcuts import ContextShortcutActivator, register_shortcut
import snaked.core.manager
import snaked.core.editor

tab_bar_pos_mapping = {
    'top': gtk.POS_TOP,
    'bottom': gtk.POS_BOTTOM,
    'left': gtk.POS_LEFT,
    'right': gtk.POS_RIGHT
}

class TabbedEditorManager(snaked.core.manager.EditorManager):
    def __init__(self, session):
        super(TabbedEditorManager, self).__init__(session)

        self.last_switch_time = None
        self.panels = weakref.WeakKeyDictionary()

        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
        self.window.connect('delete-event', self.on_delete_event)

        # set border width handling, see self.on_state_event for more details
        self.window.connect('window-state-event', self.on_state_event)
        self.note.set_border_width(0)
        self.note.set_show_border(False)

        self.window.set_property('default-width', 800)
        self.window.set_property('default-height', 500)

        self.activator = ContextShortcutActivator(self.window, self.get_context)

        self.main_pane = gtk.VPaned()
        self.main_pane_position_set = False
        self.window.add(self.main_pane)

        self.note = gtk.Notebook()
        self.note.set_show_tabs(self.snaked_conf['SHOW_TABS'])
        self.note.set_scrollable(True)
        self.note.set_property('tab-hborder', 10)
        self.note.set_property('homogeneous', False)
        self.note.connect_after('switch-page', self.on_switch_page)
        self.note.connect('page_removed', self.on_page_removed)
        self.note.connect('page_reordered', self.on_page_reordered)
        self.note.props.tab_pos = tab_bar_pos_mapping.get(
        self.snaked_conf['TAB_BAR_PLACEMENT'], gtk.POS_TOP)
        self.main_pane.add1(self.note)

        register_shortcut('toggle-tabs-visibility', '<alt>F11', 'Window', 'Toggles tabs visibility')
        register_shortcut('next-editor', '<alt>Right', 'Window', 'Switches to next editor')
        register_shortcut('prev-editor', '<alt>Left', 'Window', 'Switches to previous editor')
        register_shortcut('next-editor-alt', '<ctrl>Page_Down', 'Window', 'Switches to next editor')
        register_shortcut('prev-editor-alt', '<ctrl>Page_Up', 'Window', 'Switches to previous editor')
        register_shortcut('move-tab-left', '<shift><ctrl>Page_Up', 'Window', 'Move tab to the left')
        register_shortcut('move-tab-right', '<shift><ctrl>Page_Down', 'Window', 'Move tab to the right')

        register_shortcut('fullscreen', 'F11', 'Window', 'Toggles fullscreen mode')

        register_shortcut('toggle-console', '<alt>grave', 'Window', 'Toggles console')
        register_shortcut('send-to-console', '<alt>Return', 'Window',
            'Send selection or buffer to console')

        if self.snaked_conf['RESTORE_POSITION'] and 'LAST_POSITION' in self.snaked_conf:
            pos, size = self.snaked_conf['LAST_POSITION']
            self.window.move(*pos)
            self.window.resize(*size)

        self.window.show_all()

        if self.snaked_conf['FULLSCREEN']:
            self.window.fullscreen()

    def get_context(self):
        widget = self.note.get_nth_page(self.note.get_current_page())
        for e in self.editors:
            if e.widget is widget:
                return (e,)

        return (None,)

    def manage_editor(self, editor):
        label = gtk.Label('Unknown')
        self.note.append_page(editor.widget, label)
        self.note.set_tab_reorderable(editor.widget, True)
        self.focus_editor(editor)
        editor.view.grab_focus()

    def focus_editor(self, editor):
        idx = self.note.page_num(editor.widget)
        self.note.set_current_page(idx)

    def update_top_level_title(self):
        idx = self.note.get_current_page()
        if idx < 0:
            return

        editor = self.get_context()[0]
        if editor:
            title = editor.get_window_title.emit()

        if not title:
            title = self.note.get_tab_label_text(self.note.get_nth_page(idx))

        if title is not None:
            self.window.set_title(title)

    def set_editor_title(self, editor, title):
        self.note.set_tab_label_text(editor.widget, title)
        if self.note.get_current_page() == self.note.page_num(editor.widget):
            self.update_top_level_title()

    def on_delete_event(self, *args):
        self.quit(self.get_context()[0])

    def on_state_event(self, widget, event):
        """Sets the window border depending on state
        
        The window border eases the resizing of the window using the mouse.
        In maximized and fullscreen state the this use case is irrelevant.
        Removing the border in this cases makes it easier to hit the scrollbar.
        
        Unfortunately this currently only works with tabs hidden.
        """
        state = event.new_window_state
        if state & gtk.gdk.WINDOW_STATE_MAXIMIZED or state & gtk.gdk.WINDOW_STATE_FULLSCREEN:
            self.window.set_border_width(0)
        else:
{'fraction_non_alphanumeric': 0.11766522544780729, 'fraction_numerical': 0.0036030471484455426, 'mean_word_length': 3.0211092715231787, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 25, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '76935', 'n_tokens_mistral': 3118, 'n_tokens_neox': 3029, 'n_words': 554}