KNewFileMenu Class
The 'Create New' submenu, for creating files using templates (e.g. "new HTML file") and directories. More...
Header: | #include <KNewFileMenu> |
CMake: | find_package(KF6 REQUIRED COMPONENTS KIO) target_link_libraries(mytarget PRIVATE KF6::KIOFileWidgets) |
Public Functions
(since 5.100) | KNewFileMenu(QObject *parent) |
virtual | ~KNewFileMenu() override |
(since 6.2) bool | isCreateDirectoryRunning() |
(since 6.2) bool | isCreateFileRunning() |
bool | isModal() const |
void | setModal(bool modality) |
(since 5.100) void | setNewFileShortcutAction(QAction *action) |
(since 5.100) void | setNewFolderShortcutAction(QAction *action) |
void | setParentWidget(QWidget *parentWidget) |
(since 5.76) void | setSelectDirWhenAlreadyExist(bool b) |
void | setSupportedMimeTypes(const QStringList &mime) |
(since 5.97.) void | setWorkingDirectory(const QUrl &directory) |
QStringList | supportedMimeTypes() const |
(since 5.97.) QUrl | workingDirectory() const |
Public Slots
void | checkUpToDate() |
void | createDirectory() |
(since 5.53) void | createFile() |
Signals
void | directoryCreated(const QUrl &url) |
(since 6.2) void | directoryCreationRejected(const QUrl &url) |
(since 6.2) void | directoryCreationStarted(const QUrl &url) |
void | fileCreated(const QUrl &url) |
(since 6.2) void | fileCreationRejected(const QUrl &url) |
(since 6.2) void | fileCreationStarted(const QUrl &url) |
(since 5.76) void | selectExistingDir(const QUrl &url) |
Protected Slots
virtual void | slotResult(KJob *job) |
Detailed Description
The same instance can be used by both for the File menu and the RMB popup menu, in a file manager. This is also used in the file dialog's RMB menu.
To use this class, you need to connect aboutToShow() of the File menu with slotCheckUpToDate() and to call slotCheckUpToDate() before showing the RMB popupmenu.
KNewFileMenu automatically updates the list of templates shown if installed templates are added/updated/deleted.
Member Function Documentation
[since 5.100]
KNewFileMenu::KNewFileMenu(QObject *parent)
Constructor.
parent the parent object, for ownership. If the parent object is a widget, it will also be used as the parent widget for any dialogs that this class might show. Otherwise, call setParentWidget.
This function was introduced in 5.100.
[override virtual noexcept]
KNewFileMenu::~KNewFileMenu()
Destructor. KNewMenu uses internally a globally shared cache, so that multiple instances of it don't need to parse the installed templates multiple times. Therefore you can safely create and delete KNewMenu instances without a performance issue.
[slot]
void KNewFileMenu::checkUpToDate()
Checks if updating the list is necessary IMPORTANT : Call this in the slot for aboutToShow.
[slot]
void KNewFileMenu::createDirectory()
Call this to create a new directory as if the user had done it using a popupmenu. This is useful to make sure that creating a directory with a key shortcut (e.g. F10) triggers the exact same code as when using the New menu. Requirements: since 5.97 call setWorkingDirectory first (for older releases call setPopupFiles first), and keep this KNewFileMenu instance alive (the mkdir is async).
[slot, since 5.53]
void KNewFileMenu::createFile()
Call this to create a new file as if the user had done it using a popupmenu. This is useful to make sure that creating a directory with a key shortcut (e.g. Shift-F10) triggers the exact same code as when using the New menu. Requirements: since 5.97 call setWorkingDirectory first (for older releases call setPopupFiles first), and keep this KNewFileMenu instance alive (the copy is async).
This function was introduced in 5.53.
[signal]
void KNewFileMenu::directoryCreated(const QUrl &url)
Emitted once the directory @p url has been successfully created
[signal, since 6.2]
void KNewFileMenu::directoryCreationRejected(const QUrl &url)
Emitted once the creation for directory @p url has been rejected
This function was introduced in 6.2.
[signal, since 6.2]
void KNewFileMenu::directoryCreationStarted(const QUrl &url)
Emitted once the creation job for directory @p url has been started
This function was introduced in 6.2.
[signal]
void KNewFileMenu::fileCreated(const QUrl &url)
Emitted once the file (or symlink) @p url has been successfully created
[signal, since 6.2]
void KNewFileMenu::fileCreationRejected(const QUrl &url)
Emitted once the creation for file @p url has been rejected
This function was introduced in 6.2.
[signal, since 6.2]
void KNewFileMenu::fileCreationStarted(const QUrl &url)
Emitted once the creation job for file @p url has been started
This function was introduced in 6.2.
[since 6.2]
bool KNewFileMenu::isCreateDirectoryRunning()
Use this to check if namejob for new directory creation still running. Namejob is what spawns the new directory dialog, which can be slow in, for example, network folders.
This function was introduced in 6.2.
[since 6.2]
bool KNewFileMenu::isCreateFileRunning()
Use this to check if the file creation process is still running.
This function was introduced in 6.2.
bool KNewFileMenu::isModal() const
Returns the modality of dialogs
[signal, since 5.76]
void KNewFileMenu::selectExistingDir(const QUrl &url)
Emitted when trying to create a new directory that has the same name as an existing one, so that KDirOperator can select the existing item in the view (in case the user wants to use that directory instead of creating a new one).
This function was introduced in 5.76.
void KNewFileMenu::setModal(bool modality)
Sets the modality of dialogs created by KNewFile. Set to false if you do not want to block your application window when entering a new directory name i.e.
See also isModal().
[since 5.100]
void KNewFileMenu::setNewFileShortcutAction(QAction *action)
Use this to set a shortcut for the new file action.
The shortcut is copied from action.
This function was introduced in 5.100.
[since 5.100]
void KNewFileMenu::setNewFolderShortcutAction(QAction *action)
Use this to set a shortcut for the "New Folder" action.
The shortcut is copied from action.
This function was introduced in 5.100.
void KNewFileMenu::setParentWidget(QWidget *parentWidget)
Sets a parent widget for the dialogs shown by KNewFileMenu. This is strongly recommended, for apps with a main window.
[since 5.76]
void KNewFileMenu::setSelectDirWhenAlreadyExist(bool b)
Whether on not the dialog should emit `selectExistingDir` when trying to create an exist directory
default: false
This function was introduced in 5.76.
void KNewFileMenu::setSupportedMimeTypes(const QStringList &mime)
Only show the files in a given set of MIME types. This is useful in specialized applications (while file managers, on the other hand, want to show all MIME types).
See also supportedMimeTypes().
[since 5.97.]
void KNewFileMenu::setWorkingDirectory(const QUrl &directory)
Set the working directory. Files will be created relative to this directory.
This function was introduced in 5.97..
See also workingDirectory().
[virtual protected slot]
void KNewFileMenu::slotResult(KJob *job)
Called when the job that copied the template has finished. This method is virtual so that error handling can be reimplemented. Make sure to call the base class slotResult when !job->error() though.
QStringList KNewFileMenu::supportedMimeTypes() const
Returns the MIME types set in supportedMimeTypes()
See also setSupportedMimeTypes().
[since 5.97.]
QUrl KNewFileMenu::workingDirectory() const
Returns the working directory. Files will be created relative to this directory.
This function was introduced in 5.97..
See also setWorkingDirectory().