Commits

Andreas Tscharner  committed 6dfdc3e

gui: Delete selected (single) entries when clicking [Remove]

  • Participants
  • Parent commits 1a3c855

Comments (0)

Files changed (4)

File src/gui/AddRemoveHandlers.cxx

 #include <gtkmm/builder.h>
 #include <gtkmm/button.h>
 #include <gtkmm/stock.h>
+#include <gtkmm/treeview.h>
 #include "AddRemoveHandlers.hxx"
 
 
 
 void AddRemoveHandlers::on_remove_button_clicked(void)
 {
+	Gtk::TreeView *resFileView;
+	Glib::RefPtr<Gtk::TreeSelection> selectedRes;
+
+
+	m_refBuilder->get_widget("resTreeView", resFileView);
+	selectedRes = resFileView->get_selection();
+	m_listHandler->removeSelected(selectedRes);
 }
 
 AddRemoveHandlers::AddRemoveHandlers(Glib::RefPtr<Gtk::Builder> p_refBuilder)
 	Glib::RefPtr<Gtk::FileFilter> anyFile = Gtk::FileFilter::create();
 
 
+	m_refBuilder = p_refBuilder;
+
 	p_refBuilder->get_widget("bnAdd", m_addButton);
 	m_addButton->signal_clicked().connect(sigc::mem_fun(*this,
 	                                         &AddRemoveHandlers::on_add_button_clicked));

File src/gui/AddRemoveHandlers.hxx

  * main window
  *
  * \author Andreas Tscharner
- * \date 2012-07-29
+ * \date 2012-08-31
  */
 
 
 class AddRemoveHandlers
 {
 	private:
+		Glib::RefPtr<Gtk::Builder> m_refBuilder; //!< Reference to main builder
 		Gtk::Button *m_addButton;      //!< Reference to "Add" button
 		Gtk::Button *m_removeButton;   //!< Reference to "Remove" button
 		Gtk::FileChooserDialog *m_addFilesDlg;   //!< Reference to "Add Files" dialog

File src/gui/ListHandler.cxx

 
 	return NO_ERROR;
 }
+
+int ListHandler::removeSelected(Glib::RefPtr<Gtk::TreeSelection> p_selection)
+{
+	std::vector<Gtk::TreeModel::Path> selectedRes;
+	Gtk::TreeModel::iterator selectedIter;
+
+
+	selectedRes = p_selection->get_selected_rows();
+	for (auto oneResPath : selectedRes) {
+		selectedIter = m_listResEntries->get_iter(oneResPath);
+		m_listResEntries->erase(selectedIter);
+	};
+
+	return NO_ERROR;
+}

File src/gui/ListHandler.hxx

  * removing new entries
  *
  * \author Andreas Tscharner
- * \date 2012-07-29
+ * \date 2012-08-31
  */
 
 
 
 
 #include <gtkmm/liststore.h>
+#include <gtkmm/treeselection.h>
 #include "ResColumnModel.hxx"
 
 
 
 		/*! \brief Add new files to TreeView
 		 *
-		 * This class adds the new (given) files into the TreeView. It
+		 * This method adds the new (given) files into the TreeView. It
 		 * checks for duplicates and removes them if any
 		 *
 		 * \param[in] p_newFiles List of (new) files
 		 * \retval NO_ERROR Files successfully added
 		 */
 		int newFilesAdded(std::vector<std::string>);
+
+		/*! \brief Remove the selected resource
+		 *
+		 * This method removes the currently selected resources from the list
+		 * without confirmation
+		 *
+		 * \param[in] p_selection Selection in view
+		 *
+		 * \retval NO_ERROR Resource successfully removed
+		 */
+		int removeSelected(Glib::RefPtr<Gtk::TreeSelection>);
 };