paperbox r102 - in trunk: . src



Author: markoa
Date: Sat Feb 23 22:42:09 2008
New Revision: 102
URL: http://svn.gnome.org/viewvc/paperbox?rev=102&view=rev

Log:
Sketches of CategoryEditor and its model

Added:
   trunk/src/category-editor-model.cc
   trunk/src/category-editor-model.hh
   trunk/src/category-editor.cc
      - copied, changed from r101, /trunk/src/dialog-categories.cc
   trunk/src/category-editor.hh
      - copied, changed from r101, /trunk/src/dialog-categories.hh
Removed:
   trunk/src/dialog-categories.cc
   trunk/src/dialog-categories.hh
Modified:
   trunk/ChangeLog
   trunk/src/Makefile.am
   trunk/src/browser.cc
   trunk/src/category-factory.cc
   trunk/src/main-window.cc

Modified: trunk/src/Makefile.am
==============================================================================
--- trunk/src/Makefile.am	(original)
+++ trunk/src/Makefile.am	Sat Feb 23 22:42:09 2008
@@ -11,12 +11,14 @@
 	browser.hh \
 	category.cc \
 	category.hh \
+	category-editor.cc \
+	category-editor.hh \
+	category-editor-model.cc \
+	category-editor-model.hh \
 	category-factory.cc \
 	category-factory.hh \
 	category-view.cc \
 	category-view.hh \
-	dialog-categories.cc \
-	dialog-categories.hh \
 	dialog-entry.cc \
 	dialog-entry.hh \
 	dialog-tag-entry.cc \

Modified: trunk/src/browser.cc
==============================================================================
--- trunk/src/browser.cc	(original)
+++ trunk/src/browser.cc	Sat Feb 23 22:42:09 2008
@@ -57,7 +57,6 @@
 
     Browser::~Browser()
     {
-        std::cout << "browser in destruction" << std::endl;
     }
 
     void

Added: trunk/src/category-editor-model.cc
==============================================================================
--- (empty file)
+++ trunk/src/category-editor-model.cc	Sat Feb 23 22:42:09 2008
@@ -0,0 +1,76 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+
+/*
+ *  PaperBox - category-editor-model.cc
+ *
+ *  Copyright (C) 2008 Marko Anastasov
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#include "category-editor-model.hh"
+
+namespace paperbox {
+
+    using std::map;
+
+    typedef map<Glib::ustring, CategoryEditorData*>::iterator editor_data_iter;
+
+    CategoryEditorModel::CategoryEditorModel()
+    {
+    }
+
+    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
+    void
+    CategoryEditorModel::load_category_data()
+    {
+    }
+
+    CategoryEditorData*
+    CategoryEditorModel::create_category_data(const Glib::ustring& name)
+    {
+        CategoryEditorData* data = 0;
+
+        data = new CategoryEditorData;
+        //TODO
+
+        return data;
+    }
+
+    void
+    CategoryEditorModel::new_category(const Glib::ustring& name)
+    {
+    }
+
+    void
+    CategoryEditorModel::save_category(const Glib::ustring& name)
+    {
+    }
+
+    void
+    CategoryEditorModel::delete_category(const Glib::ustring& name)
+    {
+    }
+
+} // namespace paperbox

Added: trunk/src/category-editor-model.hh
==============================================================================
--- (empty file)
+++ trunk/src/category-editor-model.hh	Sat Feb 23 22:42:09 2008
@@ -0,0 +1,64 @@
+// -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*-
+
+/*
+ *  PaperBox - category-editor-model.hh
+ *
+ *  Copyright (C) 2008 Marko Anastasov
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU Library General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License along
+ *  with this program; if not, write to the Free Software Foundation, Inc.,
+ *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __PAPER_BOX_CATEGORY_EDITOR_MODEL_HH__
+#define __PAPER_BOX_CATEGORY_EDITOR_MODEL_HH__
+
+#include <map>
+#include <boost/shared_ptr.hpp>
+#include <gtkmm/textbuffer.h>
+#include "category.hh"
+#include "category-factory.hh"
+
+namespace paperbox {
+
+    struct CategoryEditorData
+    {
+        boost::shared_ptr<Category> category;
+        Glib::RefPtr<Gtk::TextBuffer> buffer;
+    };
+
+    class CategoryEditorModel
+    {
+    public:
+        explicit CategoryEditorModel();
+        ~CategoryEditorModel();
+
+        // throws CategoryExists, propagated from CategoryFactory
+        void new_category(const Glib::ustring& name);
+
+        void save_category(const Glib::ustring& name);
+
+        // throws CategoryNotFound, from CategoryFactory
+        void delete_category(const Glib::ustring& name);
+
+    protected:
+        void load_category_data();
+
+        CategoryEditorData* create_category_data(const Glib::ustring& name);
+
+        std::map<Glib::ustring, CategoryEditorData*> workdata_;
+    };
+
+} // namespace paperbox
+
+#endif // __PAPER_BOX_CATEGORY_EDITOR_MODEL_HH__

Copied: trunk/src/category-editor.cc (from r101, /trunk/src/dialog-categories.cc)
==============================================================================
--- /trunk/src/dialog-categories.cc	(original)
+++ trunk/src/category-editor.cc	Sat Feb 23 22:42:09 2008
@@ -1,7 +1,7 @@
 // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
 /*
- *  PaperBox - dialog-categories.cc
+ *  PaperBox - category-editor.cc
  *
  *  Copyright (C) 2008 Marko Anastasov
  *
@@ -21,15 +21,17 @@
  */
 
 #include <gtkmm/stock.h>
