Skip to content

FileManager, History, Collections: expose file dialog buttons#12845

Merged
hius07 merged 5 commits into
koreader:masterfrom
hius07:file-dialog-buttons
Dec 5, 2024
Merged

FileManager, History, Collections: expose file dialog buttons#12845
hius07 merged 5 commits into
koreader:masterfrom
hius07:file-dialog-buttons

Conversation

@hius07

@hius07 hius07 commented Dec 4, 2024

Copy link
Copy Markdown
Member

This

-- (We may not need to do the following if we extend showFileDialog
-- code in filemanager.lua to check for existence and call a
-- method: self:getAdditionalButtons() to add our buttons
-- to its own set.)

Closes #12823.


This change is Reviewable

@poire-z poire-z left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks clean and proper - hope it works :)

return true
end

function FileManager:addFileDialogButtons(row_id, row_func) -- FileManager, History, Collections file_dialog

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Should this one be called addFileDialogButtonRow() as it expects a row ? Or just Buttons plural is enough to make it clear?)

self.file_dialog_added_buttons = nil
else
self.file_dialog_added_buttons.index[row_id] = nil
for id, idx in pairs(self.file_dialog_added_buttons.index) do

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(I thing using pairs() is right - just asking so you too are sure we should not use ipairs().)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

index is a hashmap table, { row_id = row index in the buttons table }.

Comment on lines +512 to +513
function CoverBrowser.addFileDialogButtons(widget)
FileManager.addFileDialogButtons(widget, "coverbrowser_1", function(file, is_file, bookinfo)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(It's good these use . and not : as they are utilities functions. Took me a few seconds to get that right - widget can be a FileManager instance :) and we will call FileManager (class) .addFileDialogButtons( FileManager (instance) ) - wondering if it needs a comment - or nevermind.)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add buttons, in an outer module we call:
FileManager:addFileDialogButtons(row_id, row_func)

(In CoverBrowser we do FileManager.addFileDialogButtons(FileManager, row_id, row_func) for unification)

FileManager.addFileDialogButtons(FileManagerHistory, row_id, row_func)

FileManager.addFileDialogButtons(FileManagerCollections, row_id, row_func)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid triplicating the code.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and we will call FileManager (class) .addFileDialogButtons( FileManager (instance) )

No, additional buttons are saved to the baseclass.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For FM we can add them to FileChooser, that was a choice.
I decided that FileManager was more logical, since the additional buttons to be added to the FM file dialog.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I did understand all this and it is perfect - explanations were not needed :)

It's just that reading FileManager.addFileDialogButtons(FileManager, row_id, row_func) felt odd, until I noticed that the first . wasn't a : and that FileManager.addFileDialogButtons is a function and not a method. Some little comment may have saved me a few seconds :)

@hius07 hius07 merged commit cd8ef3c into koreader:master Dec 5, 2024
@hius07 hius07 deleted the file-dialog-buttons branch December 5, 2024 16:54
@hius07 hius07 added this to the 2025.01 milestone Dec 5, 2024
hius07 added a commit that referenced this pull request Dec 15, 2024
Remove unused UIManager:clearRenderStack().
Previously it was used by CoverBrowser plugin when extending the FileManager popup file dialog with aditional buttons.
Now the buttons are inserted through the api added in #12845.
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
0xstillb pushed a commit to 0xstillb/koreader-thai that referenced this pull request May 9, 2026
Remove unused UIManager:clearRenderStack().
Previously it was used by CoverBrowser plugin when extending the FileManager popup file dialog with aditional buttons.
Now the buttons are inserted through the api added in koreader#12845.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FR: Allow adding buttons to Filemanager's file_dialog (similar to addToHighlightDialog)

2 participants