Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * savecopy.c
- *
- * https://www.geany.org/manual/reference/howto.html
- *
- * yum install intltool geany-devel
- *
- * gcc -c savecopy.c -fPIC `pkg-config --cflags geany`
- * gcc savecopy.o -o savecopy.so -shared `pkg-config --libs geany`
- *
- * Copyright 2018 Nikolay <xeritt(at)gmail.com>
- *
- * 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 2 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, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
- #include <geanyplugin.h>
- static void write_data(const gchar *filename, const gchar *data){
- gint error_nr = utils_write_file(filename, data);
- gchar *utf8_filename = utils_get_utf8_from_locale(filename);
- if (error_nr == 0)
- ui_set_statusbar(TRUE, _("Document successfully exported as '%s'."), utf8_filename);
- else
- ui_set_statusbar(TRUE, _("File '%s' could not be written (%s)."),
- utf8_filename, g_strerror(error_nr));
- g_free(utf8_filename);
- }
- static void item_activate_cb(GtkMenuItem *menuitem, gpointer user_data){
- GeanyDocument *doc;
- doc = document_get_current();
- gint doc_len, i;
- gchar c, c_next;
- doc_len = sci_get_length(doc->editor->sci);
- GString *body;
- body = g_string_new("");
- char new_name[doc_len];
- sprintf(new_name, "%s_copy", doc->file_name);
- for (i = 0; i < doc_len; i++){
- c = sci_get_char_at(doc->editor->sci, i);
- g_string_append_c(body, c);
- }
- write_data(new_name, body->str);
- g_string_free(body, TRUE);
- }
- static gboolean save_init(GeanyPlugin *plugin, gpointer pdata){
- GtkWidget *main_menu_item;
- // Create a new menu item and show it
- main_menu_item = gtk_menu_item_new_with_mnemonic("Save copy");
- gtk_widget_show(main_menu_item);
- gtk_container_add(GTK_CONTAINER(plugin->geany_data->main_widgets->tools_menu),
- main_menu_item);
- g_signal_connect(main_menu_item, "activate",
- G_CALLBACK(item_activate_cb), NULL);
- geany_plugin_set_data(plugin, main_menu_item, NULL);
- return TRUE;
- }
- static void save_cleanup(GeanyPlugin *plugin, gpointer pdata)
- {
- GtkWidget *main_menu_item = (GtkWidget *) pdata;
- gtk_widget_destroy(main_menu_item);
- }
- G_MODULE_EXPORT
- void geany_load_module(GeanyPlugin *plugin)
- {
- /* Step 1: Set metadata */
- plugin->info->name = "Save Copy";
- plugin->info->description = "Just save copy document";
- plugin->info->version = "1.0";
- plugin->info->author = "Nikolay <xeritt@gmail.com>";
- /* Step 2: Set functions */
- plugin->funcs->init = save_init;
- plugin->funcs->cleanup = save_cleanup;
- /* Step 3: Register! */
- GEANY_PLUGIN_REGISTER(plugin, 225);
- /* alternatively:
- GEANY_PLUGIN_REGISTER_FULL(plugin, 225, data, free_func); */
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement