Handling App Specific Actions
We're almost done now. If you compiled and ran kedit at this point,
you see that all of the standard actions display just fine.. but none
of the app specific ones will. This is because we have not defined
where those actions should go just yet. This is done with an app
specific XML file.
Here is what it looks like:
keditui.rc
<!DOCTYPE kpartgui>
<kpartgui name="kedit">
<MenuBar>
<Menu name="file"><text>&File</text>
<Action name="file_open_url"/>
<Action name="save_to_url"/>
</Menu>
<Menu name="edit"><text>&Edit</text>
<Action name="insert_file"/>
<Action name="insert_date"/>
<Action name="clean_spaces"/>
</Menu>
</MenuBar>
</kpartgui>
| | |
This will insert your Open URL and Save To URL items into the standard
file menu and the other actions into the standard edit menu. None of
the app specific items are inserted into the toolbar.
Which menu or toolbar you insert your items into is a judgement call.
If your Menu or ToolBar name is identical to a standard menu or
toolbar, then your items will be merged into that container. If you
specify a different name, then a new menu or toolbar will be created,
containing only your items.
Final Step
This is it, the final step. We have constructed our actions and built
our XML/rc file... all we need to do is install that file. This takes
a very quick adjustment to the Makefile.am
Makefile.am
INCLUDES = $(all_includes)
LDFLAGS = $(all_libraries) $(KDE_RPATH)
LDADD = -lkspell $(LIB_KFILE) $(LIB_KIO)
bin_PROGRAMS = kedit
kedit_SOURCES = kedit.cpp print.cpp mail.cpp urldlg.cpp optiondialog.cpp
noinst_HEADERS = kedit.h print.h version.h mail.h urldlg.h optiondialog.h
METASOURCES = kedit.moc print.moc mail.moc urldlg.moc optiondialog.moc
SUBDIRS = pixmaps
apps_DATA = KEdit.desktop
appsdir = $(kde_appsdir)/Applications
EXTRA_DIST = $(apps_DATA)
rcdir = $(kde_datadir)/kedit
rc_DATA = keditui.rc
messages: rc.cpp
$(XGETTEXT) rc.cpp $(kedit_SOURCES) -o $(podir)/kedit.pot
| | |
The code in bold is new. The rcdir stuff is pretty self-explanatory.
The rc.cpp code is needed so that the XML is localised along side the
application. It's a special case handled during the Makefile
preprocessing. I haven't a clue how it works but am told that it is
necessary and it does work (somehow), so just do it. Don't forget to
make install before you test it.
|