38 |
#include <gtkmm/targetentry.h> |
#include <gtkmm/targetentry.h> |
39 |
#include <gtkmm/main.h> |
#include <gtkmm/main.h> |
40 |
#include <gtkmm/toggleaction.h> |
#include <gtkmm/toggleaction.h> |
41 |
|
#include <gtkmm/accelmap.h> |
42 |
#if GTKMM_MAJOR_VERSION < 3 |
#if GTKMM_MAJOR_VERSION < 3 |
43 |
#include "wrapLabel.hh" |
#include "wrapLabel.hh" |
44 |
#endif |
#endif |
60 |
#include "../../gfx/status_detached.xpm" |
#include "../../gfx/status_detached.xpm" |
61 |
#include "gfx/builtinpix.h" |
#include "gfx/builtinpix.h" |
62 |
#include "MacroEditor.h" |
#include "MacroEditor.h" |
63 |
|
#include "MacrosSetup.h" |
64 |
|
|
65 |
MainWindow::MainWindow() : |
MainWindow::MainWindow() : |
66 |
m_DimRegionChooser(*this), |
m_DimRegionChooser(*this), |
286 |
actionGroup->add(toggle_action); |
actionGroup->add(toggle_action); |
287 |
|
|
288 |
|
|
289 |
|
actionGroup->add(Gtk::Action::create("MenuMacro", _("_Macro"))); |
290 |
|
|
291 |
|
|
292 |
actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w"))); |
actionGroup->add(Gtk::Action::create("MenuView", _("Vie_w"))); |
293 |
toggle_action = |
toggle_action = |
294 |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
Gtk::ToggleAction::create("Statusbar", _("_Statusbar")); |
465 |
" <menuitem action='CopySampleTune'/>" |
" <menuitem action='CopySampleTune'/>" |
466 |
" <menuitem action='CopySampleLoop'/>" |
" <menuitem action='CopySampleLoop'/>" |
467 |
" </menu>" |
" </menu>" |
468 |
|
" <menu action='MenuMacro'>" |
469 |
|
" </menu>" |
470 |
" <menu action='MenuSample'>" |
" <menu action='MenuSample'>" |
471 |
" <menuitem action='SampleProperties'/>" |
" <menuitem action='SampleProperties'/>" |
472 |
" <menuitem action='AddGroup'/>" |
" <menuitem action='AddGroup'/>" |
832 |
); |
); |
833 |
updateClipboardPasteAvailable(); |
updateClipboardPasteAvailable(); |
834 |
updateClipboardCopyAvailable(); |
updateClipboardCopyAvailable(); |
835 |
|
|
836 |
|
// setup macros and their keyboard accelerators |
837 |
|
{ |
838 |
|
Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>( |
839 |
|
uiManager->get_widget("/MenuBar/MenuMacro") |
840 |
|
)->get_submenu(); |
841 |
|
|
842 |
|
const Gdk::ModifierType primaryModifierKey = |
843 |
|
#if defined(__APPLE__) |
844 |
|
Gdk::META_MASK; // Cmd key on Mac |
845 |
|
#else |
846 |
|
Gdk::CONTROL_MASK; // Ctrl key on all other OSs |
847 |
|
#endif |
848 |
|
|
849 |
|
const Gdk::ModifierType noModifier = (Gdk::ModifierType)0; |
850 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_0", GDK_KEY_F1, noModifier); |
851 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_1", GDK_KEY_F2, noModifier); |
852 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_2", GDK_KEY_F3, noModifier); |
853 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_3", GDK_KEY_F4, noModifier); |
854 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_4", GDK_KEY_F5, noModifier); |
855 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_5", GDK_KEY_F6, noModifier); |
856 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_6", GDK_KEY_F7, noModifier); |
857 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_7", GDK_KEY_F8, noModifier); |
858 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_8", GDK_KEY_F9, noModifier); |
859 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_9", GDK_KEY_F10, noModifier); |
860 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_10", GDK_KEY_F11, noModifier); |
861 |
|
Gtk::AccelMap::add_entry("<Macros>/macro_11", GDK_KEY_F12, noModifier); |
862 |
|
Gtk::AccelMap::add_entry("<Macros>/SetupMacros", 'm', primaryModifierKey); |
863 |
|
|
864 |
|
Glib::RefPtr<Gtk::AccelGroup> accelGroup = this->get_accel_group(); |
865 |
|
menuMacro->set_accel_group(accelGroup); |
866 |
|
|
867 |
|
updateMacroMenu(); |
868 |
|
} |
869 |
} |
} |
870 |
|
|
871 |
MainWindow::~MainWindow() |
MainWindow::~MainWindow() |
872 |
{ |
{ |
873 |
} |
} |
874 |
|
|
875 |
|
void MainWindow::updateMacroMenu() { |
876 |
|
Gtk::Menu* menuMacro = dynamic_cast<Gtk::MenuItem*>( |
877 |
|
uiManager->get_widget("/MenuBar/MenuMacro") |
878 |
|
)->get_submenu(); |
879 |
|
|
880 |
|
// remove all entries from "Macro" menu |
881 |
|
{ |
882 |
|
const std::vector<Gtk::Widget*> children = menuMacro->get_children(); |
883 |
|
for (int i = 0; i < children.size(); ++i) { |
884 |
|
Gtk::Widget* child = children[i]; |
885 |
|
menuMacro->remove(*child); |
886 |
|
delete child; |
887 |
|
} |
888 |
|
} |
889 |
|
|
890 |
|
// (re)load all macros from config file |
891 |
|
try { |
892 |
|
Settings::singleton()->loadMacros(m_macros); |
893 |
|
} catch (Serialization::Exception e) { |
894 |
|
std::cerr << "Exception while loading macros: " << e.Message << std::endl; |
895 |
|
} catch (...) { |
896 |
|
std::cerr << "Unknown exception while loading macros!" << std::endl; |
897 |
|
} |
898 |
|
|
899 |
|
// add all configured macros as menu items to the "Macro" menu |
900 |
|
for (int iMacro = 0; iMacro < m_macros.size(); ++iMacro) { |
901 |
|
const Serialization::Archive& macro = m_macros[iMacro]; |
902 |
|
std::string name = |
903 |
|
macro.name().empty() ? |
904 |
|
(std::string(_("Unnamed Macro")) + " " + ToString(iMacro+1)) : macro.name(); |
905 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(name); |
906 |
|
item->signal_activate().connect( |
907 |
|
sigc::bind( |
908 |
|
sigc::mem_fun(*this, &MainWindow::onMacroSelected), iMacro |
909 |
|
) |
910 |
|
); |
911 |
|
menuMacro->append(*item); |
912 |
|
item->set_accel_path("<Macros>/macro_" + ToString(iMacro)); |
913 |
|
} |
914 |
|
// if there are no macros configured at all, then show a dummy entry instead |
915 |
|
if (m_macros.empty()) { |
916 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(_("No Macros")); |
917 |
|
item->set_sensitive(false); |
918 |
|
menuMacro->append(*item); |
919 |
|
} |
920 |
|
|
921 |
|
// add separator line to menu |
922 |
|
menuMacro->append(*new Gtk::SeparatorMenuItem); |
923 |
|
|
924 |
|
{ |
925 |
|
Gtk::MenuItem* item = new Gtk::MenuItem(_("Setup Macros ...")); |
926 |
|
item->signal_activate().connect( |
927 |
|
sigc::mem_fun(*this, &MainWindow::setupMacros) |
928 |
|
); |
929 |
|
menuMacro->append(*item); |
930 |
|
item->set_accel_path("<Macros>/SetupMacros"); |
931 |
|
} |
932 |
|
|
933 |
|
menuMacro->show_all_children(); |
934 |
|
} |
935 |
|
|
936 |
|
void MainWindow::onMacroSelected(int iMacro) { |
937 |
|
printf("onMacroSelected(%d)\n", iMacro); |
938 |
|
if (iMacro < 0 || iMacro >= m_macros.size()) return; |
939 |
|
Glib::ustring errorText; |
940 |
|
try { |
941 |
|
applyMacro(m_macros[iMacro]); |
942 |
|
} catch (Serialization::Exception e) { |
943 |
|
errorText = e.Message; |
944 |
|
} catch (...) { |
945 |
|
errorText = _("Unknown exception while applying macro"); |
946 |
|
} |
947 |
|
if (!errorText.empty()) { |
948 |
|
Glib::ustring txt = _("Applying macro failed:\n") + errorText; |
949 |
|
Gtk::MessageDialog msg(*this, txt, false, Gtk::MESSAGE_ERROR); |
950 |
|
msg.run(); |
951 |
|
} |
952 |
|
} |
953 |
|
|
954 |
|
void MainWindow::setupMacros() { |
955 |
|
MacrosSetup* setup = new MacrosSetup(); |
956 |
|
setup->setMacros(m_macros); |
957 |
|
setup->signal_macros_changed().connect( |
958 |
|
sigc::mem_fun(*this, &MainWindow::onMacrosSetupChanged) |
959 |
|
); |
960 |
|
setup->show(); |
961 |
|
} |
962 |
|
|
963 |
|
void MainWindow::onMacrosSetupChanged(const std::vector<Serialization::Archive>& macros) { |
964 |
|
m_macros = macros; |
965 |
|
Settings::singleton()->saveMacros(m_macros); |
966 |
|
updateMacroMenu(); |
967 |
|
} |
968 |
|
|
969 |
bool MainWindow::on_delete_event(GdkEventAny* event) |
bool MainWindow::on_delete_event(GdkEventAny* event) |
970 |
{ |
{ |
971 |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
return !file_is_shared && file_is_changed && !close_confirmation_dialog(); |
3864 |
} |
} |
3865 |
|
|
3866 |
void MainWindow::adjust_clipboard_content() { |
void MainWindow::adjust_clipboard_content() { |
3867 |
MacroEditor* editor = new MacroEditor; |
MacroEditor* editor = new MacroEditor(); |
3868 |
editor->setMacro(&m_serializationArchive); |
editor->setMacro(&m_serializationArchive); |
3869 |
editor->show(); |
editor->show(); |
3870 |
} |
} |
3906 |
updateClipboardCopyAvailable(); |
updateClipboardCopyAvailable(); |
3907 |
} |
} |
3908 |
|
|
3909 |
|
//NOTE: Might throw exception !!! |
3910 |
|
void MainWindow::applyMacro(Serialization::Archive& macro) { |
3911 |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
3912 |
|
if (!pDimRgn) return; |
3913 |
|
|
3914 |
|
for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin(); |
3915 |
|
itDimReg != dimreg_edit.dimregs.end(); ++itDimReg) |
3916 |
|
{ |
3917 |
|
gig::DimensionRegion* pDimRgn = *itDimReg; |
3918 |
|
dimreg_to_be_changed_signal.emit(pDimRgn); |
3919 |
|
m_serializationArchive.deserialize(pDimRgn); |
3920 |
|
dimreg_changed_signal.emit(pDimRgn); |
3921 |
|
} |
3922 |
|
//region_changed() |
3923 |
|
file_changed(); |
3924 |
|
dimreg_changed(); |
3925 |
|
} |
3926 |
|
|
3927 |
void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) { |
void MainWindow::on_clipboard_received(const Gtk::SelectionData& selection_data) { |
3928 |
const std::string target = selection_data.get_target(); |
const std::string target = selection_data.get_target(); |
3929 |
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
if (target == CLIPBOARD_DIMENSIONREGION_TARGET) { |
|
gig::DimensionRegion* pDimRgn = m_DimRegionChooser.get_main_dimregion(); |
|
|
if (!pDimRgn) return; |
|
|
|
|
3930 |
Glib::ustring errorText; |
Glib::ustring errorText; |
3931 |
try { |
try { |
3932 |
m_serializationArchive.decode( |
m_serializationArchive.decode( |
3933 |
selection_data.get_data(), selection_data.get_length() |
selection_data.get_data(), selection_data.get_length() |
3934 |
); |
); |
3935 |
|
applyMacro(m_serializationArchive); |
|
for (std::set<gig::DimensionRegion*>::iterator itDimReg = dimreg_edit.dimregs.begin(); |
|
|
itDimReg != dimreg_edit.dimregs.end(); ++itDimReg) |
|
|
{ |
|
|
gig::DimensionRegion* pDimRgn = *itDimReg; |
|
|
|
|
|
dimreg_to_be_changed_signal.emit(pDimRgn); |
|
|
|
|
|
m_serializationArchive.deserialize(pDimRgn); |
|
|
|
|
|
dimreg_changed_signal.emit(pDimRgn); |
|
|
} |
|
|
|
|
|
//region_changed() |
|
|
file_changed(); |
|
|
dimreg_changed(); |
|
|
|
|
3936 |
} catch (Serialization::Exception e) { |
} catch (Serialization::Exception e) { |
3937 |
errorText = e.Message; |
errorText = e.Message; |
3938 |
} catch (...) { |
} catch (...) { |
3939 |
errorText = _("Unknown exception during deserialization decoding"); |
errorText = _("Unknown exception while pasting DimensionRegion"); |
3940 |
} |
} |
3941 |
if (!errorText.empty()) { |
if (!errorText.empty()) { |
3942 |
Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText; |
Glib::ustring txt = _("Pasting DimensionRegion failed:\n") + errorText; |