paperbox r103 - in trunk: . src
- From: markoa svn gnome org
- To: svn-commits-list gnome org
- Subject: paperbox r103 - in trunk: . src
- Date: Sun, 24 Feb 2008 00:09:48 +0000 (GMT)
Author: markoa
Date: Sun Feb 24 00:09:48 2008
New Revision: 103
URL: http://svn.gnome.org/viewvc/paperbox?rev=103&view=rev
Log:
Category creation and selection in editor
Modified:
trunk/ChangeLog
trunk/src/category-editor-model.cc
trunk/src/category-editor-model.hh
trunk/src/category-editor.cc
trunk/src/category-editor.hh
trunk/src/main-window.cc
Modified: trunk/src/category-editor-model.cc
==============================================================================
--- trunk/src/category-editor-model.cc (original)
+++ trunk/src/category-editor-model.cc Sun Feb 24 00:09:48 2008
@@ -25,8 +25,11 @@
namespace paperbox {
using std::map;
+ using boost::shared_ptr;
- typedef map<Glib::ustring, CategoryEditorData*>::iterator editor_data_iter;
+ typedef map<Glib::ustring,
+ boost::shared_ptr<CategoryEditorData> >::iterator
+ model_data_iter;
CategoryEditorModel::CategoryEditorModel()
{
@@ -34,11 +37,6 @@
CategoryEditorModel::~CategoryEditorModel()
{
- editor_data_iter it(workdata_.begin());
- editor_data_iter end(workdata_.end());
-
- for ( ; it != end; ++it)
- delete it->second;
}
// loads data for all existing categories
@@ -47,20 +45,34 @@
{
}
- CategoryEditorData*
- CategoryEditorModel::create_category_data(const Glib::ustring& name)
+ boost::shared_ptr<CategoryEditorData>
+ CategoryEditorModel::new_category(const Glib::ustring& name)
{
CategoryEditorData* data = 0;
+ shared_ptr<CategoryEditorData> ptr;
data = new CategoryEditorData;
- //TODO
- return data;
+ // might throw CategoryNotFound to the caller here
+ data->category = CategoryFactory::create_category(name);
+ data->buffer = Gtk::TextBuffer::create();
+
+ ptr.reset(data);
+ model_data_[name] = ptr;
+
+ return ptr;
}
- void
- CategoryEditorModel::new_category(const Glib::ustring& name)
+ shared_ptr<CategoryEditorData>
+ CategoryEditorModel::get_category(const Glib::ustring& name)
{
+ shared_ptr<CategoryEditorData> ptr;
+ model_data_iter it = model_data_.find(name);
+
+ if (it != model_data_.end())
+ ptr = it->second;
+
+ return ptr;
}
void
Modified: trunk/src/category-editor-model.hh
==============================================================================
--- trunk/src/category-editor-model.hh (original)
+++ trunk/src/category-editor-model.hh Sun Feb 24 00:09:48 2008
@@ -44,7 +44,10 @@
~CategoryEditorModel();
// throws CategoryExists, propagated from CategoryFactory
- void new_category(const Glib::ustring& name);
+ boost::shared_ptr<CategoryEditorData> new_category(const Glib::ustring& name);
+
+ // check for pointer, might return null
+ boost::shared_ptr<CategoryEditorData> get_category(const Glib::ustring& name);
void save_category(const Glib::ustring& name);
@@ -54,9 +57,8 @@
protected:
void load_category_data();
- CategoryEditorData* create_category_data(const Glib::ustring& name);
-
- std::map<Glib::ustring, CategoryEditorData*> workdata_;
+ std::map<Glib::ustring,
+ boost::shared_ptr<CategoryEditorData> > model_data_;
};
} // namespace paperbox
Modified: trunk/src/category-editor.cc
==============================================================================
--- trunk/src/category-editor.cc (original)
+++ trunk/src/category-editor.cc Sun Feb 24 00:09:48 2008
@@ -29,6 +29,8 @@
namespace paperbox {
+ using boost::shared_ptr;
+
CategoryEditor::CategoryEditor(
GtkDialog* cobject,
const Glib::RefPtr<Gnome::Glade::Xml>& glade)
@@ -99,20 +101,32 @@
{
button_new_.signal_clicked().connect(
sigc::mem_fun(*this, &CategoryEditor::on_button_new_clicked));
+
+ button_delete_.signal_clicked().connect(
+ sigc::mem_fun(*this, &CategoryEditor::on_button_delete_clicked));
+
+ // connect the selection function
+ category_view_->selection->set_select_function(
+ sigc::mem_fun(*this, &CategoryEditor::on_category_selected));
+
+ // and select the first list
+ //TODO: yes, but we need to load them all first
+// if (! category_view_->treemodel->children().empty())
+// category_view_->selection->select(
+// category_view_->treemodel->children().begin());
}
int
CategoryEditor::run()
{
int response = Gtk::Dialog::run();
-
return response;
}
void
CategoryEditor::on_button_new_clicked()
{
- boost::shared_ptr<DialogEntry> dialog(DialogEntry::create());
+ shared_ptr<DialogEntry> dialog(DialogEntry::create());
// TODO: verify the string and wrap in _()
dialog->set_instructions("Name the new category:");
@@ -124,11 +138,50 @@
if (response != Gtk::RESPONSE_OK) return;
try {
- model_->new_category(name);
- // TODO: create a new row, get the textbuffer and assign it
+ // create a new data model and category file
+ shared_ptr<CategoryEditorData> data = model_->new_category(name);
+
+ // update our view - create a new row, set the buffer
+ Gtk::TreeModel::Row row = *(category_view_->treemodel->append());
+
+ row[category_view_->columns.col_name] = name;
+ category_view_->selection->select(row);
+
+ text_view_.set_buffer(data->buffer);
+
} catch (const CategoryExists& ex) {
Gtk::Util::display_dialog_error(ex.what());
}
}
+ void
+ CategoryEditor::on_button_delete_clicked()
+ {
+ }
+
+ bool
+ CategoryEditor::on_category_selected(const Glib::RefPtr<Gtk::TreeModel>& ,
+ const Gtk::TreeModel::Path& path,
+ bool path_selected)
+ {
+ Gtk::TreeModel::Row row = *(category_view_->treemodel->get_iter(path));
+ Glib::ustring cat_name = row[category_view_->columns.col_name];
+
+ if (! ((cat_name != selected_name_) && (! path_selected)))
+ return true; // selection hasn't changed
+
+ try {
+ shared_ptr<CategoryEditorData> data =
+ model_->get_category(cat_name);
+
+ text_view_.set_buffer(data->buffer);
+ } catch (const CategoryNotFound& ex) {
+ // this would be rather odd, someone would need to mess with
+ // the files in $config, but here goes
+ Gtk::Util::display_dialog_error(ex.what());
+ }
+
+ return true;
+ }
+
} // namespace paperbox
Modified: trunk/src/category-editor.hh
==============================================================================
--- trunk/src/category-editor.hh (original)
+++ trunk/src/category-editor.hh Sun Feb 24 00:09:48 2008
@@ -51,7 +51,12 @@
void get_widgets();
void init_gui();
void connect_signals();
+
void on_button_new_clicked();
+ void on_button_delete_clicked();
+ bool on_category_selected(const Glib::RefPtr<Gtk::TreeModel>& model,
+ const Gtk::TreeModel::Path& path,
+ bool path_selected);
Glib::RefPtr<Gnome::Glade::Xml> glade_;
@@ -61,6 +66,7 @@
Gtk::HBox* hbox_contents_;
boost::shared_ptr<CategoryView> category_view_;
+ Glib::ustring selected_name_;
Gtk::Button button_new_;
Gtk::Button button_delete_;
Modified: trunk/src/main-window.cc
==============================================================================
--- trunk/src/main-window.cc (original)
+++ trunk/src/main-window.cc Sun Feb 24 00:09:48 2008
@@ -278,6 +278,8 @@
dialog->set_default_response(Gtk::RESPONSE_OK);
dialog->run();
+
+ //TODO: update category treeview
}
} // namespace paperbox
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]