NoteEditor: Build a bottom bar which shows the current folder

Also allow notes to be moved to a folder.
This commit is contained in:
Vishesh Handa
2020-05-05 10:00:14 +02:00
parent bdecc19126
commit 48b6fa21f7
6 changed files with 44 additions and 12 deletions

View File

@ -159,6 +159,8 @@ class ChecklistEditorState extends State<ChecklistEditor>
Expanded(child: FocusScope(child: checklistWidget)),
],
),
bottomNavigationBar:
buildEditorBottonBar(context, widget, this, checklist.note),
);
}

View File

@ -17,7 +17,7 @@ abstract class EditorState {
Note getNote();
}
enum DropDownChoices { Rename, MoveToFolder, DiscardChanges, Share }
enum DropDownChoices { Rename, DiscardChanges, Share }
AppBar buildEditorAppBar(
Editor editor,
@ -58,11 +58,6 @@ AppBar buildEditorAppBar(
editor.renameNoteSelected(note);
return;
case DropDownChoices.MoveToFolder:
var note = editorState.getNote();
editor.moveNoteToFolderSelected(note);
return;
case DropDownChoices.DiscardChanges:
var note = editorState.getNote();
editor.discardChangesSelected(note);
@ -80,10 +75,6 @@ AppBar buildEditorAppBar(
value: DropDownChoices.Rename,
child: Text('Edit File Name'),
),
const PopupMenuItem<DropDownChoices>(
value: DropDownChoices.MoveToFolder,
child: Text('Move to Folder'),
),
const PopupMenuItem<DropDownChoices>(
value: DropDownChoices.DiscardChanges,
child: Text('Discard Changes'),
@ -97,3 +88,33 @@ AppBar buildEditorAppBar(
],
);
}
BottomAppBar buildEditorBottonBar(
BuildContext context,
Editor editor,
EditorState editorState,
Note note,
) {
var folderName = note.parent.pathSpec();
if (folderName.isEmpty) {
folderName = "Root Folder";
}
return BottomAppBar(
elevation: 0.0,
color: Theme.of(context).scaffoldBackgroundColor,
child: Row(
children: <Widget>[
FlatButton.icon(
icon: Icon(Icons.folder),
label: Text(folderName),
onPressed: () {
var note = editorState.getNote();
editor.moveNoteToFolderSelected(note);
},
)
],
mainAxisAlignment: MainAxisAlignment.center,
),
);
}

View File

@ -84,6 +84,7 @@ class JournalEditorState extends State<JournalEditor> implements EditorState {
return Scaffold(
appBar: buildEditorAppBar(widget, this, noteModified: _noteModified),
body: editor,
bottomNavigationBar: buildEditorBottonBar(context, widget, this, note),
);
}

View File

@ -115,6 +115,7 @@ class MarkdownEditorState extends State<MarkdownEditor> implements EditorState {
extraButtons: [extraButton],
),
body: body,
bottomNavigationBar: buildEditorBottonBar(context, widget, this, note),
);
}

View File

@ -81,6 +81,7 @@ class RawEditorState extends State<RawEditor> implements EditorState {
return Scaffold(
appBar: buildEditorAppBar(widget, this, noteModified: _noteModified),
body: editor,
bottomNavigationBar: buildEditorBottonBar(context, widget, this, note),
);
}

View File

@ -287,8 +287,14 @@ class NoteEditorState extends State<NoteEditor> {
builder: (context) => FolderSelectionDialog(),
);
if (destFolder != null) {
var stateContainer = Provider.of<StateContainer>(context, listen: false);
stateContainer.moveNote(note, destFolder);
if (_isNewNote) {
note.parent = destFolder;
setState(() {});
} else {
var stateContainer =
Provider.of<StateContainer>(context, listen: false);
stateContainer.moveNote(note, destFolder);
}
}
}