KNewFileMenu

Search for usage in LXR

#include <KNewFileMenu>

Inheritance diagram for KNewFileMenu:

Signals

void directoryCreated (const QUrl &url)
 
void fileCreated (const QUrl &url)
 
void selectExistingDir (const QUrl &url)
 

Public Slots

void checkUpToDate ()
 
void createDirectory ()
 
void createFile ()
 

Public Member Functions

 KNewFileMenu (KActionCollection *collection, const QString &name, QObject *parent)
 
 KNewFileMenu (QObject *parent)
 
 ~KNewFileMenu () override
 
bool isModal () const
 
QList< QUrlpopupFiles () const
 
void setModal (bool modality)
 
void setNewFileShortcutAction (QAction *action)
 
void setNewFolderShortcutAction (QAction *action)
 
void setParentWidget (QWidget *parentWidget)
 
void setPopupFiles (const QList< QUrl > &files)
 
void setPopupFiles (const QUrl &file)
 
void setSelectDirWhenAlreadyExist (bool b)
 
void setSupportedMimeTypes (const QStringList &mime)
 
void setViewShowsHiddenFiles (bool b)
 
void setWorkingDirectory (const QUrl &directory)
 
QStringList supportedMimeTypes () const
 
QUrl workingDirectory () const
 
- Public Member Functions inherited from KActionMenu
void addAction (QAction *action)
 
bool delayed () const
 
QMenupopupMenu ()
 
QToolButton::ToolButtonPopupMode popupMode () const
 
void remove (QAction *)
 
void setDelayed (bool delayed)
 
void setPopupMode (QToolButton::ToolButtonPopupMode popupMode)
 
void setStickyMenu (bool sticky)
 
bool stickyMenu () const
 
- Public Member Functions inherited from QWidgetAction
 QWidgetAction (QObject *parent)
 
QWidgetdefaultWidget () const const
 
void releaseWidget (QWidget *widget)
 
QWidgetrequestWidget (QWidget *parent)
 
void setDefaultWidget (QWidget *widget)
 
- Public Member Functions inherited from QAction
 QAction (const QIcon &icon, const QString &text, QObject *parent)
 
 QAction (const QString &text, QObject *parent)
 
 QAction (QObject *parent)
 
QActionGroupactionGroup () const const
 
void activate (QAction::ActionEvent event)
 
QList< QGraphicsWidget * > associatedGraphicsWidgets () const const
 
QList< QWidget * > associatedWidgets () const const
 
bool autoRepeat () const const
 
void changed ()
 
QVariant data () const const
 
QFont font () const const
 
void hover ()
 
void hovered ()
 
QIcon icon () const const
 
QString iconText () const const
 
bool isCheckable () const const
 
bool isChecked () const const
 
bool isEnabled () const const
 
bool isIconVisibleInMenu () const const
 
bool isSeparator () const const
 
bool isShortcutVisibleInContextMenu () const const
 
bool isVisible () const const
 
QMenumenu () const const
 
QAction::MenuRole menuRole () const const
 
QWidgetparentWidget () const const
 
QAction::Priority priority () const const
 
void setActionGroup (QActionGroup *group)
 
void setAutoRepeat (bool)
 
void setCheckable (bool)
 
void setChecked (bool)
 
void setData (const QVariant &userData)
 
void setDisabled (bool b)
 
void setEnabled (bool)
 
void setFont (const QFont &font)
 
void setIcon (const QIcon &icon)
 
void setIconText (const QString &text)
 
void setIconVisibleInMenu (bool visible)
 
void setMenu (QMenu *menu)
 
void setMenuRole (QAction::MenuRole menuRole)
 
void setPriority (QAction::Priority priority)
 
void setSeparator (bool b)
 
void setShortcut (const QKeySequence &shortcut)
 
void setShortcutContext (Qt::ShortcutContext context)
 
void setShortcuts (const QList< QKeySequence > &shortcuts)
 
void setShortcuts (QKeySequence::StandardKey key)
 
void setShortcutVisibleInContextMenu (bool show)
 
void setStatusTip (const QString &statusTip)
 
void setText (const QString &text)
 
void setToolTip (const QString &tip)
 