-#include "dialog-categories.hh"
+#include <gtkmm-utils/dialog.h>
+#include "category-editor.hh"
+#include "category-editor-model.hh"
 #include "dialog-entry.hh"
 #include "paths.hh"
 
 namespace paperbox {
 
-    DialogCategories::DialogCategories(
-	    GtkDialog* cobject,
-	    const Glib::RefPtr<Gnome::Glade::Xml>& glade)
+    CategoryEditor::CategoryEditor(
+        GtkDialog* cobject,
+        const Glib::RefPtr<Gnome::Glade::Xml>& glade)
         :
         Gtk::Dialog(cobject),
         glade_(glade),
@@ -39,25 +41,26 @@
     {
         init_gui();
         connect_signals();
+        model_.reset(new CategoryEditorModel());
     }
 
-    DialogCategories::~DialogCategories()
+    CategoryEditor::~CategoryEditor()
     {
     }
 
-    DialogCategories*
-    DialogCategories::create()
+    CategoryEditor*
+    CategoryEditor::create()
     {
         Glib::RefPtr<Gnome::Glade::Xml> glade_xml =
             Gnome::Glade::Xml::create(paperbox::glade_dialog_categories);
 
-        DialogCategories* p = 0;
+        CategoryEditor* p = 0;
         glade_xml->get_widget_derived("dialog_categories", p);
         return p;
     }
 
     void
-    DialogCategories::get_widgets()
+    CategoryEditor::get_widgets()
     {
         glade_->get_widget("vbox_left", vbox_left_);
         g_assert(vbox_left_);
@@ -70,7 +73,7 @@
     }
 
     void
-    DialogCategories::init_gui()
+    CategoryEditor::init_gui()
     {
         get_widgets();
 
@@ -79,6 +82,7 @@
         vbox_left_->pack_start(button_new_, false, false);
         vbox_left_->pack_start(button_delete_, false, false);
 
+        // TODO: verify the string and wrap in _()
         label_category_tags_.set_text("Here are the contents:");
         hbox_contents_->pack_start(label_category_tags_);
         hbox_contents_->pack_start(button_save_);
@@ -91,14 +95,14 @@
     }
 
     void
-    DialogCategories::connect_signals()
+    CategoryEditor::connect_signals()
     {
         button_new_.signal_clicked().connect(
-            sigc::mem_fun(*this, &DialogCategories::on_button_new_clicked));
+            sigc::mem_fun(*this, &CategoryEditor::on_button_new_clicked));
     }
 
     int
-    DialogCategories::run()
+    CategoryEditor::run()
     {
         int response = Gtk::Dialog::run();
 
@@ -106,16 +110,24 @@
     }
 
     void
