00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "kstdaction.h"
00020
00021 #include <qtoolbutton.h>
00022 #include <qwhatsthis.h>
00023
00024 #include <kaboutdata.h>
00025 #include <kaction.h>
00026 #include <kapplication.h>
00027 #include <kdebug.h>
00028 #include <kglobal.h>
00029 #include <kiconloader.h>
00030 #include <klocale.h>
00031 #include <kstdaccel.h>
00032 #include <kmainwindow.h>
00033
00034 namespace KStdAction
00035 {
00036
00037 struct KStdActionInfo
00038 {
00039 StdAction id;
00040 KStdAccel::StdAccel idAccel;
00041 const char* psName;
00042 const char* psLabel;
00043 const char* psWhatsThis;
00044 const char* psIconName;
00045 };
00046
00047 const KStdActionInfo g_rgActionInfo[] =
00048 {
00049 { New, KStdAccel::New, "file_new", I18N_NOOP("&New"), 0, "filenew" },
00050 { Open, KStdAccel::Open, "file_open", I18N_NOOP("&Open..."), 0, "fileopen" },
00051 { OpenRecent, KStdAccel::AccelNone, "file_open_recent", I18N_NOOP("Open &Recent"), 0, 0 },
00052 { Save, KStdAccel::Save, "file_save", I18N_NOOP("&Save"), 0, "filesave" },
00053 { SaveAs, KStdAccel::AccelNone, "file_save_as", I18N_NOOP("Save &As..."), 0, "filesaveas" },
00054 { Revert, KStdAccel::AccelNone, "file_revert", I18N_NOOP("Re&vert"), 0, "revert" },
00055 { Close, KStdAccel::Close, "file_close", I18N_NOOP("&Close"), 0, "fileclose" },
00056 { Print, KStdAccel::Print, "file_print", I18N_NOOP("&Print..."), 0, "fileprint" },
00057 { PrintPreview, KStdAccel::AccelNone, "file_print_preview", I18N_NOOP("Print Previe&w..."), 0, "filequickprint" },
00058 { Mail, KStdAccel::AccelNone, "file_mail", I18N_NOOP("&Mail..."), 0, "mail_send" },
00059 { Quit, KStdAccel::Quit, "file_quit", I18N_NOOP("&Quit"), 0, "exit" },
00060
00061 { Undo, KStdAccel::Undo, "edit_undo", I18N_NOOP("&Undo"), 0, "undo" },
00062 { Redo, KStdAccel::Redo, "edit_redo", I18N_NOOP("Re&do"), 0, "redo" },
00063 { Cut, KStdAccel::Cut, "edit_cut", I18N_NOOP("Cu&t"), 0, "editcut" },
00064 { Copy, KStdAccel::Copy, "edit_copy", I18N_NOOP("&Copy"), 0, "editcopy" },
00065 { Paste, KStdAccel::Paste, "edit_paste", I18N_NOOP("&Paste"), 0, "editpaste" },
00066 { SelectAll, KStdAccel::SelectAll, "edit_select_all", I18N_NOOP("Select &All"), 0, 0 },
00067 { Deselect, KStdAccel::Deselect, "edit_deselect", I18N_NOOP("Dese&lect"), 0, 0 },
00068 { Find, KStdAccel::Find, "edit_find", I18N_NOOP("&Find..."), 0, "find" },
00069 { FindNext, KStdAccel::FindNext, "edit_find_next", I18N_NOOP("Find &Next"), 0, "next" },
00070 { FindPrev, KStdAccel::FindPrev, "edit_find_last", I18N_NOOP("Find Pre&vious"), 0, "previous" },
00071 { Replace, KStdAccel::Replace, "edit_replace", I18N_NOOP("&Replace..."), 0, 0 },
00072
00073 { ActualSize, KStdAccel::AccelNone, "view_actual_size", I18N_NOOP("&Actual Size"), 0, 0 },
00074 { FitToPage, KStdAccel::AccelNone, "view_fit_to_page", I18N_NOOP("&Fit to Page"), 0, 0 },
00075 { FitToWidth, KStdAccel::AccelNone, "view_fit_to_width", I18N_NOOP("Fit to Page &Width"), 0, 0 },
00076 { FitToHeight, KStdAccel::AccelNone, "view_fit_to_height", I18N_NOOP("Fit to Page &Height"), 0, 0 },
00077 { ZoomIn, KStdAccel::ZoomIn, "view_zoom_in", I18N_NOOP("Zoom &In"), 0, "viewmag+" },
00078 { ZoomOut, KStdAccel::ZoomOut, "view_zoom_out", I18N_NOOP("Zoom &Out"), 0, "viewmag-" },
00079 { Zoom, KStdAccel::AccelNone, "view_zoom", I18N_NOOP("&Zoom..."), 0, "viewmag" },
00080 { Redisplay, KStdAccel::AccelNone, "view_redisplay", I18N_NOOP("&Redisplay"), 0, "reload" },
00081
00082 { Up, KStdAccel::Up, "go_up", I18N_NOOP("&Up"), 0, "up" },
00083
00084 { Back, KStdAccel::Back, "go_back", 0, 0, "back" },
00085 { Forward, KStdAccel::Forward, "go_forward", 0, 0, "forward" },
00086 { Home, KStdAccel::Home, "go_home", 0, 0, "gohome" },
00087 { Prior, KStdAccel::Prior, "go_previous", I18N_NOOP("&Previous Page"), 0, "previous" },
00088 { Next, KStdAccel::Next, "go_next", I18N_NOOP("&Next Page"), 0, "next" },
00089 { Goto, KStdAccel::AccelNone, "go_goto", I18N_NOOP("&Go To..."), 0, 0 },
00090 { GotoPage, KStdAccel::AccelNone, "go_goto_page", I18N_NOOP("&Go to Page..."), 0, "goto" },
00091 { GotoLine, KStdAccel::GotoLine, "go_goto_line", I18N_NOOP("&Go to Line..."), 0, 0 },
00092 { FirstPage, KStdAccel::Home, "go_first", I18N_NOOP("&First Page"), 0, "top" },
00093 { LastPage, KStdAccel::End, "go_last", I18N_NOOP("&Last Page"), 0, "bottom" },
00094
00095 { AddBookmark, KStdAccel::AddBookmark, "bookmark_add", I18N_NOOP("&Add Bookmark"), 0, "bookmark_add" },
00096 { EditBookmarks, KStdAccel::AccelNone, "bookmark_edit", I18N_NOOP("&Edit Bookmarks"), 0, "bookmark" },
00097
00098 { Spelling, KStdAccel::AccelNone, "tools_spelling", I18N_NOOP("&Spelling..."), 0, "spellcheck" },
00099
00100 { ShowMenubar, KStdAccel::ShowMenubar, "options_show_menubar", I18N_NOOP("Show &Menubar"), 0, "showmenu" },
00101 { ShowToolbar, KStdAccel::AccelNone, "options_show_toolbar", I18N_NOOP("Show &Toolbar"), 0, 0 },
00102 { ShowStatusbar, KStdAccel::AccelNone, "options_show_statusbar", I18N_NOOP("Show St&atusbar"), 0, 0 },
00103 { SaveOptions, KStdAccel::AccelNone, "options_save_options", I18N_NOOP("&Save Settings"), 0, 0 },
00104 { KeyBindings, KStdAccel::AccelNone, "options_configure_keybinding", I18N_NOOP("Configure S&hortcuts..."), 0,"configure_shortcuts" },
00105 { Preferences, KStdAccel::AccelNone, "options_configure", I18N_NOOP("&Configure %1..."), 0, "configure" },
00106 { ConfigureToolbars, KStdAccel::AccelNone, "options_configure_toolbars", I18N_NOOP("Configure Tool&bars..."), 0,"configure_toolbars" },
00107 { ConfigureNotifications, KStdAccel::AccelNone, "options_configure_notifications", I18N_NOOP("Configure &Notifications..."), 0, "knotify" },
00108
00109 { Help, KStdAccel::Help, "help", 0, 0, "help" },
00110 { HelpContents, KStdAccel::AccelNone, "help_contents", I18N_NOOP("%1 &Handbook"), 0, "contents" },
00111 { WhatsThis, KStdAccel::WhatsThis, "help_whats_this", I18N_NOOP("What's &This?"), 0, "contexthelp" },
00112 { TipofDay, KStdAccel::AccelNone, "help_show_tip", I18N_NOOP("Tip of the &Day"), 0, "idea" },
00113 { ReportBug, KStdAccel::AccelNone, "help_report_bug", I18N_NOOP("&Report Bug..."), 0, 0 },
00114 { AboutApp, KStdAccel::AccelNone, "help_about_app", I18N_NOOP("&About %1"), 0, 0 },
00115 { AboutKDE, KStdAccel::AccelNone, "help_about_kde", I18N_NOOP("About &KDE"), 0,"about_kde" },
00116 { ActionNone, KStdAccel::AccelNone, 0, 0, 0, 0 }
00117 };
00118
00119 static const KStdActionInfo* infoPtr( StdAction id )
00120 {
00121 for( uint i = 0; g_rgActionInfo[i].id != ActionNone; i++ ) {
00122 if( g_rgActionInfo[i].id == id )
00123 return &g_rgActionInfo[i];
00124 }
00125 return 0;
00126 }
00127
00128 QStringList stdNames()
00129 {
00130 QStringList result;
00131
00132 for( uint i = 0; g_rgActionInfo[i].id != ActionNone; i++ )
00133 if (g_rgActionInfo[i].psLabel)
00134 result.append(i18n(g_rgActionInfo[i].psLabel));
00135 return result;
00136 }
00137
00138 KAction* create( StdAction id, const char *name, const QObject *recvr, const char *slot, KActionCollection* parent )
00139 {
00140 KAction* pAction = 0;
00141 const KStdActionInfo* pInfo = infoPtr( id );
00142 kdDebug(125) << "KStdAction::create( " << id << "=" << (pInfo ? pInfo->psName : (const char*)0) << ", " << parent << ", " << name << " )" << endl;
00143 if( pInfo ) {
00144 QString sLabel, iconName = pInfo->psIconName;
00145 switch( id ) {
00146 case Back: sLabel = i18n("go back", "&Back");
00147 if (QApplication::reverseLayout() )
00148 iconName = "forward";
00149 break;
00150
00151 case Forward: sLabel = i18n("go forward", "&Forward");
00152 if (QApplication::reverseLayout() )
00153 iconName = "back";
00154 break;
00155
00156 case Home: sLabel = i18n("beginning (of line)", "&Home"); break;
00157 case Help: sLabel = i18n("show help", "&Help"); break;
00158 case AboutApp: iconName = kapp->miniIconName();
00159 case Preferences:
00160 case HelpContents:
00161 {
00162 const KAboutData *aboutData = KGlobal::instance()->aboutData();
00163 QString appName = (aboutData) ? aboutData->programName() : QString::fromLatin1(qApp->name());
00164 sLabel = i18n(pInfo->psLabel).arg(appName);
00165 }
00166 break;
00167 default: sLabel = i18n(pInfo->psLabel);
00168 }
00169
00170 if (QApplication::reverseLayout()){
00171 if (id == Prior) iconName = "next";
00172 if (id == Next ) iconName = "previous";
00173 }
00174
00175 KShortcut cut = KStdAccel::shortcut(pInfo->idAccel);
00176 switch( id ) {
00177 case OpenRecent:
00178 pAction = new KRecentFilesAction( sLabel, cut,
00179 recvr, slot,
00180 parent, (name) ? name : pInfo->psName );
00181 break;
00182 case ShowMenubar:
00183 case ShowToolbar:
00184 case ShowStatusbar:
00185 KToggleAction *ret;
00186 ret = new KToggleAction( sLabel, pInfo->psIconName, cut,
00187 recvr, slot,
00188 parent, (name) ? name : pInfo->psName );
00189 ret->setChecked( true );
00190 pAction = ret;
00191 break;
00192 default:
00193 pAction = new KAction( sLabel, iconName, cut,
00194 recvr, slot,
00195 parent, (name) ? name : pInfo->psName );
00196 break;
00197 }
00198 }
00199 return pAction;
00200 }
00201
00202 const char* name( StdAction id )
00203 {
00204 const KStdActionInfo* pInfo = infoPtr( id );
00205 return (pInfo) ? pInfo->psName : 0;
00206 }
00207
00208 KAction *openNew( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00209 { return KStdAction::create( New, name, recvr, slot, parent ); }
00210 KAction *open( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00211 { return KStdAction::create( Open, name, recvr, slot, parent ); }
00212 KRecentFilesAction *openRecent( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00213 { return (KRecentFilesAction*) KStdAction::create( OpenRecent, name, recvr, slot, parent ); }
00214 KAction *save( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00215 { return KStdAction::create( Save, name, recvr, slot, parent ); }
00216 KAction *saveAs( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00217 { return KStdAction::create( SaveAs, name, recvr, slot, parent ); }
00218 KAction *revert( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00219 { return KStdAction::create( Revert, name, recvr, slot, parent ); }
00220 KAction *print( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00221 { return KStdAction::create( Print, name, recvr, slot, parent ); }
00222 KAction *printPreview( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00223 { return KStdAction::create( PrintPreview, name, recvr, slot, parent ); }
00224 KAction *close( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00225 { return KStdAction::create( Close, name, recvr, slot, parent ); }
00226 KAction *mail( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00227 { return KStdAction::create( Mail, name, recvr, slot, parent ); }
00228 KAction *quit( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00229 { return KStdAction::create( Quit, name, recvr, slot, parent ); }
00230 KAction *undo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00231 { return KStdAction::create( Undo, name, recvr, slot, parent ); }
00232 KAction *redo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00233 { return KStdAction::create( Redo, name, recvr, slot, parent ); }
00234 KAction *cut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00235 { return KStdAction::create( Cut, name, recvr, slot, parent ); }
00236 KAction *copy( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00237 { return KStdAction::create( Copy, name, recvr, slot, parent ); }
00238 KAction *paste( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00239 { return KStdAction::create( Paste, name, recvr, slot, parent ); }
00240 KAction *selectAll( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00241 { return KStdAction::create( SelectAll, name, recvr, slot, parent ); }
00242 KAction *deselect( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00243 { return KStdAction::create( Deselect, name, recvr, slot, parent ); }
00244 KAction *find( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00245 { return KStdAction::create( Find, name, recvr, slot, parent ); }
00246 KAction *findNext( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00247 { return KStdAction::create( FindNext, name, recvr, slot, parent ); }
00248 KAction *findPrev( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00249 { return KStdAction::create( FindPrev, name, recvr, slot, parent ); }
00250 KAction *replace( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00251 { return KStdAction::create( Replace, name, recvr, slot, parent ); }
00252 KAction *actualSize( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00253 { return KStdAction::create( ActualSize, name, recvr, slot, parent ); }
00254 KAction *fitToPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00255 { return KStdAction::create( FitToPage, name, recvr, slot, parent ); }
00256 KAction *fitToWidth( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00257 { return KStdAction::create( FitToWidth, name, recvr, slot, parent ); }
00258 KAction *fitToHeight( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00259 { return KStdAction::create( FitToHeight, name, recvr, slot, parent ); }
00260 KAction *zoomIn( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00261 { return KStdAction::create( ZoomIn, name, recvr, slot, parent ); }
00262 KAction *zoomOut( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00263 { return KStdAction::create( ZoomOut, name, recvr, slot, parent ); }
00264 KAction *zoom( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00265 { return KStdAction::create( Zoom, name, recvr, slot, parent ); }
00266 KAction *redisplay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00267 { return KStdAction::create( Redisplay, name, recvr, slot, parent ); }
00268 KAction *up( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00269 { return KStdAction::create( Up, name, recvr, slot, parent ); }
00270 KAction *back( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00271 { return KStdAction::create( Back, name, recvr, slot, parent ); }
00272 KAction *forward( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00273 { return KStdAction::create( Forward, name, recvr, slot, parent ); }
00274 KAction *home( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00275 { return KStdAction::create( Home, name, recvr, slot, parent ); }
00276 KAction *prior( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00277 { return KStdAction::create( Prior, name, recvr, slot, parent ); }
00278 KAction *next( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00279 { return KStdAction::create( Next, name, recvr, slot, parent ); }
00280 KAction *goTo( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00281 { return KStdAction::create( Goto, name, recvr, slot, parent ); }
00282 KAction *gotoPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00283 { return KStdAction::create( GotoPage, name, recvr, slot, parent ); }
00284 KAction *gotoLine( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00285 { return KStdAction::create( GotoLine, name, recvr, slot, parent ); }
00286 KAction *firstPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00287 { return KStdAction::create( FirstPage, name, recvr, slot, parent ); }
00288 KAction *lastPage( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00289 { return KStdAction::create( LastPage, name, recvr, slot, parent ); }
00290 KAction *addBookmark( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00291 { return KStdAction::create( AddBookmark, name, recvr, slot, parent ); }
00292 KAction *editBookmarks( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00293 { return KStdAction::create( EditBookmarks, name, recvr, slot, parent ); }
00294 KAction *spelling( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00295 { return KStdAction::create( Spelling, name, recvr, slot, parent ); }
00296
00297 KToggleAction *showMenubar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
00298 {
00299 KToggleAction *ret;
00300 ret = new KToggleAction(i18n("Show &Menubar"), "showmenu", KStdAccel::shortcut(KStdAccel::ShowMenubar), recvr, slot,
00301 parent, _name ? _name : name(ShowMenubar));
00302 ret->setChecked(true);
00303 return ret;
00304 }
00305
00306 KToggleAction *showToolbar( const QObject *recvr, const char *slot, KActionCollection* parent, const char *_name )
00307 {
00308 KToggleAction *ret;
00309 ret = new KToggleAction(i18n("Show &Toolbar"), 0, recvr, slot, parent,
00310 _name ? _name : name(ShowToolbar));
00311 ret->setChecked(true);
00312 return ret;
00313
00314 }
00315
00316 KToggleToolBarAction *showToolbar( const char* toolBarName, KActionCollection* parent, const char *_name )
00317 {
00318 KToggleToolBarAction *ret;
00319 ret = new KToggleToolBarAction(toolBarName, i18n("Show &Toolbar"), parent,
00320 _name ? _name : name(ShowToolbar));
00321 return ret;
00322 }
00323
00324 KToggleAction *showStatusbar( const QObject *recvr, const char *slot,
00325 KActionCollection* parent, const char *_name )
00326 {
00327 KToggleAction *ret;
00328 ret = new KToggleAction(i18n("Show St&atusbar"), 0, recvr, slot, parent,
00329 _name ? _name : name(ShowStatusbar));
00330 ret->setChecked(true);
00331 return ret;
00332 }
00333
00334 KAction *saveOptions( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00335 { return KStdAction::create( SaveOptions, name, recvr, slot, parent ); }
00336 KAction *keyBindings( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00337 { return KStdAction::create( KeyBindings, name, recvr, slot, parent ); }
00338 KAction *preferences( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00339 { return KStdAction::create( Preferences, name, recvr, slot, parent ); }
00340 KAction *configureToolbars( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00341 { return KStdAction::create( ConfigureToolbars, name, recvr, slot, parent ); }
00342 KAction *configureNotifications( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00343 { return KStdAction::create( ConfigureNotifications, name, recvr, slot, parent ); }
00344 KAction *help( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00345 { return KStdAction::create( Help, name, recvr, slot, parent ); }
00346 KAction *helpContents( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00347 { return KStdAction::create( HelpContents, name, recvr, slot, parent ); }
00348 KAction *whatsThis( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00349 { return KStdAction::create( WhatsThis, name, recvr, slot, parent ); }
00350 KAction *tipOfDay( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00351 { return KStdAction::create( TipofDay, name, recvr, slot, parent ); }
00352 KAction *reportBug( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00353 { return KStdAction::create( ReportBug, name, recvr, slot, parent ); }
00354 KAction *aboutApp( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00355 { return KStdAction::create( AboutApp, name, recvr, slot, parent ); }
00356 KAction *aboutKDE( const QObject *recvr, const char *slot, KActionCollection* parent, const char *name )
00357 { return KStdAction::create( AboutKDE, name, recvr, slot, parent ); }
00358
00359 }