void setVisible (bool)
 
void setWhatsThis (const QString &what)
 
QKeySequence shortcut () const const
 
Qt::ShortcutContext shortcutContext () const const
 
QList< QKeySequenceshortcuts () const const
 
bool showStatusText (QWidget *widget)
 
QString statusTip () const const
 
QString text () const const
 
void toggle ()
 
void toggled (bool checked)
 
QString toolTip () const const
 
void trigger ()
 
void triggered (bool checked)
 
QString whatsThis () const const
 
- Public Member Functions inherited from QObject
 QObject (QObject *parent)
 
bool blockSignals (bool block)
 
const QObjectListchildren () const const
 
QMetaObject::Connection connect (const QObject *sender, const char *signal, const char *method, Qt::ConnectionType type) const const
 
void deleteLater ()
 
void destroyed (QObject *obj)
 
bool disconnect (const char *signal, const QObject *receiver, const char *method) const const
 
bool disconnect (const QObject *receiver, const char *method) const const
 
void dumpObjectInfo ()
 
void dumpObjectInfo () const const
 
void dumpObjectTree ()
 
void dumpObjectTree () const const
 
QList< QByteArraydynamicPropertyNames () const const
 
findChild (const QString &name, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegExp &regExp, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QRegularExpression &re, Qt::FindChildOptions options) const const
 
QList< T > findChildren (const QString &name, Qt::FindChildOptions options) const const
 
bool inherits (const char *className) const const
 
void installEventFilter (QObject *filterObj)
 
bool isWidgetType () const const
 
bool isWindowType () const const
 
void killTimer (int id)
 
virtual const QMetaObjectmetaObject () const const
 
void moveToThread (QThread *targetThread)
 
QString objectName () const const
 
void objectNameChanged (const QString &objectName)
 
QObjectparent () const const
 
QVariant property (const char *name) const const
 
 Q_CLASSINFO (Name, Value)
 
 Q_DISABLE_COPY (Class)
 
 Q_DISABLE_COPY_MOVE (Class)
 
 Q_DISABLE_MOVE (Class)
 
 Q_EMIT Q_EMIT
 
 Q_ENUM (...)
 
 Q_ENUM_NS (...)
 
 Q_ENUMS (...)
 
 Q_FLAG (...)
 
 Q_FLAG_NS (...)
 
 Q_FLAGS (...)
 
 Q_GADGET Q_GADGET
 
 Q_INTERFACES (...)
 
 Q_INVOKABLE Q_INVOKABLE
 
 Q_NAMESPACE Q_NAMESPACE
 
 Q_NAMESPACE_EXPORT (EXPORT_MACRO)
 
 Q_OBJECT Q_OBJECT
 
 Q_PROPERTY (...)
 
 Q_REVISION Q_REVISION
 
 Q_SET_OBJECT_NAME (Object)
 
 Q_SIGNAL Q_SIGNAL
 
 Q_SIGNALS Q_SIGNALS
 
 Q_SLOT Q_SLOT
 
 Q_SLOTS Q_SLOTS
 
qFindChild (const QObject *obj, const QString &name)
 
QList< T > qFindChildren (const QObject *obj, const QRegExp &regExp)
 
QList< T > qFindChildren (const QObject *obj, const QString &name)
 
qobject_cast (const QObject *object)
 
qobject_cast (QObject *object)
 
 QT_NO_NARROWING_CONVERSIONS_IN_CONNECT QT_NO_NARROWING_CONVERSIONS_IN_CONNECT
 
void removeEventFilter (QObject *obj)
 
void setObjectName (const QString &name)
 
void setParent (QObject *parent)
 
bool setProperty (const char *name, const QVariant &value)
 
bool signalsBlocked () const const
 
int startTimer (int interval, Qt::TimerType timerType)
 
int startTimer (std::chrono::milliseconds time, Qt::TimerType timerType)
 
QThreadthread () const const
 

Protected Slots

virtual void slotResult (KJob *job)
 

Additional Inherited Members

- Public Types inherited from QAction
enum  ActionEvent
 
enum  MenuRole
 
enum  Priority
 
