/[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 3134 by schoenebeck, Fri Apr 28 12:41:12 2017 UTC revision 3148 by schoenebeck, Thu May 4 11:47:45 2017 UTC
# Line 198  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")));
# Line 212  MainWindow::MainWindow() : Line 212  MainWindow::MainWindow() :
212      Gdk::CONTROL_MASK; // Ctrl key on all other OSs      Gdk::CONTROL_MASK; // Ctrl key on all other OSs
213  #endif  #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",      actionGroup->add(Gtk::Action::create("SelectPrevRegion",
226                                           _("Select Previous Region")),                                           _("Select Previous Region")),
227                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),                       Gtk::AccelKey(GDK_KEY_Left, primaryModifierKey),
# Line 268  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 426  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'/>"          "      <menuitem action='SelectPrevRegion'/>"
443          "      <menuitem action='SelectNextRegion'/>"          "      <menuitem action='SelectNextRegion'/>"
444          "      <separator/>"          "      <separator/>"
# Line 798  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 870  void MainWindow::update_dimregs() Line 889  void MainWindow::update_dimregs()
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()
# Line 3664  void MainWindow::select_next_dimension() Line 3686  void MainWindow::select_next_dimension()
3686      m_DimRegionChooser.select_next_dimension();      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  }  }

Legend:
Removed from v.3134  
changed lines
  Added in v.3148

  ViewVC Help
Powered by ViewVC