File indexing completed on 2024-11-10 04:05:04
0001 /* This file is part of the KDE libraries 0002 SPDX-FileCopyrightText: 1999, 2000 Kurt Granroth <granroth@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #ifndef KSTANDARDACTION_PRIVATE_H 0008 #define KSTANDARDACTION_PRIVATE_H 0009 0010 #include <QAction> 0011 #include <QApplication> 0012 0013 #include <klocalizedstring.h> 0014 #include <kstandardshortcut.h> 0015 0016 namespace KStandardAction 0017 { 0018 0019 struct KStandardActionInfo { 0020 StandardAction id; 0021 KStandardShortcut::StandardShortcut idAccel; 0022 const char *psName; 0023 const char *psLabel; 0024 const char *psToolTip; 0025 const char *psIconName; 0026 }; 0027 0028 static const KStandardActionInfo g_rgActionInfo[] = { 0029 { New, KStandardShortcut::New, "file_new", I18N_NOOP("&New"), I18N_NOOP("Create new document"), "document-new" }, 0030 { Open, KStandardShortcut::Open, "file_open", I18N_NOOP("&Open..."), I18N_NOOP("Open an existing document"), "document-open" }, 0031 { OpenRecent, KStandardShortcut::AccelNone, "file_open_recent", I18N_NOOP("Open &Recent"), I18N_NOOP("Open a document which was recently opened"), "document-open-recent" }, 0032 { Save, KStandardShortcut::Save, "file_save", I18N_NOOP("&Save"), I18N_NOOP("Save document"), "document-save" }, 0033 { SaveAs, KStandardShortcut::SaveAs, "file_save_as", I18N_NOOP("Save &As..."), I18N_NOOP("Save document under a new name"), "document-save-as" }, 0034 { Revert, KStandardShortcut::Revert, "file_revert", I18N_NOOP("Re&vert"), I18N_NOOP("Revert unsaved changes made to document"), "document-revert" }, 0035 { Close, KStandardShortcut::Close, "file_close", I18N_NOOP("&Close"), I18N_NOOP("Close document"), "document-close" }, 0036 { Print, KStandardShortcut::Print, "file_print", I18N_NOOP("&Print..."), I18N_NOOP("Print document"), "document-print" }, 0037 { PrintPreview, KStandardShortcut::PrintPreview, "file_print_preview", I18N_NOOP("Print Previe&w"), I18N_NOOP("Show a print preview of document"), "document-print-preview" }, 0038 { Mail, KStandardShortcut::Mail, "file_mail", I18N_NOOP("&Mail..."), I18N_NOOP("Send document by mail"), "mail-send" }, 0039 { Quit, KStandardShortcut::Quit, "file_quit", I18N_NOOP("&Quit"), I18N_NOOP("Quit application"), "application-exit" }, 0040 0041 { Undo, KStandardShortcut::Undo, "edit_undo", I18N_NOOP("&Undo"), I18N_NOOP("Undo last action"), "edit-undo" }, 0042 { Redo, KStandardShortcut::Redo, "edit_redo", I18N_NOOP("Re&do"), I18N_NOOP("Redo last undone action"), "edit-redo" }, 0043 { Cut, KStandardShortcut::Cut, "edit_cut", I18N_NOOP("Cu&t"), I18N_NOOP("Cut selection to clipboard"), "edit-cut" }, 0044 { Copy, KStandardShortcut::Copy, "edit_copy", I18N_NOOP("&Copy"), I18N_NOOP("Copy selection to clipboard"), "edit-copy" }, 0045 { Paste, KStandardShortcut::Paste, "edit_paste", I18N_NOOP("&Paste"), I18N_NOOP("Paste clipboard content"), "edit-paste" }, 0046 { PasteText, KStandardShortcut::Paste, "edit_paste", I18N_NOOP("&Paste"), I18N_NOOP("Paste clipboard content"), "edit-paste" }, 0047 { Clear, KStandardShortcut::Clear, "edit_clear", I18N_NOOP("C&lear"), 0, "edit-clear" }, 0048 { SelectAll, KStandardShortcut::SelectAll, "edit_select_all", I18N_NOOP("Select &All"), 0, "edit-select-all" }, 0049 { Deselect, KStandardShortcut::Deselect, "edit_deselect", I18N_NOOP("Dese&lect"), 0, 0 }, 0050 { Find, KStandardShortcut::Find, "edit_find", I18N_NOOP("&Find..."), 0, "edit-find" }, 0051 { FindNext, KStandardShortcut::FindNext, "edit_find_next", I18N_NOOP("Find &Next"), 0, "go-down-search" }, 0052 { FindPrev, KStandardShortcut::FindPrev, "edit_find_prev", I18N_NOOP("Find Pre&vious"), 0, "go-up-search" }, 0053 { Replace, KStandardShortcut::Replace, "edit_replace", I18N_NOOP("&Replace..."), 0, 0 }, 0054 0055 { ActualSize, KStandardShortcut::ActualSize, "view_actual_size", I18N_NOOP("&Actual Size"), I18N_NOOP("View document at its actual size"), "zoom-original" }, 0056 { FitToPage, KStandardShortcut::FitToPage, "view_fit_to_page", I18N_NOOP("&Fit to Page"), I18N_NOOP("Zoom to fit page in window"), 0 }, 0057 { FitToWidth, KStandardShortcut::FitToWidth, "view_fit_to_width", I18N_NOOP("Fit to Page &Width"), I18N_NOOP("Zoom to fit page width in window"), 0 }, 0058 { FitToHeight, KStandardShortcut::FitToHeight, "view_fit_to_height", I18N_NOOP("Fit to Page &Height"), I18N_NOOP("Zoom to fit page height in window"), 0 }, 0059 { ZoomIn, KStandardShortcut::ZoomIn, "view_zoom_in", I18N_NOOP("Zoom &In"), 0, "zoom-in" }, 0060 { ZoomOut, KStandardShortcut::ZoomOut, "view_zoom_out", I18N_NOOP("Zoom &Out"), 0, "zoom-out" }, 0061 { Zoom, KStandardShortcut::Zoom, "view_zoom", I18N_NOOP("&Zoom..."), I18N_NOOP("Select zoom level"), 0 }, 0062 { Redisplay, KStandardShortcut::Reload, "view_redisplay", I18N_NOOP("&Redisplay"), I18N_NOOP("Redisplay document"), "view-refresh" }, 0063 0064 { Up, KStandardShortcut::Up, "go_up", I18N_NOOP("&Up"), I18N_NOOP("Go up"), "go-up" }, 0065 // The following three have special i18n() needs for sLabel 0066 { Back, KStandardShortcut::Back, "go_back", 0, 0, "go-previous" }, 0067 { Forward, KStandardShortcut::Forward, "go_forward", 0, 0, "go-next" }, 0068 { Home, KStandardShortcut::Home, "go_home", 0, 0, "go-home" }, 0069 { Prior, KStandardShortcut::Prior, "go_previous", I18N_NOOP("&Previous Page"), I18N_NOOP("Go to previous page"), "go-previous-view-page" }, 0070 { Next, KStandardShortcut::Next, "go_next", I18N_NOOP("&Next Page"), I18N_NOOP("Go to next page"), "go-next-view-page" }, 0071 { Goto, KStandardShortcut::Goto, "go_goto", I18N_NOOP("&Go To..."), 0, 0 }, 0072 { GotoPage, KStandardShortcut::GotoPage, "go_goto_page", I18N_NOOP("&Go to Page..."), 0, "go-jump" }, 0073 { GotoLine, KStandardShortcut::GotoLine, "go_goto_line", I18N_NOOP("&Go to Line..."), 0, 0 }, 0074 { FirstPage, KStandardShortcut::Begin, "go_first", I18N_NOOP("&First Page"), I18N_NOOP("Go to first page"), "go-first-view-page" }, 0075 { LastPage, KStandardShortcut::End, "go_last", I18N_NOOP("&Last Page"), I18N_NOOP("Go to last page"), "go-last-view-page" }, 0076 { DocumentBack, KStandardShortcut::DocumentBack, "go_document_back", I18N_NOOP("&Back"), I18N_NOOP("Go back in document"), "go-previous" }, 0077 { DocumentForward, KStandardShortcut::DocumentForward, "go_document_forward", I18N_NOOP("&Forward"), I18N_NOOP("Go forward in document"), "go-next" }, 0078 0079 { AddBookmark, KStandardShortcut::AddBookmark, "bookmark_add", I18N_NOOP("&Add Bookmark"), 0, "bookmark-new" }, 0080 { EditBookmarks, KStandardShortcut::EditBookmarks, "bookmark_edit", I18N_NOOP("&Edit Bookmarks..."), 0, "bookmarks-organize" }, 0081 0082 { Spelling, KStandardShortcut::Spelling, "tools_spelling", I18N_NOOP("&Spelling..."), I18N_NOOP("Check spelling in document"), "tools-check-spelling" }, 0083 0084 { ShowMenubar, KStandardShortcut::ShowMenubar, "options_show_menubar", I18N_NOOP("Show &Menubar"), I18N_NOOP("Show or hide menubar"), "show-menu" }, 0085 { ShowToolbar, KStandardShortcut::ShowToolbar, "options_show_toolbar", I18N_NOOP("Show &Toolbar"), I18N_NOOP("Show or hide toolbar"), 0 }, 0086 { ShowStatusbar, KStandardShortcut::ShowStatusbar, "options_show_statusbar", I18N_NOOP("Show St&atusbar"), I18N_NOOP("Show or hide statusbar"), 0 }, 0087 { FullScreen, KStandardShortcut::FullScreen, "fullscreen", I18N_NOOP("F&ull Screen Mode"), 0, "view-fullscreen" }, 0088 { SaveOptions, KStandardShortcut::SaveOptions, "options_save_options", I18N_NOOP("&Save Settings"), 0, 0 }, 0089 { KeyBindings, KStandardShortcut::KeyBindings, "options_configure_keybinding", I18N_NOOP("Configure S&hortcuts..."), 0, "configure-shortcuts" }, 0090 { Preferences, KStandardShortcut::Preferences, "options_configure", I18N_NOOP("&Configure %1..."), 0, "configure" }, 0091 { ConfigureToolbars, KStandardShortcut::ConfigureToolbars, "options_configure_toolbars", I18N_NOOP("Configure Tool&bars..."), 0, "configure-toolbars" }, 0092 { ConfigureNotifications, KStandardShortcut::ConfigureNotifications, "options_configure_notifications", I18N_NOOP("Configure &Notifications..."), 0, "preferences-desktop-notification" }, 0093 { ResetConfigurations, KStandardShortcut::ReportBug, "reset_configurations", I18N_NOOP("Reset Configurations"), 0, "configure-toolbars" }, 0094 0095 0096 // the idea here is that Contents is used in menus, and Help in dialogs, so both share the same 0097 // shortcut 0098 { Help, KStandardShortcut::Help, "help", 0, 0, "help-contents" }, 0099 { HelpContents, KStandardShortcut::Help, "help_contents", I18N_NOOP("%1 &Handbook"), 0, "help-contents" }, 0100 { WhatsThis, KStandardShortcut::WhatsThis, "help_whats_this", I18N_NOOP("What's &This?"), 0, "help-contextual" }, 0101 { TipofDay, KStandardShortcut::TipofDay, "help_show_tip", I18N_NOOP("Tip of the &Day"), 0, "help-hint" }, 0102 { ReportBug, KStandardShortcut::ReportBug, "help_report_bug", I18N_NOOP("&Report Bug..."), 0, "tools-report-bug" }, 0103 { SwitchApplicationLanguage, KStandardShortcut::SwitchApplicationLanguage, "switch_application_language", I18N_NOOP("Switch Application &Language..."), 0, "preferences-desktop-locale" }, 0104 { AboutApp, KStandardShortcut::AccelNone, "help_about_app", I18N_NOOP("&About %1"), 0, 0 }, 0105 { AboutKDE, KStandardShortcut::AccelNone, "help_about_kde", I18N_NOOP("About &KDE"), 0, "kde" }, 0106 { ActionNone, KStandardShortcut::AccelNone, 0, 0, 0, 0 } 0107 }; 0108 0109 inline const KStandardActionInfo *infoPtr(StandardAction id) 0110 { 0111 for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) { 0112 if (g_rgActionInfo[i].id == id) { 0113 return &g_rgActionInfo[i]; 0114 } 0115 } 0116 0117 return 0; 0118 } 0119 0120 static inline QStringList internal_stdNames() 0121 { 0122 QStringList result; 0123 0124 for (uint i = 0; g_rgActionInfo[i].id != ActionNone; i++) 0125 if (g_rgActionInfo[i].psLabel) { 0126 if (QByteArray(g_rgActionInfo[i].psLabel).contains("%1")) 0127 // Prevents i18n from complaining about unsubstituted placeholder. 0128 { 0129 result.append(i18n(g_rgActionInfo[i].psLabel, QString())); 0130 } else { 0131 result.append(i18n(g_rgActionInfo[i].psLabel)); 0132 } 0133 } 0134 0135 return result; 0136 } 0137 0138 class AutomaticAction : public QAction 0139 { 0140 Q_OBJECT 0141 0142 public: 0143 AutomaticAction(const QIcon &icon, const QString &text, const QList<QKeySequence> &shortcut, const char *slot, 0144 QObject *parent); 0145 public Q_SLOTS: 0146 inline void cut() 0147 { 0148 invokeEditSlot("cut"); 0149 } 0150 inline void copy() 0151 { 0152 invokeEditSlot("copy"); 0153 } 0154 inline void paste() 0155 { 0156 invokeEditSlot("paste"); 0157 } 0158 inline void clear() 0159 { 0160 invokeEditSlot("clear"); 0161 } 0162 inline void selectAll() 0163 { 0164 invokeEditSlot("selectAll"); 0165 } 0166 0167 void invokeEditSlot(const char *slot) 0168 { 0169 if (qApp->focusWidget()) { 0170 QMetaObject::invokeMethod(qApp->focusWidget(), slot); 0171 } 0172 } 0173 0174 }; 0175 0176 } 0177 0178 #endif