summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2019-01-11 08:35:13 +0000
committerMarc Jeanmougin <marc@jeanmougin.fr>2019-01-11 08:35:13 +0000
commit513b467b11116b80e576e273285cc7f5356e6adf (patch)
treef098fc4ec7a6e395ca61957f8d0717d6e008880f /src
parentPrevent window from stealing key presses. (diff)
downloadinkscape-513b467b11116b80e576e273285cc7f5356e6adf.tar.gz
inkscape-513b467b11116b80e576e273285cc7f5356e6adf.zip
Add button to delete prefs
Diffstat (limited to 'src')
-rw-r--r--src/preferences.cpp39
-rw-r--r--src/preferences.h4
-rw-r--r--src/ui/dialog/inkscape-preferences.cpp10
-rw-r--r--src/ui/dialog/inkscape-preferences.h1
4 files changed, 44 insertions, 10 deletions
diff --git a/src/preferences.cpp b/src/preferences.cpp
index 51c363fce..4321b9e0d 100644
--- a/src/preferences.cpp
+++ b/src/preferences.cpp
@@ -160,15 +160,6 @@ void Preferences::_load()
g_free(msg);
return;
}
- // create some subdirectories for user stuff
- char const *user_dirs[] = {"extensions", "fonts", "icons", "keys", "palettes", "templates", nullptr};
- for (int i=0; user_dirs[i]; ++i) {
- // XXX Why are we doing this here? shouldn't this be an IO load item?
- char *dir = Inkscape::IO::Resource::profile_path(user_dirs[i]);
- g_mkdir(dir, 0755);
- g_free(dir);
- }
-
} else if (!g_file_test(_prefs_dir, G_FILE_TEST_IS_DIR)) {
// The profile dir is not actually a directory
//_reportError(Glib::ustring::compose(_("%1 is not a valid directory."),
@@ -178,6 +169,15 @@ void Preferences::_load()
g_free(msg);
return;
}
+ // create some subdirectories for user stuff
+ char const *user_dirs[] = {"extensions", "fonts", "icons", "keys", "palettes", "templates", nullptr};
+ for (int i=0; user_dirs[i]; ++i) {
+ // XXX Why are we doing this here? shouldn't this be an IO load item?
+ char *dir = Inkscape::IO::Resource::profile_path(user_dirs[i]);
+ if (!g_file_test(dir, G_FILE_TEST_EXISTS))
+ g_mkdir(dir, 0755);
+ g_free(dir);
+ }
// The profile dir exists and is valid.
if (!g_file_set_contents(_prefs_filename.c_str(), preferences_skeleton, PREFERENCES_SKELETON_SIZE, nullptr)) {
// The write failed.
@@ -292,6 +292,27 @@ void Preferences::save()
}
}
+/**
+ * Deletes the preferences.xml file
+ */
+void Preferences::reset()
+{
+ if (g_file_test(_prefs_filename.c_str(), G_FILE_TEST_EXISTS)) {
+ int retcode = g_unlink (_prefs_filename.c_str());
+ if (retcode == 0) g_strdup_printf(_("Preferences file was deleted."));
+ else g_warning(_("There was an error trying to delete the preferences file."));
+ }
+ for (_ObsMap::iterator i = _observer_map.begin(); i != _observer_map.end(); ) {
+ delete (*i++).second; // avoids reference to a deleted key
+ }
+ _observer_map.clear();
+ Inkscape::GC::release(_prefs_doc);
+ _prefs_doc = nullptr;
+ _loadDefaults();
+ _load();
+ save();
+}
+
bool Preferences::getLastError( Glib::ustring& primary, Glib::ustring& secondary )
{
bool result = _hasError;
diff --git a/src/preferences.h b/src/preferences.h
index 96b8074de..0b3f8ff16 100644
--- a/src/preferences.h
+++ b/src/preferences.h
@@ -272,6 +272,10 @@ public:
void save();
/**
+ * Deletes the preferences.xml file.
+ */
+ void reset();
+ /**
* Check whether saving the preferences will have any effect.
*/
bool isWritable() { return _writable; }
diff --git a/src/ui/dialog/inkscape-preferences.cpp b/src/ui/dialog/inkscape-preferences.cpp
index 429fab403..789d45551 100644
--- a/src/ui/dialog/inkscape-preferences.cpp
+++ b/src/ui/dialog/inkscape-preferences.cpp
@@ -2300,8 +2300,11 @@ void InkscapePreferences::initPageSystem()
_sys_user_prefs.set_text(prefs->getPrefsFilename());
_sys_user_prefs.set_editable(false);
+ Gtk::Button* reset_prefs = Gtk::manage(new Gtk::Button(_("Reset Preferences")));
+ reset_prefs->signal_clicked().connect(sigc::mem_fun(*this, &InkscapePreferences::on_reset_prefs_clicked));
+
_page_system.add_line(true, _("User preferences: "), _sys_user_prefs, "",
- _("Location of the user’s preferences file"), true);
+ _("Location of the user’s preferences file"), true, reset_prefs);
_sys_user_config.init((char const *)Inkscape::IO::Resource::profile_path(""), _("Open preferences folder"));
_page_system.add_line(true, _("User config: "), _sys_user_config, "", _("Location of users configuration"), true);
@@ -2446,6 +2449,11 @@ void InkscapePreferences::on_reset_open_recent_clicked()
}
}
+void InkscapePreferences::on_reset_prefs_clicked()
+{
+ Inkscape::Preferences::get()->reset();
+}
+
void InkscapePreferences::on_pagelist_selection_changed()
{
// show new selection
diff --git a/src/ui/dialog/inkscape-preferences.h b/src/ui/dialog/inkscape-preferences.h
index f375a4cab..ef7c64c07 100644
--- a/src/ui/dialog/inkscape-preferences.h
+++ b/src/ui/dialog/inkscape-preferences.h
@@ -555,6 +555,7 @@ protected:
void on_pagelist_selection_changed();
void on_reset_open_recent_clicked();
+ void on_reset_prefs_clicked();
void initPageTools();
void initPageUI();