git-svn-id: https://xournal.svn.sourceforge.net/svnroot/xournal/trunk/xournalpp@76 9fe2bcd3-a095-4d8b-a836-9b85dc8d7627presentation
parent
efd8af6eef
commit
a82d0800a6
21 changed files with 733 additions and 198 deletions
@ -0,0 +1,165 @@ |
||||
#include "ToolbarDialog.h" |
||||
#include "../toolbarMenubar/model/ToolbarData.h" |
||||
#include "../toolbarMenubar/model/ToolbarModel.h" |
||||
|
||||
#include <config.h> |
||||
#include <glib/gi18n-lib.h> |
||||
|
||||
enum { |
||||
COLUMN_STRING, COLUMN_BOLD, COLUMN_POINTER, COLUMN_EDITABLE, N_COLUMNS |
||||
}; |
||||
|
||||
ToolbarDialog::ToolbarDialog(GladeSearchpath * gladeSearchPath, ToolbarModel * model) : |
||||
GladeGui(gladeSearchPath, "toolbar.glade", "DialogEditToolbar") { |
||||
|
||||
this->tbModel = model; |
||||
this->selected = NULL; |
||||
|
||||
GtkTreeIter iter; |
||||
this->model = gtk_list_store_new(N_COLUMNS, G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER, G_TYPE_BOOLEAN); |
||||
gtk_list_store_append(this->model, &iter); |
||||
gtk_list_store_set(this->model, &iter, COLUMN_STRING, _("Predefined"), COLUMN_BOLD, PANGO_WEIGHT_BOLD, COLUMN_POINTER, NULL, COLUMN_EDITABLE, false, -1); |
||||
|
||||
ListIterator<ToolbarData *> it = model->iterator(); |
||||
|
||||
while (it.hasNext()) { |
||||
ToolbarData * data = it.next(); |
||||
if (data->isPredefined()) { |
||||
gtk_list_store_append(this->model, &iter); |
||||
gtk_list_store_set(this->model, &iter, COLUMN_STRING, data->getName().c_str(), COLUMN_BOLD, PANGO_WEIGHT_NORMAL, COLUMN_POINTER, data, |
||||
COLUMN_EDITABLE, false, -1); |
||||
} |
||||
} |
||||
|
||||
gtk_list_store_append(this->model, &iter); |
||||
gtk_list_store_set(this->model, &iter, COLUMN_STRING, _("Customized"), COLUMN_BOLD, PANGO_WEIGHT_BOLD, COLUMN_POINTER, NULL, COLUMN_EDITABLE, false, -1); |
||||
|
||||
ListIterator<ToolbarData *> it2 = model->iterator(); |
||||
|
||||
while (it2.hasNext()) { |
||||
ToolbarData * data = it2.next(); |
||||
if (!data->isPredefined()) { |
||||
gtk_list_store_append(this->model, &iter); |
||||
gtk_list_store_set(this->model, &iter, COLUMN_STRING, data->getName().c_str(), COLUMN_BOLD, PANGO_WEIGHT_NORMAL, COLUMN_POINTER, data, |
||||
COLUMN_EDITABLE, true, -1); |
||||
} |
||||
} |
||||
|
||||
GtkWidget * tree = get("toolbarList"); |
||||
gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(this->model)); |
||||
|
||||
GtkCellRenderer * renderer = gtk_cell_renderer_text_new(); |
||||
GtkTreeViewColumn * column = gtk_tree_view_column_new_with_attributes(_("Toolbars"), renderer, "text", COLUMN_STRING, "weight", COLUMN_BOLD, "editable", |
||||
COLUMN_EDITABLE, NULL); |
||||
|
||||
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column); |
||||
//gtk_tree_view_set_column_drag_function
|
||||
|
||||
GtkTreeSelection * select = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree)); |
||||
gtk_tree_selection_set_mode(select, GTK_SELECTION_SINGLE); |
||||
g_signal_connect(G_OBJECT(select), "changed", G_CALLBACK (treeSelectionChangedCallback), this); |
||||
|
||||
g_signal_connect(renderer, "edited", (GCallback) treeCellEditedCallback, this); |
||||
|
||||
g_signal_connect(get("btNew"), "clicked", G_CALLBACK(buttonNewCallback), this); |
||||
g_signal_connect(get("btDelete"), "clicked", G_CALLBACK(buttonDeleteCallback), this); |
||||
g_signal_connect(get("btCopy"), "clicked", G_CALLBACK(buttonCopyCallback), this); |
||||
|
||||
entrySelected(NULL); |
||||
} |
||||
|
||||
ToolbarDialog::~ToolbarDialog() { |
||||
g_object_unref(this->model); |
||||
this->tbModel = NULL; |
||||
} |
||||
|
||||
void ToolbarDialog::buttonNewCallback(GtkButton * button, ToolbarDialog * dlg) { |
||||
ToolbarData * data = new ToolbarData(false); |
||||
data->setName(_("New")); |
||||
dlg->addToolbarData(data); |
||||
} |
||||
|
||||
void ToolbarDialog::buttonDeleteCallback(GtkButton * button, ToolbarDialog * dlg) { |
||||
if (dlg->selected) { |
||||
dlg->tbModel->remove(dlg->selected); |
||||
GtkTreeIter iter; |
||||
if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(dlg->model), &iter)) { |
||||
do { |
||||
ToolbarData * data = NULL; |
||||
gtk_tree_model_get(GTK_TREE_MODEL(dlg->model), &iter, COLUMN_POINTER, &data, -1); |
||||
|
||||
if (data == dlg->selected) { |
||||
gtk_list_store_remove(dlg->model, &iter); |
||||
break; |
||||
} |
||||
} while (gtk_tree_model_iter_next(GTK_TREE_MODEL(dlg->model), &iter)); |
||||
} |
||||
|
||||
dlg->entrySelected(NULL); |
||||
} |
||||
} |
||||
|
||||
void ToolbarDialog::buttonCopyCallback(GtkButton * button, ToolbarDialog * dlg) { |
||||
if (dlg->selected) { |
||||
ToolbarData * data = new ToolbarData(*dlg->selected); |
||||
dlg->addToolbarData(data); |
||||
} |
||||
} |
||||
|
||||
void ToolbarDialog::addToolbarData(ToolbarData * data) { |
||||
this->tbModel->add(data); |
||||
GtkTreeIter iter; |
||||
gtk_list_store_append(this->model, &iter); |
||||
gtk_list_store_set(this->model, &iter, COLUMN_STRING, data->getName().c_str(), COLUMN_BOLD, PANGO_WEIGHT_NORMAL, COLUMN_POINTER, data, COLUMN_EDITABLE, |
||||
true, -1); |
||||
|
||||
GtkWidget * tree = get("toolbarList"); |
||||
|
||||
GtkTreePath * path = gtk_tree_model_get_path(GTK_TREE_MODEL(this->model), &iter); |
||||
GtkTreeViewColumn * column = gtk_tree_view_get_column(GTK_TREE_VIEW(tree), 0); |
||||
|
||||
gtk_tree_view_set_cursor(GTK_TREE_VIEW(tree), path, column, true); |
||||
} |
||||
|
||||
void ToolbarDialog::treeCellEditedCallback(GtkCellRendererText * renderer, gchar * pathString, gchar * newText, ToolbarDialog * dlg) { |
||||
GtkTreeIter iter; |
||||
ToolbarData * data = NULL; |
||||
|
||||
gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(dlg->model), &iter, pathString); |
||||
gtk_tree_model_get(GTK_TREE_MODEL(dlg->model), &iter, COLUMN_POINTER, &data, -1); |
||||
if (data) { |
||||
gtk_list_store_set(dlg->model, &iter, COLUMN_STRING, newText, -1); |
||||
data->setName(newText); |
||||
} |
||||
} |
||||
|
||||
void ToolbarDialog::entrySelected(ToolbarData * data) { |
||||
GtkWidget * btCopy = get("btCopy"); |
||||
GtkWidget * btDelete = get("btDelete"); |
||||
|
||||
if (data == NULL) { |
||||
gtk_widget_set_sensitive(btCopy, false); |
||||
gtk_widget_set_sensitive(btDelete, false); |
||||
} else { |
||||
gtk_widget_set_sensitive(btCopy, true); |
||||
gtk_widget_set_sensitive(btDelete, !data->isPredefined()); |
||||
} |
||||
|
||||
this->selected = data; |
||||
} |
||||
|
||||
void ToolbarDialog::treeSelectionChangedCallback(GtkTreeSelection * selection, ToolbarDialog * dlg) { |
||||
GtkTreeIter iter; |
||||
GtkTreeModel * model = NULL; |
||||
ToolbarData * data = NULL; |
||||
|
||||
if (gtk_tree_selection_get_selected(selection, &model, &iter)) { |
||||
gtk_tree_model_get(model, &iter, COLUMN_POINTER, &data, -1); |
||||
dlg->entrySelected(data); |
||||
} |
||||
} |
||||
|
||||
void ToolbarDialog::show() { |
||||
gtk_dialog_run(GTK_DIALOG(this->window)); |
||||
gtk_widget_hide(this->window); |
||||
} |
||||
@ -0,0 +1,46 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* Toolbar edit dialog |
||||
* |
||||
* @author Xournal Team |
||||
* http://xournal.sf.net
|
||||
* |
||||
* @license GPL |
||||
*/ |
||||
|
||||
#ifndef __TOOLBARDIALOG_H__ |
||||
#define __TOOLBARDIALOG_H__ |
||||
|
||||
#include "../GladeGui.h" |
||||
|
||||
class ToolbarModel; |
||||
class ToolbarData; |
||||
|
||||
class ToolbarDialog: public GladeGui { |
||||
public: |
||||
ToolbarDialog(GladeSearchpath * gladeSearchPath, ToolbarModel * model); |
||||
virtual ~ToolbarDialog(); |
||||
|
||||
public: |
||||
void show(); |
||||
|
||||
private: |
||||
static void treeSelectionChangedCallback(GtkTreeSelection * selection, ToolbarDialog * dlg); |
||||
static void treeCellEditedCallback(GtkCellRendererText * renderer, gchar * pathString, gchar * newText, ToolbarDialog * dlg); |
||||
|
||||
static void buttonNewCallback(GtkButton * button, ToolbarDialog * dlg); |
||||
static void buttonDeleteCallback(GtkButton * button, ToolbarDialog * dlg); |
||||
static void buttonCopyCallback(GtkButton * button, ToolbarDialog * dlg); |
||||
|
||||
void addToolbarData(ToolbarData * data); |
||||
void entrySelected(ToolbarData * data); |
||||
|
||||
private: |
||||
ToolbarModel * tbModel; |
||||
GtkListStore * model; |
||||
|
||||
ToolbarData * selected; |
||||
}; |
||||
|
||||
#endif /* __TOOLBARDIALOG_H__ */ |
||||
@ -0,0 +1,58 @@ |
||||
#include "ToolbarData.h" |
||||
#include <string.h> |
||||
|
||||
ToolbarData::ToolbarData(bool predefined) { |
||||
this->predefined = predefined; |
||||
} |
||||
|
||||
String ToolbarData::getName() { |
||||
return this->name; |
||||
} |
||||
|
||||
void ToolbarData::setName(String name) { |
||||
this->name = name; |
||||
} |
||||
|
||||
String ToolbarData::getId() { |
||||
return this->id; |
||||
} |
||||
|
||||
bool ToolbarData::isPredefined() { |
||||
return this->predefined; |
||||
} |
||||
|
||||
void ToolbarData::load(GKeyFile * config, const char * group) { |
||||
gsize length = 0; |
||||
gchar ** keys = g_key_file_get_keys(config, group, &length, NULL); |
||||
if (keys == NULL) { |
||||
return; |
||||
} |
||||
|
||||
gchar * name = g_key_file_get_locale_string(config, group, "name", NULL, NULL); |
||||
if (name != NULL) { |
||||
this->name = name; |
||||
g_free(name); |
||||
} |
||||
|
||||
for (gsize i = 0; i < length; i++) { |
||||
if (strcmp(keys[i], "name") == 0 || strncmp(keys[i], "name[", 5) == 0) { |
||||
continue; |
||||
} |
||||
|
||||
ToolbarEntry e; |
||||
gsize keyLen = 0; |
||||
e.name = keys[i]; |
||||
gchar ** list = g_key_file_get_string_list(config, group, keys[i], &keyLen, NULL); |
||||
|
||||
for (gsize x = 0; x < keyLen; x++) { |
||||
String s = list[x]; |
||||
e.entries.push_back(s.trim()); |
||||
} |
||||
|
||||
contents.push_back(e); |
||||
|
||||
g_strfreev(list); |
||||
} |
||||
|
||||
g_strfreev(keys); |
||||
} |
||||
@ -0,0 +1,44 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* Toolbar definitions model |
||||
* |
||||
* @author Xournal Team |
||||
* http://xournal.sf.net
|
||||
* |
||||
* @license GPL |
||||
*/ |
||||
|
||||
#ifndef __TOOLBARDATA_H__ |
||||
#define __TOOLBARDATA_H__ |
||||
|
||||
#include <glib.h> |
||||
#include "../../../util/String.h" |
||||
#include <vector> |
||||
|
||||
#include "ToolbarEntry.h" |
||||
|
||||
class ToolbarData { |
||||
public: |
||||
ToolbarData(bool predefined); |
||||
|
||||
public: |
||||
String getName(); |
||||
void setName(String name); |
||||
String getId(); |
||||
|
||||
void load(GKeyFile * config, const char * group); |
||||
|
||||
bool isPredefined(); |
||||
private: |
||||
String id; |
||||
String name; |
||||
std::vector<ToolbarEntry> contents; |
||||
|
||||
bool predefined; |
||||
|
||||
friend class ToolbarModel; |
||||
friend class ToolMenuHandler; |
||||
}; |
||||
|
||||
#endif /* __TOOLBARDATA_H__ */ |
||||
@ -0,0 +1,103 @@ |
||||
#include "ToolbarModel.h" |
||||
#include "ToolbarData.h" |
||||
|
||||
#include <string.h> |
||||
|
||||
ToolbarModel::ToolbarModel() { |
||||
this->toolbars = NULL; |
||||
this->colorNameTable = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); |
||||
} |
||||
|
||||
ToolbarModel::~ToolbarModel() { |
||||
for (GList * l = this->toolbars; l != NULL; l = l->next) { |
||||
delete (ToolbarData *) l->data; |
||||
} |
||||
g_list_free(this->toolbars); |
||||
this->toolbars = NULL; |
||||
|
||||
g_hash_table_destroy(this->colorNameTable); |
||||
this->colorNameTable = NULL; |
||||
} |
||||
|
||||
ListIterator<ToolbarData *> ToolbarModel::iterator() { |
||||
return ListIterator<ToolbarData *> (this->toolbars); |
||||
} |
||||
|
||||
void ToolbarModel::parseGroup(GKeyFile * config, const char * group, bool predefined) { |
||||
ToolbarData * data = new ToolbarData(predefined); |
||||
|
||||
String name; |
||||
if (predefined) { |
||||
name = "predef_"; |
||||
} else { |
||||
name = "custom_"; |
||||
} |
||||
|
||||
data->name = name; |
||||
data->id = group; |
||||
|
||||
data->load(config, group); |
||||
|
||||
add(data); |
||||
} |
||||
|
||||
void ToolbarModel::remove(ToolbarData * data) { |
||||
this->toolbars = g_list_remove(this->toolbars, data); |
||||
} |
||||
|
||||
void ToolbarModel::add(ToolbarData * data) { |
||||
this->toolbars = g_list_append(this->toolbars, data); |
||||
} |
||||
|
||||
const char * ToolbarModel::getColorName(const char * color) { |
||||
const char * name = (char *) g_hash_table_lookup(this->colorNameTable, color); |
||||
return name; |
||||
} |
||||
|
||||
bool ToolbarModel::parse(const char * file, bool predefined) { |
||||
GKeyFile * config = g_key_file_new(); |
||||
g_key_file_set_list_separator(config, ','); |
||||
if (!g_key_file_load_from_file(config, file, G_KEY_FILE_NONE, NULL)) { |
||||
g_key_file_free(config); |
||||
return false; |
||||
} |
||||
|
||||
gsize lenght = 0; |
||||
gchar ** groups = g_key_file_get_groups(config, &lenght); |
||||
|
||||
for (gsize i = 0; i < lenght; i++) { |
||||
if (groups[i][0] == '_') { |
||||
if (strcmp("_ColorNames", groups[i]) == 0) { |
||||
parseColors(config, groups[i]); |
||||
} |
||||
|
||||
continue; |
||||
} |
||||
|
||||
parseGroup(config, groups[i], predefined); |
||||
} |
||||
|
||||
g_strfreev(groups); |
||||
g_key_file_free(config); |
||||
return true; |
||||
} |
||||
|
||||
void ToolbarModel::parseColors(GKeyFile * config, const char * group) { |
||||
gsize length = 0; |
||||
gchar ** keys = g_key_file_get_keys(config, group, &length, NULL); |
||||
if (keys == NULL) { |
||||
return; |
||||
} |
||||
|
||||
for (gsize i = 0; i < length; i++) { |
||||
if (strstr(keys[i], "[")) { |
||||
// skip localized keys
|
||||
continue; |
||||
} |
||||
|
||||
char * name = g_key_file_get_locale_string(config, group, keys[i], NULL, NULL); |
||||
g_hash_table_insert(this->colorNameTable, g_strdup(keys[i]), name); |
||||
} |
||||
|
||||
g_strfreev(keys); |
||||
} |
||||
@ -0,0 +1,41 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* Toolbar definitions model |
||||
* |
||||
* @author Xournal Team |
||||
* http://xournal.sf.net
|
||||
* |
||||
* @license GPL |
||||
*/ |
||||
|
||||
#ifndef __TOOLBARMODEL_H__ |
||||
#define __TOOLBARMODEL_H__ |
||||
|
||||
#include <glib.h> |
||||
#include "../../../util/ListIterator.h" |
||||
|
||||
class ToolbarData; |
||||
|
||||
class ToolbarModel { |
||||
public: |
||||
ToolbarModel(); |
||||
virtual ~ToolbarModel(); |
||||
|
||||
public: |
||||
ListIterator<ToolbarData *> iterator(); |
||||
bool parse(const char * file, bool predefined); |
||||
const char * getColorName(const char * color); |
||||
void add(ToolbarData * data); |
||||
void remove(ToolbarData * data); |
||||
|
||||
private: |
||||
void parseGroup(GKeyFile * config, const char * group, bool predefined); |
||||
void parseColors(GKeyFile * config, const char * group); |
||||
|
||||
private: |
||||
GList * toolbars; |
||||
GHashTable * colorNameTable; |
||||
}; |
||||
|
||||
#endif /* __TOOLBARMODEL_H__ */ |
||||
@ -0,0 +1,129 @@ |
||||
<?xml version="1.0"?> |
||||
<glade-interface> |
||||
<!-- interface-requires gtk+ 2.16 --> |
||||
<!-- interface-naming-policy project-wide --> |
||||
<widget class="GtkDialog" id="DialogEditToolbar"> |
||||
<property name="border_width">5</property> |
||||
<property name="title" translatable="yes">Edit Toolbar</property> |
||||
<property name="icon">pixmaps/xournalpp.svg</property> |
||||
<property name="type_hint">normal</property> |
||||
<property name="has_separator">False</property> |
||||
<child internal-child="vbox"> |
||||
<widget class="GtkVBox" id="dialog-vbox1"> |
||||
<property name="visible">True</property> |
||||
<property name="orientation">vertical</property> |
||||
<property name="spacing">2</property> |
||||
<child> |
||||
<widget class="GtkVBox" id="vbox1"> |
||||
<property name="visible">True</property> |
||||
<property name="orientation">vertical</property> |
||||
<child> |
||||
<widget class="GtkHBox" id="hbox1"> |
||||
<property name="visible">True</property> |
||||
<child> |
||||
<widget class="GtkTreeView" id="toolbarList"> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
</widget> |
||||
<packing> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<widget class="GtkVBox" id="vbox2"> |
||||
<property name="visible">True</property> |
||||
<property name="orientation">vertical</property> |
||||
<child> |
||||
<widget class="GtkButton" id="btNew"> |
||||
<property name="label">gtk-new</property> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="receives_default">True</property> |
||||
<property name="use_stock">True</property> |
||||
</widget> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="padding">2</property> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<widget class="GtkButton" id="btDelete"> |
||||
<property name="label">gtk-delete</property> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="receives_default">True</property> |
||||
<property name="use_stock">True</property> |
||||
</widget> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="padding">3</property> |
||||
<property name="position">1</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<widget class="GtkButton" id="btCopy"> |
||||
<property name="label">gtk-copy</property> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="receives_default">True</property> |
||||
<property name="use_stock">True</property> |
||||
</widget> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="padding">2</property> |
||||
<property name="position">2</property> |
||||
</packing> |
||||
</child> |
||||
</widget> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="padding">5</property> |
||||
<property name="position">1</property> |
||||
</packing> |
||||
</child> |
||||
</widget> |
||||
<packing> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
<child> |
||||
<placeholder/> |
||||
</child> |
||||
<child> |
||||
<placeholder/> |
||||
</child> |
||||
</widget> |
||||
<packing> |
||||
<property name="position">1</property> |
||||
</packing> |
||||
</child> |
||||
<child internal-child="action_area"> |
||||
<widget class="GtkHButtonBox" id="dialog-action_area1"> |
||||
<property name="visible">True</property> |
||||
<property name="layout_style">end</property> |
||||
<child> |
||||
<widget class="GtkButton" id="button4"> |
||||
<property name="label">gtk-close</property> |
||||
<property name="visible">True</property> |
||||
<property name="can_focus">True</property> |
||||
<property name="receives_default">True</property> |
||||
<property name="use_stock">True</property> |
||||
</widget> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="fill">False</property> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
</widget> |
||||
<packing> |
||||
<property name="expand">False</property> |
||||
<property name="pack_type">end</property> |
||||
<property name="position">0</property> |
||||
</packing> |
||||
</child> |
||||
</widget> |
||||
</child> |
||||
</widget> |
||||
</glade-interface> |
||||
Loading…
Reference in new issue