/[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 3417 by schoenebeck, Fri Feb 9 15:29:13 2018 UTC revision 3460 by persson, Sat Feb 2 07:48:50 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2017 Andreas Persson   * Copyright (C) 2006-2019 Andreas Persson
3   *   *
4   * This program is free software; you can redistribute it and/or   * This program is free software; you can redistribute it and/or
5   * modify it under the terms of the GNU General Public License as   * modify it under the terms of the GNU General Public License as
# Line 1356  MainWindow::MainWindow() : Line 1356  MainWindow::MainWindow() :
1356      m_TreeView.set_model(m_refTreeModelFilter);      m_TreeView.set_model(m_refTreeModelFilter);
1357    
1358      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);      m_TreeView.get_selection()->set_mode(Gtk::SELECTION_MULTIPLE);
1359      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_has_tooltip(true);
1360        m_TreeView.signal_query_tooltip().connect(
1361            sigc::mem_fun(*this, &MainWindow::onQueryTreeViewTooltip)
1362        );
1363      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(      instrument_name_connection = m_refTreeModel->signal_row_changed().connect(
1364          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)          sigc::mem_fun(*this, &MainWindow::instrument_name_changed)
1365      );      );
# Line 1633  MainWindow::MainWindow() : Line 1636  MainWindow::MainWindow() :
1636          Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);          Gtk::AccelMap::add_entry("<Scripts>/script_16", GDK_KEY_F17, Gdk::SHIFT_MASK);
1637          Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);          Gtk::AccelMap::add_entry("<Scripts>/script_17", GDK_KEY_F18, Gdk::SHIFT_MASK);
1638          Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);          Gtk::AccelMap::add_entry("<Scripts>/script_18", GDK_KEY_F19, Gdk::SHIFT_MASK);
1639            Gtk::AccelMap::add_entry("<Scripts>/DropAllScriptSlots", GDK_KEY_BackSpace, Gdk::SHIFT_MASK);
1640    
1641          Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();          Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group();
1642          assign_scripts_menu->set_accel_group(accelGroup);          assign_scripts_menu->set_accel_group(accelGroup);
# Line 2636  void MainWindow::on_show_tooltips_change Line 2640  void MainWindow::on_show_tooltips_change
2640      dimreg_all_regions.set_has_tooltip(b);      dimreg_all_regions.set_has_tooltip(b);
2641      dimreg_all_dimregs.set_has_tooltip(b);      dimreg_all_dimregs.set_has_tooltip(b);
2642      dimreg_stereo.set_has_tooltip(b);      dimreg_stereo.set_has_tooltip(b);
2643      m_TreeView.set_has_tooltip(b);  
2644        // Not doing this here, we let onQueryTreeViewTooltip() handle this per cell
2645        //m_TreeView.set_has_tooltip(b);
2646    
2647      m_TreeViewSamples.set_has_tooltip(b);      m_TreeViewSamples.set_has_tooltip(b);
2648      m_TreeViewScripts.set_has_tooltip(b);      m_TreeViewScripts.set_has_tooltip(b);
2649    
# Line 2662  void MainWindow::on_action_help_about() Line 2669  void MainWindow::on_action_help_about()
2669      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
2670  #endif  #endif
2671      dialog.set_version(VERSION);      dialog.set_version(VERSION);
2672      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2019 Andreas Persson");
2673      const std::string sComment =      const std::string sComment =
2674          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
2675          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 2758  PropDialog::PropDialog() Line 2765  PropDialog::PropDialog()
2765  #endif  #endif
2766    
2767      add(vbox);      add(vbox);
2768  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2769      table.set_margin(5);      table.set_margin(5);
2770  #else  #else
2771      table.set_border_width(5);      table.set_border_width(5);
# Line 2766  PropDialog::PropDialog() Line 2773  PropDialog::PropDialog()
2773      vbox.add(table);      vbox.add(table);
2774      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2775      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2776  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2777      buttonBox.set_margin(5);      buttonBox.set_margin(5);
2778  #else  #else
2779      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
# Line 2797  void PropDialog::set_file(gig::File* fil Line 2804  void PropDialog::set_file(gig::File* fil
2804      std::vector<std::string> txts;      std::vector<std::string> txts;
2805      std::vector<int> values;      std::vector<int> values;
2806      txts.push_back(sGiga + "2"); values.push_back(2);      txts.push_back(sGiga + "2"); values.push_back(2);
2807      txts.push_back(sGiga + "3/v4"); values.push_back(3);      txts.push_back(sGiga + "3"); values.push_back(3);
2808      if (major != 2 && major != 3) {      txts.push_back(sGiga + "4"); values.push_back(4);
2809        if (major < 2 || major > 4) {
2810          txts.push_back(sGiga + ToString(major)); values.push_back(major);          txts.push_back(sGiga + ToString(major)); values.push_back(major);
2811      }      }
2812      std::vector<const char*> texts;      std::vector<const char*> texts;
# Line 2917  InstrumentProps::InstrumentProps() : Line 2925  InstrumentProps::InstrumentProps() :
2925      table.add(eDimensionKeyRangeHigh);      table.add(eDimensionKeyRangeHigh);
2926    
2927      add(vbox);      add(vbox);
2928  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2929      table.set_margin(5);      table.set_margin(5);
2930  #else  #else
2931      table.set_border_width(5);      table.set_border_width(5);
# Line 2926  InstrumentProps::InstrumentProps() : Line 2934  InstrumentProps::InstrumentProps() :
2934      table.show();      table.show();
2935      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);      vbox.pack_start(buttonBox, Gtk::PACK_SHRINK);
2936      buttonBox.set_layout(Gtk::BUTTONBOX_END);      buttonBox.set_layout(Gtk::BUTTONBOX_END);
2937  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
2938      buttonBox.set_margin(5);      buttonBox.set_margin(5);
2939  #else  #else
2940      buttonBox.set_border_width(5);      buttonBox.set_border_width(5);
# Line 2988  void MainWindow::updateSampleRefCountMap Line 2996  void MainWindow::updateSampleRefCountMap
2996      }      }
2997  }  }
2998    
2999    bool MainWindow::onQueryTreeViewTooltip(int x, int y, bool keyboardTip, const Glib::RefPtr<Gtk::Tooltip>& tooltip) {
3000        Gtk::TreeModel::iterator iter;
3001        if (!m_TreeView.get_tooltip_context_iter(x, y, keyboardTip, iter)) {
3002            return false;
3003        }
3004        Gtk::TreeModel::Path path(iter);
3005        Gtk::TreeModel::Row row = *iter;
3006        Gtk::TreeViewColumn* pointedColumn = NULL;
3007        // resolve the precise table column the mouse points to
3008        {
3009            Gtk::TreeModel::Path path; // unused
3010            int cellX, cellY; // unused
3011            m_TreeView.get_path_at_pos(x, y, path, pointedColumn, cellX, cellY);
3012        }
3013        Gtk::TreeViewColumn* scriptsColumn = m_TreeView.get_column(2);
3014        if (pointedColumn == scriptsColumn) { // mouse hovers scripts column ...
3015            // show the script(s) assigned to the hovered instrument as tooltip
3016            tooltip->set_markup( row[m_Columns.m_col_tooltip] );
3017            m_TreeView.set_tooltip_cell(tooltip, &path, scriptsColumn, NULL);
3018        } else {
3019            // if beginners' tooltips is disabled then don't show the following one
3020            if (!Settings::singleton()->showTooltips)
3021                return false;
3022            // yeah, a beginners tooltip
3023            tooltip->set_text(_(
3024                "Right click here for actions on instruments & MIDI Rules. "
3025                "Drag & drop to change the order of instruments."
3026            ));
3027            m_TreeView.set_tooltip_cell(tooltip, &path, pointedColumn, NULL);
3028        }
3029        return true;
3030    }
3031    
3032    static Glib::ustring scriptTooltipFor(gig::Instrument* instrument, int index) {
3033        Glib::ustring name(gig_to_utf8(instrument->pInfo->Name));
3034        const int iScriptSlots = instrument->ScriptSlotCount();
3035        Glib::ustring tooltip = "<u>(" + ToString(index) + ") “"  + name + "”</u>\n\n";
3036        if (!iScriptSlots)
3037            tooltip += "<span foreground='red'><i>No script assigned</i></span>";
3038        else {
3039            for (int i = 0; i < iScriptSlots; ++i) {
3040                tooltip += "• " + ToString(i+1) + ". Script: “<span foreground='#46DEFF'><b>" +
3041                           instrument->GetScriptOfSlot(i)->Name + "</b></span>”";
3042                if (i + 1 < iScriptSlots) tooltip += "\n\n";
3043            }
3044        }
3045        return tooltip;
3046    }
3047    
3048  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)  void MainWindow::load_gig(gig::File* gig, const char* filename, bool isSharedInstrument)
3049  {  {
3050      file = 0;      file = 0;
# Line 3017  void MainWindow::load_gig(gig::File* gig Line 3074  void MainWindow::load_gig(gig::File* gig
3074          row[m_Columns.m_col_name] = name;          row[m_Columns.m_col_name] = name;
3075          row[m_Columns.m_col_instr] = instrument;          row[m_Columns.m_col_instr] = instrument;
3076          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3077            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3078    
3079  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
3080          add_instrument_to_menu(name);          add_instrument_to_menu(name);
# Line 3134  void MainWindow::instr_name_changed_by_i Line 3192  void MainWindow::instr_name_changed_by_i
3192      gig::Instrument* instrument = row[m_Columns.m_col_instr];      gig::Instrument* instrument = row[m_Columns.m_col_instr];
3193      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));      Glib::ustring gigname(gig_to_utf8(instrument->pInfo->Name));
3194      if (gigname != name) {      if (gigname != name) {
3195            Gtk::TreeModel::Path path(*it);
3196            const int index = path[0];
3197          row[m_Columns.m_col_name] = gigname;          row[m_Columns.m_col_name] = gigname;
3198            row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3199      }      }
3200  }  }
3201    
# Line 3180  void MainWindow::onScriptSlotsModified(g Line 3241  void MainWindow::onScriptSlotsModified(g
3241          Gtk::TreeModel::Row row = model->children()[i];          Gtk::TreeModel::Row row = model->children()[i];
3242          if (row[m_Columns.m_col_instr] != pInstrument) continue;          if (row[m_Columns.m_col_instr] != pInstrument) continue;
3243          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";          row[m_Columns.m_col_scripts] = iScriptSlots ? ToString(iScriptSlots) : "";
3244            row[m_Columns.m_col_tooltip] = scriptTooltipFor(pInstrument, i);
3245          break;          break;
3246      }      }
3247    
# Line 3205  void MainWindow::assignScript(gig::Scrip Line 3267  void MainWindow::assignScript(gig::Scrip
3267      onScriptSlotsModified(pInstrument);      onScriptSlotsModified(pInstrument);
3268  }  }
3269    
3270    void MainWindow::dropAllScriptSlots() {
3271        gig::Instrument* pInstrument = get_instrument();
3272        if (!pInstrument) {
3273            printf("!instrument\n");
3274            return;
3275        }
3276    
3277        const int iScriptSlots = pInstrument->ScriptSlotCount();
3278        for (int i = iScriptSlots - 1; i >= 0; --i)
3279            pInstrument->RemoveScriptSlot(i);
3280    
3281        onScriptSlotsModified(pInstrument);
3282    }
3283    
3284  void MainWindow::on_action_refresh_all() {  void MainWindow::on_action_refresh_all() {
3285      __refreshEntireGUI();      __refreshEntireGUI();
3286  }  }
# Line 3379  void MainWindow::select_instrument(gig:: Line 3455  void MainWindow::select_instrument(gig::
3455              show_intruments_tab();              show_intruments_tab();
3456              m_TreeView.get_selection()->unselect_all();              m_TreeView.get_selection()->unselect_all();
3457                            
3458  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3459              auto iterSel = model->children()[i].get_iter();              auto iterSel = model->children()[i].get_iter();
3460              m_TreeView.get_selection()->select(iterSel);              m_TreeView.get_selection()->select(iterSel);
3461  #else  #else
# Line 3409  bool MainWindow::select_dimension_region Line 3485  bool MainWindow::select_dimension_region
3485              // select and show the respective instrument in the list view              // select and show the respective instrument in the list view
3486              show_intruments_tab();              show_intruments_tab();
3487              m_TreeView.get_selection()->unselect_all();              m_TreeView.get_selection()->unselect_all();
3488  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3489              auto iterSel = model->children()[i].get_iter();              auto iterSel = model->children()[i].get_iter();
3490              m_TreeView.get_selection()->select(iterSel);              m_TreeView.get_selection()->select(iterSel);
3491  #else  #else
# Line 3445  void MainWindow::select_sample(gig::Samp Line 3521  void MainWindow::select_sample(gig::Samp
3521              if (rowSample[m_SamplesModel.m_col_sample] == sample) {              if (rowSample[m_SamplesModel.m_col_sample] == sample) {
3522                  show_samples_tab();                  show_samples_tab();
3523                  m_TreeViewSamples.get_selection()->unselect_all();                  m_TreeViewSamples.get_selection()->unselect_all();
3524  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
3525                  auto iterSel = rowGroup.children()[s].get_iter();                  auto iterSel = rowGroup.children()[s].get_iter();
3526                  m_TreeViewSamples.get_selection()->select(iterSel);                  m_TreeViewSamples.get_selection()->select(iterSel);
3527  #else  #else
# Line 3645  void MainWindow::updateScriptListOfMenu( Line 3721  void MainWindow::updateScriptListOfMenu(
3721          assign_scripts_menu->append(*item);          assign_scripts_menu->append(*item);
3722      }      }
3723    
3724        // add separator line to menu
3725        assign_scripts_menu->append(*new Gtk::SeparatorMenuItem);
3726    
3727        {
3728            Gtk::MenuItem* item = new Gtk::MenuItem(_("Unassign All Scripts"));
3729            item->signal_activate().connect(
3730                sigc::mem_fun(*this, &MainWindow::dropAllScriptSlots)
3731            );
3732            assign_scripts_menu->append(*item);
3733            item->set_accel_path("<Scripts>/DropAllScriptSlots");
3734        }
3735    
3736  #if HAS_GTKMM_SHOW_ALL_CHILDREN  #if HAS_GTKMM_SHOW_ALL_CHILDREN
3737      assign_scripts_menu->show_all_children();      assign_scripts_menu->show_all_children();
3738  #endif  #endif
# Line 3693  void MainWindow::add_instrument(gig::Ins Line 3781  void MainWindow::add_instrument(gig::Ins
3781      instrument_name_connection.block();      instrument_name_connection.block();
3782      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();      Gtk::TreeModel::iterator iterInstr = m_refTreeModel->append();
3783      Gtk::TreeModel::Row rowInstr = *iterInstr;      Gtk::TreeModel::Row rowInstr = *iterInstr;
3784      rowInstr[m_Columns.m_col_nr] = m_refTreeModel->children().size() - 1;      const int index = m_refTreeModel->children().size() - 1;
3785        rowInstr[m_Columns.m_col_nr] = index;
3786      rowInstr[m_Columns.m_col_name] = name;      rowInstr[m_Columns.m_col_name] = name;
3787      rowInstr[m_Columns.m_col_instr] = instrument;      rowInstr[m_Columns.m_col_instr] = instrument;
3788      rowInstr[m_Columns.m_col_scripts] = "";      rowInstr[m_Columns.m_col_scripts] = "";
3789        rowInstr[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3790      instrument_name_connection.unblock();      instrument_name_connection.unblock();
3791    
3792  #if !USE_GTKMM_BUILDER  #if !USE_GTKMM_BUILDER
# Line 3783  void MainWindow::on_action_remove_instru Line 3873  void MainWindow::on_action_remove_instru
3873                       it != m_refTreeModel->children().end(); ++it, ++index)                       it != m_refTreeModel->children().end(); ++it, ++index)
3874                  {                  {
3875                      Gtk::TreeModel::Row row = *it;                      Gtk::TreeModel::Row row = *it;
3876                        gig::Instrument* instrument = row[m_Columns.m_col_instr];
3877                      row[m_Columns.m_col_nr] = index;                      row[m_Columns.m_col_nr] = index;
3878                        row[m_Columns.m_col_tooltip] = scriptTooltipFor(instrument, index);
3879                  }                  }
3880              }              }
3881    
# Line 4704  bool MainWindow::instrument_row_visible( Line 4796  bool MainWindow::instrument_row_visible(
4796      trim(pattern);      trim(pattern);
4797      if (pattern.empty()) return true;      if (pattern.empty()) return true;
4798    
4799  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 22)  #if GTKMM_MAJOR_VERSION > 3 || (GTKMM_MAJOR_VERSION == 3 && GTKMM_MINOR_VERSION > 24)
4800      //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.      //HACK: on GTKMM4 development branch const_iterator cannot be easily converted to iterator, probably going to be fixed before final GTKMM4 release though.
4801      Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);      Gtk::TreeModel::Row row = **(Gtk::TreeModel::iterator*)(&iter);
4802  #else  #else

Legend:
Removed from v.3417  
changed lines
  Added in v.3460

  ViewVC Help
Powered by ViewVC