[gnote] * Insert Time Stamp addon.
- From: Hubert Figuière <hub src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnote] * Insert Time Stamp addon.
- Date: Fri, 24 Apr 2009 12:55:06 -0400 (EDT)
commit d6656c2609d82dc6f0b038476a8b645c020860c9
Author: Hubert Figuiere <hub figuiere net>
Date: Fri Apr 24 12:29:55 2009 -0400
* Insert Time Stamp addon.
* Implement addin preferences.
---
NEWS | 2 +
configure.ac | 1 +
data/gnote.schemas.in | 5 +-
po/POTFILES.in | 2 +
src/addinmanager.cpp | 16 ++
src/addinmanager.hpp | 7 +-
src/addins/Makefile.am | 5 +-
src/addins/inserttimestamp/Makefile.am | 12 ++
.../inserttimestamp/inserttimestampnoteaddin.cpp | 119 ++++++++++++++++
.../inserttimestamp/inserttimestampnoteaddin.hpp | 73 ++++++++++
.../inserttimestamp/inserttimestamppreferences.cpp | 144 ++++++++++++++++++++
.../inserttimestamp/inserttimestamppreferences.hpp | 70 ++++++++++
.../inserttimestamppreferencesfactory.hpp | 47 +++++++
src/preferencesdialog.cpp | 123 ++++++++++-------
src/preferencesdialog.hpp | 2 +
src/sharp/datetime.hpp | 4 +
16 files changed, 578 insertions(+), 54 deletions(-)
diff --git a/NEWS b/NEWS
index b057c6d..a0379fc 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
New features:
* Print addon.
+ * Insert Time Stamp addon.
+ * Implement addin preferences.
0.2.1 -
diff --git a/configure.ac b/configure.ac
index 1132153..8cefbce 100644
--- a/configure.ac
+++ b/configure.ac
@@ -188,6 +188,7 @@ src/Makefile
src/addins/Makefile
src/addins/addins.mk
src/addins/fixedwidth/Makefile
+src/addins/inserttimestamp/Makefile
src/addins/printnotes/Makefile
po/Makefile.in
po/Makefile
diff --git a/data/gnote.schemas.in b/data/gnote.schemas.in
index 834a2c8..70e1678 100644
--- a/data/gnote.schemas.in
+++ b/data/gnote.schemas.in
@@ -537,11 +537,12 @@
<applyto>/apps/gnote/insert_timestamp/format</applyto>
<owner>gnote</owner>
<type>string</type>
- <default>dddd, MMMM d, h:mm tt</default>
+ <default>%c</default>
<locale name="C">
<short>Timestamp format</short>
<long>
- The date format that is used for the timestamp.
+ The date format that is used for the timestamp. It followe the format of
+ strftime(3).
</long>
</locale>
</schema>
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 9d91cad..1c9ce84 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -23,3 +23,5 @@ src/notebooks/notebooknoteaddin.cpp
src/addins/fixedwidth/fixedwidthmenuitem.cpp
src/addins/fixedwidth/fixedwidthnoteaddin.cpp
src/addins/printnotes/printnotesnoteaddin.cpp
+src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
+src/addins/inserttimestamp/inserttimestamppreferences.cpp
diff --git a/src/addinmanager.cpp b/src/addinmanager.cpp
index 4bce85a..9addfd4 100644
--- a/src/addinmanager.cpp
+++ b/src/addinmanager.cpp
@@ -26,6 +26,7 @@
#include "sharp/dynamicmodule.hpp"
#include "addinmanager.hpp"
+#include "addinpreferencefactory.hpp"
#include "debug.hpp"
#include "watchers.hpp"
#include "notebooks/notebookapplicationaddin.hpp"
@@ -55,6 +56,7 @@ namespace gnote {
std::for_each(iter->second.begin(), iter->second.end(),
boost::bind(&boost::checked_delete<NoteAddin>, _1));
}
+ sharp::map_delete_all_second(m_addin_prefs);
}
void AddinManager::initialize_sharp_addins()
@@ -91,6 +93,11 @@ namespace gnote {
m_note_addin_infos.insert(std::make_pair(typeid(*f).name(), f));
}
+ f = dmod->query_interface(AddinPreferenceFactory::IFACE_NAME);
+ if(f) {
+ AddinPreferenceFactory * factory = dynamic_cast<AddinPreferenceFactory*>((*f)());
+ m_addin_prefs.insert(std::make_pair((*iter)->id(), factory));
+ }
}
}
@@ -129,4 +136,13 @@ namespace gnote {
{
sharp::map_get_values(m_pref_tab_addins, l);
}
+
+ Gtk::Widget * AddinManager::create_addin_preference_widget(const std::string & id)
+ {
+ IdAddinPrefsMap::const_iterator iter = m_addin_prefs.find(id);
+ if(iter != m_addin_prefs.end()) {
+ return iter->second->create_preference_widget();
+ }
+ return NULL;
+ }
}
diff --git a/src/addinmanager.hpp b/src/addinmanager.hpp
index d05061a..eaec27c 100644
--- a/src/addinmanager.hpp
+++ b/src/addinmanager.hpp
@@ -37,6 +37,7 @@ namespace gnote {
class ApplicationAddin;
class PreferenceTabAddin;
+class AddinPreferenceFactory;
class AddinManager
@@ -54,6 +55,8 @@ public:
return m_module_manager.get_modules();
}
+ Gtk::Widget * create_addin_preference_widget(const std::string & id);
+
sigc::signal<void> & signal_application_addin_list_changed();
private:
@@ -72,7 +75,9 @@ private:
typedef std::map<std::string, sharp::IfaceFactoryBase*> IdInfoMap;
IdInfoMap m_note_addin_infos;
typedef std::map<std::string, PreferenceTabAddin*> IdPrefTabAddinMap;
- IdPrefTabAddinMap m_pref_tab_addins;
+ IdPrefTabAddinMap m_pref_tab_addins;
+ typedef std::map<std::string, AddinPreferenceFactory*> IdAddinPrefsMap;
+ IdAddinPrefsMap m_addin_prefs;
sigc::signal<void> m_application_addin_list_changed;
};
diff --git a/src/addins/Makefile.am b/src/addins/Makefile.am
index 550a5cd..6e6a16c 100644
--- a/src/addins/Makefile.am
+++ b/src/addins/Makefile.am
@@ -1,4 +1,7 @@
-SUBDIRS = fixedwidth printnotes
\ No newline at end of file
+SUBDIRS = fixedwidth \
+ inserttimestamp \
+ printnotes \
+ $(NULL)
\ No newline at end of file
diff --git a/src/addins/inserttimestamp/Makefile.am b/src/addins/inserttimestamp/Makefile.am
new file mode 100644
index 0000000..25dd0dd
--- /dev/null
+++ b/src/addins/inserttimestamp/Makefile.am
@@ -0,0 +1,12 @@
+
+include $(builddir)/../addins.mk
+
+addinsdir = $(ADDINSDIR)
+addins_LTLIBRARIES = inserttimestamp.la
+
+
+inserttimestamp_la_SOURCES = inserttimestampnoteaddin.hpp \
+ inserttimestampnoteaddin.cpp \
+ inserttimestamppreferences.hpp inserttimestamppreferences.cpp \
+ inserttimestamppreferencesfactory.hpp \
+ $(NULL)
diff --git a/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp b/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
new file mode 100644
index 0000000..7867cf8
--- /dev/null
+++ b/src/addins/inserttimestamp/inserttimestampnoteaddin.cpp
@@ -0,0 +1,119 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <glibmm/i18n.h>
+
+#include "sharp/datetime.hpp"
+#include "inserttimestamppreferencesfactory.hpp"
+#include "inserttimestampnoteaddin.hpp"
+#include "notewindow.hpp"
+#include "preferences.hpp"
+
+using gnote::Preferences;
+
+namespace inserttimestamp {
+
+ InsertTimeStampModule::InsertTimeStampModule()
+ {
+ add(gnote::NoteAddin::IFACE_NAME,
+ new sharp::IfaceFactory<InsertTimestampNoteAddin>);
+ add(gnote::AddinPreferenceFactory::IFACE_NAME,
+ new sharp::IfaceFactory<InsertTimestampPreferencesFactory>);
+ }
+ const char * InsertTimeStampModule::id() const
+ {
+ return "InsertTimestampAddin";
+ }
+ const char * InsertTimeStampModule::name() const
+ {
+ return _("Insert Timestamp");
+ }
+ const char * InsertTimeStampModule::description() const
+ {
+ return _("Inserts current date and time at the cursor position.");
+ }
+ const char * InsertTimeStampModule::authors() const
+ {
+ return _("Hubert Figuiere and Tomboy Project");
+ }
+ const char * InsertTimeStampModule::category() const
+ {
+ return "Tools";
+ }
+ const char * InsertTimeStampModule::version() const
+ {
+ return "0.1";
+ }
+
+
+ void InsertTimestampNoteAddin::initialize()
+ {
+ }
+
+
+ void InsertTimestampNoteAddin::shutdown()
+ {
+ }
+
+
+ void InsertTimestampNoteAddin::on_note_opened()
+ {
+ // Add the menu item when the window is created
+ m_item = manage(new Gtk::MenuItem(_("Insert Timestamp")));
+ m_item->signal_activate().connect(
+ sigc::mem_fun(*this, &InsertTimestampNoteAddin::on_menu_item_activated));
+ m_item->add_accelerator ("activate", get_window()->get_accel_group(),
+ GDK_d, Gdk::CONTROL_MASK,
+ Gtk::ACCEL_VISIBLE);
+ m_item->show ();
+ add_plugin_menu_item (m_item);
+
+ // Get the format from GConf and subscribe to changes
+ m_date_format = Preferences::obj().get<std::string>(
+ Preferences::INSERT_TIMESTAMP_FORMAT);
+ Preferences::obj().signal_setting_changed().connect(
+ sigc::mem_fun(
+ *this, &InsertTimestampNoteAddin::on_format_setting_changed));
+ }
+
+
+ void InsertTimestampNoteAddin::on_menu_item_activated()
+ {
+ std::string text = sharp::DateTime::now().to_string(m_date_format);
+ Gtk::TextIter cursor = get_buffer()->get_iter_at_mark (get_buffer()->get_insert());
+ std::vector<Glib::ustring> names;
+ names.push_back("datetime");
+ get_buffer()->insert_with_tags_by_name (cursor, text, names);
+ }
+
+
+ void InsertTimestampNoteAddin::on_format_setting_changed(gnote::Preferences*,
+ GConfEntry* entry)
+ {
+ const gchar *key = gconf_entry_get_key(entry);
+ if(strcmp(key, Preferences::INSERT_TIMESTAMP_FORMAT) == 0) {
+ GConfValue * conf_value = gconf_entry_get_value(entry);
+ const gchar *value = gconf_value_get_string(conf_value);
+ m_date_format = value ? value : "";
+ }
+ }
+
+}
+
diff --git a/src/addins/inserttimestamp/inserttimestampnoteaddin.hpp b/src/addins/inserttimestamp/inserttimestampnoteaddin.hpp
new file mode 100644
index 0000000..0aa1232
--- /dev/null
+++ b/src/addins/inserttimestamp/inserttimestampnoteaddin.hpp
@@ -0,0 +1,73 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+
+
+
+#ifndef __INSERTIMESTAMP_NOTEADDIN_HPP_
+#define __INSERTIMESTAMP_NOTEADDIN_HPP_
+
+#include <gtkmm/menuitem.h>
+
+#include "sharp/dynamicmodule.hpp"
+#include "noteaddin.hpp"
+#include "preferences.hpp"
+
+namespace inserttimestamp {
+
+class InsertTimeStampModule
+ : public sharp::DynamicModule
+{
+public:
+ InsertTimeStampModule();
+ virtual const char * id() const;
+ virtual const char * name() const;
+ virtual const char * description() const;
+ virtual const char * authors() const;
+ virtual const char * category() const;
+ virtual const char * version() const;
+};
+
+
+DECLARE_MODULE(InsertTimeStampModule);
+
+
+class InsertTimestampNoteAddin
+ : public gnote::NoteAddin
+{
+public:
+ static InsertTimestampNoteAddin* create()
+ {
+ return new InsertTimestampNoteAddin;
+ }
+ virtual void initialize();
+ virtual void shutdown();
+ virtual void on_note_opened();
+private:
+ void on_menu_item_activated();
+ void on_format_setting_changed(gnote::Preferences*, GConfEntry*);
+
+ std::string m_date_format;
+ Gtk::MenuItem *m_item;
+};
+
+}
+
+#endif
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.cpp b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
new file mode 100644
index 0000000..d2c4b34
--- /dev/null
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.cpp
@@ -0,0 +1,144 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#include <string>
+
+#include <glibmm/i18n.h>
+
+#include "sharp/datetime.hpp"
+#include "sharp/propertyeditor.hpp"
+
+#include "preferences.hpp"
+#include "inserttimestamppreferences.hpp"
+
+using gnote::Preferences;
+
+namespace inserttimestamp {
+
+ bool InsertTimestampPreferences::s_static_inited = false;
+ std::vector<std::string> InsertTimestampPreferences::s_formats;
+
+ void InsertTimestampPreferences::_init_static()
+ {
+ if(!s_static_inited) {
+ s_formats.push_back("%c");
+ s_formats.push_back("%m/%d/%y %H:%M:%S");
+ s_formats.push_back("%m/%d/%y");
+ s_formats.push_back("%Y-%m-%d %H:%M:%S");
+ s_formats.push_back("%Y-%m-%d");
+
+ s_static_inited = true;
+ }
+ }
+
+
+ InsertTimestampPreferences::InsertTimestampPreferences()
+ : Gtk::VBox(false, 12)
+ {
+ _init_static();
+ // Get current values
+ std::string dateFormat = Preferences::obj().get<std::string> (
+ Preferences::INSERT_TIMESTAMP_FORMAT);
+
+ sharp::DateTime now = sharp::DateTime::now();
+
+ // Label
+ Gtk::Label *label = manage(new Gtk::Label (_("Choose one of the predefined formats "
+ "or use your own.")));
+ label->property_wrap() = true;
+ label->property_xalign() = 0;
+ pack_start (*label);
+
+ // Use Selected Format
+ Gtk::RadioButtonGroup group;
+ selected_radio = manage(new Gtk::RadioButton (group, _("Use _Selected Format"), true));
+ pack_start (*selected_radio);
+
+ // 1st column (visible): formatted date
+ // 2nd column (not visible): date format
+ store = Gtk::ListStore::create(m_columns);
+
+ for(std::vector<std::string>::const_iterator iter = s_formats.begin();
+ iter != s_formats.end(); ++iter) {
+
+ Gtk::TreeIter treeiter = store->append();
+ treeiter->set_value(0, now.to_string(*iter));
+ treeiter->set_value(1, *iter);
+ }
+
+ scroll = manage(new Gtk::ScrolledWindow());
+ scroll->set_shadow_type(Gtk::SHADOW_IN);
+ pack_start (*scroll);
+
+ tv = manage(new Gtk::TreeView (store));
+ tv->set_headers_visible(false);
+ tv->append_column ("Format", m_columns.formatted);
+
+ scroll->add (*tv);
+
+ // Use Custom Format
+ Gtk::HBox *customBox = manage(new Gtk::HBox (false, 12));
+ pack_start (*customBox);
+
+ custom_radio = manage(new Gtk::RadioButton (group, _("_Use Custom Format"), true));
+ customBox->pack_start (*custom_radio);
+
+ custom_entry = manage(new Gtk::Entry());
+ customBox->pack_start (*custom_entry);
+
+ sharp::PropertyEditor * entryEditor = new sharp::PropertyEditor(
+ Preferences::INSERT_TIMESTAMP_FORMAT, *custom_entry);
+ entryEditor->setup ();
+
+ // Activate/deactivate widgets
+ bool useCustom = true;
+ Gtk::TreeIter iter;
+ for(iter = store->children().begin();
+ iter != store->children().end(); ++iter) {
+
+ const Gtk::TreeRow & row(*iter);
+ std::string value = row[m_columns.format];
+ if (dateFormat == value) {
+ // Found format in list
+ useCustom = false;
+ break;
+ }
+ }
+
+ if (useCustom) {
+ custom_radio->set_active(true);
+ scroll->set_sensitive(false);
+ }
+ else {
+ selected_radio->set_active(true);
+ custom_entry->set_sensitive(false);
+ tv->get_selection()->select(iter);
+ Gtk::TreePath treepath = store->get_path (iter);
+ tv->scroll_to_row(treepath);
+ }
+
+ // Register Toggled event for one radio button only
+// selected_radio.Toggled += OnSelectedRadioToggled;
+// tv.Selection.Changed += OnSelectionChanged;
+
+ show_all ();
+ }
+
+}
diff --git a/src/addins/inserttimestamp/inserttimestamppreferences.hpp b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
new file mode 100644
index 0000000..215f13c
--- /dev/null
+++ b/src/addins/inserttimestamp/inserttimestamppreferences.hpp
@@ -0,0 +1,70 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+
+#ifndef __INSERTTIMESTAMP_PREFERENCES_HPP_
+#define __INSERTTIMESTAMP_PREFERENCES_HPP_
+
+
+#include <gtkmm/box.h>
+#include <gtkmm/entry.h>
+#include <gtkmm/liststore.h>
+#include <gtkmm/radiobutton.h>
+#include <gtkmm/scrolledwindow.h>
+#include <gtkmm/treeview.h>
+
+
+namespace inserttimestamp {
+
+class InsertTimestampPreferences
+ : public Gtk::VBox
+{
+public:
+ InsertTimestampPreferences();
+private:
+ static void _init_static();
+ class FormatColumns
+ : public Gtk::TreeModelColumnRecord
+ {
+ public:
+ FormatColumns()
+ { add(formatted); add(format); }
+
+ Gtk::TreeModelColumn<std::string> formatted;
+ Gtk::TreeModelColumn<std::string> format;
+ };
+ void on_selected_radio_toggled();
+ void on_selection_changed();
+
+ static bool s_static_inited;
+ static std::vector<std::string> s_formats;
+ FormatColumns m_columns;
+ Gtk::RadioButton *selected_radio;
+ Gtk::RadioButton *custom_radio;
+
+ Gtk::ScrolledWindow *scroll;
+ Gtk::TreeView *tv;
+ Glib::RefPtr<Gtk::ListStore> store;
+ Gtk::Entry *custom_entry;
+};
+
+
+}
+
+#endif
diff --git a/src/addins/inserttimestamp/inserttimestamppreferencesfactory.hpp b/src/addins/inserttimestamp/inserttimestamppreferencesfactory.hpp
new file mode 100644
index 0000000..c45f177
--- /dev/null
+++ b/src/addins/inserttimestamp/inserttimestamppreferencesfactory.hpp
@@ -0,0 +1,47 @@
+/*
+ * gnote
+ *
+ * Copyright (C) 2009 Hubert Figuiere
+ *
+ * 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 3 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _INSERTTIMESTAMP_PREFERENCES_FACTORY_HPP__
+#define _INSERTTIMESTAMP_PREFERENCES_FACTORY_HPP__
+
+
+#include "addinpreferencefactory.hpp"
+#include "inserttimestamppreferences.hpp"
+
+namespace inserttimestamp {
+
+
+ class InsertTimestampPreferencesFactory
+ : public gnote::AddinPreferenceFactory
+ {
+ public:
+ static gnote::AddinPreferenceFactory * create()
+ {
+ return new InsertTimestampPreferencesFactory;
+ }
+ virtual Gtk::Widget * create_preference_widget()
+ {
+ return Gtk::manage(new InsertTimestampPreferences());
+ }
+ };
+
+
+}
+
+#endif
diff --git a/src/preferencesdialog.cpp b/src/preferencesdialog.cpp
index f41ff56..323ea95 100644
--- a/src/preferencesdialog.cpp
+++ b/src/preferencesdialog.cpp
@@ -671,68 +671,91 @@ namespace gnote {
void PreferencesDialog::on_addin_prefs_button()
{
-// const sharp::DynamicModule * module = get_selected_addin();
-#if 0
- Gtk::Dialog dialog = null;
-// Mono.Addins.Addin addin =
-// addin_tree.ActiveAddinData as Mono.Addins.Addin;
- if (addin == null)
+ const sharp::DynamicModule * module = get_selected_addin();
+ Gtk::Dialog *dialog;
+
+ if (!module) {
return;
+ }
- if (addin_prefs_dialogs.ContainsKey (addin.Id) == false) {
+ std::map<std::string, Gtk::Dialog* >::iterator iter;
+ iter = addin_prefs_dialogs.find(module->id());
+ if (iter == addin_prefs_dialogs.end()) {
// A preference dialog isn't open already so create a new one
- Gtk::Image icon =
- new Gtk::Image (Gtk::Stock::PREFERENCES, Gtk::IconSize.Dialog);
- Gtk::Label caption = new Gtk::Label ();
- caption.Markup = string.Format (
- "<span size='large' weight='bold'>{0} {1}</span>",
- addin.Name, addin.Version);
- caption.Xalign = 0;
- caption.UseMarkup = true;
- caption.UseUnderline = false;
-
- Gtk::Widget pref_widget =
- addin_manager.CreateAddinPreferenceWidget (addin);
-
- if (pref_widget == null)
- pref_widget = new Gtk::Label (Catalog.GetString ("Not Implemented"));
-
- Gtk::HBox hbox = new Gtk::HBox (false, 6);
- Gtk::VBox vbox = new Gtk::VBox (false, 6);
- vbox.BorderWidth = 6;
- hbox.PackStart (icon, false, false, 0);
- hbox.PackStart (caption, true, true, 0);
- vbox.PackStart (hbox, false, false, 0);
-
- vbox.PackStart (pref_widget, true, true, 0);
- vbox.ShowAll ();
-
- dialog = new Gtk::Dialog (
- string.Format (Catalog.GetString ("{0} Preferences"),
- addin.Name),
- this,
- Gtk::DialogFlags.DestroyWithParent | Gtk::DialogFlags.NoSeparator,
- Gtk::Stock.Close, Gtk::ResponseType.Close);
-
- dialog.VBox.PackStart (vbox, true, true, 0);
- dialog.DeleteEvent += AddinPrefDialogDeleted;
- dialog.Response += AddinPrefDialogResponse;
+ Gtk::Image *icon =
+ manage(new Gtk::Image (Gtk::Stock::PREFERENCES, Gtk::ICON_SIZE_DIALOG));
+ Gtk::Label *caption = manage(new Gtk::Label());
+ caption->set_markup(
+ str(boost::format("<span size='large' weight='bold'>%1% %2%</span>")
+ % module->name() % module->version()));
+ caption->property_xalign() = 0;
+ caption->set_use_markup(true);
+ caption->set_use_underline(false);
+
+ Gtk::Widget * pref_widget =
+ m_addin_manager.create_addin_preference_widget (module->id());
+
+ if (pref_widget == NULL) {
+ pref_widget = manage(new Gtk::Label (_("Not Implemented")));
+ }
+
+ Gtk::HBox *hbox = manage(new Gtk::HBox (false, 6));
+ Gtk::VBox *vbox = manage(new Gtk::VBox (false, 6));
+ vbox->set_border_width(6);
+ hbox->pack_start (*icon, false, false, 0);
+ hbox->pack_start (*caption, true, true, 0);
+ vbox->pack_start (*hbox, false, false, 0);
+
+ vbox->pack_start (*pref_widget, true, true, 0);
+ vbox->show_all ();
+
+ dialog = new Gtk::Dialog(
+ str(boost::format(_("%1% Preferences")) % module->name()),
+ *this, false, false);
+ dialog->property_destroy_with_parent() = true;
+ dialog->add_button(Gtk::Stock::CLOSE, Gtk::RESPONSE_CLOSE);
+
+ dialog->get_vbox()->pack_start (*vbox, true, true, 0);
+ dialog->signal_delete_event().connect(
+ sigc::bind(
+ sigc::mem_fun(*this, &PreferencesDialog::addin_pref_dialog_deleted),
+ dialog), false);
+ dialog->signal_response().connect(
+ sigc::bind(
+ sigc::mem_fun(*this, &PreferencesDialog::addin_pref_dialog_response),
+ dialog));
// Store this dialog off in the dictionary so it can be
// presented again if the user clicks on the preferences button
// again before closing the preferences dialog.
- dialog.Data ["AddinId"] = addin.Id;
- addin_prefs_dialogs [addin.Id] = dialog;
- } else {
+// dialog->set_data(Glib::Quark("AddinId"), module->id());
+ addin_prefs_dialogs [module->id()] = dialog;
+ }
+ else {
// It's already opened so just present it again
- dialog = addin_prefs_dialogs [addin.Id];
+ dialog = iter->second;
}
- dialog.Present ();
-#endif
+ dialog->present ();
}
+ bool PreferencesDialog::addin_pref_dialog_deleted(GdkEventAny*,
+ Gtk::Dialog* dialog)
+ {
+ // Remove the addin from the addin_prefs_dialogs Dictionary
+ dialog->hide ();
+
+// addin_prefs_dialogs.erase(dialog->get_addin_id());
+
+ return false;
+ }
+
+ void PreferencesDialog::addin_pref_dialog_response(int, Gtk::Dialog* dialog)
+ {
+ addin_pref_dialog_deleted(NULL, dialog);
+ }
+
void PreferencesDialog::on_addin_info_button()
{
const sharp::DynamicModule * addin = get_selected_addin();
@@ -776,7 +799,7 @@ namespace gnote {
dialog->hide ();
AddinInfoDialog *addin_dialog = static_cast<AddinInfoDialog*>(dialog);
- addin_prefs_dialogs.erase(addin_dialog->get_addin_id());
+ addin_info_dialogs.erase(addin_dialog->get_addin_id());
return false;
}
diff --git a/src/preferencesdialog.hpp b/src/preferencesdialog.hpp
index d509178..34e33e8 100644
--- a/src/preferencesdialog.hpp
+++ b/src/preferencesdialog.hpp
@@ -71,6 +71,8 @@ private:
void on_enable_addin_button();
void on_disable_addin_button();
void on_addin_prefs_button();
+ bool addin_pref_dialog_deleted(GdkEventAny*, Gtk::Dialog*);
+ void addin_pref_dialog_response(int, Gtk::Dialog*);
void on_addin_info_button();
bool addin_info_dialog_deleted(GdkEventAny*, Gtk::Dialog*);
void addin_info_dialog_response(int, Gtk::Dialog*);
diff --git a/src/sharp/datetime.hpp b/src/sharp/datetime.hpp
index f7f9979..9cd7efc 100644
--- a/src/sharp/datetime.hpp
+++ b/src/sharp/datetime.hpp
@@ -53,6 +53,10 @@ public:
bool operator>(const DateTime & dt) const;
std::string to_string(const char * format) const;
+ std::string to_string(const std::string & format) const
+ {
+ return to_string(format.c_str());
+ }
std::string to_short_time_string() const;
std::string to_iso8601() const;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]