<commit_before>'''
 ====================================================================
 Copyright (c) 2003-2017 <NAME>.  All rights reserved.

 This software is licensed as described in the file LICENSE.txt,
 which you should have received as part of this distribution.

 ====================================================================

    wb_scm_preferences_dialog.py

    Based on code from pysvn WorkBench

'''
import pathlib

from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore

import wb_pick_path_dialogs
import wb_shell_commands
import wb_platform_specific
import wb_dialog_bases

class WbScmPreferencesDialog(wb_dialog_bases.WbTabbedDialog):
    def __init__( self, app, parent ):
        self.app = app

        super().__init__( parent=parent, size=(75, 20) )

        self.setWindowTitle( T_('Preferences - %s') % (' '.join( app.app_name_parts ),) )

    def completeTabsInit( self ):
        self.tabs = QtWidgets.QTabWidget()
        for tab_class in (ProjectsTab, EditorTab, ShellTab, LogHistoryTab, FontTab):
            tab = tab_class( self.app )
            self.addTab( tab )

        for tab in self.app.prefs_manager.getAllPreferenceTabs():
            self.addTab( tab )

    def savePreferences( self ):
        for index in range( self.tabs.count() ):
            tab = self.tabs.widget( index )
            tab.savePreferences()

class ProjectsTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Projects') )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.projects_defaults

        self.new_projects_folder = QtWidgets.QLineEdit()
        if self.prefs.new_projects_folder is not None:
            self.new_projects_folder.setText( str(self.prefs.new_projects_folder) )

        else:            # show the default
            self.new_projects_folder.setText( str(wb_platform_specific.getHomeFolder()) )

        self.browse_folder = QtWidgets.QPushButton( T_('Browse...') )
        self.browse_folder.clicked.connect( self.__pickFolder )

        self.addRow( T_('New projects folder'), self.new_projects_folder, self.browse_folder )

    def savePreferences( self ):
        if self.prefs is None:
            return

        self.prefs.new_projects_folder = self.new_projects_folder.text()

    def __pickFolder( self ):
        folder = wb_pick_path_dialogs.pickFolder( self, pathlib.Path( self.new_projects_folder.text() ) )
        if folder is not None:
            self.new_projects_folder.setText( str(folder) )

class EditorTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Editor') )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.editor

        self.editor_program = QtWidgets.QLineEdit( '' )
        self.editor_options = QtWidgets.QLineEdit( '' )

        if self.prefs is not None:
            self.editor_program.setText( self.prefs.program )
            self.editor_options.setText( self.prefs.options )

        self.browse = QtWidgets.QPushButton( T_('Browse…') )

        self.addRow( T_('Editor'), self.editor_program, self.browse )
        self.addRow( T_('Editor Options'), self.editor_options )

        self.browse.clicked.connect( self.pickEditor )

    def savePreferences( self ):
        if self.prefs is None:
            return

        self.prefs.program = self.editor_program.text()
        self.prefs.options = self.editor_options.text()

    def pickEditor( self ):
        editor = wb_pick_path_dialogs.pickExecutable( self, pathlib.Path( self.editor_program.text() ) )
        if editor is not None:
            self.editor_program.setText( str(editor) )

class ShellTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Shell') )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.shell

        terminal_program_list = wb_shell_commands.getTerminalProgramList()
        file_browser_program_list = wb_shell_commands.getFileBrowserProgramList()

        self.terminal_program = QtWidgets.QComboBox()
        self.terminal_program.addItems( terminal_program_list )
        self.terminal_init = QtWidgets.QLineEdit( '' )
        self.file_browser_program = QtWidgets.QComboBox()
        self.file_browser_program.addItems( file_browser_program_list )

        if self.prefs is not None:
            self.terminal_program.setCurrentText( self.prefs.terminal_program )
            self.terminal_init.setText( self.prefs.terminal_init )
            self.file_browser_program.setCurrentText( self.prefs.file_browser )

        self.addRow( T_('Terminal Program'), self.terminal_program )
        self.addRow( T_('Terminal Init Command'), self.terminal_init )
        self.addRow( T_('File Browser Program'), self.file_browser_program )

    def savePreferences( self ):
        if self.prefs is None:
            return

        self.prefs.terminal_program = self.terminal_program.currentText()
        self.prefs.terminal_init = self.terminal_init.text()
        self.prefs.file_browser = self.file_browser_program.currentText()

class LogHistoryTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Commit Log History - %s') % (' '.join( app.app_name_parts ),) )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.log_history

        self.default_limit = QtWidgets.QSpinBox()
        self.default_limit.setRange( 1, 100000 )
        self.default_limit.setSuffix( T_(' Commits') )

        self.use_default_limit = QtWidgets.QCheckBox( T_('Use limit') )

        self.default_until = QtWidgets.QSpinBox()
        self.default_until.setRange( 1, 365 )
        self.default_until.setSuffix( T_(' days') )

        self.use_default_until = QtWidgets.QCheckBox( T_('Use until') )

        self.default_since = QtWidgets.QSpinBox()
        self.default_since.setRange( 2, 365 )
        self.default_since.setSuffix( T_(' days') )

        self.use_default_since = QtWidgets.QCheckBox( T_('Use since') )

        if self.prefs is not None:
            self.default_limit.setValue( self.prefs.default_limit )<commit_msg>Fix bad edit to pref tab title<commit_after>'''
 ====================================================================
 Copyright (c) 2003-2017 <NAME>.  All rights reserved.

 This software is licensed as described in the file LICENSE.txt,
 which you should have received as part of this distribution.

 ====================================================================

    wb_scm_preferences_dialog.py

    Based on code from pysvn WorkBench

'''
import pathlib

