Permalink
Browse files

Allow FontForge's menu shortcuts (hot keys, whatever) to be user defi…

…nable. We use a gettext based mechanism, type

$ make FontForge-MenuShortCuts.pot
to get a pot file for the process. It needs to be converted to an mo file and
installed in $(prefix)/share/locale/$(LANG)/LC_MESSAGES, just like any other getext file.
  • Loading branch information...
1 parent 29e2d35 commit 06b3ed9985178a9e8db304164e610b489c1986a8 George Williams committed Feb 16, 2007
@@ -101,6 +101,10 @@ distclean cleaner: clean
install:
( cd .. ; make install )
+FontForge-MenuShortCuts.pot: *.c
+ xgettext --from-code=UTF-8 -kH_ -oFontForge-MenuShortCuts.pot *.c ../gdraw/*.c
+ patch < potmstitle.patch
+
FontForge.pot: *.c utf8.pot
echo "If this doesn't work try make fontforge-old.pot instead"
xgettext --from-code=UTF-8 -k_ -kN_ -kS_ -kU_ -kNU_ -kP_:1,2 --add-comments=GT: -oFontForge.pot *.c ../gdraw/*.c
View
@@ -101,6 +101,10 @@ distclean cleaner: clean
install:
( cd .. ; make install )
+FontForge-MenuShortCuts.pot: *.c
+ xgettext --from-code=UTF-8 -kH_ -oFontForge-MenuShortCuts.pot *.c ../gdraw/*.c
+ patch < potmstitle.patch
+
FontForge.pot: *.c utf8.pot
echo "If this doesn't work try make fontforge-old.pot instead"
xgettext --from-code=UTF-8 -k_ -kN_ -kS_ -kU_ -kNU_ -kP_:1,2 --add-comments=GT: -oFontForge.pot *.c ../gdraw/*.c
@@ -90,6 +90,10 @@ clean:
distclean cleaner: clean
-rm -f Makefile
+FontForge-MenuShortCuts.pot: *.c
+ xgettext --from-code=UTF-8 -kH_ -oFontForge-MenuShortCuts.pot *.c ../gdraw/*.c
+ patch < potmstitle.patch
+
FontForge.pot: *.c utf8.pot
echo "If this doesn't work try make fontforge-old.pot instead"
xgettext --from-code=UTF-8 -k_ -kN_ -kS_ -kU_ -kNU_ -kP_:1,2 --add-comments=GT: -oFontForge.pot *.c ../gdraw/*.c
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,99 @@
+--- FtForge-MenuShortCuts.pot~ 2007-02-15 18:17:23.000000000 -0800
++++ FontForge-MenuShortCuts.pot 2007-02-15 18:17:23.000000000 -0800
+@@ -1,7 +1,7 @@
+-# SOME DESCRIPTIVE TITLE.
+-# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+-# This file is distributed under the same license as the PACKAGE package.
+-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
++# Menu shortcuts for FontForge.
++# Copyright (C) 2000-2007 by George Williams
++# This file is distributed under the same license as the FontForge package.
++# George Williams, <pfaedit@users.sourceforge.net>, 2007.
+ #
+ #, fuzzy
+ msgid ""
+@@ -12,9 +12,83 @@
+ "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
+ "Language-Team: LANGUAGE <LL@li.org>\n"
+ "MIME-Version: 1.0\n"
+-"Content-Type: text/plain; charset=CHARSET\n"
++"Content-Type: text/plain; charset=UTF-8\n"
+ "Content-Transfer-Encoding: 8bit\n"
+
++#. This file allows you to change FontForge's menu shortcuts. It is a gettext
++#. based system, which means it is locale dependant.
++
++#. These entries are formatted as follows:
++#. First we have the (English) name of the command as it appears in
++#. the menu.
++#. Then we have a "|" (which is used as a separator)
++#. Finally we have the shortcut for the command as a textual string.
++#.
++#. If you wish to change a shortcut simply provide its textual representation
++#. in the msgstr field. So if you want the shortcut for New Outline Window
++#. to be Ctl+O
++#. msgid "New Outline Window|Ctl+H"
++#. msgstr "Ctl+O"
++#. (NOTE: You do NOT have to include "New Outline Window|" in your msgstr)
++#. If you wish to remove a shortcut
++#. msgid "New Outline Window|Ctl+H"
++#. msgstr "No Shortcut"
++#. If you wish to use a function key (or similar)
++#. msgid "New Outline Window|Ctl+H"
++#. msgstr "F2"
++#. or
++#. msgid "New Outline Window|Ctl+H"
++#. msgstr "Backspace"
++
++#. You may apply one or several modifiers to shortcuts. FontForge recognizes:
++#. Ctl+ Shft+ Alt+ CapsLock+
++#. Some keyboards have additional modifier keys, X maps them to a flag bit in
++#. the keyboard state mask of the XKeyEvent. If you want to use these modifiers
++#. you need to know what that bit is. FontForge will also recognize:
++#. Flag0x01+ Flag0x02+ Flag0x04+ Flag0x08+
++#. Flag0x10+ Flag0x20+ Flag0x40+ Flag0x80+
++#. (I can't come up with better names than these because in general
++#. I don't know what they are myself).
++#. The mac has two additional modifier keys: Command and Option
++#. X never gets the Command key (or rather the X application's menubar gets
++#. it and client programs never see it) so we can't use it.
++#. But clients can get at the Option key and FontForge recognizes
++#. Opt+
++
++#. So...
++#. msgid "New Outline Window|Ctl+H"
++#. msgstr "Ctl+Shft+Alt+Flag10+Opt+F2"
++#. would be practically untypable, but syntactically valid.
++
++#. When FF displays a shortcut in the menu it will use a similar syntax.
++#. That may not be appropriate for non-English terminals. On a French system
++#. it might be better to show the Shift modifier as Majuscule. At the bottom of
++#. this file are several entries which are not used to set shortcuts but are
++#. used in displaying the shortcuts in the menu, thus
++#. #: ../gdraw/gmenu.c:120
++#. msgid "Shft+"
++#. msgstr "Maj+"
++
++#. Even though not obvious from this file, it is also possible to add names for
++#. special keys. So you could add:
++#. msgid "Escape"
++#. msgstr "Échappe"
++#. msgid "Delete"
++#. msgstr "Efface"
++#. (or whatever is appropriate for keyboards)
++#.
++#. The English names accepted are those defined under XK_MISCELLANY in
++#. keysymdef.h of the X11 header files -- without the initial XK_
++
++
++#. I am told that the use of "|" to provide contextual information in a
++#. gettext string is non-standard. However it is documented in section
++#. 10.2.6 of http://www.gnu.org/software/gettext/manual/html_mono/gettext.html
++#. I need it, and I will use it.
++#.
++#. --------------------------------------------------------------------------
++
++
+ #: bitmapview.c:1681 charview.c:7792 fontview.c:7767 metricsview.c:2611
+ msgid "New Outline Window|Ctl+H"
+ msgstr ""
View
@@ -6,9 +6,9 @@
-# This file is distributed under the same license as the PACKAGE package.
-# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
+# (American) English User Interface strings for FontForge.
-+# Copyright (C) 2000-2006 by George Williams
++# Copyright (C) 2000-2007 by George Williams
+# This file is distributed under the same license as the FontForge package.
-+# George Williams, <pfaedit@users.sourceforge.net>, 2006.
++# George Williams, <pfaedit@users.sourceforge.net>, 2007.
#
#, fuzzy
msgid ""
View
@@ -1,5 +1,5 @@
#include <time.h>
-const time_t source_modtime = 1171073809;
-const char *source_modtime_str = "18:16 9-Feb-2007";
-const char *source_version_str = "20070209";
+const time_t source_modtime = 1171594719;
+const char *source_modtime_str = "18:58 15-Feb-2007";
+const char *source_version_str = "20070215";
View
@@ -629,6 +629,9 @@ int FontForgeMain( int argc, char **argv ) {
add_pixmap_directory (PIXMAP_DIR);
#endif
+ GMenuSetShortcutDomain("FontForge-MenuShortCuts");
+ bind_textdomain_codeset("FontForge-MenuShortCuts","UTF-8");
+ bindtextdomain("FontForge-MenuShortCuts", getLocaleDir());
bind_textdomain_codeset("FontForge","UTF-8");
bindtextdomain("FontForge", getLocaleDir());
textdomain("FontForge");
View
@@ -926,9 +926,10 @@ extern void MenuIndex(GWindow base,struct gmenuitem *mi,GEvent *e);
extern void MenuAbout(GWindow base,struct gmenuitem *mi,GEvent *e);
extern void MenuLicense(GWindow base,struct gmenuitem *mi,GEvent *e);
extern void MenuNew(GWindow gw,struct gmenuitem *mi,GEvent *e);
-extern void WindowMenuBuild(GWindow base,struct gmenuitem *mi,GEvent *,struct gmenuitem *);
+extern void WindowMenuBuild(GWindow base,struct gmenuitem *mi,GEvent *);
extern void MenuRecentBuild(GWindow base,struct gmenuitem *mi,GEvent *);
extern void MenuScriptsBuild(GWindow base,struct gmenuitem *mi,GEvent *);
+extern void mb2DoGetText(GMenuItem2 *mb);
extern void mbDoGetText(GMenuItem *mb);
extern int RecentFilesAny(void);
extern void _aplistbuild(struct gmenuitem *mi,SplineFont *sf,
@@ -1335,7 +1336,7 @@ struct instrdlg;
uint8 *_IVParse(struct instrdlg *iv, char *text, int *len);
#ifdef FONTFORGE_CONFIG_GDRAW
-extern GMenuItem helplist[];
+extern GMenuItem2 helplist[];
#endif
extern BasePoint last_ruler_offset[];
View
@@ -48,7 +48,7 @@ static void AddMI(GMenuItem *mi,GWindow gw,int changed, int top) {
}
/* Builds up a menu containing the titles of all the major windows */
-void WindowMenuBuild(GWindow basew,struct gmenuitem *mi,GEvent *e, struct gmenuitem *base) {
+void WindowMenuBuild(GWindow basew,struct gmenuitem *mi,GEvent *e) {
int i, cnt, precnt;
FontView *fv;
CharView *cv;
@@ -58,17 +58,7 @@ void WindowMenuBuild(GWindow basew,struct gmenuitem *mi,GEvent *e, struct gmenui
BDFFont *bdf;
extern void GMenuItemArrayFree(GMenuItem *mi);
- if ( mi->sub!=NULL ) {
- GMenuItemArrayFree(mi->sub);
- mi->sub = NULL;
- }
-
- precnt = 0;
- for ( sub = base; sub->ti.text!=NULL || sub->ti.line; ++sub )
- ++precnt;
- if ( sub->ti.text!=NULL ) /* Skip two lines now */
- for ( ++sub; sub->ti.text!=NULL || sub->ti.line; ++sub )
- ++precnt;
+ precnt = 6;
cnt = precnt;
for ( fv = fv_list; fv!=NULL; fv = fv->next ) {
@@ -91,7 +81,12 @@ void WindowMenuBuild(GWindow basew,struct gmenuitem *mi,GEvent *e, struct gmenui
return;
}
sub = gcalloc(cnt+1,sizeof(GMenuItem));
- memcpy(sub,base,precnt*sizeof(struct gmenuitem));
+ memcpy(sub,mi->sub,precnt*sizeof(struct gmenuitem));
+ for ( i=0; i<precnt; ++i )
+ mi->sub[i].ti.text = NULL;
+ GMenuItemArrayFree(mi->sub);
+ mi->sub = sub;
+
for ( i=0; sub[i].ti.text!=NULL || sub[i].ti.line; ++i ) {
if ( sub[i].ti.text_is_1byte && sub[i].ti.text_in_resource) {
sub[i].ti.text = utf82u_mncopy((char *) sub[i].ti.text,&sub[i].ti.mnemonic);
@@ -121,7 +116,6 @@ return;
for ( mv=fv->metrics; mv!=NULL; mv=mv->next )
AddMI(&sub[cnt++],mv->gw,false,false);
}
- mi->sub = sub;
}
static void RecentSelect(GWindow base,struct gmenuitem *mi,GEvent *e) {
@@ -468,4 +462,19 @@ return;
}
}
}
+
+void mb2DoGetText(GMenuItem2 *mb) {
+ /* perform gettext substitutions on this menu and all sub menus */
+ int i;
+
+ if ( mb==NULL )
+return;
+ for ( i=0; mb[i].ti.text!=NULL || mb[i].ti.line || mb[i].ti.image!=NULL; ++i ) {
+ if ( mb[i].ti.text!=NULL ) {
+ mb[i].ti.text = (unichar_t *) S_((char *) mb[i].ti.text);
+ if ( mb[i].sub!=NULL )
+ mb2DoGetText(mb[i].sub);
+ }
+ }
+}
#endif
View
@@ -501,6 +501,9 @@ extern int GTextInfoArrayCount(GTextInfo **ti);
extern int GTextInfoCompare(GTextInfo *ti1, GTextInfo *ti2);
extern void GMenuItemArrayFree(GMenuItem *mi);
extern GMenuItem *GMenuItemArrayCopy(GMenuItem *mi, uint16 *cnt);
+extern void GMenuItem2ArrayFree(GMenuItem2 *mi);
+extern GMenuItem *GMenuItem2ArrayCopy(GMenuItem2 *mi, uint16 *cnt);
+extern void GMenuItemParseShortCut(GMenuItem *mi,char *shortcut);
extern GGadget *_GGadget_Create(GGadget *g, struct gwindow *base, GGadgetData *gd,void *data, GBox *def);
extern void _GGadget_FinalPosition(GGadget *g, struct gwindow *base, GGadgetData *gd);
View
@@ -1841,3 +1841,8 @@ void GMatrixEditSetColumnChoices(GGadget *g, int col, GTextInfo *ti) {
else
gme->col_data[col].enum_vals = NULL;
}
+
+int GMatrixEditGetColCnt(GGadget *g) {
+ GMatrixEdit *gme = (GMatrixEdit *) g;
+return( gme->cols );
+}
View
@@ -115,26 +115,54 @@ typedef struct gmenu {
static void shorttext(GMenuItem *gi,unichar_t *buf) {
unichar_t *pt = buf;
+ static int initted = false;
+ struct { int mask; char *modifier; } mods[8] = {
+ { ksm_shift, H_("Shft+") },
+ { ksm_capslock, H_("CapsLk+") },
+ { ksm_control, H_("Ctl+") },
+ { ksm_meta, H_("Alt+") },
+ { 0x10, H_("Flag0x10+") },
+ { 0x20, H_("Flag0x20+") },
+ { 0x40, H_("Flag0x40+") },
+ { 0x80, H_("Flag0x80+") }
+ };
+ int i;
+ char buffer[32];
+
+ if ( !initted ) {
+ char *temp;
+ for ( i=0; i<8; ++i ) {
+ sprintf( buffer,"Flag0x%02x", 1<<i );
+ temp = dgettext(GMenuGetShortcutDomain(),buffer);
+ if ( strcmp(temp,buffer)!=0 )
+ mods[i].modifier = temp;
+ else
+ mods[i].modifier = dgettext(GMenuGetShortcutDomain(),mods[i].modifier);
+ }
+ /* It used to be that the Command key was available to X on the mac */
+ /* but no longer. So we used to use it, but we can't now */
+ /* if ( strcmp(mods[2].modifier,"Ctl+")==0 ) */
+ /* mods[2].modifier = keyboard!=kb_mac?"Ctl+":"Cmd+"; */
+ if ( strcmp(mods[3].modifier,"Alt+")==0 )
+ mods[3].modifier = keyboard==kb_ibm?"Alt+":keyboard==kb_mac?"Opt+":keyboard==kb_ppc?"Cmd+":"Meta+";
+ }
if ( gi->shortcut==0 ) {
*pt = '\0';
return;
}
- if ( gi->short_mask&ksm_meta ) {
- uc_strcpy(pt,keyboard==kb_ibm?"Alt+":keyboard==kb_mac?"Opt+":keyboard==kb_ppc?"Cmd+":"Meta+");
- pt += u_strlen(pt);
- }
- if ( gi->short_mask&ksm_control ) {
- uc_strcpy(pt,"Ctl+"/*keyboard!=kb_mac?"Ctl+":"Cmd+"*/); /* Used to be that X made the command key available on the mac. But no longer */
- pt += u_strlen(pt);
- }
- if ( gi->short_mask&ksm_shift ) {
- uc_strcpy(pt,"Shft+");
- pt += u_strlen(pt);
+
+ for ( i=7; i>=0 ; --i ) {
+ if ( gi->short_mask&(1<<i) ) {
+ uc_strcpy(pt,mods[i].modifier);
+ pt += u_strlen(pt);
+ }
}
- if ( gi->shortcut>=0xff00 && GDrawKeysyms[gi->shortcut-0xff00] )
- u_strcpy(pt,GDrawKeysyms[gi->shortcut-0xff00]);
- else {
+
+ if ( gi->shortcut>=0xff00 && GDrawKeysyms[gi->shortcut-0xff00] ) {
+ cu_strcpy(buffer,GDrawKeysyms[gi->shortcut-0xff00]);
+ utf82u_strcpy(pt,dgettext(GMenuGetShortcutDomain(),buffer));
+ } else {
*pt++ = islower(gi->shortcut)?toupper(gi->shortcut):gi->shortcut;
*pt = '\0';
}
@@ -228,7 +256,7 @@ static void GMenuDrawDownArrow(struct gmenu *m, int ybase) {
}
static int GMenuDrawMenuLine(struct gmenu *m, GMenuItem *mi, int y) {
- unichar_t shortbuf[30];
+ unichar_t shortbuf[300];
int as = GTextInfoGetAs(m->w,&mi->ti,m->font);
int h, width;
Color fg = m->box->main_foreground;
@@ -845,7 +873,7 @@ static GMenu *_GMenu_Create(GWindow owner,GMenuItem *mi, GPoint *where,
GDisplay *disp = GDrawGetDisplayOfWindow(owner);
GWindowAttrs pattrs;
int i, width, keywidth;
- unichar_t buffer[100];
+ unichar_t buffer[300];
FontInstance *old;
int ds, ld, temp;
GRect screen;
@@ -872,6 +900,7 @@ static GMenu *_GMenu_Create(GWindow owner,GMenuItem *mi, GPoint *where,
if ( mi[i].sub!=NULL && 3*m->as>keywidth )
keywidth = 3*m->as;
}
+ GDrawSetFont(owner,old);
m->mcnt = m->lcnt = i;
if ( keywidth!=0 ) width += keywidth + GDrawPointsToPixels(owner,8);
if ( m->hasticks ) {
@@ -1305,6 +1334,30 @@ GGadget *GMenuBarCreate(struct gwindow *base, GGadgetData *gd,void *data) {
return( &mb->g );
}
+GGadget *GMenu2BarCreate(struct gwindow *base, GGadgetData *gd,void *data) {
+ GMenuBar *mb = gcalloc(1,sizeof(GMenuBar));
+
+ if ( !gmenubar_inited )
+ GMenuInit();
+ mb->g.funcs = &gmenubar_funcs;
+ _GGadget_Create(&mb->g,base,gd,data,&menubar_box);
+
+ mb->mi = GMenuItem2ArrayCopy(gd->u.menu2,&mb->mtot);
+ mb->xs = galloc((mb->mtot+1)*sizeof(uint16));
+ mb->entry_with_mouse = -1;
+ mb->font = menu_font;
+
+ GMenuBarFit(mb,gd);
+ GMenuBarFindXs(mb);
+
+ if ( gd->flags & gg_group_end )
+ _GGadgetCloseGroup(&mb->g);
+ _GWidget_SetMenuBar(&mb->g);
+
+ mb->g.takes_input = true;
+return( &mb->g );
+}
+
/* ************************************************************************** */
static GMenuItem *GMenuBarFindMid(GMenuItem *mi, int mid) {
int i;
Oops, something went wrong.

0 comments on commit 06b3ed9

Please sign in to comment.