1import os 2from cudatext import * 3from cudax_lib import get_translation 4from .projman_glob import * 5 6_ = get_translation(__file__) # i18n 7 8 9def bool_to_str(b): 10 return '1' if b else '0' 11def str_to_bool(s): 12 return s=='1' 13 14 15def get_themes_filetype(): 16 17 dir = os.path.join(app_path(APP_DIR_DATA), 'filetypeicons') 18 return sorted(os.listdir(dir)) 19 20def get_themes_toolbar(): 21 22 dir = os.path.join(app_path(APP_DIR_DATA), 'projtoolbaricons') 23 return sorted(os.listdir(dir)) 24 25 26def dialog_config(op): 27 28 RES_NO_FILES = 1 29 RES_NO_DIRS = 3 30 RES_NO_HIDDEN = 4 31 RES_RECENTS = 6 32 RES_ON_START = 7 33 RES_TOOLBAR = 8 34 RES_GOTO_OPEN = 9 35 RES_PREVIEW = 10 36 RES_D_CLICK = 11 37 RES_CHECK_GIT = 12 38 RES_ICONS = 14 39 RES_ICONS_TB = 16 40 RES_OK = 19 41 42 themes = get_themes_filetype() 43 try: 44 s = op.get('icon_theme', 'vscode_16x16') 45 theme_index = themes.index(s) 46 except: 47 theme_index = -1 48 49 themes_tb = get_themes_toolbar() 50 try: 51 s = op.get('toolbar_theme', 'default_16x16') 52 theme_index_tb = themes_tb.index(s) 53 except: 54 theme_index_tb = -1 55 56 c1 = chr(1) 57 text = '\n'.join([] 58 +[c1.join(['type=label', 'pos=6,4,110,0', 'cap='+_('Ignore &files:')])] 59 +[c1.join(['type=edit', 'pos=116,4,500,0', 'val='+op.get('no_files', '')])] 60 61 +[c1.join(['type=label', 'pos=6,34,110,0', 'cap='+_('Ignore fold&ers:')])] 62 +[c1.join(['type=edit', 'pos=116,34,500,0', 'val='+op.get('no_dirs', '.git;.svn')])] 63 64 +[c1.join(['type=check', 'pos=6,62,500,84', 'cap='+_('Ignore all &hidden files/folders'), 65 'val='+bool_to_str(op.get('no_hidden', True))])] 66 67 +[c1.join(['type=label', 'pos=6,88,500,0', 'cap='+_('&Recent projects:')])] 68 +[c1.join(['type=memo', 'pos=6,104,500,180', 69 'val='+'\t'.join(op.get('recent_projects', [])) ])] 70 +[c1.join(['type=check', 'pos=6,186,400,0', 'cap='+_('&Load on app start, reopen last project (*)'), 71 'val='+bool_to_str(op.get('on_start', False)) ])] 72 +[c1.join(['type=check', 'pos=6,210,400,0', 'cap='+_('&Show toolbar'), 73 'val='+bool_to_str(op.get('toolbar', True)) ])] 74 +[c1.join(['type=check', 'pos=6,236,400,0', 'cap='+_('Open file after "&Go to file" command'), 75 'val='+bool_to_str(op.get('goto_open', False)) ])] 76 +[c1.join(['type=check', 'pos=6,262,400,0', 'cap='+_('&Use "preview tab" on item clicking'), 77 'val='+bool_to_str(op.get('preview', True)) ])] 78 +[c1.join(['type=check', 'pos=6,288,400,0', 'cap='+_('Open files by &double-click'), 79 'val='+bool_to_str(op.get('d_click', False)) ])] 80 +[c1.join(['type=check', 'pos=6,314,400,0', 'cap='+_('On opening file in Git/SVN repo, create project from repo (*)'), 81 'val='+bool_to_str(op.get('check_git', True)) ])] 82 83 +[c1.join(['type=label', 'pos=6,360,130,0', 'cap='+_('File type icons:')])] 84 +[c1.join(['type=combo_ro', 'pos=160,355,400,0', 85 'items='+'\t'.join(themes), 86 'val='+str(theme_index) 87 ])] 88 89 +[c1.join(['type=label', 'pos=6,390,130,0', 'cap='+_('Toolbar icons:')])] 90 +[c1.join(['type=combo_ro', 'pos=160,385,400,0', 91 'items='+'\t'.join(themes_tb), 92 'val='+str(theme_index_tb) 93 ])] 94 95 +[c1.join(['type=label', 'pos=6,416,600,0', 'cap='+_('For more icons, get add-ons of kind "filetypeicons", "projtoolbaricons"')])] 96 +[c1.join(['type=label', 'pos=6,440,600,0', 'cap='+_('(*) - requires CudaText restart')])] 97 +[c1.join(['type=button', 'pos=300,470,400,0', 'cap='+_('&OK'), 'ex0=1'])] 98 +[c1.join(['type=button', 'pos=406,470,502,0', 'cap='+_('Cancel')])] 99 ) 100 101 res = dlg_custom(_('Project Manager options'), 508, 504, text, get_dict=True) 102 if res is None: 103 return 104 105 if res['clicked'] != RES_OK: 106 return 107 108 op['no_files'] = res[RES_NO_FILES].strip() 109 op['no_dirs'] = res[RES_NO_DIRS].strip() 110 op['no_hidden'] = str_to_bool(res[RES_NO_HIDDEN]) 111 112 s = res[RES_RECENTS].split('\t') 113 op['recent_projects'] = s 114 115 op['on_start'] = str_to_bool(res[RES_ON_START]) 116 op['toolbar'] = str_to_bool(res[RES_TOOLBAR]) 117 op['goto_open'] = str_to_bool(res[RES_GOTO_OPEN]) 118 op['preview'] = str_to_bool(res[RES_PREVIEW]) 119 op['d_click'] = str_to_bool(res[RES_D_CLICK]) 120 op['check_git'] = str_to_bool(res[RES_CHECK_GIT]) 121 122 index = int(res[RES_ICONS]) 123 if index>=0: 124 op['icon_theme'] = themes[index] 125 126 index = int(res[RES_ICONS_TB]) 127 if index>=0: 128 op['toolbar_theme'] = themes_tb[index] 129 130 return True 131 132 133def dialog_proj_prop(prop): 134 135 list_vars = prop.get('vars', '') 136 main_file = prop.get('mainfile', '') 137 138 RES_VARS = 1 139 RES_OK = 4 140 141 c1 = chr(1) 142 text = '\n'.join([] 143 +[c1.join(['type=label', 'pos=6,6,500,0', 'cap='+_('&Variables (in form Name=Value)')])] 144 +[c1.join(['type=memo', 'pos=6,26,500,180', 'val='+'\t'.join(list_vars) ])] 145 +[c1.join(['type=label', 'pos=6,186,500,0', 'cap='+_('&Main file (read-only, change in context menu)')])] 146 +[c1.join(['type=edit', 'pos=6,206,500,0', 'ex0=1', 'ex1=0', 'ex2=1', 'val='+main_file])] 147 +[c1.join(['type=button', 'pos=300,300,400,0', 'cap='+_('&OK'), 'ex0=1'])] 148 +[c1.join(['type=button', 'pos=406,300,502,0', 'cap='+_('Cancel')])] 149 ) 150 151 res = dlg_custom(_('Project properties'), 508, 330, text, get_dict=True) 152 if res is None: 153 return 154 155 if res['clicked'] != RES_OK: 156 return 157 158 s = res[RES_VARS].split('\t') 159 s = [item.strip() for item in s if '=' in item] 160 prop['vars'] = s 161 162 return True 163