- Properties inherited from QAction
 autoRepeat
 
 checkable
 
 checked
 
 enabled
 
 font
 
 icon
 
 iconText
 
 iconVisibleInMenu
 
 menuRole
 
 priority
 
 shortcut
 
 shortcutContext
 
 shortcutVisibleInContextMenu
 
 statusTip
 
 text
 
 toolTip
 
 visible
 
 whatsThis
 
- Properties inherited from QObject
 objectName
 
- Static Public Member Functions inherited from QObject
QMetaObject::Connection connect (const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *context, Functor functor, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method, Qt::ConnectionType type)
 
QMetaObject::Connection connect (const QObject *sender, PointerToMemberFunction signal, Functor functor)
 
bool disconnect (const QMetaObject::Connection &connection)
 
bool disconnect (const QObject *sender, const char *signal, const QObject *receiver, const char *method)
 
bool disconnect (const QObject *sender, const QMetaMethod &signal, const QObject *receiver, const QMetaMethod &method)
 
bool disconnect (const QObject *sender, PointerToMemberFunction signal, const QObject *receiver, PointerToMemberFunction method)
 
QString tr (const char *sourceText, const char *disambiguation, int n)
 
QString trUtf8 (const char *sourceText, const char *disambiguation, int n)
 
- Public Attributes inherited from QAction
 AboutQtRole
 
 AboutRole
 
 ApplicationSpecificRole
 
 HighPriority
 
 Hover
 
 LowPriority
 
 NormalPriority
 
 NoRole
 
 PreferencesRole
 
 QuitRole
 
 TextHeuristicRole
 
 Trigger
 
- Public Attributes inherited from QObject
typedef QObjectList
 
- Protected Member Functions inherited from QWidgetAction
QList< QWidget * > createdWidgets () const const
 
virtual QWidgetcreateWidget (QWidget *parent)
 
virtual void deleteWidget (QWidget *widget)
 
virtual bool event (QEvent *event) override
 
virtual bool eventFilter (QObject *obj, QEvent *event) override
 
- Protected Member Functions inherited from QObject
virtual void childEvent (QChildEvent *event)
 
virtual void connectNotify (const QMetaMethod &signal)
 
virtual void customEvent (QEvent *event)
 
virtual void disconnectNotify (const QMetaMethod &signal)
 
bool isSignalConnected (const QMetaMethod &signal) const const
 
int receivers (const char *signal) const const
 
QObjectsender () const const
 
int senderSignalIndex () const const
 
virtual void timerEvent (QTimerEvent *event)
 

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
Bj√∂rn Ruberg bjoer[email protected][email protected][email protected]berg-[email protected]wege[email protected]ner.d[email protected]e Made dialogs working asynchronously
David Faure faure[email protected]@kde[email protected].org Ideas and code for the new template handling mechanism ('link' desktop files) from Christoph Pickart picka[email protected][email protected][email protected]am.un[email protected]i-bo[email protected]nn.de
Since
4.5

Definition at line 47 of file knewfilemenu.h.

Constructor & Destructor Documentation

◆ KNewFileMenu() [1/2]

KNewFileMenu::KNewFileMenu ( KActionCollection collection,
const QString name,
QObject parent 
)

Constructor.

Parameters
collectionthe KActionCollection the QAction with name name should be added to.
nameaction name, when adding the action to collection
parentthe 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.
Note
If you want the "Create directory..." action shortcut to show up next to its text, make sure to have an action with name "create_dir" (and shortcut set) in collection. This will only work with KIO >= 5.27. From KIO >= 5.53, an action named "create_file" (and shortcut set) in collection will be linked to the creation of the first file template (either from XDG_TEMPLATES_DIR or from :/kio5/newfile-templates)
Deprecated:
since 5.100, use KNewFileMenu(QObject *) instead. To associate the action shortcuts use setNewFileShortcutAction() and setNewFileShortcutAction()

Definition at line 1382 of file knewfilemenu.cpp.

◆ KNewFileMenu() [2/2]

KNewFileMenu::KNewFileMenu ( QObject parent)

Constructor.

Parameters
parentthe 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.
Since
5.100

Definition at line 1404 of file knewfilemenu.cpp.