from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import QtCore

import wb_pick_path_dialogs
import wb_shell_commands
import wb_platform_specific
import wb_dialog_bases

class WbScmPreferencesDialog(wb_dialog_bases.WbTabbedDialog):
    def __init__( self, app, parent ):
        self.app = app

        super().__init__( parent=parent, size=(75, 20) )

        self.setWindowTitle( T_('Preferences - %s') % (' '.join( app.app_name_parts ),) )

    def completeTabsInit( self ):
        self.tabs = QtWidgets.QTabWidget()
        for tab_class in (ProjectsTab, EditorTab, ShellTab, LogHistoryTab, FontTab):
            tab = tab_class( self.app )
            self.addTab( tab )

        for tab in self.app.prefs_manager.getAllPreferenceTabs():
            self.addTab( tab )

    def savePreferences( self ):
        for index in range( self.tabs.count() ):
            tab = self.tabs.widget( index )
            tab.savePreferences()

class ProjectsTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Projects') )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.projects_defaults

        self.new_projects_folder = QtWidgets.QLineEdit()
        if self.prefs.new_projects_folder is not None:
            self.new_projects_folder.setText( str(self.prefs.new_projects_folder) )

        else:            # show the default
            self.new_projects_folder.setText( str(wb_platform_specific.getHomeFolder()) )

        self.browse_folder = QtWidgets.QPushButton( T_('Browse...') )
        self.browse_folder.clicked.connect( self.__pickFolder )

        self.addRow( T_('New projects folder'), self.new_projects_folder, self.browse_folder )

    def savePreferences( self ):
        if self.prefs is None:
            return

        self.prefs.new_projects_folder = self.new_projects_folder.text()

    def __pickFolder( self ):
        folder = wb_pick_path_dialogs.pickFolder( self, pathlib.Path( self.new_projects_folder.text() ) )
        if folder is not None:
            self.new_projects_folder.setText( str(folder) )

class EditorTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Editor') )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.editor

        self.editor_program = QtWidgets.QLineEdit( '' )
        self.editor_options = QtWidgets.QLineEdit( '' )

        if self.prefs is not None:
            self.editor_program.setText( self.prefs.program )
            self.editor_options.setText( self.prefs.options )

        self.browse = QtWidgets.QPushButton( T_('Browse…') )

        self.addRow( T_('Editor'), self.editor_program, self.browse )
        self.addRow( T_('Editor Options'), self.editor_options )

        self.browse.clicked.connect( self.pickEditor )

    def savePreferences( self ):
        if self.prefs is None:
            return

        self.prefs.program = self.editor_program.text()
        self.prefs.options = self.editor_options.text()

    def pickEditor( self ):
        editor = wb_pick_path_dialogs.pickExecutable( self, pathlib.Path( self.editor_program.text() ) )
        if editor is not None:
            self.editor_program.setText( str(editor) )

class ShellTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Shell') )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.shell

        terminal_program_list = wb_shell_commands.getTerminalProgramList()
        file_browser_program_list = wb_shell_commands.getFileBrowserProgramList()

        self.terminal_program = QtWidgets.QComboBox()
        self.terminal_program.addItems( terminal_program_list )
        self.terminal_init = QtWidgets.QLineEdit( '' )
        self.file_browser_program = QtWidgets.QComboBox()
        self.file_browser_program.addItems( file_browser_program_list )

        if self.prefs is not None:
            self.terminal_program.setCurrentText( self.prefs.terminal_program )
            self.terminal_init.setText( self.prefs.terminal_init )
            self.file_browser_program.setCurrentText( self.prefs.file_browser )

        self.addRow( T_('Terminal Program'), self.terminal_program )
        self.addRow( T_('Terminal Init Command'), self.terminal_init )
        self.addRow( T_('File Browser Program'), self.file_browser_program )

    def savePreferences( self ):
        if self.prefs is None:
            return

        self.prefs.terminal_program = self.terminal_program.currentText()
        self.prefs.terminal_init = self.terminal_init.text()
        self.prefs.file_browser = self.file_browser_program.currentText()

class LogHistoryTab(wb_dialog_bases.WbTabBase):
    def __init__( self, app ):
        super().__init__( app, T_('Commit Log History') )

        if self.app is None:
            self.prefs = None
        else:
            self.prefs = self.app.prefs.log_history

        self.default_limit = QtWidgets.QSpinBox()
        self.default_limit.setRange( 1, 100000 )
        self.default_limit.setSuffix( T_(' Commits') )

        self.use_default_limit = QtWidgets.QCheckBox( T_('Use limit') )

        self.default_until = QtWidgets.QSpinBox()
        self.default_until.setRange( 1, 365 )
        self.default_until.setSuffix( T_(' days') )

        self.use_default_until = QtWidgets.QCheckBox( T_('Use until') )

        self.default_since = QtWidgets.QSpinBox()
        self.default_since.setRange( 2, 365 )
        self.default_since.setSuffix( T_(' days') )

        self.use_default_since = QtWidgets.QCheckBox( T_('Use since') )

        if self.prefs is not None:
            self.default_limit.setValue( self.prefs.default_limit )
{'fraction_non_alphanumeric': 0.11896497317765857, 'fraction_numerical': 0.004733354370463868, 'mean_word_length': 2.749482401656315, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6330596', 'n_tokens_mistral': 3988, 'n_tokens_neox': 3792, 'n_words': 779}