155 lines
3.7 KiB
Python
155 lines
3.7 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import easymacro as app
|
|
|
|
|
|
ID_EXTENSION = ''
|
|
_ = None
|
|
# ~ cmd = 'service:' + ID_EXTENSION + '?'
|
|
|
|
|
|
class Controllers(object):
|
|
|
|
def __init__(self, dlg):
|
|
self.d = dlg
|
|
self.paths = []
|
|
|
|
def button_add_action(self, event):
|
|
path = app.paths.get_file()
|
|
# ~ if not path:
|
|
# ~ return
|
|
# ~ if path in self.paths:
|
|
# ~ msg = _('Path previously added')
|
|
# ~ app.msgbox(msg, self.TITLE)
|
|
# ~ return
|
|
|
|
# ~ self.paths.append(path)
|
|
# ~ p, filename, n, e = app.get_info_path(path)
|
|
# ~ self.d.grid.add_row((filename, '', path))
|
|
# ~ self.d.grid.set_cell_tooltip(0, self.d.grid.rows-1, p)
|
|
# ~ self.d.grid.sort(0)
|
|
app.debug(path)
|
|
return
|
|
|
|
def button_save_action(self, event):
|
|
msg = _('¿Want you save your favorites?')
|
|
if not app.question(msg, self.TITLE):
|
|
return
|
|
|
|
base = 'service:net.elmau.zaz.Favorites?{}'
|
|
paths = []
|
|
submenus = []
|
|
for row in range(self.d.grid.rows):
|
|
label = '{}. {}'.format(row + 1, self.d.grid[0, row])
|
|
path = self.d.grid[2, row]
|
|
paths.append(path)
|
|
path = app._path_url(path)
|
|
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'
|
|
data = {
|
|
'Label': 'Favorites',
|
|
'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', paths)
|
|
|
|
self.d.close(1)
|
|
msg = _('Favorites saved correctly')
|
|
app.msgbox(msg, self.TITLE)
|
|
return
|
|
|
|
def grid_click(self, event):
|
|
col = self.d.grid.column
|
|
row = self.d.grid.row
|
|
if col != 1:
|
|
return
|
|
|
|
msg = _('¿Want you delete this file?')
|
|
if app.question(msg, self.TITLE):
|
|
path = self.d.grid[2, row]
|
|
self.paths.remove(path)
|
|
self.d.grid.remove_row(row)
|
|
return
|
|
|
|
def grid_double_click(self, event):
|
|
col = self.d.grid.column
|
|
row = self.d.grid.row
|
|
if col == -1 or row == -1 or col != 0:
|
|
return
|
|
|
|
app.msgbox(self.d.grid.get_cell_tooltip(col, row))
|
|
return
|
|
|
|
|
|
def _config():
|
|
dlg = _create_dialog()
|
|
dlg.open()
|
|
return
|
|
|
|
|
|
def _create_dialog():
|
|
TITLE = _('ZAZ Favorites')
|
|
|
|
args = {
|
|
'Name': 'dialog',
|
|
'Title': TITLE,
|
|
'Width': 160,
|
|
'Height': 160,
|
|
}
|
|
dlg = app.create_dialog(args)
|
|
dlg.id = ID_EXTENSION
|
|
dlg.events = Controllers
|
|
|
|
args = {
|
|
'Type': 'Button',
|
|
'Name': 'button_add',
|
|
'Label': _('~Add'),
|
|
'ImageURL': 'add.svg',
|
|
'ImagePosition': 1,
|
|
'Width': 60,
|
|
'Height': 20,
|
|
'Y': 5,
|
|
}
|
|
dlg.add_control(args)
|
|
|
|
args = {
|
|
'Type': 'Button',
|
|
'Name': 'button_save',
|
|
'Label': _('~Save'),
|
|
'ImageURL': 'save.svg',
|
|
'ImagePosition': 1,
|
|
'Width': 60,
|
|
'Height': 20,
|
|
}
|
|
dlg.add_control(args)
|
|
|
|
dlg.button_add.center()
|
|
dlg.button_save.move(dlg.button_add)
|
|
dlg.button_save.center()
|
|
|
|
return dlg
|
|
|
|
@app.catch_exception
|
|
def run(args, path_locales):
|
|
global _
|
|
|
|
_ = app.install_locales(path_locales)
|
|
|
|
if args == 'config':
|
|
_config()
|
|
return
|
|
|
|
app.docs.open(args)
|
|
return
|