summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-03-27 18:55:11 +0000
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>2010-03-27 18:55:11 +0000
commite89d32b22816459b9540bafef48688cbdb32abe0 (patch)
tree07620861fdf44380b3dade68b278fc8ce176cd94
parent6832ed4a0fcdf0f96ab3e47a790c585e1b1508b4 (diff)
downloadnavit-svn-e89d32b22816459b9540bafef48688cbdb32abe0.tar.gz
Add:core:Added cut/copy/paste for bookmarks
git-svn-id: http://svn.code.sf.net/p/navit/code/trunk/navit/navit@3089 ffa7fe5e-494d-0410-b361-a75ebd5db220
-rw-r--r--bookmarks.c57
-rw-r--r--bookmarks.h3
2 files changed, 59 insertions, 1 deletions
diff --git a/bookmarks.c b/bookmarks.c
index 8dd1d190..595923bc 100644
--- a/bookmarks.c
+++ b/bookmarks.c
@@ -36,6 +36,7 @@ struct bookmarks {
GList *bookmarks_list;
char* bookmark_file;
char *working_file;
+ struct bookmark_item_priv* clipboard;
//Refs to other objects
struct transformation *trans;
@@ -116,6 +117,8 @@ bookmarks_new(struct attr *parent, /*struct attr **attrs,*/struct transformation
bookmarks_load_hash(this_);
}
+ this_->clipboard=g_new0(struct bookmark_item_priv,1);
+
return this_;
}
@@ -130,6 +133,8 @@ bookmarks_destroy(struct bookmarks *this_) {
g_free(this_->bookmark_file);
g_free(this_->working_file);
+ g_free(this_->clipboard);
+
g_free(this_);
}
@@ -298,7 +303,7 @@ bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *pc, const char *d
b_item.c.x=pc->x;
b_item.c.y=pc->y;
- b_item.label=description;
+ b_item.label=(char *)description;
b_item.type=type_bookmark;
this_->bookmarks_list=g_list_first(this_->bookmarks_list);
@@ -314,6 +319,56 @@ bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *pc, const char *d
}
int
+bookmarks_cut_bookmark(struct bookmarks *this_, const char *description) {
+ if (bookmarks_copy_bookmark(this_,description)) {
+ return bookmarks_del_bookmark(this_,description);
+ }
+
+ return FALSE;
+}
+int
+bookmarks_copy_bookmark(struct bookmarks *this_, const char *description) {
+ struct bookmark_item_priv *b_item;
+ b_item=(struct bookmark_item_priv*)g_hash_table_lookup(this_->bookmarks_hash,description);
+ if (b_item) {
+ this_->clipboard->c=b_item->c;
+ this_->clipboard->type=b_item->type;
+ if (!this_->clipboard->label) {
+ g_free(this_->clipboard->label);
+ }
+ this_->clipboard->label=g_strdup(b_item->label);
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+int
+bookmarks_paste_bookmark(struct bookmarks *this_, const char* path) {
+ char *fullLabel;
+ int result;
+ struct pcoord pc;
+
+ //check, if we need to add a trailing "/" to path
+ if (path[strlen(path)-1]!='/') {
+ fullLabel=g_strjoin(NULL,path,"/",this_->clipboard->label,NULL);
+ } else {
+ fullLabel=g_strjoin(NULL,path,this_->clipboard->label,NULL);
+ }
+
+ pc.x=this_->clipboard->c.x;
+ pc.y=this_->clipboard->c.y;
+ pc.pro=projection_mg; //Bookmarks are always stored in mg
+
+ result=bookmarks_add_bookmark(this_,&pc,fullLabel);
+
+ g_free(fullLabel);
+
+ return result;
+}
+
+
+int
bookmarks_del_bookmark(struct bookmarks *this_, const char *description) {
struct bookmark_item_priv *b_item;
int result;
diff --git a/bookmarks.h b/bookmarks.h
index 203e64de..8b1c83c7 100644
--- a/bookmarks.h
+++ b/bookmarks.h
@@ -30,6 +30,9 @@ struct bookmarks *bookmarks_new(struct attr *parent,/* struct attr **attrs,*/ st
void bookmarks_destroy(struct bookmarks *this_);
void bookmarks_add_callback(struct bookmarks *this_, struct callback *cb);
int bookmarks_add_bookmark(struct bookmarks *this_, struct pcoord *c, const char *description);
+int bookmarks_cut_bookmark(struct bookmarks *this_, const char *description);
+int bookmarks_copy_bookmark(struct bookmarks *this_, const char *description);
+int bookmarks_paste_bookmark(struct bookmarks *this_, const char *path);
int bookmarks_del_bookmark(struct bookmarks *this_, const char *description);
struct map* bookmarks_get_map(struct bookmarks *this_);