◆ ~KNewFileMenu()

KNewFileMenu::~KNewFileMenu ( )
overridedefault

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.

Member Function Documentation

◆ checkUpToDate

void KNewFileMenu::checkUpToDate ( )
slot

Checks if updating the list is necessary IMPORTANT : Call this in the slot for aboutToShow.

Definition at line 1422 of file knewfilemenu.cpp.

◆ createDirectory

void KNewFileMenu::createDirectory ( )
slot

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).

Definition at line 1451 of file knewfilemenu.cpp.

◆ createFile

void KNewFileMenu::createFile ( )
slot

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).

Since
5.53

Definition at line 1503 of file knewfilemenu.cpp.

◆ directoryCreated

void KNewFileMenu::directoryCreated ( const QUrl url)
signal

Emitted once the directory url has been successfully created.

◆ fileCreated

void KNewFileMenu::fileCreated ( const QUrl url)
signal

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

◆ isModal()

bool KNewFileMenu::isModal ( ) const

Returns the modality of dialogs.

Definition at line 1517 of file knewfilemenu.cpp.

◆ popupFiles()

QList< QUrl > KNewFileMenu::popupFiles ( ) const

Returns the files that the popup is shown for.

Deprecated:
since 5.97, use KNewFileMenu::workingDirectory().

Definition at line 1523 of file knewfilemenu.cpp.

◆ selectExistingDir

void KNewFileMenu::selectExistingDir ( const QUrl url)
signal

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).

Since
5.76

◆ setModal()

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.

Definition at line 1529 of file knewfilemenu.cpp.

◆ setNewFileShortcutAction()

void KNewFileMenu::setNewFileShortcutAction ( QAction action)

Use this to set a shortcut for the new file action.

The shortcut is copied from

Parameters
action.
Since
5.100

Definition at line 1645 of file knewfilemenu.cpp.

◆ setNewFolderShortcutAction()

void KNewFileMenu::setNewFolderShortcutAction ( QAction action)

Use this to set a shortcut for the "New Folder" action.

The shortcut is copied from

Parameters
action.
Since
5.100

Definition at line 1640 of file knewfilemenu.cpp.

◆ setParentWidget()

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.

Definition at line 1554 of file knewfilemenu.cpp.

◆ setPopupFiles()

void KNewFileMenu::setPopupFiles ( const QList< QUrl > &  files)

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

Deprecated:
since 5.97, use KNewFileMenu::setWorkingDirectory(const QUrl &).

Definition at line 1535 of file knewfilemenu.cpp.

◆ setSelectDirWhenAlreadyExist()

void KNewFileMenu::setSelectDirWhenAlreadyExist ( bool  b)

Whether on not the dialog should emit selectExistingDir when trying to create an exist directory.

default: false

Since
5.76

Definition at line 1253 of file knewfilemenu.cpp.

◆ setSupportedMimeTypes()

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).

Definition at line 1559 of file knewfilemenu.cpp.

◆ setViewShowsHiddenFiles()

void KNewFileMenu::setViewShowsHiddenFiles ( bool  b)

Set if the directory view currently shows dot files.

Deprecated:
since 5.97. Calling this has no effect.

Definition at line 1565 of file knewfilemenu.cpp.

◆ setWorkingDirectory()

void KNewFileMenu::setWorkingDirectory ( const QUrl directory)

Set the working directory.

Files will be created relative to this directory.

Since
5.97.

Definition at line 1617 of file knewfilemenu.cpp.

◆ slotResult

void KNewFileMenu::slotResult ( KJob job)
protectedvirtualslot

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.

Definition at line 1571 of file knewfilemenu.cpp.

◆ supportedMimeTypes()

QStringList KNewFileMenu::supportedMimeTypes ( ) const

Returns the MIME types set in supportedMimeTypes()

Definition at line 1612 of file knewfilemenu.cpp.

◆ workingDirectory()

QUrl KNewFileMenu::workingDirectory ( ) const

Returns the working directory.

Files will be created relative to this directory.

Since
5.97.

Definition at line 1635 of file knewfilemenu.cpp.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Tue Dec 6 2022 03:56:07 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.