-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__init__.py
92 lines (72 loc) · 2.38 KB
/
__init__.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# -*- coding: utf-8 -*-
# Copyright 2017 Jaap Karssenberg <[email protected]>
from zim.plugins import PluginClass, extends, WindowExtension
from zim.main import NotebookCommand, UsageError
from zim.actions import action
from zim.notebook import Path
from .functions import *
class LinkAnalysisPlugin(PluginClass):
plugin_info = {
'name': _('Link Analysis'), # T: plugin name
'description': _('''\
This plugin provides functions to analyze the link structure of a notebook
'''), # T: plugin description
'author': 'Jaap Karssenberg',
'help': None,
}
plugin_preferences = (
# key, type, label, default
#('pane', 'choice', _('Position in the window'), RIGHT_PANE, PANE_POSITIONS),
# T: option for plugin preferences
)
class LinkAnalysisCommand(NotebookCommand):
arguments = ('COMMAND', 'NOTEBOOK', '[PAGE1]', '[PAGE2]')
options = (
('direction=', 'd', 'Link direction'),
)
def build_notebook(self):
# HACK around hardcoding of argument sequence
self.arguments = ('NOTEBOOK',)
self.args = (self.args[1],)
return NotebookCommand.build_notebook(self)
def run(self):
args = self.get_arguments()
command = args[0]
notebook, p = self.build_notebook()
if self.opts.get('direction', 'forw').lower().startswith('back'):
dir = LINK_DIR_BACKWARD
else:
dir = LINK_DIR_FORWARD
if command == 'sort':
list = sort_by_number_of_links(notebook, dir)
elif command == 'compare':
if args[3] is not None:
page1 = Path(Path.makeValidPageName(args[2]))
page2 = Path(Path.makeValidPageName(args[3]))
list = find_common_links(notebook, page1, page2, dir)
elif args[2] is not None:
page1 = Path(Path.makeValidPageName(args[2]))
list = compare_by_links(notebook, dir, page1)
else:
list = compare_by_links(notebook, dir)
else:
raise UsageError, _('Unknown command: %s') % command
for columns in list:
print '\t'.join(map(unicode, columns))
@extends('MainWindow')
class MainWindowExtension(WindowExtension):
uimanager_xml = '''
<ui>
<menubar name='menubar'>
<menu action='view_menu'>
<placeholder name='plugin_items'>
<menuitem action='show_pages_by_number_of_links'/>
</placeholder>
</menu>
</menubar>
</ui>
'''
@action('Sort pages by number of links...')
def show_pages_by_number_of_links(self):
from .dialog import PagesByNumberOfLinksDialog
PagesByNumberOfLinksDialog(self.window, self.window.notebook).run()