Skip to content

Commit f949e7f

Browse files
author
troiganto
committed
feat(attach): add event to delete attachments of archived headlines
1 parent 4df557c commit f949e7f

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

lua/orgmode/capture/init.lua

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ local fs = require('orgmode.utils.fs')
33
local config = require('orgmode.config')
44
local Templates = require('orgmode.capture.templates')
55
local Template = require('orgmode.capture.template')
6+
local EventManager = require('orgmode.events')
67
local Menu = require('orgmode.ui.menu')
78
local Range = require('orgmode.files.elements.range')
89
local CaptureWindow = require('orgmode.capture.window')
@@ -300,6 +301,7 @@ function Capture:refile_file_headline_to_archive(headline)
300301
local headline_category = headline:get_category()
301302
local outline_path = headline:get_outline_path()
302303

304+
EventManager.dispatch(EventManager.event.HeadlineArchived:new(headline, destination_file))
303305
return self
304306
:_refile_from_org_file({
305307
source_headline = headline,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---@param event OrgHeadlineArchivedEvent
2+
return function(event)
3+
require('orgmode.attach'):maybe_delete_archived(event.headline)
4+
end

lua/orgmode/events/listeners/init.lua

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
local Events = require('orgmode.events.types')
22
local AlignTags = require('orgmode.events.listeners.align_tags')
3+
local AttachMaybeDeleteArchived = require('orgmode.events.listeners.attach_maybe_delete_archived')
34

45
return {
56
[Events.TodoChanged] = {
@@ -11,4 +12,7 @@ return {
1112
[Events.HeadlinePromoted] = {
1213
AlignTags,
1314
},
15+
[Events.HeadlineArchived] = {
16+
AttachMaybeDeleteArchived,
17+
},
1418
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---@class OrgHeadlineArchivedEvent: OrgEvent
2+
---@field type string
3+
---@field headline OrgHeadline
4+
---@field destination_file OrgFile
5+
local HeadlineArchivedEvent = {
6+
type = 'orgmode.headline_archived',
7+
}
8+
9+
---@param headline OrgHeadline
10+
---@param destination_file OrgFile
11+
---@return OrgHeadlineArchivedEvent
12+
function HeadlineArchivedEvent:new(headline, destination_file)
13+
local obj = setmetatable({}, self)
14+
self.__index = self
15+
obj.headline = headline
16+
obj.destination_file = destination_file
17+
return obj
18+
end
19+
20+
return HeadlineArchivedEvent

lua/orgmode/events/types/init.lua

+1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ return {
88
HeadingToggled = require('orgmode.events.types.heading_toggled'),
99
AttachChanged = require('orgmode.events.types.attach_changed_event'),
1010
AttachOpened = require('orgmode.events.types.attach_opened_event'),
11+
HeadlineArchived = require('orgmode.events.types.headline_archived_event'),
1112
}

0 commit comments

Comments
 (0)