From 854998f204ff4a556eadac098f0c6c6f05f761a3 Mon Sep 17 00:00:00 2001 From: twanvl Date: Wed, 21 Jul 2010 18:37:47 +0000 Subject: [PATCH] Fix #25: Program throws exception when clicking on the 'stylesheet' list if there are no stylesheets. git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1450 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/control/gallery_list.hpp | 5 +++++ src/gui/control/package_list.hpp | 2 +- src/gui/new_window.cpp | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/gui/control/gallery_list.hpp b/src/gui/control/gallery_list.hpp index 55cad7b2..d2b1a518 100644 --- a/src/gui/control/gallery_list.hpp +++ b/src/gui/control/gallery_list.hpp @@ -37,6 +37,11 @@ class GalleryList : public wxPanel { void select(size_t item, size_t subcol = NO_SELECTION, bool event = true); /// Is there an item selected? inline bool hasSelection(size_t subcol = 0) const { return subcolumns[subcol].selection < itemCount(); } + /// Get the id of the selected item, throws if there is no selection + inline size_t getSelectionId(size_t subcol = 0) const { + if (!hasSelection(subcol)) throw Error(_("No selection")); + return subcolumns[subcol].selection; + } /// Is the given item selected? inline bool isSelected(size_t item, size_t subcol = 0) const { return subcol < subcolumns.size() && subcolumns[subcol].selection == item; diff --git a/src/gui/control/package_list.hpp b/src/gui/control/package_list.hpp index 012fb8d6..2349ec72 100644 --- a/src/gui/control/package_list.hpp +++ b/src/gui/control/package_list.hpp @@ -39,7 +39,7 @@ class PackageList : public GalleryList { * Throws if the selection is not of type T */ template intrusive_ptr getSelection(bool load_fully = true) const { - intrusive_ptr ret = dynamic_pointer_cast(packages.at(subcolumns[0].selection).package); + intrusive_ptr ret = dynamic_pointer_cast(packages.at(getSelectionId()).package); if (!ret) throw InternalError(_("PackageList: Selected package has the wrong type")); if (load_fully) ret->loadFully(); return ret; diff --git a/src/gui/new_window.cpp b/src/gui/new_window.cpp index 0463c3e9..78f518ff 100644 --- a/src/gui/new_window.cpp +++ b/src/gui/new_window.cpp @@ -90,6 +90,7 @@ void NewSetWindow::OnOK(wxCommandEvent&) { void NewSetWindow::done() { try { + if (!stylesheet_list->hasSelection()) return; StyleSheetP stylesheet = stylesheet_list->getSelection(); set = intrusive(new Set(stylesheet)); set->validate();