FileBrowser: "Open containing folder" automatically selects file in the OS's file manager (#7700)
Introduces a new class FileRevealer to manage file selection across different platforms (Windows, macOS, Linux, and other *nix operating systems with xdg). Includes methods to open and select files or directories using the default file manager on the respective platform. --------- Co-authored-by: Tres Finocchiaro <tres.finocchiaro@gmail.com> Co-authored-by: Hyunjin Song <tteu.ingog@gmail.com> Co-authored-by: Sotonye Atemie <sakertooth@gmail.com> Co-authored-by: Dalton Messmer <messmer.dalton@gmail.com>
This commit is contained in:
@@ -195,8 +195,6 @@ private slots:
|
||||
bool openInNewSampleTrack( lmms::gui::FileItem* item );
|
||||
void sendToActiveInstrumentTrack( lmms::gui::FileItem* item );
|
||||
void updateDirectory( QTreeWidgetItem * item );
|
||||
void openContainingFolder( lmms::gui::FileItem* item );
|
||||
|
||||
} ;
|
||||
|
||||
|
||||
|
||||
77
include/FileRevealer.h
Normal file
77
include/FileRevealer.h
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* FileRevealer.h - include file for FileRevealer
|
||||
*
|
||||
* Copyright (c) 2025 Andrew Wiltshire <aw1lt / at/ proton/ dot/me >
|
||||
*
|
||||
* This file is part of LMMS - https://lmms.io
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public
|
||||
* License along with this program (see COPYING); if not, write to the
|
||||
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||||
* Boston, MA 02110-1301 USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LMMS_FILE_REVEALER_H
|
||||
#define LMMS_FILE_REVEALER_H
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
namespace lmms {
|
||||
|
||||
/**
|
||||
* @class FileRevealer
|
||||
* @brief A utility class for revealing files and directories in the system's file manager.
|
||||
*/
|
||||
class FileRevealer
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* @brief Retrieves the default file manager for the current platform.
|
||||
* @return The name or command of the default file manager.
|
||||
*/
|
||||
static const QString& getDefaultFileManager();
|
||||
|
||||
/**
|
||||
* @brief Opens the directory containing the specified file or folder in the file manager.
|
||||
* @param item The QFileInfo object representing the file or folder.
|
||||
*/
|
||||
static void openDir(const QFileInfo item);
|
||||
|
||||
/**
|
||||
* @brief Checks whether the file manager supports selecting a specific file.
|
||||
* @return True if selection is supported, otherwise false.
|
||||
*/
|
||||
static const QStringList& getSelectCommand();
|
||||
|
||||
/**
|
||||
* @brief Opens the file manager and selects the specified file if supported.
|
||||
* @param item The QFileInfo object representing the file to reveal.
|
||||
*/
|
||||
static void reveal(const QFileInfo item);
|
||||
|
||||
private:
|
||||
static bool s_canSelect;
|
||||
|
||||
protected:
|
||||
/**
|
||||
* @brief Determines if the given command supports the argument
|
||||
* @param command The name of the file manager to check.
|
||||
* @param arg The command line argument to parse for
|
||||
* @return True if the file command the argument, otherwise false.
|
||||
*/
|
||||
static bool supportsArg(const QString& command, const QString& arg);
|
||||
};
|
||||
|
||||
} // namespace lmms
|
||||
#endif // LMMS_FILE_REVEALER_H
|
||||
Reference in New Issue
Block a user