Add:core:Added cut/copy/paste for bookmarks
authorakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 27 Mar 2010 18:55:11 +0000 (18:55 +0000)
committerakashihi <akashihi@ffa7fe5e-494d-0410-b361-a75ebd5db220>
Sat, 27 Mar 2010 18:55:11 +0000 (18:55 +0000)
git-svn-id: https://navit.svn.sourceforge.net/svnroot/navit/trunk@3089 ffa7fe5e-494d-0410-b361-a75ebd5db220

navit/navit/bookmarks.c
navit/navit/bookmarks.h

index 8dd1d19..595923b 100644 (file)
@@ -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;
index 203e64d..8b1c83c 100644 (file)
@@ -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_);