Skip to content

Commit

Permalink
Merge pull request praat#2786 from PaulBoersma/master
Browse files Browse the repository at this point in the history
Script and Notebook structures contain full paths (sortable) and a "t…
  • Loading branch information
PaulBoersma authored Nov 14, 2024
2 parents 23ebeec + 9395fbb commit bb2e3cb
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 23 deletions.
2 changes: 1 addition & 1 deletion melder/melder_files.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
struct FLAC__StreamDecoder;
struct FLAC__StreamEncoder;

#define kMelder_MAXPATH 1023 /* excluding the null byte */
#define kMelder_MAXPATH 1023 /* excluding the null character */

struct structMelderFile {
FILE *filePointer;
Expand Down
4 changes: 2 additions & 2 deletions sys/Notebook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@

#include "Notebook.h"

Thing_implement (Notebook, Daata, 0);
Thing_implement (Notebook, SimpleString, 0);

autoNotebook Notebook_createFromFile (MelderFile file) {
autoNotebook me = Thing_new (Notebook);
MelderFile_copy (file, & my file);
my string = Melder_dup (file -> path);
return me;
}

Expand Down
8 changes: 4 additions & 4 deletions sys/Notebook.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _Notebook_h_
/* Notebook.h
*
* Copyright (C) 2023 Paul Boersma
* Copyright (C) 2023,2024 Paul Boersma
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,10 +18,10 @@
* along with this work. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Data.h"
#include "Collection.h"

Thing_define (Notebook, Daata) {
structMelderFile file;
Thing_define (Notebook, SimpleString) {
bool trusted;
};

autoNotebook Notebook_createFromFile (MelderFile file);
Expand Down
13 changes: 8 additions & 5 deletions sys/NotebookEditor.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* NotebookEditor.cpp
*
* Copyright (C) 2023 Paul Boersma
* Copyright (C) 2023,2024 Paul Boersma
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -199,20 +199,23 @@ autoNotebookEditor NotebookEditor_createFromText (conststring32 initialText) {

autoNotebookEditor NotebookEditor_createFromNotebook_canBeNull (Notebook notebook) {
try {
structMelderFile notebookFile;
for (integer ieditor = 1; ieditor <= theReferencesToAllOpenNotebookEditors.size; ieditor ++) {
NotebookEditor editor = theReferencesToAllOpenNotebookEditors.at [ieditor];
if (MelderFile_equal (& notebook -> file, & editor -> file)) {
if (Melder_equ (notebook -> string.get(), editor -> file. path)) {
Editor_raise (editor);
Melder_appendError (U"The notebook ", & notebook -> file, U" is already open and has been moved to the front.");
Melder_pathToFile (notebook -> string.get(), & notebookFile);
Melder_appendError (U"The notebook ", & notebookFile, U" is already open and has been moved to the front.");
if (editor -> dirty)
Melder_appendError (U"Choose “Reopen from disk” if you want to revert to the old version.");
Melder_flushError ();
return autoNotebookEditor(); // safe null
}
}
autostring32 text = MelderFile_readText (& notebook -> file);
Melder_pathToFile (notebook -> string.get(), & notebookFile);
autostring32 text = MelderFile_readText (& notebookFile);
autoNotebookEditor me = NotebookEditor_createFromText (text.get());
MelderFile_copy (& notebook -> file, & my file);
MelderFile_copy (& notebookFile, & my file);
Thing_setName (me.get(), nullptr);
return me;
} catch (MelderError) {
Expand Down
6 changes: 3 additions & 3 deletions sys/Script.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* Script.cpp
*
* Copyright (C) 1997-2005,2009,2011,2015,2016,2020 Paul Boersma
* Copyright (C) 1997-2005,2009,2011,2015,2016,2020,2024 Paul Boersma
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,11 +18,11 @@

#include "Script.h"

Thing_implement (Script, Daata, 0);
Thing_implement (Script, SimpleString, 0);

autoScript Script_createFromFile (MelderFile file) {
autoScript me = Thing_new (Script);
MelderFile_copy (file, & my file);
my string = Melder_dup (file -> path);
return me;
}

Expand Down
8 changes: 4 additions & 4 deletions sys/Script.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define _Script_h_
/* Script.h
*
* Copyright (C) 1997-2005,2007,2011,2015,2016,2020 Paul Boersma
* Copyright (C) 1997-2005,2007,2011,2015,2016,2020,2024 Paul Boersma
*
* This code is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -18,10 +18,10 @@
* along with this work. If not, see <http://www.gnu.org/licenses/>.
*/

#include "Data.h"
#include "Collection.h"

Thing_define (Script, Daata) {
structMelderFile file;
Thing_define (Script, SimpleString) {
bool trusted;
};

autoScript Script_createFromFile (MelderFile file);
Expand Down
11 changes: 7 additions & 4 deletions sys/ScriptEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,20 +373,23 @@ autoScriptEditor ScriptEditor_createFromText (Editor optionalOwningEditor, const

autoScriptEditor ScriptEditor_createFromScript_canBeNull (Editor optionalOwningEditor, Script script) {
try {
structMelderFile scriptFile;
for (integer ieditor = 1; ieditor <= theReferencesToAllOpenScriptEditors.size; ieditor ++) {
ScriptEditor editor = theReferencesToAllOpenScriptEditors.at [ieditor];
if (MelderFile_equal (& script -> file, & editor -> file)) {
if (Melder_equ (script -> string.get(), editor -> file. path)) {
Editor_raise (editor);
Melder_appendError (U"The script ", & script -> file, U" is already open and has been moved to the front.");
Melder_pathToFile (script -> string.get(), & scriptFile); // ensure correct messaging format
Melder_appendError (U"The script ", & scriptFile, U" is already open and has been moved to the front.");
if (editor -> dirty)
Melder_appendError (U"Choose “Reopen from disk” if you want to revert to the old version.");
Melder_flushError ();
return autoScriptEditor(); // safe null
}
}
autostring32 text = MelderFile_readText (& script -> file);
Melder_pathToFile (script -> string.get(), & scriptFile);
autostring32 text = MelderFile_readText (& scriptFile);
autoScriptEditor me = ScriptEditor_createFromText (optionalOwningEditor, text.get());
MelderFile_copy (& script -> file, & my file);
MelderFile_copy (& scriptFile, & my file);
Thing_setName (me.get(), nullptr);
return me;
} catch (MelderError) {
Expand Down

0 comments on commit bb2e3cb

Please sign in to comment.