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 |
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.")); |
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); |
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); |
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'/>" |
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() |
889 |
} |
} |
890 |
} |
} |
891 |
|
|
892 |
|
m_RegionChooser.setModifyAllRegions(all_regions); |
893 |
m_DimRegionChooser.setModifyAllRegions(all_regions); |
m_DimRegionChooser.setModifyAllRegions(all_regions); |
894 |
m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs); |
m_DimRegionChooser.setModifyAllDimensionRegions(all_dimregs); |
895 |
m_DimRegionChooser.setModifyBothChannels(stereo); |
m_DimRegionChooser.setModifyBothChannels(stereo); |
896 |
|
|
897 |
|
updateClipboardCopyAvailable(); |
898 |
} |
} |
899 |
|
|
900 |
void MainWindow::dimreg_all_dimregs_toggled() |
void MainWindow::dimreg_all_dimregs_toggled() |
1527 |
std::cout << "Starting sample import\n" << std::flush; |
std::cout << "Starting sample import\n" << std::flush; |
1528 |
Glib::ustring error_files; |
Glib::ustring error_files; |
1529 |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
printf("Samples to import: %d\n", int(m_SampleImportQueue.size())); |
1530 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
for (std::map<gig::Sample*, SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
1531 |
iter != m_SampleImportQueue.end(); ) { |
iter != m_SampleImportQueue.end(); ) { |
1532 |
printf("Importing sample %s\n",(*iter).sample_path.c_str()); |
printf("Importing sample %s\n",iter->second.sample_path.c_str()); |
1533 |
SF_INFO info; |
SF_INFO info; |
1534 |
info.format = 0; |
info.format = 0; |
1535 |
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); |
1536 |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
sf_command(hFile, SFC_SET_SCALE_FLOAT_INT_READ, 0, SF_TRUE); |
1537 |
try { |
try { |
1538 |
if (!hFile) throw std::string(_("could not open file")); |
if (!hFile) throw std::string(_("could not open file")); |
1555 |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
throw std::string(_("format not supported")); // unsupported subformat (yet?) |
1556 |
} |
} |
1557 |
|
|
1558 |
|
// reset write position for sample |
1559 |
|
iter->first->SetPos(0); |
1560 |
|
|
1561 |
const int bufsize = 10000; |
const int bufsize = 10000; |
1562 |
switch (bitdepth) { |
switch (bitdepth) { |
1563 |
case 16: { |
case 16: { |
1567 |
// libsndfile does the conversion for us (if needed) |
// libsndfile does the conversion for us (if needed) |
1568 |
int n = sf_readf_short(hFile, buffer, bufsize); |
int n = sf_readf_short(hFile, buffer, bufsize); |
1569 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1570 |
iter->gig_sample->Write(buffer, n); |
iter->first->Write(buffer, n); |
1571 |
cnt -= n; |
cnt -= n; |
1572 |
} |
} |
1573 |
delete[] buffer; |
delete[] buffer; |
1587 |
dstbuf[j++] = srcbuf[i] >> 24; |
dstbuf[j++] = srcbuf[i] >> 24; |
1588 |
} |
} |
1589 |
// write from buffer directly (physically) into .gig file |
// write from buffer directly (physically) into .gig file |
1590 |
iter->gig_sample->Write(dstbuf, n); |
iter->first->Write(dstbuf, n); |
1591 |
cnt -= n; |
cnt -= n; |
1592 |
} |
} |
1593 |
delete[] srcbuf; |
delete[] srcbuf; |
1598 |
// cleanup |
// cleanup |
1599 |
sf_close(hFile); |
sf_close(hFile); |
1600 |
// let the sampler re-cache the sample if needed |
// let the sampler re-cache the sample if needed |
1601 |
sample_changed_signal.emit(iter->gig_sample); |
sample_changed_signal.emit(iter->first); |
1602 |
// on success we remove the sample from the import queue, |
// on success we remove the sample from the import queue, |
1603 |
// otherwise keep it, maybe it works the next time ? |
// otherwise keep it, maybe it works the next time ? |
1604 |
std::list<SampleImportItem>::iterator cur = iter; |
std::map<gig::Sample*, SampleImportItem>::iterator cur = iter; |
1605 |
++iter; |
++iter; |
1606 |
m_SampleImportQueue.erase(cur); |
m_SampleImportQueue.erase(cur); |
1607 |
} catch (std::string what) { |
} catch (std::string what) { |
1608 |
// remember the files that made trouble (and their cause) |
// remember the files that made trouble (and their cause) |
1609 |
if (!error_files.empty()) error_files += "\n"; |
if (!error_files.empty()) error_files += "\n"; |
1610 |
error_files += (*iter).sample_path += " (" + what + ")"; |
error_files += iter->second.sample_path += " (" + what + ")"; |
1611 |
++iter; |
++iter; |
1612 |
} |
} |
1613 |
} |
} |
2829 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2830 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
2831 |
sched_item.sample_path = *iter; |
sched_item.sample_path = *iter; |
2832 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
2833 |
// add sample to the tree view |
// add sample to the tree view |
2834 |
if (replace) { |
if (replace) { |
2835 |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
row[m_SamplesModel.m_col_name] = gig_to_utf8(sample->pInfo->Name); |
2939 |
SampleImportItem sched_item; |
SampleImportItem sched_item; |
2940 |
sched_item.gig_sample = sample; |
sched_item.gig_sample = sample; |
2941 |
sched_item.sample_path = filename; |
sched_item.sample_path = filename; |
2942 |
m_SampleImportQueue.push_back(sched_item); |
m_SampleImportQueue[sample] = sched_item; |
2943 |
sf_close(hFile); |
sf_close(hFile); |
2944 |
file_changed(); |
file_changed(); |
2945 |
} |
} |
2991 |
// if sample(s) were just previously added, remove |
// if sample(s) were just previously added, remove |
2992 |
// them from the import queue |
// them from the import queue |
2993 |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
for (std::list<gig::Sample*>::iterator member = members.begin(); |
2994 |
member != members.end(); ++member) { |
member != members.end(); ++member) |
2995 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
{ |
2996 |
iter != m_SampleImportQueue.end(); ++iter) { |
if (m_SampleImportQueue.count(*member)) { |
2997 |
if ((*iter).gig_sample == *member) { |
printf("Removing previously added sample '%s' from group '%s'\n", |
2998 |
printf("Removing previously added sample '%s' from group '%s'\n", |
m_SampleImportQueue[sample].sample_path.c_str(), name.c_str()); |
2999 |
(*iter).sample_path.c_str(), name.c_str()); |
m_SampleImportQueue.erase(*member); |
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
3000 |
} |
} |
3001 |
} |
} |
3002 |
file_changed(); |
file_changed(); |
3011 |
samples_removed_signal.emit(); |
samples_removed_signal.emit(); |
3012 |
// if sample was just previously added, remove it from |
// if sample was just previously added, remove it from |
3013 |
// the import queue |
// the import queue |
3014 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
3015 |
iter != m_SampleImportQueue.end(); ++iter) { |
printf("Removing previously added sample '%s'\n", |
3016 |
if ((*iter).gig_sample == sample) { |
m_SampleImportQueue[sample].sample_path.c_str()); |
3017 |
printf("Removing previously added sample '%s'\n", |
m_SampleImportQueue.erase(sample); |
|
(*iter).sample_path.c_str()); |
|
|
m_SampleImportQueue.erase(iter); |
|
|
break; |
|
|
} |
|
3018 |
} |
} |
3019 |
dimreg_changed(); |
dimreg_changed(); |
3020 |
file_changed(); |
file_changed(); |
3070 |
gig::Sample* sample = *itSample; |
gig::Sample* sample = *itSample; |
3071 |
// remove sample from the .gig file |
// remove sample from the .gig file |
3072 |
file->DeleteSample(sample); |
file->DeleteSample(sample); |
3073 |
// if sample was just previously added, remove it fro the import queue |
// if sample was just previously added, remove it from the import queue |
3074 |
for (std::list<SampleImportItem>::iterator iter = m_SampleImportQueue.begin(); |
if (m_SampleImportQueue.count(sample)) { |
3075 |
iter != m_SampleImportQueue.end(); ++iter) |
printf("Removing previously added sample '%s'\n", |
3076 |
{ |
m_SampleImportQueue[sample].sample_path.c_str()); |
3077 |
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; |
|
|
} |
|
3078 |
} |
} |
3079 |
} |
} |
3080 |
} catch (RIFF::Exception e) { |
} catch (RIFF::Exception e) { |
3650 |
m_TreeViewNotebook.set_current_page(2); |
m_TreeViewNotebook.set_current_page(2); |
3651 |
} |
} |
3652 |
|
|
3653 |
|
void MainWindow::select_prev_region() { |
3654 |
|
m_RegionChooser.select_prev_region(); |
3655 |
|
} |
3656 |
|
|
3657 |
|
void MainWindow::select_next_region() { |
3658 |
|
m_RegionChooser.select_next_region(); |
3659 |
|
} |
3660 |
|
|
3661 |
|
void MainWindow::select_next_dim_rgn_zone() { |
3662 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3663 |
|
m_DimRegionChooser.select_next_dimzone(); |
3664 |
|
} |
3665 |
|
|
3666 |
|
void MainWindow::select_prev_dim_rgn_zone() { |
3667 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3668 |
|
m_DimRegionChooser.select_prev_dimzone(); |
3669 |
|
} |
3670 |
|
|
3671 |
|
void MainWindow::select_add_next_dim_rgn_zone() { |
3672 |
|
m_DimRegionChooser.select_next_dimzone(true); |
3673 |
|
} |
3674 |
|
|
3675 |
|
void MainWindow::select_add_prev_dim_rgn_zone() { |
3676 |
|
m_DimRegionChooser.select_prev_dimzone(true); |
3677 |
|
} |
3678 |
|
|
3679 |
|
void MainWindow::select_prev_dimension() { |
3680 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3681 |
|
m_DimRegionChooser.select_prev_dimension(); |
3682 |
|
} |
3683 |
|
|
3684 |
|
void MainWindow::select_next_dimension() { |
3685 |
|
if (m_DimRegionChooser.has_focus()) return; // avoid conflict with key stroke handler of DimenionRegionChooser |
3686 |
|
m_DimRegionChooser.select_next_dimension(); |
3687 |
|
} |
3688 |
|
|
3689 |
|
#define CLIPBOARD_DIMENSIONREGION_TARGET \ |
3690 |
|
("libgig.DimensionRegion." + m_serializationArchive.rawDataFormat()) |
3691 |
|
|
3692 |
|
void MainWindow::copy_selected_dimrgn() { |
3693 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
3694 |
|
if (!pDimRgn) { |
3695 |
|
updateClipboardPasteAvailable(); |
3696 |
|
updateClipboardCopyAvailable(); |
3697 |
|
return; |
3698 |
|
} |
3699 |
|
|
3700 |
|
std::vector<Gtk::TargetEntry> targets; |
3701 |
|
targets.push_back( Gtk::TargetEntry(CLIPBOARD_DIMENSIONREGION_TARGET) ); |
3702 |
|
|
3703 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
3704 |
|
clipboard->set( |
3705 |
|
targets, |
3706 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_get), |
3707 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_clear) |
3708 |
|
); |
3709 |
|
|
3710 |
|
m_serializationArchive.serialize(pDimRgn); |
3711 |
|
|
3712 |
|
updateClipboardPasteAvailable(); |
3713 |
|
} |
3714 |
|
|
3715 |
|
void MainWindow::paste_copied_dimrgn() { |
3716 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
3717 |
|
clipboard->request_contents( |
3718 |
|
CLIPBOARD_DIMENSIONREGION_TARGET, |
3719 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_received) |
3720 |
|
); |
3721 |
|
updateClipboardPasteAvailable(); |
3722 |
|
} |
3723 |
|
|
3724 |
|
void MainWindow::updateClipboardPasteAvailable() { |
3725 |
|
Glib::RefPtr<Gtk::Clipboard> clipboard = Gtk::Clipboard::get(); |
3726 |
|
clipboard->request_targets( |
3727 |
|
sigc::mem_fun(*this, &MainWindow::on_clipboard_received_targets) |
3728 |
|
); |
3729 |
|
} |
3730 |
|
|
3731 |
|
void MainWindow::updateClipboardCopyAvailable() { |
3732 |
|
bool bDimensionRegionCopyIsPossible = m_DimRegionChooser.get_main_dimregion(); |
3733 |
|
static_cast<Gtk::MenuItem*>( |
3734 |
|
uiManager->get_widget("/MenuBar/MenuEdit/CopyDimRgn") |
3735 |
|
)->set_sensitive(bDimensionRegionCopyIsPossible); |
3736 |
|
} |
3737 |
|
|
3738 |
|
void MainWindow::on_clipboard_owner_change(GdkEventOwnerChange* event) { |
3739 |
|
updateClipboardPasteAvailable(); |
3740 |
|
} |
3741 |
|
|
3742 |
|
void MainWindow::on_clipboard_get(Gtk::SelectionData& selection_data, guint /*info*/) { |
3743 |
|
const std::string target = selection_data.get_target(); |
3744 |
|
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
3745 |
|
selection_data.set( |
3746 |
|
CLIPBOARD_DIMENSIONREGION_TARGET, 8 /* "format": probably unused*/, |
3747 |
|
&m_serializationArchive.rawData()[0], |
3748 |
|
m_serializationArchive.rawData().size() |
3749 |
|
); |
3750 |
|
} else { |
3751 |
|
std::cerr << "Clipboard: content for unknown target '" << target << "' requested\n"; |
3752 |
|
} |
3753 |
|
} |
3754 |
|
|
3755 |
|
void MainWindow::on_clipboard_clear() { |
3756 |
|
m_serializationArchive.clear(); |
3757 |
|
updateClipboardPasteAvailable(); |
3758 |
|
updateClipboardCopyAvailable(); |
3759 |
|
} |
3760 |
|
|
3761 |
|
void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) { |
3762 |
|
const std::string target = selection_data.get_target(); |
3763 |
|
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
3764 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
3765 |
|
if (!pDimRgn) return; |
3766 |
|
|
3767 |
|
Glib::ustring errorText; |
3768 |
|
try { |
3769 |
|
m_serializationArchive.decode( |
3770 |
|
selection_data.get_data(), selection_data.get_length() |
3771 |
|
); |
3772 |
|
|
3773 |
|
for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin(); |
3774 |
|
itDimReg != dimreg_edit.dimregs.end(); ++itDimReg) |
3775 |
|
{ |
3776 |
|
gig::DimensionRegion* pDimRgn = *itDimReg; |
3777 |
|
|
3778 |
|
dimreg_to_be_changed_signal.emit(pDimRgn); |
3779 |
|
|
3780 |
|
m_serializationArchive.deserialize(pDimRgn); |
3781 |
|
|
3782 |
|
dimreg_changed_signal.emit(pDimRgn); |
3783 |
|
} |
3784 |
|
|
3785 |
|
//region_changed() |
3786 |
|
file_changed(); |
3787 |
|
dimreg_changed(); |
3788 |
|
|
3789 |
|
} catch (Serialization::Exception e) { |
3790 |
|
errorText = e.Message; |
3791 |
|
} catch (...) { |
3792 |
|
errorText = _("Unknown exception during deserialization decoding"); |
3793 |
|
} |
3794 |
|
if (!errorText.empty()) { |
3795 |
|
Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText; |
3796 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
3797 |
|
msg.run(); |
3798 |
|
} |
3799 |
|
} |
3800 |
|
} |
3801 |
|
|
3802 |
|
void MainWindow::on_clipboard_received_targets(const std::vector<Glib::ustring>& targets) { |
3803 |
|
const bool bDimensionRegionPasteIsPossible = |
3804 |
|
std::find(targets.begin(), targets.end(), |
3805 |
|
CLIPBOARD_DIMENSIONREGION_TARGET) != targets.end(); |
3806 |
|
|
3807 |
|
static_cast<Gtk::MenuItem*>( |
3808 |
|
uiManager->get_widget("/MenuBar/MenuEdit/PasteDimRgn") |
3809 |
|
)->set_sensitive(bDimensionRegionPasteIsPossible); |
3810 |
|
} |
3811 |
|
|
3812 |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
sigc::signal<void, gig::File*>& MainWindow::signal_file_structure_to_be_changed() { |
3813 |
return file_structure_to_be_changed_signal; |
return file_structure_to_be_changed_signal; |
3814 |
} |
} |