KNewFileMenu

KDE 4.5 PyKDE API Reference

- KDE's Python API

# KNewFileMenu Class Reference

`from PyKDE4.kio import *`

Inherits: KActionMenu → KAction → QWidgetAction → QAction → QObject

## Detailed Description

The 'Create New' submenu, for creating files using templates (e.g. "new HTML file") and directories.

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.

Author:
  David Faure <faure@kde.org>

Ideas and code for the new template handling mechanism ('link' desktop files) from Christoph Pickart <pickart@iam.uni-bonn.de>

Since:
  4.5

## Signals
| directoryCreated (KUrl url)
| fileCreated (KUrl url)
## Methods
| __init__ (self, KActionCollection collection, QString name, QObject parent)
| checkUpToDate (self)
| createDirectory (self)
KUrl.List | popupFiles (self)
| setParentWidget (self, QWidget parentWidget)
| setPopupFiles (self, KUrl.List files)
| setSupportedMimeTypes (self, QStringList mime)
| setViewShowsHiddenFiles (self, bool b)
| slotResult (self, KJob job)
QStringList | supportedMimeTypes (self)

## Signal Documentation

directoryCreated | ( | KUrl | url
| ) |  |  |

Emitted once the directory url has been successfully created

Signal syntax:
  `QObject.connect(source, SIGNAL("directoryCreated(const KUrl&)"), target_slot)`

fileCreated | ( | KUrl | url
| ) |  |  |

Emitted once the file (or symlink) url has been successfully created

Signal syntax:
  `QObject.connect(source, SIGNAL("fileCreated(const KUrl&)"), target_slot)`

## Method Documentation

__init__ | ( | self, |
|  | KActionCollection | collection,
|  | QString | name,
|  | QObject | parent
| ) |  |  |

Constructor.

Parameters:

  | parent | the KActionCollection this KAction should be added to.
  | name | action name, when adding the action to the collection
  | parent | the parent object, for ownership. If the parent object is a widget, it will also used as parent widget for any dialogs that this class might show. Otherwise, call setParentWidget.

checkUpToDate | ( |  | self ) |

Checks if updating the list is necessary IMPORTANT : Call this in the slot for aboutToShow. And while you're there, you probably want to call setViewShowsHiddenFiles ;)

createDirectory | ( |  | self ) |

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: call setPopupFiles first, and keep this KNewFileMenu instance alive (the mkdir is async).

KUrl.List popupFiles | ( |  | self ) |

Returns the files that the popup is shown for

setParentWidget | ( | self, |
|  | QWidget | parentWidget
| ) |  |  |

Sets a parent widget for the dialogs shown by KNewFileMenu. This is strongly recommended, for apps with a main window.

setPopupFiles | ( | self, |
|  | KUrl.List | files
| ) |  |  |

Set the files the popup is shown for Call this before showing up the menu

setSupportedMimeTypes | ( | self, |
|  | QStringList | mime
| ) |  |  |

Only show the files in a given set of mimetypes. This is useful in specialized applications (while file managers, on the other hand, want to show all mimetypes).

setViewShowsHiddenFiles | ( | self, |
|  | bool | b
| ) |  |  |

Set if the directory view currently shows dot files.

slotResult | ( | self, |
|  | 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 supportedMimeTypes | ( |  | self ) |

Returns the mimetypes set in supportedMimeTypes()