/[svn]/gigedit/trunk/src/mainwindow.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/mainwindow.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1075 by schoenebeck, Tue Mar 6 01:17:03 2007 UTC revision 1084 by schoenebeck, Thu Mar 8 16:47:15 2007 UTC
# Line 27  Line 27 
27  #if GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6  #if GTKMM_MAJOR_VERSION == 2 && GTKMM_MINOR_VERSION >= 6
28  #define ABOUT_DIALOG  #define ABOUT_DIALOG
29  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
30    #include <gtkmm/messagedialog.h>
31  #endif  #endif
32    
33  #define _(String) gettext(String)  #define _(String) gettext(String)
34    
35    template<class T> inline std::string ToString(T o) {
36        std::stringstream ss;
37        ss << o;
38        return ss.str();
39    }
40    
41  bool update_gui;  bool update_gui;
42    
43  uint8_t& access_UnityNote(gig::DimensionRegion* dimreg)  uint8_t& access_UnityNote(gig::DimensionRegion* dimreg)
# Line 523  MainWindow::MainWindow() : Line 530  MainWindow::MainWindow() :
530      m_TreeView.signal_button_press_event().connect_notify(      m_TreeView.signal_button_press_event().connect_notify(
531          sigc::mem_fun(*this, &MainWindow::on_button_release));          sigc::mem_fun(*this, &MainWindow::on_button_release));
532    
533      // Add the TreeView, inside a ScrolledWindow, with the button underneath:      // Add the TreeView tab, inside a ScrolledWindow, with the button underneath:
534      m_ScrolledWindow.add(m_TreeView);      m_ScrolledWindow.add(m_TreeViewNotebook);
535      m_ScrolledWindow.set_size_request(400, 600);      m_ScrolledWindow.set_size_request(400, 600);
536      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);      m_ScrolledWindow.set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
537    
# Line 783  MainWindow::MainWindow() : Line 790  MainWindow::MainWindow() :
790      m_HPaned.add2(m_Notebook);      m_HPaned.add2(m_Notebook);
791    
792    
793        m_TreeViewNotebook.append_page(m_TreeViewSamples, "Samples");
794        m_TreeViewNotebook.append_page(m_TreeView, "Instruments");
795    
796    
797      actionGroup = Gtk::ActionGroup::create();      actionGroup = Gtk::ActionGroup::create();
798    
799      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));      actionGroup->add(Gtk::Action::create("MenuFile", _("_File")));
# Line 826  MainWindow::MainWindow() : Line 837  MainWindow::MainWindow() :
837                       sigc::mem_fun(                       sigc::mem_fun(
838                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
839  #endif  #endif
840      action = Gtk::Action::create("Remove", "Ta bort");      action = Gtk::Action::create("Remove", Gtk::Stock::REMOVE);
841      actionGroup->add(action,      actionGroup->add(action,
842                       sigc::mem_fun(                       sigc::mem_fun(
843                           *this, &MainWindow::hide));                           *this, &MainWindow::hide));
844    
845        // sample right-click popup actions
846        actionGroup->add(
847            Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
848            sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
849        );
850        actionGroup->add(
851            Gtk::Action::create("AddGroup", _("Add _Group")),
852            sigc::mem_fun(*this, &MainWindow::on_action_add_group)
853        );
854        actionGroup->add(
855            Gtk::Action::create("AddSample", _("Add _Sample")),
856            sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
857        );
858        actionGroup->add(
859            Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
860            sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
861        );
862    
863      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
864      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
865      // add_accel_group(uiManager->get_accel_group());      // add_accel_group(uiManager->get_accel_group());
# Line 861  MainWindow::MainWindow() : Line 890  MainWindow::MainWindow() :
890          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
891          "    <menuitem action='Remove'/>"          "    <menuitem action='Remove'/>"
892          "  </popup>"          "  </popup>"
893            "  <popup name='SamplePopupMenu'>"
894            "    <menuitem action='SampleProperties'/>"
895            "    <menuitem action='AddGroup'/>"
896            "    <menuitem action='AddSample'/>"
897            "    <separator/>"
898            "    <menuitem action='RemoveSample'/>"
899            "  </popup>"
900          "</ui>";          "</ui>";
901      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
902    
# Line 886  MainWindow::MainWindow() : Line 922  MainWindow::MainWindow() :
922      m_TreeView.append_column("Instrument", m_Columns.m_col_name);      m_TreeView.append_column("Instrument", m_Columns.m_col_name);
923      m_TreeView.set_headers_visible(false);      m_TreeView.set_headers_visible(false);
924    
925        // create samples treeview (including its data model)
926        m_refSamplesTreeModel = Gtk::TreeStore::create(m_SamplesModel);
927        m_TreeViewSamples.set_model(m_refSamplesTreeModel);
928        m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name);
929        m_TreeViewSamples.set_headers_visible(false);
930        m_TreeViewSamples.signal_button_press_event().connect_notify(
931            sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
932        );
933    
934      file = 0;      file = 0;
935    
936      show_all_children();      show_all_children();
# Line 1255  void MainWindow::on_action_file_open() Line 1300  void MainWindow::on_action_file_open()
1300          instrument_menu->get_submenu()->items().clear();          instrument_menu->get_submenu()->items().clear();
1301    
1302          m_refTreeModel->clear();          m_refTreeModel->clear();
1303            m_refSamplesTreeModel->clear();
1304          if (file) delete file;          if (file) delete file;
1305    
1306          // getInfo(dialog.get_filename().c_str(), *this);          // getInfo(dialog.get_filename().c_str(), *this);
# Line 1510  void MainWindow::load_gig(gig::File* gig Line 1556  void MainWindow::load_gig(gig::File* gig
1556      }      }
1557      instrument_menu->show();      instrument_menu->show();
1558      instrument_menu->get_submenu()->show_all_children();      instrument_menu->get_submenu()->show_all_children();
1559    
1560        for (gig::Group* group = gig->GetFirstGroup(); group; group = gig->GetNextGroup()) {
1561            Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1562            Gtk::TreeModel::Row rowGroup = *iterGroup;
1563            rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();
1564            rowGroup[m_SamplesModel.m_col_group]  = group;
1565            rowGroup[m_SamplesModel.m_col_sample] = NULL;
1566            for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) {
1567                Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children());
1568                Gtk::TreeModel::Row rowSample = *iterSample;
1569                rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();
1570                rowSample[m_SamplesModel.m_col_sample] = sample;
1571                rowSample[m_SamplesModel.m_col_group]  = NULL;
1572            }
1573        }
1574  }  }
1575    
1576  void MainWindow::on_button_release(GdkEventButton* button)  void MainWindow::on_button_release(GdkEventButton* button)
# Line 1535  void MainWindow::on_button_release(GdkEv Line 1596  void MainWindow::on_button_release(GdkEv
1596  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(int index) {
1597      m_RegionChooser.set_instrument(file->GetInstrument(index));      m_RegionChooser.set_instrument(file->GetInstrument(index));
1598  }  }
1599    
1600    void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
1601        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1602            Gtk::Menu* sample_popup =
1603                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
1604            // update enabled/disabled state of sample popup items
1605            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1606            Gtk::TreeModel::iterator it = sel->get_selected();
1607            bool group_selected  = false;
1608            bool sample_selected = false;
1609            if (it) {
1610                Gtk::TreeModel::Row row = *it;
1611                group_selected  = row[m_SamplesModel.m_col_group];
1612                sample_selected = row[m_SamplesModel.m_col_sample];
1613            }
1614            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->set_sensitive(group_selected || sample_selected);
1615            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->set_sensitive(group_selected || sample_selected);
1616            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->set_sensitive(file);
1617            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->set_sensitive(group_selected || sample_selected);
1618            // show sample popup
1619            sample_popup->popup(button->button, button->time);
1620        }
1621    }
1622    
1623    void MainWindow::on_action_sample_properties() {
1624         //TODO: show a dialog where the selected sample's properties can be edited
1625    }
1626    
1627    void MainWindow::on_action_add_group() {
1628        static int __sample_indexer = 0;
1629        if (!file) return;
1630        gig::Group* group = file->AddGroup();
1631        group->Name = "Unnamed Group";
1632        if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1633        __sample_indexer++;
1634        // update sample tree view
1635        Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1636        Gtk::TreeModel::Row rowGroup = *iterGroup;
1637        rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();
1638        rowGroup[m_SamplesModel.m_col_sample] = NULL;
1639        rowGroup[m_SamplesModel.m_col_group] = group;
1640    }
1641    
1642    void MainWindow::on_action_add_sample() {
1643        //TODO: open browse for file dialog for adding new samples
1644    }
1645    
1646    void MainWindow::on_action_remove_sample() {
1647        if (!file) return;
1648        Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1649        Gtk::TreeModel::iterator it = sel->get_selected();
1650        if (it) {
1651            Gtk::TreeModel::Row row = *it;
1652            gig::Group* group   = row[m_SamplesModel.m_col_group];
1653            gig::Sample* sample = row[m_SamplesModel.m_col_sample];
1654            try {
1655                // remove group or sample from the gig file
1656                if (group) {
1657                    file->DeleteGroup(group);
1658                } else if (sample) {
1659                    file->DeleteSample(sample);
1660                }
1661                // remove respective row(s) from samples tree view
1662                m_refSamplesTreeModel->erase(it);
1663            } catch (RIFF::Exception e) {
1664                Gtk::MessageDialog msg(*this, e.Message.c_str(), false, Gtk::MESSAGE_ERROR);
1665                msg.run();
1666            }
1667        }
1668    }

Legend:
Removed from v.1075  
changed lines
  Added in v.1084

  ViewVC Help
Powered by ViewVC