mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-02-02 03:20:06 +00:00
Added File::userPicturesDirectory, and improved detection of special file locations on linux.
This commit is contained in:
parent
98fcdca3ba
commit
e6faf25559
6 changed files with 176 additions and 100 deletions
|
|
@ -23,14 +23,19 @@
|
|||
==============================================================================
|
||||
*/
|
||||
|
||||
static bool exeIsAvailable (const char* const executable)
|
||||
{
|
||||
ChildProcess child;
|
||||
const bool ok = child.start ("which " + String (executable))
|
||||
&& child.readAllProcessOutput().trim().isNotEmpty();
|
||||
|
||||
child.waitForProcessToFinish (60 * 1000);
|
||||
return ok;
|
||||
}
|
||||
|
||||
bool FileChooser::isPlatformDialogAvailable()
|
||||
{
|
||||
ChildProcess child;
|
||||
const bool ok = child.start ("which zenity")
|
||||
&& child.readAllProcessOutput().trim().isNotEmpty();
|
||||
|
||||
child.waitForProcessToFinish (60 * 1000);
|
||||
return ok;
|
||||
return exeIsAvailable ("zenity") || exeIsAvailable ("kdialog");
|
||||
}
|
||||
|
||||
void FileChooser::showPlatformDialog (Array<File>& results,
|
||||
|
|
@ -44,35 +49,82 @@ void FileChooser::showPlatformDialog (Array<File>& results,
|
|||
bool selectMultipleFiles,
|
||||
FilePreviewComponent* previewComponent)
|
||||
{
|
||||
const String separator (":");
|
||||
|
||||
String separator;
|
||||
StringArray args;
|
||||
args.add ("zenity");
|
||||
args.add ("--file-selection");
|
||||
|
||||
if (title.isNotEmpty()) args.add ("--title=" + title);
|
||||
if (isDirectory) args.add ("--directory");
|
||||
if (isSave) args.add ("--save");
|
||||
|
||||
if (selectMultipleFiles)
|
||||
{
|
||||
args.add ("--multiple");
|
||||
args.add ("--separator=" + separator);
|
||||
}
|
||||
|
||||
const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
|
||||
const bool isKdeFullSession = SystemStats::getEnvironmentVariable ("KDE_FULL_SESSION", String::empty)
|
||||
.equalsIgnoreCase ("true");
|
||||
|
||||
if (file.isDirectory())
|
||||
if (exeIsAvailable ("kdialog") && (isKdeFullSession || ! exeIsAvailable ("zenity")))
|
||||
{
|
||||
file.setAsCurrentWorkingDirectory();
|
||||
}
|
||||
else if (file.exists())
|
||||
{
|
||||
file.getParentDirectory().setAsCurrentWorkingDirectory();
|
||||
args.add ("--filename=" + file.getFileName());
|
||||
}
|
||||
// use kdialog for KDE sessions or if zenity is missing
|
||||
args.add ("kdialog");
|
||||
|
||||
args.add ("2>&1");
|
||||
if (title.isNotEmpty())
|
||||
args.add ("--title=" + title);
|
||||
|
||||
if (selectMultipleFiles)
|
||||
{
|
||||
separator = "\n";
|
||||
args.add ("--multiple");
|
||||
args.add ("--separate-output");
|
||||
args.add ("--getopenfilename");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isSave) args.add ("--getsavefilename");
|
||||
else if (isDirectory) args.add ("--getexistingdirectory");
|
||||
else args.add ("--getopenfilename");
|
||||
}
|
||||
|
||||
String startPath;
|
||||
|
||||
if (file.exists() || file.getParentDirectory().exists())
|
||||
{
|
||||
startPath = file.getFullPathName();
|
||||
}
|
||||
else
|
||||
{
|
||||
startPath = File::getSpecialLocation (File::userHomeDirectory).getFullPathName();
|
||||
|
||||
if (isSave)
|
||||
startPath += "/" + file.getFileName();
|
||||
}
|
||||
|
||||
args.add (startPath);
|
||||
}
|
||||
else
|
||||
{
|
||||
// zenity
|
||||
args.add ("zenity");
|
||||
args.add ("--file-selection");
|
||||
|
||||
if (title.isNotEmpty())
|
||||
args.add ("--title=" + title);
|
||||
|
||||
if (selectMultipleFiles)
|
||||
{
|
||||
separator = ":";
|
||||
args.add ("--multiple");
|
||||
args.add ("--separator=" + separator);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (isDirectory) args.add ("--directory");
|
||||
if (isSave) args.add ("--save");
|
||||
}
|
||||
|
||||
if (file.isDirectory())
|
||||
file.setAsCurrentWorkingDirectory();
|
||||
else if (file.getParentDirectory().exists())
|
||||
file.getParentDirectory().setAsCurrentWorkingDirectory();
|
||||
else
|
||||
File::getSpecialLocation (File::userHomeDirectory).setAsCurrentWorkingDirectory();
|
||||
|
||||
if (! file.getFileName().isEmpty())
|
||||
args.add ("--filename=" + file.getFileName());
|
||||
}
|
||||
|
||||
ChildProcess child;
|
||||
if (child.start (args))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue