(null);
+ const [saveName, setSaveName] = useState(DEFAULT_DOCUMENT_NAME);
+
+ const [saveExtension, setSaveExtension] = useState(Extensions.TXT);
+
+ useEffect(() => {
+ setText(note);
+ setOriginalText(note);
+ setDocumentName(backendDocumentName);
+ setStatuses(getStatusCounts(note, note.length));
+ }, [note, backendDocumentName]);
const handleCloseDialog = () => setActiveDialog(Dialogs.NONE);
- const handleSave = (newDocumentName: string = documentName) => {
- logger.log(`Saving the document as ${newDocumentName}`);
- act('UpdateNote', { newnote: text });
- setOriginalText(text);
- setDocumentName(newDocumentName);
- logger.log('Attempting to retry previous action');
+ const handleSave = () => {
+ logger.log(`Saving the document as ${documentName}`);
+ act('save', { note: text });
setActiveDialog(Dialogs.NONE);
-
- // Retry the previous action now that we've saved. The previous action could be to
- // close the application, a new document being created or
- // an existing document being opened
if (retryAction) {
- retryAction(true);
+ setRetryAction(null);
}
- setRetryAction(null);
+ };
+ const handleSaveAs = () => setActiveDialog(Dialogs.SAVE);
+ const handleOpenNote = (retrying = false) => {
+ if (ensureUnsavedChangesAreHandled(handleOpenNote, retrying)) {
+ return;
+ }
+ setSelectedFileUid(null);
+ setActiveDialog(Dialogs.SELECT_FILE);
};
const ensureUnsavedChangesAreHandled = (
action: () => void,
@@ -391,6 +447,7 @@ export const NtosNotepad = (props) => {
setDocumentName(DEFAULT_DOCUMENT_NAME);
};
+ const selectedFile = files.find((file) => file.uid === selectedFileUid);
// MS Notepad displays an asterisk when there's unsaved changes
const unsavedAsterisk = text !== originalText ? '*' : '';
return (
@@ -403,8 +460,10 @@ export const NtosNotepad = (props) => {
document.execCommand('cut')}
onCopySelected={() => document.execCommand('copy')}
onPasteSelected={() => document.execCommand('paste')}
@@ -426,13 +485,108 @@ export const NtosNotepad = (props) => {
{showStatusBar && }
+ {activeDialog === Dialogs.SELECT_FILE && (
+
+ )}
+ {activeDialog === Dialogs.SAVE && (
+
+ )}
{activeDialog === Dialogs.UNSAVED_CHANGES && (