menubar.cpp 7.59 KB
Newer Older
Wayne Stambaugh's avatar
Wayne Stambaugh committed
1 2 3
/*
 * This program source code file is part of KiCad, a free EDA CAD application.
 *
4 5 6
 * Copyright (C) 2013 Jean-Pierre Charras, jp.charras at wanadoo.fr
 * Copyright (C) 2009-2013 Wayne Stambaugh <stambaughw@verizon.net>
 * Copyright (C) 1992-2013 KiCad Developers, see AUTHORS.txt for contributors.
Wayne Stambaugh's avatar
Wayne Stambaugh committed
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, you may find one here:
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * or you may search the http://www.gnu.org website for the version 2 license,
 * or you may write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
 */

26 27 28 29
/**
 * @file gerbview/menubar.cpp
 * @brief (Re)Create the main menubar for GerbView
 */
30
#include <fctsys.h>
31

32 33
#include <pgm_base.h>
#include <kiface_i.h>
34 35 36
#include <gerbview.h>
#include <gerbview_id.h>
#include <hotkeys.h>
37
#include <menus_helpers.h>
38

39

40
void GERBVIEW_FRAME::ReCreateMenuBar()
41
{
42
    // Create and try to get the current menubar
43
    wxMenuBar* menuBar = GetMenuBar();
44

45
    if( !menuBar )
46
        menuBar = new wxMenuBar();
47

48 49 50
    // Delete all existing menus so they can be rebuilt.
    // This allows language changes of the menu text on the fly.
    menuBar->Freeze();
51

52
    while( menuBar->GetMenuCount() )
53
        delete menuBar->Remove( 0 );
54

55
    // Recreate all menus:
56 57 58 59 60

    // Menu File:
    wxMenu* fileMenu = new wxMenu;

    // Load
61 62 63 64
    AddMenuItem( fileMenu,
                 wxID_FILE,
                 _( "Load &Gerber File" ),
                 _( "Load a new Gerber file on the current layer. Previous data will be deleted" ),
65
                 KiBitmap( gerber_file_xpm ) );
66

67
    // Excellon
68 69 70 71
    AddMenuItem( fileMenu,
                 ID_GERBVIEW_LOAD_DRILL_FILE,
                 _( "Load &EXCELLON Drill File" ),
                 _( "Load excellon drill file" ),
72
                 KiBitmap( gerbview_drill_file_xpm ) );
73

74
    // Recent gerber files
75
    static wxMenu* openRecentGbrMenu;
76

77 78 79
    // Add this menu to list menu managed by m_fileHistory
    // (the file history will be updated when adding/removing files in history
    if( openRecentGbrMenu )
80
        Kiface().GetFileHistory().RemoveMenu( openRecentGbrMenu );
81

82
    openRecentGbrMenu = new wxMenu();
83 84 85 86

    Kiface().GetFileHistory().UseMenu( openRecentGbrMenu );
    Kiface().GetFileHistory().AddFilesToMenu();

87 88 89 90
    AddMenuItem( fileMenu, openRecentGbrMenu,
                 wxID_ANY,
                 _( "Open &Recent Gerber File" ),
                 _( "Open a recent opened Gerber file" ),
91
                 KiBitmap( gerber_recent_files_xpm ) );
92

93
    // Recent drill files
94
    static wxMenu* openRecentDrlMenu;
95

96
    if( openRecentDrlMenu )
97
        m_drillFileHistory.RemoveMenu( openRecentDrlMenu );
98

99 100
    openRecentDrlMenu = new wxMenu();
    m_drillFileHistory.UseMenu( openRecentDrlMenu );
101
    m_drillFileHistory.AddFilesToMenu( );
102 103
    AddMenuItem( fileMenu, openRecentDrlMenu,
                 wxID_ANY,
Wayne Stambaugh's avatar
Wayne Stambaugh committed
104
                 _( "Open Recent Dri&ll File" ),
105
                 _( "Open a recent opened drill file" ),
106
                 KiBitmap( gerbview_open_recent_drill_files_xpm ) );
107

108 109
    // Separator
    fileMenu->AppendSeparator();
110

111
    // Clear all
112 113 114 115
    AddMenuItem( fileMenu,
                 ID_GERBVIEW_ERASE_ALL,
                 _( "&Clear All" ),
                 _( "Clear all layers. All data will be deleted" ),
116
                 KiBitmap( gerbview_clear_layers_xpm ) );
117

118 119 120
    // Separator
    fileMenu->AppendSeparator();

121
    // Export to Pcbnew
122 123
    AddMenuItem( fileMenu,
                 ID_GERBVIEW_EXPORT_TO_PCBNEW,
Wayne Stambaugh's avatar
Wayne Stambaugh committed
124
                 _( "E&xport to Pcbnew" ),
125
                 _( "Export data in Pcbnew format" ),
126
                 KiBitmap( export_xpm ) );
127

128 129
    // Separator
    fileMenu->AppendSeparator();
130

131
    // Print
132 133
    AddMenuItem( fileMenu,
                 wxID_PRINT,
Wayne Stambaugh's avatar
Wayne Stambaugh committed
134
                 _( "&Print" ),
135
                 _( "Print gerber" ),
136
                 KiBitmap( print_button_xpm ) );
137

138 139 140 141
    // Separator
    fileMenu->AppendSeparator();

    // Exit
142 143 144
    AddMenuItem( fileMenu,
                 wxID_EXIT,
                 _( "E&xit" ),
145
                 _( "Quit GerbView" ),
146
                 KiBitmap( exit_xpm ) );
147

148 149 150 151
    // Menu for configuration and preferences
    wxMenu* configMenu = new wxMenu;

    // Hide layer manager
152 153 154
    AddMenuItem( configMenu,
                 ID_MENU_GERBVIEW_SHOW_HIDE_LAYERS_MANAGER_DIALOG,
                 _( "Hide &Layers Manager" ),
155 156
                 m_show_layer_manager_tools ?
                           _( "Hide &Layers Manager" ) : _("Show &Layers Manager" ),
157
                 KiBitmap( layers_manager_xpm ) );
158

159
    // Options (Preferences on WXMAC)
160

161
#ifdef __WXMAC__
162
    configMenu->Append(wxID_PREFERENCES);
163
#else
164 165 166 167
    AddMenuItem( configMenu,
                 wxID_PREFERENCES,
                 _( "&Options" ),
                 _( "Set options to draw items" ),
168
                 KiBitmap( preference_xpm ) );
169 170
#endif // __WXMAC__

171
    // Language submenu
172
    Pgm().AddMenuLanguageList( configMenu );
173

174 175
    // Hotkey submenu
    AddHotkeyConfigMenu( configMenu );
176

177 178
    // Menu miscellaneous
    wxMenu* miscellaneousMenu = new wxMenu;
179

180
    // List dcodes
181 182 183 184
    AddMenuItem( miscellaneousMenu,
                 ID_GERBVIEW_SHOW_LIST_DCODES,
                 _( "&List DCodes" ),
                 _( "List and edit D-codes" ),
185
                 KiBitmap( show_dcodenumber_xpm ) );
186 187

    // Show source
188 189 190 191
    AddMenuItem( miscellaneousMenu,
                 ID_GERBVIEW_SHOW_SOURCE,
                 _( "&Show Source" ),
                 _( "Show source file for the current layer" ),
192
                 KiBitmap( tools_xpm ) );
193

194 195 196 197
    // Separator
    miscellaneousMenu->AppendSeparator();

    // Clear layer
198 199 200 201
    AddMenuItem( miscellaneousMenu,
                 ID_GERBVIEW_GLOBAL_DELETE,
                 _( "&Clear Layer" ),
                 _( "Clear current layer" ),
202
                 KiBitmap( general_deletions_xpm ) );
203

204 205 206 207
    // Separator
    miscellaneousMenu->AppendSeparator();

    // Text editor
208 209 210 211
    AddMenuItem( miscellaneousMenu,
                 ID_MENU_GERBVIEW_SELECT_PREFERED_EDITOR,
                 _( "&Text Editor" ),
                 _( "Select your preferred text editor" ),
212
                 KiBitmap( editor_xpm ) );
213

214
    // Menu Help
215
    wxMenu* helpMenu = new wxMenu;
216 217

    // Version info
218
    AddHelpVersionInfoMenuEntry( helpMenu );
219 220

    // Contents
221 222 223
    AddMenuItem( helpMenu,
                 wxID_HELP,
                 _( "&Contents" ),
224
                 _( "Open the GerbView handbook" ),
225
                 KiBitmap( help_xpm ) );
226

227
    // About GerbView
228 229 230
    AddMenuItem( helpMenu,
                 wxID_ABOUT,
                 _( "&About GerbView" ),
231
                 _( "About GerbView gerber and drill viewer" ),
232
                 KiBitmap( online_help_xpm ) );
233

234 235 236 237
    // Append menus to the menubar
    menuBar->Append( fileMenu, _( "&File" ) );
    menuBar->Append( configMenu, _( "&Preferences" ) );
    menuBar->Append( miscellaneousMenu, _( "&Miscellaneous" ) );
238 239
    menuBar->Append( helpMenu, _( "&Help" ) );

240 241 242 243 244 245 246
    menuBar->Thaw();

    // Associate the menu bar with the frame, if no previous menubar
    if( GetMenuBar() == NULL )
        SetMenuBar( menuBar );
    else
        menuBar->Refresh();
247
}