Skip to content

Commit 9f3d1f9

Browse files
committed
On OS X, the default directory for files explicitly saved/loaded by the user is now ~/Documents/open-ephys. Added CoreServices::getDefaultUserSaveDirectory(), which returns ~/Documents/open-ephys on OS X and the current working directory on other platforms.
1 parent 642a606 commit 9f3d1f9

8 files changed

Lines changed: 25 additions & 14 deletions

File tree

Source/CoreServices.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,18 @@ const char* getApplicationResource(const char* name, int& size)
159159
{
160160
return BinaryData::getNamedResource(name, size);
161161
}
162+
163+
File getDefaultUserSaveDirectory()
164+
{
165+
#if defined(__APPLE__)
166+
File dir = File::getSpecialLocation(File::userDocumentsDirectory).getChildFile("open-ephys");
167+
if (!dir.isDirectory()) {
168+
dir.createDirectory();
169+
}
170+
return std::move(dir);
171+
#else
172+
return File::getCurrentWorkingDirectory();
173+
#endif
174+
}
162175

163176
};

Source/CoreServices.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ PLUGIN_API int addSpikeElectrode(SpikeRecordInfo* elec);
104104
};
105105

106106
PLUGIN_API const char* getApplicationResource(const char* name, int& size);
107+
108+
/** Gets the default directory for user-initiated file saving/loading */
109+
PLUGIN_API File getDefaultUserSaveDirectory();
107110

108111
};
109112

Source/MainWindow.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ void MainWindow::loadWindowBounds()
182182
std::cout << "Loading window bounds." << std::endl;
183183
std::cout << std::endl;
184184

185-
//File file = File::getCurrentWorkingDirectory().getChildFile("windowState.xml");
186-
187185
File file = getSavedStateDirectory().getChildFile("windowState.xml");
188186

189187
XmlDocument doc(file);

Source/Plugins/ChannelMappingNode/ChannelMappingEditor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,7 @@ void ChannelMappingEditor::buttonEvent(Button* button)
553553
if (!acquisitionIsActive)
554554
{
555555
FileChooser fc("Choose the file name...",
556-
File::getCurrentWorkingDirectory(),
556+
CoreServices::getDefaultUserSaveDirectory(),
557557
"*",
558558
true);
559559

@@ -576,7 +576,7 @@ void ChannelMappingEditor::buttonEvent(Button* button)
576576
if (!acquisitionIsActive)
577577
{
578578
FileChooser fc("Choose a file to load...",
579-
File::getCurrentWorkingDirectory(),
579+
CoreServices::getDefaultUserSaveDirectory(),
580580
"*",
581581
true);
582582

Source/Processors/FileReader/FileReaderEditor.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ FileReaderEditor::FileReaderEditor (GenericProcessor* parentNode, bool useDefaul
3636
, recTotalTime (0)
3737
, m_isFileDragAndDropActive (false)
3838
{
39-
lastFilePath = File::getCurrentWorkingDirectory();
39+
lastFilePath = CoreServices::getDefaultUserSaveDirectory();
4040

4141
fileButton = new UtilityButton ("F:", Font ("Small Text", 13, Font::plain));
4242
fileButton->addListener (this);

Source/UI/ControlPanel.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -427,10 +427,7 @@ ControlPanel::ControlPanel(ProcessorGraph* graph_, AudioComponent* audio_)
427427

428428

429429
#if defined(__APPLE__)
430-
const File dataDirectory = File::getSpecialLocation(File::userDocumentsDirectory).getChildFile("open-ephys");
431-
if (!dataDirectory.isDirectory()) {
432-
dataDirectory.createDirectory();
433-
}
430+
const File dataDirectory = CoreServices::getDefaultUserSaveDirectory();
434431
#else
435432
const File dataDirectory = File::getSpecialLocation(File::currentExecutableFile).getParentDirectory();
436433
#endif

Source/UI/EditorViewport.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1231,7 +1231,7 @@ const String EditorViewport::saveState(File fileToUse)
12311231
currentFile = fileToUse;
12321232

12331233
// FileChooser fc("Choose the file to save...",
1234-
// File::getCurrentWorkingDirectory(),
1234+
// CoreServices::getDefaultUserSaveDirectory(),
12351235
// "*",
12361236
// true);
12371237

@@ -1411,7 +1411,7 @@ const String EditorViewport::loadState(File fileToLoad)
14111411
{
14121412

14131413
// FileChooser fc("Choose a file to load...",
1414-
// File::getCurrentWorkingDirectory(),
1414+
// CoreServices::getDefaultUserSaveDirectory(),
14151415
// "*.xml",
14161416
// true);
14171417

Source/UI/UIComponent.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -531,7 +531,7 @@ bool UIComponent::perform(const InvocationInfo& info)
531531
case openConfiguration:
532532
{
533533
FileChooser fc("Choose a file to load...",
534-
File::getCurrentWorkingDirectory(),
534+
CoreServices::getDefaultUserSaveDirectory(),
535535
"*",
536536
true);
537537

@@ -557,7 +557,7 @@ bool UIComponent::perform(const InvocationInfo& info)
557557
else
558558
{
559559
FileChooser fc("Choose the file name...",
560-
File::getCurrentWorkingDirectory(),
560+
CoreServices::getDefaultUserSaveDirectory(),
561561
"*",
562562
true);
563563

@@ -580,7 +580,7 @@ bool UIComponent::perform(const InvocationInfo& info)
580580
{
581581

582582
FileChooser fc("Choose the file name...",
583-
File::getCurrentWorkingDirectory(),
583+
CoreServices::getDefaultUserSaveDirectory(),
584584
"*",
585585
true);
586586

0 commit comments

Comments
 (0)