/[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 1081 by schoenebeck, Tue Mar 6 23:16:18 2007 UTC revision 1082 by schoenebeck, Thu Mar 8 01:43:18 2007 UTC
# Line 31  Line 31 
31    
32  #define _(String) gettext(String)  #define _(String) gettext(String)
33    
34    template<class T> inline std::string ToString(T o) {
35        std::stringstream ss;
36        ss << o;
37        return ss.str();
38    }
39    
40  bool update_gui;  bool update_gui;
41    
42  uint8_t& access_UnityNote(gig::DimensionRegion* dimreg)  uint8_t& access_UnityNote(gig::DimensionRegion* dimreg)
# Line 830  MainWindow::MainWindow() : Line 836  MainWindow::MainWindow() :
836                       sigc::mem_fun(                       sigc::mem_fun(
837                           *this, &MainWindow::on_action_help_about));                           *this, &MainWindow::on_action_help_about));
838  #endif  #endif
839      action = Gtk::Action::create("Remove", "Ta bort");      action = Gtk::Action::create("Remove", Gtk::Stock::REMOVE);
840      actionGroup->add(action,      actionGroup->add(action,
841                       sigc::mem_fun(                       sigc::mem_fun(
842                           *this, &MainWindow::hide));                           *this, &MainWindow::hide));
843    
844        // sample right-click popup actions
845        actionGroup->add(
846            Gtk::Action::create("SampleProperties", Gtk::Stock::PROPERTIES),
847            sigc::mem_fun(*this, &MainWindow::on_action_sample_properties)
848        );
849        actionGroup->add(
850            Gtk::Action::create("AddGroup", _("Add _Group")),
851            sigc::mem_fun(*this, &MainWindow::on_action_add_group)
852        );
853        actionGroup->add(
854            Gtk::Action::create("AddSample", _("Add _Sample")),
855            sigc::mem_fun(*this, &MainWindow::on_action_add_sample)
856        );
857        actionGroup->add(
858            Gtk::Action::create("RemoveSample", Gtk::Stock::REMOVE),
859            sigc::mem_fun(*this, &MainWindow::on_action_remove_sample)
860        );
861    
862      uiManager = Gtk::UIManager::create();      uiManager = Gtk::UIManager::create();
863      uiManager->insert_action_group(actionGroup);      uiManager->insert_action_group(actionGroup);
864      // add_accel_group(uiManager->get_accel_group());      // add_accel_group(uiManager->get_accel_group());
# Line 865  MainWindow::MainWindow() : Line 889  MainWindow::MainWindow() :
889          "    <menuitem action='InstrProperties'/>"          "    <menuitem action='InstrProperties'/>"
890          "    <menuitem action='Remove'/>"          "    <menuitem action='Remove'/>"
891          "  </popup>"          "  </popup>"
892            "  <popup name='SamplePopupMenu'>"
893            "    <menuitem action='SampleProperties'/>"
894            "    <menuitem action='AddGroup'/>"
895            "    <menuitem action='AddSample'/>"
896            "    <separator/>"
897            "    <menuitem action='RemoveSample'/>"
898            "  </popup>"
899          "</ui>";          "</ui>";
900      uiManager->add_ui_from_string(ui_info);      uiManager->add_ui_from_string(ui_info);
901    
# Line 895  MainWindow::MainWindow() : Line 926  MainWindow::MainWindow() :
926      m_TreeViewSamples.set_model(m_refSamplesTreeModel);      m_TreeViewSamples.set_model(m_refSamplesTreeModel);
927      m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name);      m_TreeViewSamples.append_column("Samples", m_SamplesModel.m_col_name);
928      m_TreeViewSamples.set_headers_visible(false);      m_TreeViewSamples.set_headers_visible(false);
929        m_TreeViewSamples.signal_button_press_event().connect_notify(
930            sigc::mem_fun(*this, &MainWindow::on_sample_treeview_button_release)
931        );
932    
933      file = 0;      file = 0;
934    
# Line 1526  void MainWindow::load_gig(gig::File* gig Line 1560  void MainWindow::load_gig(gig::File* gig
1560          Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();          Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1561          Gtk::TreeModel::Row rowGroup = *iterGroup;          Gtk::TreeModel::Row rowGroup = *iterGroup;
1562          rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();          rowGroup[m_SamplesModel.m_col_name]   = group->Name.c_str();
1563          rowGroup[m_SamplesModel.m_col_sample] = group;          rowGroup[m_SamplesModel.m_col_group]  = group;
1564            rowGroup[m_SamplesModel.m_col_sample] = NULL;
1565          for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) {          for (gig::Sample* sample = group->GetFirstSample(); sample; sample = group->GetNextSample()) {
1566              Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children());              Gtk::TreeModel::iterator iterSample = m_refSamplesTreeModel->append(rowGroup.children());
1567              Gtk::TreeModel::Row rowSample = *iterSample;              Gtk::TreeModel::Row rowSample = *iterSample;
1568              rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();              rowSample[m_SamplesModel.m_col_name]   = sample->pInfo->Name.c_str();
1569              rowSample[m_SamplesModel.m_col_sample] = sample;              rowSample[m_SamplesModel.m_col_sample] = sample;
1570                rowSample[m_SamplesModel.m_col_group]  = NULL;
1571          }          }
1572      }      }
1573  }  }
# Line 1559  void MainWindow::on_button_release(GdkEv Line 1595  void MainWindow::on_button_release(GdkEv
1595  void MainWindow::on_instrument_selection_change(int index) {  void MainWindow::on_instrument_selection_change(int index) {
1596      m_RegionChooser.set_instrument(file->GetInstrument(index));      m_RegionChooser.set_instrument(file->GetInstrument(index));
1597  }  }
1598    
1599    void MainWindow::on_sample_treeview_button_release(GdkEventButton* button) {
1600        if (button->type == GDK_BUTTON_PRESS && button->button == 3) {
1601            Gtk::Menu* sample_popup =
1602                dynamic_cast<Gtk::Menu*>(uiManager->get_widget("/SamplePopupMenu"));
1603            // update enabled/disabled state of sample popup items
1604            Glib::RefPtr<Gtk::TreeSelection> sel = m_TreeViewSamples.get_selection();
1605            Gtk::TreeModel::iterator it = sel->get_selected();
1606            bool group_selected  = false;
1607            bool sample_selected = false;
1608            if (it) {
1609                Gtk::TreeModel::Row row = *it;
1610                group_selected  = row[m_SamplesModel.m_col_group];
1611                sample_selected = row[m_SamplesModel.m_col_sample];
1612            }
1613            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/SampleProperties"))->set_sensitive(group_selected || sample_selected);
1614            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddSample"))->set_sensitive(group_selected || sample_selected);
1615            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/AddGroup"))->set_sensitive(file);
1616            dynamic_cast<Gtk::MenuItem*>(uiManager->get_widget("/SamplePopupMenu/RemoveSample"))->set_sensitive(group_selected || sample_selected);
1617            // show sample popup
1618            sample_popup->popup(button->button, button->time);
1619        }
1620    }
1621    
1622    void MainWindow::on_action_sample_properties() {
1623         //TODO: show a dialog where the selected sample's properties can be edited
1624    }
1625    
1626    void MainWindow::on_action_add_group() {
1627        static int __sample_indexer = 0;
1628        if (!file) return;
1629        gig::Group* group = file->AddGroup();
1630        group->Name = "Unnamed Group";
1631        if (__sample_indexer) group->Name += " " + ToString(__sample_indexer);
1632        __sample_indexer++;
1633        // update sample tree view
1634        Gtk::TreeModel::iterator iterGroup = m_refSamplesTreeModel->append();
1635        Gtk::TreeModel::Row rowGroup = *iterGroup;
1636        rowGroup[m_SamplesModel.m_col_name] = group->Name.c_str();
1637        rowGroup[m_SamplesModel.m_col_sample] = NULL;
1638        rowGroup[m_SamplesModel.m_col_group] = group;
1639    }
1640    
1641    void MainWindow::on_action_add_sample() {
1642        //TODO: open browse for file dialog for adding new samples
1643    }
1644    
1645    void MainWindow::on_action_remove_sample() {
1646        //TODO: remove the selected group or sample
1647    }

Legend:
Removed from v.1081  
changed lines
  Added in v.1082

  ViewVC Help
Powered by ViewVC