1"
2" Filename: cream-menu.vim
3"
4" Cream -- An easy-to-use configuration of the famous Vim text editor
5" [ http://cream.sourceforge.net ] Copyright (C) 2001-2011 Steve Hall
6"
7" License:
8" This program is free software; you can redistribute it and/or modify
9" it under the terms of the GNU General Public License as published by
10" the Free Software Foundation; either version 3 of the License, or
11" (at your option) any later version.
12" [ http://www.gnu.org/licenses/gpl.html ]
13"
14" This program is distributed in the hope that it will be useful, but
15" WITHOUT ANY WARRANTY; without even the implied warranty of
16" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17" General Public License for more details.
18"
19" You should have received a copy of the GNU General Public License
20" along with this program; if not, write to the Free Software
21" Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
22" 02111-1307, USA.
23"
24
25function! Cream_menu_translation()
26" copied from vim's own menu.vim, with a little modification
27	if exists("v:lang") || &langmenu != ""
28		" Try to find a menu translation file for the current language.
29		if &langmenu != ""
30			if &langmenu =~ "none"
31				let s:lang = ""
32			else
33				let s:lang = &langmenu
34			endif
35		else
36			let s:lang = v:lang
37		endif
38		" A language name must be at least two characters, don't accept "C"
39		if strlen(s:lang) > 1
40			" When the language does not include the charset add 'encoding'
41			if s:lang =~ '^\a\a$\|^\a\a_\a\a$'
42				let s:lang = s:lang . '.' . &encoding
43			endif
44
45			" We always use a lowercase name.
46			" Change "iso-8859" to "iso_8859" and "iso8859" to "iso_8859", some
47			" systems appear to use this.
48			" Change spaces to underscores.
49			let s:lang = substitute(tolower(s:lang), '\.iso-', ".iso_", "")
50			let s:lang = substitute(s:lang, '\.iso8859', ".iso_8859", "")
51			let s:lang = substitute(s:lang, " ", "_", "g")
52			" Remove "@euro", otherwise "LC_ALL=de_DE@euro gvim" will show English menus
53			let s:lang = substitute(s:lang, "@euro", "", "")
54			" Change "iso_8859-1" and "iso_8859-15" to "latin1", we always use the
55			" same menu file for them.
56			let s:lang = substitute(s:lang, 'iso_8859-15\=$', "latin1", "")
57			menutrans clear
58			execute "runtime! cream/lang/menu_" . s:lang . ".vim"
59
60			if !exists("did_menu_trans")
61				" There is no exact match, try matching with a wildcard added
62				" (e.g. find menu_de_de.iso_8859-1.vim if s:lang == de_DE).
63				let s:lang = substitute(s:lang, '\.[^.]*', "", "")
64				execute "runtime! cream/lang/menu_" . s:lang . "*.vim"
65
66				if !exists("did_menu_trans") && strlen($LANG) > 1
67					" On windows locale names are complicated, try using $LANG, it might
68					" have been set by set_init_1().
69					execute "runtime! cream/lang/menu_" . tolower($LANG) . "*.vim"
70				endif
71			endif
72		endif
73	endif
74endfunction
75
76function! Cream_menus()
77" Creates each menu loader and calls it
78
79	" remove existing menus
80	source $VIMRUNTIME/delmenu.vim
81	call Cream_menu_translation()
82
83	" TODO: We really shouldn't be tampering with this here...
84	" Make sure the '<' and 'C' flags are not included in 'cpoptions', otherwise
85	" <CR> would not be recognized.  See ":help 'cpoptions'".
86	let cpo_save = &cpoptions
87	set cpoptions&vim
88
89	"+++ Cream: necessary for GTK (set also from vimrc, but not effective there)
90	set guioptions+=M
91	"+++
92
93	"+++ Cream: GTK loads menus, even if you ask it not to!
94	unmenu! *
95	unmenu *
96	"+++
97
98	" load Cream menus
99	call Cream_source($CREAM . "cream-menu-file.vim")
100	call Cream_source($CREAM . "cream-menu-edit.vim")
101	call Cream_source($CREAM . "cream-menu-insert.vim")
102	call Cream_source($CREAM . "cream-menu-format.vim")
103	call Cream_source($CREAM . "cream-menu-settings.vim")
104	call Cream_source($CREAM . "cream-menu-tools.vim")
105	call Cream_source($CREAM . "cream-menu-window.vim")
106	call Cream_source($CREAM . "cream-menu-window-buffer.vim")
107	call Cream_source($CREAM . "cream-menu-help.vim")
108	call Cream_source($CREAM . "cream-menu-window.vim")
109
110	call Cream_source($CREAM . "cream-menu-developer.vim")
111
112	call Cream_source($CREAM . "cream-menu-toolbar.vim")
113	call Cream_source($CREAM . "cream-menu-popup.vim")
114
115	" restore
116	let &cpo = cpo_save
117
118endfunction
119call Cream_menus()
120
121