/[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 3021 by persson, Sun Oct 23 07:24:40 2016 UTC revision 3144 by schoenebeck, Wed May 3 19:00:11 2017 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (C) 2006-2016 Andreas Persson   * Copyright (C) 2006-2017 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 57  Line 57 
57  #include "ReferencesView.h"  #include "ReferencesView.h"
58  #include "../../gfx/status_attached.xpm"  #include "../../gfx/status_attached.xpm"
59  #include "../../gfx/status_detached.xpm"  #include "../../gfx/status_detached.xpm"
60    #include "gfx/builtinpix.h"
61    
62  MainWindow::MainWindow() :  MainWindow::MainWindow() :
63      m_DimRegionChooser(*this),      m_DimRegionChooser(*this),
64      dimreg_label(_("Changes apply to:")),      dimreg_label(_("Changes apply to:")),
65      dimreg_all_regions(_("all regions")),      dimreg_all_regions(_("all regions")),
66      dimreg_all_dimregs(_("all dimension splits")),      dimreg_all_dimregs(_("all dimension splits")),
67      dimreg_stereo(_("both channels"))      dimreg_stereo(_("both channels")),
68        labelLegend(_("Legend:")),
69        labelNoSample(_(" No Sample")),
70        labelMissingSample(_(" Missing some Sample(s)")),
71        labelLooped(_(" Looped")),
72        labelSomeLoops(_(" Some Loop(s)"))
73  {  {
74        loadBuiltInPix();
75    
76  //    set_border_width(5);  //    set_border_width(5);
77  //    set_default_size(400, 200);  //    set_default_size(400, 200);
78    
   
79      add(m_VBox);      add(m_VBox);
80    
81      // Handle selection      // Handle selection
# Line 103  MainWindow::MainWindow() : Line 109  MainWindow::MainWindow() :
109      dimreg_hbox.add(dimreg_stereo);      dimreg_hbox.add(dimreg_stereo);
110      dimreg_vbox.add(dimreg_edit);      dimreg_vbox.add(dimreg_edit);
111      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);      dimreg_vbox.pack_start(dimreg_hbox, Gtk::PACK_SHRINK);
112        {
113            legend_hbox.add(labelLegend);
114    
115            imageNoSample.set(redDot);
116            imageNoSample.set_alignment(Gtk::ALIGN_END);
117            labelNoSample.set_alignment(Gtk::ALIGN_START);
118            legend_hbox.add(imageNoSample);
119            legend_hbox.add(labelNoSample);
120    
121            imageMissingSample.set(yellowDot);
122            imageMissingSample.set_alignment(Gtk::ALIGN_END);
123            labelMissingSample.set_alignment(Gtk::ALIGN_START);
124            legend_hbox.add(imageMissingSample);
125            legend_hbox.add(labelMissingSample);
126    
127            imageLooped.set(blackLoop);
128            imageLooped.set_alignment(Gtk::ALIGN_END);
129            labelLooped.set_alignment(Gtk::ALIGN_START);
130            legend_hbox.add(imageLooped);
131            legend_hbox.add(labelLooped);
132    
133            imageSomeLoops.set(grayLoop);
134            imageSomeLoops.set_alignment(Gtk::ALIGN_END);
135            labelSomeLoops.set_alignment(Gtk::ALIGN_START);
136            legend_hbox.add(imageSomeLoops);
137            legend_hbox.add(labelSomeLoops);
138    
139            legend_hbox.show_all_children();
140        }
141        dimreg_vbox.pack_start(legend_hbox, Gtk::PACK_SHRINK);
142      m_HPaned.add2(dimreg_vbox);      m_HPaned.add2(dimreg_vbox);
143    
144      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));      dimreg_label.set_tooltip_text(_("To automatically apply your changes above globally to the entire instrument, check all 3 check boxes on the right."));
# Line 162  MainWindow::MainWindow() : Line 198  MainWindow::MainWindow() :
198          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)          sigc::mem_fun(*this, &MainWindow::show_intruments_tab)
199      );      );
200      actionGroup->add(      actionGroup->add(
201          Gtk::Action::create("MenuScript", _("S_cript")),          Gtk::Action::create("MenuScript", _("Scr_ipt")),
202          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)          sigc::mem_fun(*this, &MainWindow::show_scripts_tab)
203      );      );
204      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));      actionGroup->add(Gtk::Action::create("AllInstruments", _("_Select")));
205    
206      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));      actionGroup->add(Gtk::Action::create("MenuEdit", _("_Edit")));
207    
208        const Gdk::ModifierType primaryModifierKey =
209    #if defined(__APPLE__)
210        Gdk::META_MASK; // Cmd key on Mac
211    #else
212        Gdk::CONTROL_MASK; // Ctrl key on all other OSs
213    #endif
214    
215        actionGroup->add(Gtk::Action::create("CopyDimRgn",
216                                             _("Copy selected dimension region")),
217                         Gtk::AccelKey(GDK_KEY_c, Gdk::MOD1_MASK),
218                         sigc::mem_fun(*this, &MainWindow::copy_selected_dimrgn));
219    
220        actionGroup->add(Gtk::Action::create("PasteDimRgn",
221                                             _("Paste dimension region")),
222                         Gtk::AccelKey(GDK_KEY_v, Gdk::MOD1_MASK),
223                         sigc::mem_fun(*this, &MainWindow::paste_copied_dimrgn));
224    
225        actionGroup->add(Gtk::Action::create("SelectPrevRegion",
226                                             _("Select Previous Region")),
227                         Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
228                         sigc::mem_fun(*this, &MainWindow::select_prev_region));
229    
230        actionGroup->add(Gtk::Action::create("SelectNextRegion",
231                                             _("Select Next Region")),
232                         Gtk::AccelKey(GDK_KEY_Right, primaryModifierKey),
233                         sigc::mem_fun(*this, &MainWindow::select_next_region));
234    
235        actionGroup->add(Gtk::Action::create("SelectPrevDimRgnZone",
236                                             _("Select Previous Dimension Region Zone")),
237                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK),
238                         sigc::mem_fun(*this, &MainWindow::select_prev_dim_rgn_zone));
239    
240        actionGroup->add(Gtk::Action::create("SelectNextDimRgnZone",
241                                             _("Select Next Dimension Region Zone")),
242                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK),
243                         sigc::mem_fun(*this, &MainWindow::select_next_dim_rgn_zone));
244    
245        actionGroup->add(Gtk::Action::create("SelectPrevDimension",
246                                             _("Select Previous Dimension")),
247                         Gtk::AccelKey(GDK_KEY_Up, Gdk::MOD1_MASK),
248                         sigc::mem_fun(*this, &MainWindow::select_prev_dimension));
249    
250        actionGroup->add(Gtk::Action::create("SelectNextDimension",
251                                             _("Select Next Dimension")),
252                         Gtk::AccelKey(GDK_KEY_Down, Gdk::MOD1_MASK),
253                         sigc::mem_fun(*this, &MainWindow::select_next_dimension));
254    
255        actionGroup->add(Gtk::Action::create("SelectAddPrevDimRgnZone",
256                                             _("Add Previous Dimension Region Zone to Selection")),
257                         Gtk::AccelKey(GDK_KEY_Left, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
258                         sigc::mem_fun(*this, &MainWindow::select_add_prev_dim_rgn_zone));
259    
260        actionGroup->add(Gtk::Action::create("SelectAddNextDimRgnZone",
261                                             _("Add Next Dimension Region Zone to Selection")),
262                         Gtk::AccelKey(GDK_KEY_Right, Gdk::MOD1_MASK | Gdk::SHIFT_MASK),
263                         sigc::mem_fun(*this, &MainWindow::select_add_next_dim_rgn_zone));
264    
265      Glib::RefPtr<Gtk::ToggleAction> toggle_action =      Glib::RefPtr<Gtk::ToggleAction> toggle_action =
266          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));          Gtk::ToggleAction::create("CopySampleUnity", _("Copy Sample's _Unity Note"));
267      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 185  MainWindow::MainWindow() : Line 278  MainWindow::MainWindow() :
278      actionGroup->add(toggle_action);      actionGroup->add(toggle_action);
279    
280    
281      actionGroup->add(Gtk::Action::create("MenuView", _("_View")));      actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w")));
282      toggle_action =      toggle_action =
283          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));          Gtk::ToggleAction::create("Statusbar", _("_Statusbar"));
284      toggle_action->set_active(true);      toggle_action->set_active(true);
# Line 343  MainWindow::MainWindow() : Line 436  MainWindow::MainWindow() :
436          "      <menuitem action='Quit'/>"          "      <menuitem action='Quit'/>"
437          "    </menu>"          "    </menu>"
438          "    <menu action='MenuEdit'>"          "    <menu action='MenuEdit'>"
439            "      <menuitem action='CopyDimRgn'/>"
440            "      <menuitem action='PasteDimRgn'/>"
441            "      <separator/>"
442            "      <menuitem action='SelectPrevRegion'/>"
443            "      <menuitem action='SelectNextRegion'/>"
444            "      <separator/>"
445            "      <menuitem action='SelectPrevDimension'/>"
446            "      <menuitem action='SelectNextDimension'/>"
447            "      <menuitem action='SelectPrevDimRgnZone'/>"
448            "      <menuitem action='SelectNextDimRgnZone'/>"
449            "      <menuitem action='SelectAddPrevDimRgnZone'/>"
450            "      <menuitem action='SelectAddNextDimRgnZone'/>"
451            "      <separator/>"
452          "      <menuitem action='CopySampleUnity'/>"          "      <menuitem action='CopySampleUnity'/>"
453          "      <menuitem action='CopySampleTune'/>"          "      <menuitem action='CopySampleTune'/>"
454          "      <menuitem action='CopySampleLoop'/>"          "      <menuitem action='CopySampleLoop'/>"
# Line 705  MainWindow::MainWindow() : Line 811  MainWindow::MainWindow() :
811    
812      // select 'Instruments' tab by default      // select 'Instruments' tab by default
813      // (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)
814      m_TreeViewNotebook.set_current_page(1);      m_TreeViewNotebook.set_current_page(1);
815    
816        Gtk::Clipboard::get()->signal_owner_change().connect(
817            sigc::mem_fun(*this, &MainWindow::on_clipboard_owner_change)
818        );
819        updateClipboardPasteAvailable();
820        updateClipboardCopyAvailable();
821  }  }
822    
823  MainWindow::~MainWindow()  MainWindow::~MainWindow()
# Line 776  void MainWindow::update_dimregs() Line 888  void MainWindow::update_dimregs()
888              add_region_to_dimregs(region, stereo, all_dimregs);              add_region_to_dimregs(region, stereo, all_dimregs);
889          }          }
890      }      }
891    
892        m_DimRegionChooser.setModifyAllRegions(all_regions);
893        m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs);
894        m_DimRegionChooser.setModifyBothChannels(stereo);
895    
896        updateClipboardCopyAvailable();
897  }  }
898    
899  void MainWindow::dimreg_all_dimregs_toggled()  void MainWindow::dimreg_all_dimregs_toggled()
# Line 1408  void MainWindow::__import_queued_samples Line 1526  void MainWindow::__import_queued_samples
1526      std::cout << "Starting sample import\n" << std::flush;      std::cout << "Starting sample import\n" << std::flush;
1527      Glib::ustring error_files;      Glib::ustring error_files;
1528      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));      printf("Samples to import: %d\n", int(m_SampleImportQueue.size()));
1529      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();      for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin();
1530           iter != m_SampleImportQueue.end(); ) {           iter != m_SampleImportQueue.end(); ) {
1531          printf("Importing sample %s\n",(*iter).sample_path.c_str());          printf("Importing sample %s\n",iter->second.sample_path.c_str());
1532          SF_INFO info;          SF_INFO info;
1533          info.format = 0;          info.format = 0;
1534          SNDFILE* hFile = sf_open((*iter).sample_path.c_str(), SFM_READ, &info);          SNDFILE* hFile = sf_open(iter->second.sample_path.c_str(), SFM_READ, &info);
1535          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);          sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE);
1536          try {          try {
1537              if (!hFile) throw std::string(_("could not open file"));              if (!hFile) throw std::string(_("could not open file"));
# Line 1436  void MainWindow::__import_queued_samples Line 1554  void MainWindow::__import_queued_samples
1554                      throw std::string(_("format not supported")); // unsupported subformat (yet?)                      throw std::string(_("format not supported")); // unsupported subformat (yet?)
1555              }              }
1556    
1557                // reset write position for sample
1558                iter->first->SetPos(0);
1559    
1560              const int bufsize = 10000;              const int bufsize = 10000;
1561              switch (bitdepth) {              switch (bitdepth) {
1562                  case 16: {                  case 16: {
# Line 1445  void MainWindow::__import_queued_samples Line 1566  void MainWindow::__import_queued_samples
1566                          // libsndfile does the conversion for us (if needed)                          // libsndfile does the conversion for us (if needed)
1567                          int n = sf_readf_short(hFile, buffer, bufsize);                          int n = sf_readf_short(hFile, buffer, bufsize);
1568                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1569                          iter->gig_sample->Write(buffer, n);                          iter->first->Write(buffer, n);
1570                          cnt -= n;                          cnt -= n;
1571                      }                      }
1572                      delete[] buffer;                      delete[] buffer;
# Line 1465  void MainWindow::__import_queued_samples Line 1586  void MainWindow::__import_queued_samples
1586                              dstbuf[j++] = srcbuf[i] >> 24;                              dstbuf[j++] = srcbuf[i] >> 24;
1587                          }                          }
1588                          // write from buffer directly (physically) into .gig file                          // write from buffer directly (physically) into .gig file
1589                          iter->gig_sample->Write(dstbuf, n);                          iter->first->Write(dstbuf, n);
1590                          cnt -= n;                          cnt -= n;
1591                      }                      }
1592                      delete[] srcbuf;                      delete[] srcbuf;
# Line 1476  void MainWindow::__import_queued_samples Line 1597  void MainWindow::__import_queued_samples
1597              // cleanup              // cleanup
1598              sf_close(hFile);              sf_close(hFile);
1599              // let the sampler re-cache the sample if needed              // let the sampler re-cache the sample if needed
1600              sample_changed_signal.emit(iter->gig_sample);              sample_changed_signal.emit(iter->first);
1601              // on success we remove the sample from the import queue,              // on success we remove the sample from the import queue,
1602              // otherwise keep it, maybe it works the next time ?              // otherwise keep it, maybe it works the next time ?
1603              std::list<SampleImportItem>::iterator cur = iter;              std::map<gig::Sample*, SampleImportItem>::iterator cur = iter;
1604              ++iter;              ++iter;
1605              m_SampleImportQueue.erase(cur);              m_SampleImportQueue.erase(cur);
1606          } catch (std::string what) {          } catch (std::string what) {
1607              // remember the files that made trouble (and their cause)              // remember the files that made trouble (and their cause)
1608              if (!error_files.empty()) error_files += "\n";              if (!error_files.empty()) error_files += "\n";
1609              error_files += (*iter).sample_path += " (" + what + ")";              error_files += iter->second.sample_path += " (" + what + ")";
1610              ++iter;              ++iter;
1611          }          }
1612      }      }
# Line 1527  void MainWindow::on_action_help_about() Line 1648  void MainWindow::on_action_help_about()
1648      dialog.set_name("Gigedit");      dialog.set_name("Gigedit");
1649  #endif  #endif
1650      dialog.set_version(VERSION);      dialog.set_version(VERSION);
1651      dialog.set_copyright("Copyright (C) 2006-2016 Andreas Persson");      dialog.set_copyright("Copyright (C) 2006-2017 Andreas Persson");
1652      const std::string sComment =      const std::string sComment =
1653          _("Built " __DATE__ "\nUsing ") +          _("Built " __DATE__ "\nUsing ") +
1654          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +          ::gig::libraryName() + " " + ::gig::libraryVersion() + "\n\n" +
# Line 2707  void MainWindow::add_or_replace_sample(b Line 2828  void MainWindow::add_or_replace_sample(b
2828                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2829                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2830                  sched_item.sample_path = *iter;                  sched_item.sample_path = *iter;
2831                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2832                  // add sample to the tree view                  // add sample to the tree view
2833                  if (replace) {                  if (replace) {
2834                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);                      row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name);
# Line 2817  void MainWindow::on_action_replace_all_s Line 2938  void MainWindow::on_action_replace_all_s
2938                  SampleImportItem sched_item;                  SampleImportItem sched_item;
2939                  sched_item.gig_sample  = sample;                  sched_item.gig_sample  = sample;
2940                  sched_item.sample_path = filename;                  sched_item.sample_path = filename;
2941                  m_SampleImportQueue.push_back(sched_item);                  m_SampleImportQueue[sample] = sched_item;
2942                  sf_close(hFile);                  sf_close(hFile);
2943                  file_changed();                  file_changed();
2944              }              }
# Line 2869  void MainWindow::on_action_remove_sample Line 2990  void MainWindow::on_action_remove_sample
2990                  // if sample(s) were just previously added, remove                  // if sample(s) were just previously added, remove
2991                  // them from the import queue                  // them from the import queue
2992                  for (std::list<gig::Sample*>::iterator member = members.begin();                  for (std::list<gig::Sample*>::iterator member = members.begin();
2993                       member != members.end(); ++member) {                       member != members.end(); ++member)
2994                      for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  {
2995                           iter != m_SampleImportQueue.end(); ++iter) {                      if (m_SampleImportQueue.count(*member)) {
2996                          if ((*iter).gig_sample == *member) {                          printf("Removing previously added sample '%s' from group '%s'\n",
2997                              printf("Removing previously added sample '%s' from group '%s'\n",                                 m_SampleImportQueue[sample].sample_path.c_str(), name.c_str());
2998                                     (*iter).sample_path.c_str(), name.c_str());                          m_SampleImportQueue.erase(*member);
                             m_SampleImportQueue.erase(iter);  
                             break;  
                         }  
2999                      }                      }
3000                  }                  }
3001                  file_changed();                  file_changed();
# Line 2892  void MainWindow::on_action_remove_sample Line 3010  void MainWindow::on_action_remove_sample
3010                  samples_removed_signal.emit();                  samples_removed_signal.emit();
3011                  // if sample was just previously added, remove it from                  // if sample was just previously added, remove it from
3012                  // the import queue                  // the import queue
3013                  for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();                  if (m_SampleImportQueue.count(sample)) {
3014                       iter != m_SampleImportQueue.end(); ++iter) {                      printf("Removing previously added sample '%s'\n",
3015                      if ((*iter).gig_sample == sample) {                             m_SampleImportQueue[sample].sample_path.c_str());
3016                          printf("Removing previously added sample '%s'\n",                      m_SampleImportQueue.erase(sample);
                                (*iter).sample_path.c_str());  
                         m_SampleImportQueue.erase(iter);  
                         break;  
                     }  
3017                  }                  }
3018                  dimreg_changed();                  dimreg_changed();
3019                  file_changed();                  file_changed();
# Line 2955  void MainWindow::on_action_remove_unused Line 3069  void MainWindow::on_action_remove_unused
3069              gig::Sample* sample = *itSample;              gig::Sample* sample = *itSample;
3070              // remove sample from the .gig file              // remove sample from the .gig file
3071              file->DeleteSample(sample);              file->DeleteSample(sample);
3072              // if sample was just previously added, remove it fro the import queue              // if sample was just previously added, remove it from the import queue
3073              for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin();              if (m_SampleImportQueue.count(sample)) {
3074                   iter != m_SampleImportQueue.end(); ++iter)                  printf("Removing previously added sample '%s'\n",
3075              {                         m_SampleImportQueue[sample].sample_path.c_str());
3076                  if ((*iter).gig_sample == sample) {                  m_SampleImportQueue.erase(sample);
                     printf("Removing previously added sample '%s'\n",  
                            (*iter).sample_path.c_str());  
                     m_SampleImportQueue.erase(iter);  
                     break;  
                 }  
3077              }              }
3078          }          }
3079      } catch (RIFF::Exception e) {      } catch (RIFF::Exception e) {
# Line 3540  void MainWindow::show_scripts_tab() { Line 3649  void MainWindow::show_scripts_tab() {
3649      m_TreeViewNotebook.set_current_page(2);      m_TreeViewNotebook.set_current_page(2);
3650  }  }
3651    
3652    void MainWindow::select_prev_region() {
3653        m_RegionChooser.select_prev_region();
3654    }
3655    
3656    void MainWindow::select_next_region() {
3657        m_RegionChooser.select_next_region();
3658    }
3659    
3660    void MainWindow::select_next_dim_rgn_zone() {
3661        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3662        m_DimRegionChooser.select_next_dimzone();
3663    }
3664    
3665    void MainWindow::select_prev_dim_rgn_zone() {
3666        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3667        m_DimRegionChooser.select_prev_dimzone();
3668    }
3669    
3670    void MainWindow::select_add_next_dim_rgn_zone() {
3671        m_DimRegionChooser.select_next_dimzone(true);
3672    }
3673    
3674    void MainWindow::select_add_prev_dim_rgn_zone() {
3675        m_DimRegionChooser.select_prev_dimzone(true);
3676    }
3677    
3678    void MainWindow::select_prev_dimension() {
3679        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3680        m_DimRegionChooser.select_prev_dimension();
3681    }
3682    
3683    void MainWindow::select_next_dimension() {
3684        if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser
3685        m_DimRegionChooser.select_next_dimension();
3686    }
3687    
3688    #define CLIPBOARD_DIMENSIONREGION_TARGET \
3689        ("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat())
3690    
3691    void MainWindow::copy_selected_dimrgn() {
3692        gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3693        if (!pDimRgn) {
3694            updateClipboardPasteAvailable();
3695            updateClipboardCopyAvailable();
3696            return;
3697        }
3698    
3699        std::vector<Gtk::TargetEntry> targets;
3700        targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) );
3701    
3702        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3703        clipboard->set(
3704            targets,
3705            sigc::mem_fun(*this, &MainWindow::on_clipboard_get),
3706            sigc::mem_fun(*this, &MainWindow::on_clipboard_clear)
3707        );
3708    
3709        m_serializationArchive.serialize(pDimRgn);
3710    
3711        updateClipboardPasteAvailable();
3712    }
3713    
3714    void MainWindow::paste_copied_dimrgn() {
3715        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3716        clipboard->request_contents(
3717            CLIPBOARD_DIMENSIONREGION_TARGET,
3718            sigc::mem_fun(*this, &MainWindow::on_clipboard_received)
3719        );
3720        updateClipboardPasteAvailable();
3721    }
3722    
3723    void MainWindow::updateClipboardPasteAvailable() {
3724        Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get();
3725        clipboard->request_targets(
3726            sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets)
3727        );
3728    }
3729    
3730    void MainWindow::updateClipboardCopyAvailable() {
3731        bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion();
3732        static_cast<Gtk::MenuItem*>(
3733            uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn")
3734        )->set_sensitive(bDimensionRegionCopyIsPossible);
3735    }
3736    
3737    void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) {
3738        updateClipboardPasteAvailable();
3739    }
3740    
3741    void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) {
3742        const std::string target = selection_data.get_target();
3743        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3744            selection_data.set(
3745                CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/,
3746                &m_serializationArchive.rawData()[0],
3747                m_serializationArchive.rawData().size()
3748            );
3749        } else {
3750            std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n";
3751        }
3752    }
3753    
3754    void MainWindow::on_clipboard_clear() {
3755        m_serializationArchive.clear();
3756        updateClipboardPasteAvailable();
3757        updateClipboardCopyAvailable();
3758    }
3759    
3760    void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) {
3761        const std::string target = selection_data.get_target();
3762        if (target == CLIPBOARD_DIMENSIONREGION_TARGET) {
3763            gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion();
3764            if (!pDimRgn) return;
3765    
3766            Glib::ustring errorText;
3767            try {
3768                m_serializationArchive.decode(
3769                    selection_data.get_data(), selection_data.get_length()
3770                );
3771    
3772                for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin();
3773                     itDimReg != dimreg_edit.dimregs.end(); ++itDimReg)
3774                {
3775                    gig::DimensionRegion* pDimRgn = *itDimReg;
3776    
3777                    dimreg_to_be_changed_signal.emit(pDimRgn);
3778    
3779                    m_serializationArchive.deserialize(pDimRgn);
3780    
3781                    dimreg_changed_signal.emit(pDimRgn);
3782                }
3783    
3784                //region_changed()
3785                file_changed();
3786                dimreg_changed();
3787    
3788            } catch (Serialization::Exception e) {
3789                errorText = e.Message;
3790            } catch (...) {
3791                errorText = _("Unknown exception during deserialization decoding");
3792            }
3793            if (!errorText.empty()) {
3794                Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText;
3795                Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR);
3796                msg.run();
3797            }
3798        }
3799    }
3800    
3801    void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) {
3802        const bool bDimensionRegionPasteIsPossible =
3803            std::find(targets.begin(), targets.end(),
3804                      CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end();
3805    
3806        static_cast<Gtk::MenuItem*>(
3807            uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn")
3808        )->set_sensitive(bDimensionRegionPasteIsPossible);
3809    }
3810    
3811  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {  sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() {
3812      return file_structure_to_be_changed_signal;      return file_structure_to_be_changed_signal;
3813  }  }

Legend:
Removed from v.3021  
changed lines
  Added in v.3144

  ViewVC Help
Powered by ViewVC