-    DialogCategories::on_button_new_clicked()
+    CategoryEditor::on_button_new_clicked()
     {
         boost::shared_ptr<DialogEntry> dialog(DialogEntry::create());
+
+        // TODO: verify the string and wrap in _()
+        dialog->set_instructions("Name the new category:");
         dialog->set_default_response(Gtk::RESPONSE_OK);
 
         Glib::ustring name;
         int response = dialog->run(name);
 
-        if (response == Gtk::RESPONSE_OK) {
-            g_debug("gonna create category %s", name.c_str());
+        if (response != Gtk::RESPONSE_OK) return;
+
+        try {
+            model_->new_category(name);
+            // TODO: create a new row, get the textbuffer and assign it
+        } catch (const CategoryExists& ex) {
+            Gtk::Util::display_dialog_error(ex.what());
         }
     }
 

Copied: trunk/src/category-editor.hh (from r101, /trunk/src/dialog-categories.hh)
==============================================================================
--- /trunk/src/dialog-categories.hh	(original)
+++ trunk/src/category-editor.hh	Sat Feb 23 22:42:09 2008
@@ -1,7 +1,7 @@
 // -*- Mode: C++; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
 /*
- *  PaperBox - dialog-categories.hh
+ *  PaperBox - category-editor.hh
  *
  *  Copyright (C) 2008 Marko Anastasov
  *
@@ -20,8 +20,8 @@
  *  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  */
 
-#ifndef __PAPER_BOX_DIALOG_CATEGORIES_HH__
-#define __PAPER_BOX_DIALOG_CATEGORIES_HH__
+#ifndef __PAPER_BOX_CATEGORY_EDITOR_HH__
+#define __PAPER_BOX_CATEGORY_EDITOR_HH__
 
 #include <boost/shared_ptr.hpp>
 #include <gtkmm/button.h>
@@ -34,14 +34,16 @@
 
 namespace paperbox {
 
-    class DialogCategories : public Gtk::Dialog
+    class CategoryEditorModel;
+
+    class CategoryEditor : public Gtk::Dialog
     {
     public:
-        DialogCategories(GtkDialog* cobject,
-                         const Glib::RefPtr<Gnome::Glade::Xml>& glade);
-        virtual ~DialogCategories();
+        CategoryEditor(GtkDialog* cobject,
+                       const Glib::RefPtr<Gnome::Glade::Xml>& glade);
+        virtual ~CategoryEditor();
 
-        static DialogCategories* create();
+        static CategoryEditor* create();
 
         int run();
 
@@ -66,8 +68,11 @@
         Gtk::Button button_save_;
         Gtk::ScrolledWindow scroll_window_;
         Gtk::TextView text_view_;
+
+        // the data model
+        boost::shared_ptr<CategoryEditorModel> model_;
     };
 
 } // namespace paperbox
 
-#endif // __PAPER_BOX_DIALOG_CATEGORIES_HH__
+#endif // __PAPER_BOX_CATEGORY_EDITOR_HH__

Modified: trunk/src/category-factory.cc
==============================================================================
--- trunk/src/category-factory.cc	(original)
+++ trunk/src/category-factory.cc	Sat Feb 23 22:42:09 2008
@@ -42,7 +42,8 @@
     {
         if (! is_name_available(name))
             throw CategoryExists(
-                Glib::Util::uprintf("category %s already exists",
+                // TODO: this should be _()
+                Glib::Util::uprintf("Category %s already exists",
                                     name.c_str()));
 
         shared_ptr<Category> cat(new Category(name));

Modified: trunk/src/main-window.cc
==============================================================================
--- trunk/src/main-window.cc	(original)
+++ trunk/src/main-window.cc	Sat Feb 23 22:42:09 2008
@@ -26,8 +26,8 @@
 #include <glibmm/markup.h>
 #include <gtkmm-utils/tile.h>
 #include "browser.hh"
+#include "category-editor.hh"
 #include "file-utils.hh"
-#include "dialog-categories.hh"
 #include "document-tag-cloud-model.hh"
 #include "document-tile.hh"
 #include "main-window.hh"
@@ -274,7 +274,7 @@
     void
     MainWindow::on_edit_category()
     {
-        shared_ptr<DialogCategories> dialog(DialogCategories::create());
+        shared_ptr<CategoryEditor> dialog(CategoryEditor::create());
         dialog->set_default_response(Gtk::RESPONSE_OK);
 
         dialog->run();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]