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

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

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

revision 3339 by schoenebeck, Sun Jul 30 18:57:35 2017 UTC revision 3340 by schoenebeck, Mon Jul 31 11:20:18 2017 UTC
# Line 32  Line 32 
32  #include <glibmm/dispatcher.h>  #include <glibmm/dispatcher.h>
33  #include <glibmm/miscutils.h>  #include <glibmm/miscutils.h>
34  #include <glibmm/stringutils.h>  #include <glibmm/stringutils.h>
35    #include <glibmm/regex.h>
36  #include <gtkmm/aboutdialog.h>  #include <gtkmm/aboutdialog.h>
37  #include <gtkmm/filechooserdialog.h>  #include <gtkmm/filechooserdialog.h>
38  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
# Line 121  MainWindow::MainWindow() : Line 122  MainWindow::MainWindow() :
122    
123      m_TreeViewNotebook.set_size_request(300);      m_TreeViewNotebook.set_size_request(300);
124    
125      m_HPaned.add1(m_TreeViewNotebook);      m_searchLabel.set_text(Glib::ustring(" ") + _("Filter:"));
126        m_searchField.pack_start(m_searchLabel, Gtk::PACK_SHRINK);
127        m_searchField.pack_start(m_searchText);
128        m_searchField.set_spacing(5);
129    
130        m_left_vbox.pack_start(m_TreeViewNotebook);
131        m_left_vbox.pack_start(m_searchField, Gtk::PACK_SHRINK);
132    
133        m_HPaned.add1(m_left_vbox);
134    
135      dimreg_hbox.add(dimreg_label);      dimreg_hbox.add(dimreg_label);
136      dimreg_hbox.add(dimreg_all_regions);      dimreg_hbox.add(dimreg_all_regions);
137      dimreg_hbox.add(dimreg_all_dimregs);      dimreg_hbox.add(dimreg_all_dimregs);
# Line 685  MainWindow::MainWindow() : Line 695  MainWindow::MainWindow() :
695    
696      // Create the Tree model:      // Create the Tree model:
697      m_refTreeModel = Gtk::ListStore::create(m_Columns);      m_refTreeModel = Gtk::ListStore::create(m_Columns);
698      m_TreeView.set_model(m_refTreeModel);      m_refTreeModelFilter = Gtk::TreeModelFilter::create(m_refTreeModel);
699        m_refTreeModelFilter->set_visible_func(
700            sigc::mem_fun(*this, &MainWindow::instrument_row_visible)
701        );
702        m_TreeView.set_model(m_refTreeModelFilter);
703    
704      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
705      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));      m_TreeView.set_tooltip_text(_("Right click here for actions on instruments & MIDI Rules. Drag & drop to change the order of instruments."));
706      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
# Line 861  MainWindow::MainWindow() : Line 876  MainWindow::MainWindow() :
876      dimreg_stereo.signal_toggled().connect(      dimreg_stereo.signal_toggled().connect(
877          sigc::mem_fun(*this, &MainWindow::update_dimregs));          sigc::mem_fun(*this, &MainWindow::update_dimregs));
878    
879        m_searchText.signal_changed().connect(
880            sigc::mem_fun(m_refTreeModelFilter.operator->(), &Gtk::TreeModelFilter::refilter)
881        );
882    
883      file = 0;      file = 0;
884      file_is_changed = false;      file_is_changed = false;
885    
# Line 869  MainWindow::MainWindow() : Line 888  MainWindow::MainWindow() :
888      // start with a new gig file by default      // start with a new gig file by default
889      on_action_file_new();      on_action_file_new();
890    
891        m_TreeViewNotebook.signal_switch_page().connect(
892            sigc::mem_fun(*this, &MainWindow::on_notebook_tab_switched)
893        );
894    
895      // select 'Instruments' tab by default      // select 'Instruments' tab by default
896      // (gtk allows this only if the tab childs are visible, thats why it's here)      // (gtk allows this only if the tab childs are visible, thats why it's here)
897      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
# Line 1041  void MainWindow::onMacrosSetupChanged(co Line 1064  void MainWindow::onMacrosSetupChanged(co
1064      updateMacroMenu();      updateMacroMenu();
1065  }  }
1066    
1067    void MainWindow::on_notebook_tab_switched(GtkNotebookPage* page, guint page_num) {
1068        bool isInstrumentsPage = (page_num == 1);
1069        // so far we only support filtering for the instruments list, so hide the
1070        // filter text entry field if another tab is selected
1071        m_searchField.set_visible(isInstrumentsPage);
1072    }
1073    
1074  bool MainWindow::on_delete_event(GdkEventAny* event)  bool MainWindow::on_delete_event(GdkEventAny* event)
1075  {  {
1076      return !file_is_shared && file_is_changed && !close_confirmation_dialog();      return !file_is_shared && file_is_changed && !close_confirmation_dialog();
# Line 2335  void MainWindow::onScriptSlotsModified(g Line 2365  void MainWindow::onScriptSlotsModified(g
2365      if (!pInstrument) return;      if (!pInstrument) return;
2366      const int iScriptSlots = pInstrument->ScriptSlotCount();      const int iScriptSlots = pInstrument->ScriptSlotCount();
2367    
2368      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      //NOTE: This is a big mess! Sometimes GTK requires m_TreeView.get_model(), here we need m_refTreeModelFilter->get_model(), otherwise accessing children below causes an error!
2369        //Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2370        Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2371    
2372      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2373          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2374          if (row[m_Columns.m_col_instr] != pInstrument) continue;          if (row[m_Columns.m_col_instr] != pInstrument) continue;
# Line 2467  void MainWindow::on_instrument_selection Line 2500  void MainWindow::on_instrument_selection
2500  void MainWindow::select_instrument(gig::Instrument* instrument) {  void MainWindow::select_instrument(gig::Instrument* instrument) {
2501      if (!instrument) return;      if (!instrument) return;
2502    
2503        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2504      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2505        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2506    
2507      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2508          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2509          if (row[m_Columns.m_col_instr] == instrument) {          if (row[m_Columns.m_col_instr] == instrument) {
# Line 2489  bool MainWindow::select_dimension_region Line 2525  bool MainWindow::select_dimension_region
2525      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();      gig::Region* pRegion = (gig::Region*) dimRgn->GetParent();
2526      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();      gig::Instrument* pInstrument = (gig::Instrument*) pRegion->GetParent();
2527    
2528        //NOTE: This is a big mess! Sometimes GTK requires m_refTreeModelFilter->get_model(), here we need m_TreeView.get_model(), otherwise treeview selection below causes an error!
2529      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();      Glib::RefPtr<Gtk::TreeModel> model = m_TreeView.get_model();
2530        //Glib::RefPtr<Gtk::TreeModel> model = m_refTreeModelFilter->get_model();
2531    
2532      for (int i = 0; i < model->children().size(); ++i) {      for (int i = 0; i < model->children().size(); ++i) {
2533          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
2534          if (row[m_Columns.m_col_instr] == pInstrument) {          if (row[m_Columns.m_col_instr] == pInstrument) {
# Line 3699  void MainWindow::instrument_name_changed Line 3738  void MainWindow::instrument_name_changed
3738      }      }
3739  }  }
3740    
3741    bool MainWindow::instrument_row_visible(const Gtk::TreeModel::const_iterator& iter) {
3742        if (!iter)
3743            return true;
3744    
3745        Glib::ustring pattern = m_searchText.get_text().lowercase();
3746        trim(pattern);
3747        if (pattern.empty()) return true;
3748    
3749        Gtk::TreeModel::Row row = *iter;
3750        Glib::ustring name = row[m_Columns.m_col_name];
3751        name = name.lowercase();
3752    
3753        std::vector<Glib::ustring> tokens = Glib::Regex::split_simple(" ", pattern);
3754        for (int t = 0; t < tokens.size(); ++t)
3755            if (name.find(tokens[t]) == Glib::ustring::npos)
3756                return false;
3757    
3758        return true;
3759    }
3760    
3761  void MainWindow::on_action_combine_instruments() {  void MainWindow::on_action_combine_instruments() {
3762      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);      CombineInstrumentsDialog* d = new CombineInstrumentsDialog(*this, file);
3763    

Legend:
Removed from v.3339  
changed lines
  Added in v.3340

  ViewVC Help
Powered by ViewVC