diff options
| author | Slagvi Public <JandotDarowskiattgmaildottcom> | 2013-07-04 14:19:38 +0000 |
|---|---|---|
| committer | Slagvi Public <JandotDarowskiattgmaildottcom> | 2013-07-04 14:19:38 +0000 |
| commit | 46211dc227f62c2e71b3edfa1ffb508c9fe8e0ac (patch) | |
| tree | 2941c3895a0663437a0b580608bca5ad7ef2deb1 /src | |
| parent | Templates menu item fixed (diff) | |
| download | inkscape-46211dc227f62c2e71b3edfa1ffb508c9fe8e0ac.tar.gz inkscape-46211dc227f62c2e71b3edfa1ffb508c9fe8e0ac.zip | |
Added loading templates into NewFromTemplate dialog.
(bzr r12379.2.7)
Diffstat (limited to 'src')
| -rw-r--r-- | src/file.cpp | 7 | ||||
| -rw-r--r-- | src/file.h | 1 | ||||
| -rw-r--r-- | src/ui/dialog/new-from-template.cpp | 12 | ||||
| -rw-r--r-- | src/ui/dialog/new-from-template.h | 4 | ||||
| -rw-r--r-- | src/ui/dialog/static-template-load-tab.cpp | 20 | ||||
| -rw-r--r-- | src/ui/dialog/static-template-load-tab.h | 2 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.cpp | 57 | ||||
| -rw-r--r-- | src/ui/dialog/template-load-tab.h | 25 | ||||
| -rw-r--r-- | src/verbs.cpp | 2 |
9 files changed, 109 insertions, 21 deletions
diff --git a/src/file.cpp b/src/file.cpp index 7f8bfc8bf..9d3c513ab 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -66,7 +66,6 @@ #include "verbs.h" #include "event-log.h" #include "ui/dialog/font-substitution.h" -#include "ui/dialog/new-from-template.h" #include <gtk/gtk.h> @@ -200,12 +199,6 @@ SPDesktop* sp_file_new_default() return desk; } -SPDesktop* sp_file_new_from_templatee() -{ - Inkscape::UI::NewFromTemplate dl; - dl.run(); - return sp_file_new_default(); -} /*###################### ## D E L E T E diff --git a/src/file.h b/src/file.h index acc6c5c7c..fe8ad9af3 100644 --- a/src/file.h +++ b/src/file.h @@ -45,7 +45,6 @@ Glib::ustring sp_file_default_template_uri(); */ SPDesktop* sp_file_new (const Glib::ustring &templ); SPDesktop* sp_file_new_default (void); -SPDesktop* sp_file_new_from_templatee (); /*###################### ## D E L E T E diff --git a/src/ui/dialog/new-from-template.cpp b/src/ui/dialog/new-from-template.cpp index fc590d199..b210545d1 100644 --- a/src/ui/dialog/new-from-template.cpp +++ b/src/ui/dialog/new-from-template.cpp @@ -1,5 +1,9 @@ #include "new-from-template.h" -#include "gtkmm/alignment.h" + +#include <gtkmm/alignment.h> + +#include "src/file.h" + namespace Inkscape { namespace UI { @@ -38,5 +42,11 @@ void NewFromTemplate::_createFromTemplate() response(0); } +void NewFromTemplate::load_new_from_template() +{ + NewFromTemplate dl; + dl.run(); +} + } } diff --git a/src/ui/dialog/new-from-template.h b/src/ui/dialog/new-from-template.h index f8c4bbb37..e7976d685 100644 --- a/src/ui/dialog/new-from-template.h +++ b/src/ui/dialog/new-from-template.h @@ -8,6 +8,7 @@ #include "template-load-tab.h" #include "static-template-load-tab.h" + namespace Inkscape { namespace UI { @@ -15,9 +16,10 @@ namespace UI { class NewFromTemplate : public Gtk::Dialog { public: - NewFromTemplate(); + static void load_new_from_template(); private: + NewFromTemplate(); Gtk::Notebook _main_widget; Gtk::Button _create_template_button; StaticTemplateLoadTab _tab1; diff --git a/src/ui/dialog/static-template-load-tab.cpp b/src/ui/dialog/static-template-load-tab.cpp index 94298bf1d..47c7c00b9 100644 --- a/src/ui/dialog/static-template-load-tab.cpp +++ b/src/ui/dialog/static-template-load-tab.cpp @@ -5,18 +5,25 @@ #include <gtkmm/label.h> #include <iostream> +#include "src/file.h" + namespace Inkscape { namespace UI { StaticTemplateLoadTab::StaticTemplateLoadTab() - : _more_info_button("More info") + : TemplateLoadTab() + , _more_info_button("More info") , _preview_image("preview.png") , _short_description_label("Short description - I like trains. ad asda asd asdweqe gdfg") , _template_name_label("Template_name") , _template_author_label("by template_author") { + _loading_path = "/static"; + _loadTemplates(); + _initLists(); + _template_info_column.pack_start(_template_name_label, Gtk::PACK_SHRINK, 4); _template_info_column.pack_start(_template_author_label, Gtk::PACK_SHRINK, 0); _template_info_column.pack_start(_preview_image, Gtk::PACK_SHRINK, 15); @@ -34,7 +41,14 @@ StaticTemplateLoadTab::StaticTemplateLoadTab() void StaticTemplateLoadTab::createTemplate() { - std::cout << "Static template\n"; + Glib::ustring path; + if (_templates.find(_current_template) != _templates.end()){ + path = _templates[_current_template].path; + } + else + path = ""; + + sp_file_new(path); } @@ -42,6 +56,8 @@ void StaticTemplateLoadTab::_displayTemplateInfo() { TemplateLoadTab::_displayTemplateInfo(); _template_name_label.set_text(_current_template); + _template_author_label.set_text(_templates[_current_template].author); + _short_description_label.set_text(_templates[_current_template].short_description); } } diff --git a/src/ui/dialog/static-template-load-tab.h b/src/ui/dialog/static-template-load-tab.h index a1a3adf7b..a5411296d 100644 --- a/src/ui/dialog/static-template-load-tab.h +++ b/src/ui/dialog/static-template-load-tab.h @@ -2,10 +2,12 @@ #define INKSCAPE_SEEN_UI_DIALOG_STATIC_TEMPLATE_LOAD_TAB_H #include "template-load-tab.h" + #include <gtkmm/label.h> #include <gtkmm/button.h> #include <gtkmm/image.h> + namespace Inkscape { namespace UI { diff --git a/src/ui/dialog/template-load-tab.cpp b/src/ui/dialog/template-load-tab.cpp index 5d4c3a364..5e3a16a3f 100644 --- a/src/ui/dialog/template-load-tab.cpp +++ b/src/ui/dialog/template-load-tab.cpp @@ -1,7 +1,14 @@ #include "template-load-tab.h" + #include <gtkmm/alignment.h> #include <iostream> +#include "src/interface.h" +#include "src/file.h" +#include "src/path-prefix.h" +#include "src/preferences.h" +#include "src/inkscape.h" + namespace Inkscape { namespace UI { @@ -9,6 +16,7 @@ namespace UI { TemplateLoadTab::TemplateLoadTab() : _keywords_combo(true) + , _current_keyword("") { set_border_width(10); @@ -24,8 +32,6 @@ TemplateLoadTab::TemplateLoadTab() title = manage(new Gtk::Label("Selected template")); _template_info_column.pack_start(*title, Gtk::PACK_SHRINK, 10); - _initLists(); - add(_main_box); _main_box.pack_start(_templates_column, Gtk::PACK_SHRINK, 20); _main_box.pack_start(_template_info_column, Gtk::PACK_EXPAND_WIDGET, 10); @@ -67,7 +73,6 @@ void TemplateLoadTab::_displayTemplateInfo() void TemplateLoadTab::_initKeywordsList() { _keywords_combo.append("All"); - // _keywords_combo for (int i = 0 ; i < 10 ; ++i) { _keywords_combo.append( "Keyword" + Glib::ustring::format(i)); @@ -97,12 +102,54 @@ void TemplateLoadTab::_keywordSelected() void TemplateLoadTab::_refreshTemplatesList() { _templates_ref->clear(); - for (int i = 0 ; i < 7 ; ++i) { + + for (std::map<Glib::ustring, TemplateData>::iterator it = _templates.begin() ; it != _templates.end() ; ++it) { Gtk::TreeModel::iterator iter = _templates_ref->append(); Gtk::TreeModel::Row row = *iter; - row[_templates_columns.textValue] = "Template" + Glib::ustring::format(i); + row[_templates_columns.textValue] = it->first; } } + +void TemplateLoadTab::_loadTemplates() +{ + // user's local dir + _getTemplatesFromDir(profile_path("templates") + _loading_path); + + // system templates dir + _getTemplatesFromDir(INKSCAPE_TEMPLATESDIR + _loading_path); +} + + +TemplateLoadTab::TemplateData TemplateLoadTab::_processTemplateFile(Glib::ustring path) +{ + TemplateData result; + result.path = path; + result.display_name = Glib::path_get_basename(path); + result.short_description = "LaLaLaLa"; + result.author = "JAASDASD"; + + return result; +} + + +void TemplateLoadTab::_getTemplatesFromDir(Glib::ustring path) +{ + if ( !Glib::file_test(path, Glib::FILE_TEST_EXISTS) || + !Glib::file_test(path, Glib::FILE_TEST_IS_DIR)) + return; + + Glib::Dir dir(path); + path += "/"; + Glib::ustring file = path + dir.read_name(); + while (file != path){ + if (Glib::str_has_suffix(file, ".svg")){ + TemplateData tmp = _processTemplateFile(file); + _templates[Glib::path_get_basename(file)] = tmp; + } + file = path + dir.read_name(); + } +} + } } diff --git a/src/ui/dialog/template-load-tab.h b/src/ui/dialog/template-load-tab.h index a9fa7c313..3edcf15eb 100644 --- a/src/ui/dialog/template-load-tab.h +++ b/src/ui/dialog/template-load-tab.h @@ -6,6 +6,9 @@ #include <gtkmm/frame.h> #include <gtkmm/liststore.h> #include <gtkmm/treeview.h> +#include <map> +#include <set> + namespace Inkscape { namespace UI { @@ -20,6 +23,15 @@ public: virtual void createTemplate(); protected: + struct TemplateData + { + Glib::ustring path; + Glib::ustring display_name; + Glib::ustring author; + Glib::ustring short_description; + std::set<Glib::ustring> keywords; + }; + class StringModelColumns : public Gtk::TreeModelColumnRecord { public: @@ -33,14 +45,16 @@ protected: Glib::ustring _current_keyword; Glib::ustring _current_template; + Glib::ustring _loading_path; + std::map<Glib::ustring, TemplateData> _templates; + virtual void _displayTemplateInfo(); virtual void _initKeywordsList(); virtual void _refreshTemplatesList(); - + void _loadTemplates(); void _initLists(); - void _keywordSelected(); - + Gtk::HBox _main_box; Gtk::VBox _templates_column; Gtk::VBox _template_info_column; @@ -50,6 +64,11 @@ protected: Gtk::TreeView _templates_view; Glib::RefPtr<Gtk::ListStore> _templates_ref; StringModelColumns _templates_columns; + +private: + void _getTemplatesFromDir(Glib::ustring); + void _keywordSelected(); + TemplateData _processTemplateFile(Glib::ustring); }; diff --git a/src/verbs.cpp b/src/verbs.cpp index a3d8b07a2..8b8a7e6af 100644 --- a/src/verbs.cpp +++ b/src/verbs.cpp @@ -862,7 +862,7 @@ void FileVerb::perform(SPAction *action, void *data) sp_file_exit(); break; case SP_VERB_FILE_TEMPLATES: - sp_file_new_from_templatee(); + Inkscape::UI::NewFromTemplate::load_new_from_template(); break; default: break; |
