mirror of
https://github.com/alexkay/spek.git
synced 2025-06-03 17:11:09 +03:00
Main menu and toolbar
This commit is contained in:
parent
44cb6f587d
commit
7e5ca1765a
@ -16,44 +16,82 @@
|
||||
* along with Spek. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <wx/artprov.h>
|
||||
|
||||
#include "spek-window.hh"
|
||||
|
||||
enum
|
||||
{
|
||||
ID_Quit = 1,
|
||||
ID_About,
|
||||
};
|
||||
|
||||
BEGIN_EVENT_TABLE(SpekWindow, wxFrame)
|
||||
EVT_MENU(ID_Quit, SpekWindow::OnQuit)
|
||||
EVT_MENU(ID_About, SpekWindow::OnAbout)
|
||||
EVT_MENU(wxID_OPEN, SpekWindow::OnOpen)
|
||||
EVT_MENU(wxID_SAVE, SpekWindow::OnSave)
|
||||
EVT_MENU(wxID_EXIT, SpekWindow::OnExit)
|
||||
EVT_MENU(wxID_PREFERENCES, SpekWindow::OnPreferences)
|
||||
EVT_MENU(wxID_ABOUT, SpekWindow::OnAbout)
|
||||
END_EVENT_TABLE()
|
||||
|
||||
SpekWindow::SpekWindow(const wxString& title, const wxPoint& pos, const wxSize& size)
|
||||
: wxFrame(NULL, -1, title, pos, size)
|
||||
SpekWindow::SpekWindow(const wxString& title) : wxFrame(NULL, -1, title)
|
||||
{
|
||||
wxMenu *menuFile = new wxMenu();
|
||||
// TODO: test on all platforms
|
||||
SetIcon(wxIcon(wxT("spek")));
|
||||
|
||||
menuFile->Append(ID_About, wxT("&About..."));
|
||||
menuFile->AppendSeparator();
|
||||
menuFile->Append(ID_Quit, wxT("E&xit"));
|
||||
wxMenuBar *menu = new wxMenuBar();
|
||||
|
||||
wxMenuBar *menuBar = new wxMenuBar();
|
||||
menuBar->Append(menuFile, wxT("&File"));
|
||||
wxMenu *menu_file = new wxMenu();
|
||||
wxMenuItem *menu_file_open = new wxMenuItem(menu_file, wxID_OPEN);
|
||||
menu_file->Append(menu_file_open);
|
||||
wxMenuItem *menu_file_save = new wxMenuItem(menu_file, wxID_SAVE);
|
||||
menu_file->Append(menu_file_save);
|
||||
menu_file->AppendSeparator();
|
||||
menu_file->Append(wxID_EXIT);
|
||||
menu->Append(menu_file, _("&File")); // TODO: stock text
|
||||
|
||||
SetMenuBar(menuBar);
|
||||
wxMenu *menu_edit = new wxMenu();
|
||||
wxMenuItem *menu_edit_prefs = new wxMenuItem(menu_edit, wxID_PREFERENCES);
|
||||
// TODO: check if this is needed
|
||||
menu_edit_prefs->SetItemLabel(menu_edit_prefs->GetItemLabelText() + wxT("\tCtrl+E"));
|
||||
menu_edit->Append(menu_edit_prefs);
|
||||
menu->Append(menu_edit, _("&Edit")); // TODO: stock text
|
||||
|
||||
wxMenu *menu_help = new wxMenu();
|
||||
wxMenuItem *menu_help_about = new wxMenuItem(menu_help, wxID_ABOUT);
|
||||
// TODO: check if this is needed
|
||||
menu_help_about->SetItemLabel(menu_help_about->GetItemLabelText() + wxT("\tF1"));
|
||||
menu_help->Append(menu_help_about);
|
||||
menu->Append(menu_help, _("&Help")); // TODO: stock text
|
||||
|
||||
SetMenuBar(menu);
|
||||
|
||||
wxToolBar *toolbar = CreateToolBar();
|
||||
// TODO: bundled file open/save icons suck, provide our own (tango?)
|
||||
toolbar->AddTool(
|
||||
wxID_OPEN,
|
||||
menu_file_open->GetItemLabelText(),
|
||||
wxArtProvider::GetBitmap(wxART_FILE_OPEN)
|
||||
);
|
||||
toolbar->AddTool(
|
||||
wxID_SAVE,
|
||||
menu_file_save->GetItemLabelText(),
|
||||
wxArtProvider::GetBitmap(wxART_FILE_SAVE)
|
||||
);
|
||||
toolbar->Realize();
|
||||
}
|
||||
|
||||
void SpekWindow::OnQuit(wxCommandEvent& WXUNUSED(event))
|
||||
void SpekWindow::OnOpen(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
}
|
||||
|
||||
void SpekWindow::OnSave(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
}
|
||||
|
||||
void SpekWindow::OnExit(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
Close(true);
|
||||
}
|
||||
|
||||
void SpekWindow::OnPreferences(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
}
|
||||
|
||||
void SpekWindow::OnAbout(wxCommandEvent& WXUNUSED(event))
|
||||
{
|
||||
wxMessageBox(
|
||||
wxT("This is a wxWidgets' Hello world sample"),
|
||||
wxT("About Hello World"),
|
||||
wxOK | wxICON_INFORMATION
|
||||
);
|
||||
}
|
||||
|
@ -24,10 +24,13 @@
|
||||
class SpekWindow : public wxFrame
|
||||
{
|
||||
public:
|
||||
SpekWindow(const wxString& title, const wxPoint& pos, const wxSize& size);
|
||||
SpekWindow(const wxString& title);
|
||||
|
||||
protected:
|
||||
void OnQuit(wxCommandEvent& event);
|
||||
void OnOpen(wxCommandEvent& event);
|
||||
void OnSave(wxCommandEvent& event);
|
||||
void OnExit(wxCommandEvent& event);
|
||||
void OnPreferences(wxCommandEvent& event);
|
||||
void OnAbout(wxCommandEvent& event);
|
||||
|
||||
private:
|
||||
|
@ -31,72 +31,12 @@ namespace Spek {
|
||||
private FileFilter filter_audio;
|
||||
private FileFilter filter_png;
|
||||
|
||||
private const Gtk.ActionEntry[] ACTION_ENTRIES = {
|
||||
{ "File", null, N_("_File") },
|
||||
{ "FileOpen", Stock.OPEN, null, null, null, on_file_open },
|
||||
{ "FileSave", Stock.SAVE, null, null, null, on_file_save },
|
||||
{ "FileQuit", Stock.QUIT, null, null, null, on_file_quit },
|
||||
{ "Edit", null, N_("_Edit") },
|
||||
{ "EditPreferences", Stock.PREFERENCES, null, "<Ctrl>E", null, on_edit_preferences },
|
||||
{ "Help", null, N_("_Help") },
|
||||
{ "HelpAbout", Stock.ABOUT, null, "F1", null, on_help_about }
|
||||
};
|
||||
|
||||
private const string UI = """
|
||||
<ui>
|
||||
<menubar name='MenuBar'>
|
||||
<menu action='File'>
|
||||
<menuitem action='FileOpen'/>
|
||||
<menuitem action='FileSave'/>
|
||||
<separator/>
|
||||
<menuitem action='FileQuit'/>
|
||||
</menu>
|
||||
<menu action='Edit'>
|
||||
<menuitem action='EditPreferences'/>
|
||||
</menu>
|
||||
<menu action='Help'>
|
||||
<menuitem action='HelpAbout'/>
|
||||
</menu>
|
||||
</menubar>
|
||||
|
||||
<toolbar name='ToolBar'>
|
||||
<toolitem action='FileOpen'/>
|
||||
<toolitem action='FileSave'/>
|
||||
<separator expand='true'/>
|
||||
<toolitem action='HelpAbout'/>
|
||||
</toolbar>
|
||||
</ui>
|
||||
""";
|
||||
|
||||
private const Gtk.TargetEntry[] DEST_TARGET_ENTRIES = {
|
||||
{ "text/uri-list", 0, 0 }
|
||||
};
|
||||
|
||||
public Window (string? file_name) {
|
||||
description = title = _("Spek - Acoustic Spectrum Analyser");
|
||||
set_default_icon_name ("spek");
|
||||
set_default_size (640, 480);
|
||||
destroy.connect (Gtk.main_quit);
|
||||
|
||||
var actions = new Gtk.ActionGroup ("Actions");
|
||||
actions.set_translation_domain (Config.GETTEXT_PACKAGE);
|
||||
actions.add_actions (ACTION_ENTRIES, this);
|
||||
ui = new UIManager ();
|
||||
ui.insert_action_group (actions, 0);
|
||||
add_accel_group (ui.get_accel_group ());
|
||||
try {
|
||||
ui.add_ui_from_string (UI, -1);
|
||||
} catch (Error e) {
|
||||
warning ("Could not load the UI: %s\n", e.message);
|
||||
}
|
||||
|
||||
var menubar = ui.get_widget ("/MenuBar");
|
||||
var toolbar = (Toolbar) ui.get_widget ("/ToolBar");
|
||||
toolbar.set_style (ToolbarStyle.BOTH_HORIZ);
|
||||
((ToolItem) ui.get_widget ("/ToolBar/FileOpen")).is_important = true;
|
||||
((ToolItem) ui.get_widget ("/ToolBar/FileSave")).is_important = true;
|
||||
((ToolItem) ui.get_widget ("/ToolBar/HelpAbout")).is_important = true;
|
||||
|
||||
info_bar = new InfoBar.with_buttons (Stock.OK, ResponseType.OK);
|
||||
var label = new Label (null);
|
||||
label.use_markup = true;
|
||||
@ -126,17 +66,12 @@ namespace Spek {
|
||||
}
|
||||
|
||||
var vbox = new VBox (false, 0);
|
||||
vbox.pack_start (menubar, false, true, 0);
|
||||
vbox.pack_start (toolbar, false, true, 0);
|
||||
vbox.pack_start (info_bar, false, true, 0);
|
||||
vbox.pack_start (spectrogram, true, true, 0);
|
||||
add (vbox);
|
||||
menubar.show_all ();
|
||||
toolbar.show_all ();
|
||||
spectrogram.show_all ();
|
||||
vbox.show ();
|
||||
|
||||
Platform.fix_ui (ui);
|
||||
show ();
|
||||
|
||||
// Set up Drag and Drop
|
||||
|
@ -43,7 +43,7 @@ bool Spek::OnInit()
|
||||
return false;
|
||||
}
|
||||
|
||||
SpekWindow *window = new SpekWindow(wxT("Hello World"), wxPoint(50,50), wxSize(450,340));
|
||||
SpekWindow *window = new SpekWindow(_("Spek - Acoustic Spectrum Analyser"));
|
||||
window->Show(true);
|
||||
SetTopWindow(window);
|
||||
return true;
|
||||
|
Loading…
x
Reference in New Issue
Block a user