.action("notebook_view_changed")
.varname("note_maximized")
.create();
+ app.toolbar_item("add_attachment").icon(UiIconSet::Add.as_str()).action("add_attachment").create();
app.toolbar_add_default("new_notebook", ToolbarItemPosition::SidebarLeft);
app.toolbar_add_default("go_back", ToolbarItemPosition::Left);
app.toolbar_add_default("go_forward", ToolbarItemPosition::Left);
app.toolbar_add_default("new_note", ToolbarItemPosition::Left);
+ app.toolbar_add_default("add_attachment", ToolbarItemPosition::RightPanelLeft);
app.toolbar_add_default("note_maximize", ToolbarItemPosition::RightPanelRight);
app.toolbar_appmenu(|menu|{
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
-use std::path::PathBuf;
+use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::atomic::{AtomicU64, Ordering};
use std::time::SystemTime;
})
.create();
}
+
+ #[action]
+ pub fn add_attachment(&mut self, event: &mut ActionEvent) {
+ let Some(doc) = self.doc.get_doc() else {
+ return;
+ };
+ let Some(obj) = &event.obj else {
+ return;
+ };
+
+ // TODO: currently it is unsupported to add attachments to unsaved notes
+ let NoteId::Id(note_id) = self.id else {
+ return;
+ };
+
+ let proxy = doc.doc_proxy();
+ let backend = self.backend.clone();
+ obj.openfile_dialog(false, move|event|{
+ if let EventType::FileList(file_selection) = event.event_type && let Some(file) = file_selection.get(0) {
+ let path = Path::new(file);
+ backend.add_note_attachment(note_id, path, move|result|{
+ proxy.call_mainthread(|_doc, note|{
+ match result {
+ Ok((attachment, content)) => {
+ println!("attachment: {} id: {}", attachment.attachment_id, content.attachment_id);
+ },
+ Err(e) => {
+ println!("cannot add attachment: {}", e);
+ }
+ }
+ });
+ });
+ }
+ });
+ }
}
impl NoteViewModel for Note {