Skip to content

Commit ba20899

Browse files
committed
refactor(card-cm): split context menu to single and multi-node
1 parent df4024d commit ba20899

17 files changed

Lines changed: 309 additions & 145 deletions

src/view/actions/context-menu/helpers/on-long-press.ts renamed to src/helpers/on-long-press.ts

File renamed without changes.

src/lang/lang.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const lang = {
7272
toolbar_cut_search_results: 'Cut search results',
7373
hkg_clipboard: 'Clipboard',
7474
modals_snapshots_cut_card: 'Cut card ',
75-
cm_cut: 'Cut branch',
75+
cm_cut: 'Cut',
7676
hk_cut_node: 'Cut branch',
7777
cm_paste: 'Paste',
7878
hk_paste_node: 'Paste branch',
@@ -136,18 +136,21 @@ export const lang = {
136136
// extract
137137
cmd_extract_branch: 'Extract branch to a new document',
138138
cm_extract_branch: 'Extract branch',
139+
cm_extract_section: 'Extract section',
139140
modals_snapshots_extracted_card: 'Extracted card ',
140141

141142
// export
142143
cm_export_document: 'Export document',
143-
cm_export_selection: 'Export selection',
144-
cm_export_with_subitems: 'With sub-items',
145-
cm_export_wo_subitems: 'Without sub-items',
146-
cmd_export_selection_with_subitems: 'Export selection with sub-items',
147-
cmd_export_selection_wo_subitems: 'Export selection without sub-items',
144+
cm_export_selection: 'Export',
145+
cm_export_section: 'Export section',
146+
cm_export_branch_with_subitems: 'Export branch with sub-items',
147+
cm_export_branch_wo_subitems: 'Export section without sub-items',
148+
cmd_export_branches_with_subitems: 'Export branches with sub-items',
149+
cmd_export_sections_wo_subitems: 'Export sections without sub-items',
148150

149151
// document format
150152
settings_general_default_format: 'Default format',
153+
cm_document_format: 'Document format',
151154
settings_general_default_format_desc: 'Applies to new documents',
152155
settings_format_html_elements: 'HTML elements (experimental)',
153156
settings_format_html_comments: 'HTML comments',

src/lib/tree-utils/find/find-next-node.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Sections } from 'src/stores/document/document-state-type';
2-
import { sortSections } from 'src/helpers/sort-sections';
2+
import { sortSections } from 'src/lib/tree-utils/sort/sort-sections';
33

44
export const findNextNode = (
55
sections: Sections,

src/lib/tree-utils/sort/sort-node-ids-by-depth-desc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Sections } from 'src/stores/document/document-state-type';
2-
import { sortSectionsByDepthDesc } from 'src/helpers/sort-sections-by-depth';
2+
import { sortSectionsByDepthDesc } from 'src/lib/tree-utils/sort/sort-sections-by-depth';
33

44
export const sortNodeIdsByDepthDesc = (sections: Sections, ids: string[]) => {
55
const sectionNumbers = ids.map((id) => sections.id_section[id]);

src/lib/tree-utils/sort/sort-node-ids-by-section-number.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { Sections } from 'src/stores/document/document-state-type';
2-
import { sortSections } from 'src/helpers/sort-sections';
2+
import { sortSections } from 'src/lib/tree-utils/sort/sort-sections';
33

44
export const sortNodeIdsBySectionNumber = (
55
sections: Sections,
File renamed without changes.

src/obsidian/commands/add-commands.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ const createCommands = (plugin: Lineage) => {
165165
});
166166

167167
commands.push({
168-
name: lang.cmd_export_selection_with_subitems,
168+
name: lang.cmd_export_branches_with_subitems,
169169
icon: 'file-text',
170170
checkCallback: (checking) => {
171171
const view = getActiveLineageView(plugin);
@@ -177,7 +177,7 @@ const createCommands = (plugin: Lineage) => {
177177
});
178178

179179
commands.push({
180-
name: lang.cmd_export_selection_wo_subitems,
180+
name: lang.cmd_export_sections_wo_subitems,
181181
icon: 'file-text',
182182
checkCallback: (checking) => {
183183
const view = getActiveLineageView(plugin);
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { LineageView } from 'src/view/view';
2+
import { MenuItemObject } from 'src/obsidian/context-menu/render-context-menu';
3+
import { lang } from 'src/lang/lang';
4+
import { copyActiveBranchesToClipboard } from 'src/view/actions/keyboard-shortcuts/helpers/commands/commands/helpers/clipboard/copy-active-branches-to-clipboard';
5+
import { copyActiveNodesToClipboard } from 'src/view/actions/keyboard-shortcuts/helpers/commands/commands/helpers/clipboard/copy-active-nodes-to-clipboard';
6+
import { cutNode } from 'src/view/actions/keyboard-shortcuts/helpers/commands/commands/helpers/cut-node';
7+
import { pasteNode } from 'src/view/actions/keyboard-shortcuts/helpers/commands/commands/helpers/paste-node';
8+
import { exportSelection } from 'src/view/actions/context-menu/card-context-menu/helpers/export-selection';
9+
10+
export const createMultipleNodesContextMenu = (view: LineageView) => {
11+
const menuItems: MenuItemObject[] = [
12+
{
13+
title: lang.cm_copy,
14+
icon: 'documents',
15+
submenu: [
16+
{
17+
title: lang.cm_copy_branches,
18+
icon: 'lineage-cards',
19+
action: () =>
20+
copyActiveBranchesToClipboard(view, true, false),
21+
},
22+
{
23+
title: lang.cm_copy_branches_wo_formatting,
24+
icon: 'file-text',
25+
action: () =>
26+
copyActiveBranchesToClipboard(view, false, false),
27+
},
28+
{
29+
title: lang.cm_copy_section_wo_subitems,
30+
icon: 'file-text',
31+
action: () => copyActiveNodesToClipboard(view, false),
32+
},
33+
],
34+
},
35+
{
36+
title: lang.cm_cut,
37+
icon: 'scissors',
38+
action: () => cutNode(view),
39+
},
40+
{
41+
title: lang.cm_paste,
42+
icon: 'paste',
43+
action: () => pasteNode(view),
44+
},
45+
{ type: 'separator' },
46+
{
47+
title: lang.cm_export_selection,
48+
icon: 'file-text',
49+
submenu: [
50+
{
51+
title: lang.cmd_export_branches_with_subitems,
52+
icon: 'file-text',
53+
action: () => exportSelection(view, true),
54+
},
55+
{
56+
title: lang.cmd_export_sections_wo_subitems,
57+
icon: 'file-text',
58+
action: () => exportSelection(view, false),
59+
},
60+
],
61+
},
62+
];
63+
return menuItems;
64+
};
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { LineageView } from 'src/view/view';
2+
import { MenuItemObject } from 'src/obsidian/context-menu/render-context-menu';
3+
import { lang } from 'src/lang/lang';
4+
import { copyLinkToBlock } from 'src/view/actions/context-menu/card-context-menu/helpers/copy-link-to-block';
5+
import { copyActiveNodesToClipboard } from 'src/view/actions/keyboard-shortcuts/helpers/commands/commands/helpers/clipboard/copy-active-nodes-to-clipboard';
6+
7+
export const togglePinNode = (
8+
view: LineageView,
9+
activeNode: string,
10+
isPinned: boolean,
11+
isInSidebar: boolean,
12+
) => {
13+
const viewState = view.viewStore.getValue();
14+
const id = isInSidebar ? viewState.pinnedNodes.activeNode : activeNode;
15+
view.documentStore.dispatch({
16+
type: isPinned
17+
? 'document/pinned-nodes/unpin'
18+
: 'document/pinned-nodes/pin',
19+
payload: { id: id },
20+
});
21+
};
22+
23+
type Props = {
24+
activeNode: string;
25+
isPinned: boolean;
26+
isInRecentCardsList: boolean;
27+
};
28+
export const createSidebarContextMenuItems = (
29+
view: LineageView,
30+
{ isPinned, activeNode, isInRecentCardsList }: Props,
31+
) => {
32+
const menuItems: MenuItemObject[] = [
33+
{
34+
title: lang.cm_copy_link_to_block,
35+
icon: 'links-coming-in',
36+
action: () => copyLinkToBlock(view, true),
37+
},
38+
{ type: 'separator' },
39+
{
40+
title: lang.cm_copy,
41+
icon: 'documents',
42+
action: () => copyActiveNodesToClipboard(view, true),
43+
},
44+
45+
{ type: 'separator' },
46+
{
47+
title: isPinned
48+
? lang.cm_unpin_from_left_sidebar
49+
: lang.cm_pin_in_left_sidebar,
50+
icon: isPinned ? 'pin-off' : 'pin',
51+
action: () => togglePinNode(view, activeNode, isPinned, true),
52+
disabled: isInRecentCardsList,
53+
},
54+
{ type: 'separator' },
55+
];
56+
return menuItems;
57+
};

0 commit comments

Comments
 (0)