Set and get paths

This commit is contained in:
Mauricio Baeza 2020-12-26 22:21:23 -06:00
parent 5c522ebcc4
commit 60409ceeb3
3 changed files with 43 additions and 33 deletions

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

View File

@ -5,7 +5,8 @@ import easymacro as app
ID_EXTENSION = '' ID_EXTENSION = ''
_ = None _ = None
# ~ cmd = 'service:' + ID_EXTENSION + '?'
PREFIX = 'fav'
class Controllers(object): class Controllers(object):
@ -35,37 +36,43 @@ class Controllers(object):
@app.catch_exception @app.catch_exception
def button_save_action(self, event): def button_save_action(self, event):
msg = _('Want you save your favorites?') msg = _('Want you save your favorites files?')
if not app.question(msg, self.TITLE): if not app.question(msg, self.TITLE):
return return
base = 'service:net.elmau.zaz.Favorites?{}' # ~ cmd = 'service:' + ID_EXTENSION + '?'
paths = [] base = f'service:{ID_EXTENSION}?{{}}'
# ~ paths = []
submenus = [] submenus = []
for row in range(self.d.grid.rows): for path in self.paths:
label = '{}. {}'.format(row + 1, self.d.grid[0, row]) pass
path = self.d.grid[2, row] # ~ for row in range(self.d.grid.row_count):
paths.append(path) # ~ name = self.d.grid[0, row]
path = app._path_url(path) # ~ path = self.d.grid[2, row]
sm = {'Label': label, 'CommandURL': base.format(path)}
submenus.append(sm)
sm = {'Label': '-'}
submenus.append(sm)
sm = {'Label': _('Favorites...'), 'CommandURL': base.format('config')}
submenus.append(sm)
command = 'menu.zaz.favorites' # ~ label = '{}. {}'.format(row + 1, name)
data = { # ~ paths.append(path)
'Label': 'Favorites', # ~ path = app._path_url(path)
'CommandURL': command, # ~ sm = {'Label': label, 'CommandURL': base.format(path)}
'After': '.uno:RecentFileList', # ~ submenus.append(sm)
'Submenu': submenus, # ~ sm = {'Label': '-'}
} # ~ submenus.append(sm)
# ~ sm = {'Label': _('Favorites...'), 'CommandURL': base.format('config')}
# ~ submenus.append(sm)
for doc_type in ('main', 'calc', 'writer'): # ~ command = 'menu.zaz.favorites'
app.remove_menu(doc_type, 'File', command) # ~ data = {
app.insert_menu(doc_type, 'File', **data) # ~ 'Label': 'Favorites',
app.set_config('paths', paths) # ~ 'CommandURL': command,
# ~ 'After': '.uno:RecentFileList',
# ~ 'Submenu': submenus,
# ~ }
# ~ for doc_type in ('main', 'calc', 'writer'):
# ~ app.remove_menu(doc_type, 'File', command)
# ~ app.insert_menu(doc_type, 'File', **data)
app.set_config('paths', self.paths, PREFIX)
self.d.close(1) self.d.close(1)
msg = _('Favorites saved correctly') msg = _('Favorites saved correctly')
@ -104,15 +111,18 @@ class Controllers(object):
def _config(): def _config():
dlg = _create_dialog() dlg = _create_dialog()
path_img = app.paths.join(dlg.path, 'images/delete.svg')
image = app.paths.image(path_img)
# ~ dlg.grid.set_column_image(1, app.join(self.IMAGES, 'delete.png')) paths = app.get_config('paths', prefix=PREFIX)
# ~ paths = app.get_config('paths', []) for i, path in enumerate(paths):
# ~ for path in paths: p = app.paths(path)
# ~ p, filename, n, e = app.get_info_path(path) dlg.grid.add_row((p.file_name, image, path))
# ~ dlg.grid.add_row((filename, '', path)) dlg.grid.set_cell_tooltip(0, i, p.path)
# ~ dlg.grid.set_cell_tooltip(0, dlg.grid.rows-1, p)
# ~ dlg.events.paths = paths
if paths:
dlg.grid.sort(0)
dlg.events.paths = paths
dlg.open() dlg.open()
return return