Esempio n. 1
0
static void on_program_ok_button_clicked(G_GNUC_UNUSED GtkButton *button,
	G_GNUC_UNUSED gpointer gdata)
{
	if (check_dialog_path(program_exec_entry, TRUE, R_OK | X_OK) &&
		check_dialog_path(working_dir_entry, FALSE, X_OK) &&
		check_dialog_path(load_script_entry, TRUE, R_OK))
	{
		const gchar *program_name = gtk_entry_get_text(program_exec_entry);

		if (*program_name == '\0')
			program_name = gtk_entry_get_text(load_script_entry);

		if (utils_filenamecmp(program_name, *program_executable ? program_executable :
			program_load_script))
		{
			save_program_settings();
		}

		stash_foreach((GFunc) stash_group_update, NULL);
		option_long_mr_format = dialog_long_mr_format;
		g_free(program_environment);
		program_environment = utils_text_buffer_get_text(environment, -1);
		save_program_settings();
		program_configure();
		gtk_widget_hide(program_dialog);

		if (gtk_toggle_button_get_active(delete_all_items) &&
			dialogs_show_question(_("Delete all breakpoints, watches and inspects?")))
		{
			breaks_delete_all();
			watches_delete_all();
			inspects_delete_all();
		}
	}
}
Esempio n. 2
0
/*
 * env tree view value changed hadler 
 */
static void on_value_changed(GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer user_data)
{
	GtkTreeIter  iter;
    GtkTreePath *tree_path = gtk_tree_path_new_from_string (path);
    
	gboolean empty = !gtk_tree_path_compare(tree_path, gtk_tree_row_reference_get_path(empty_row));

	gboolean res = gtk_tree_model_get_iter (
		 model,
		 &iter,
		 tree_path);
	
	gchar *striped = g_strstrip(g_strdup(new_text));
	
	if (!strlen(striped))
	{
		/* if new value is empty string, if it's a new row - do nothig
		 otheerwise - offer to delete a variable */
		if (empty)
			gtk_list_store_set(store, &iter, NAME, "", -1);
		else
		{
			if (dialogs_show_question(_("Delete variable?")))
			{
				delete_selected_rows();
				gtk_widget_grab_focus(envtree);
			}
		}
	}
	else
	{
		/* if old variable - change value, otherwise - add another empty row below */
		gchar* oldvalue;
		gtk_tree_model_get (
			model,
			&iter,
			VALUE, &oldvalue,
		   -1);

		if (strcmp(oldvalue, striped))
		{
			gtk_list_store_set(store, &iter, VALUE, striped, -1);
			if (empty)
				add_empty_row();
			
			g_object_set (renderer_value, "editable", FALSE, NULL);
		}
		
		g_free(oldvalue);
	}
	
	if (empty)
		entering_new_var = FALSE;

	gtk_tree_path_free(tree_path);
	g_free(striped);

	gtk_tree_path_free(being_edited_value);
}
Esempio n. 3
0
static void on_build_start(G_GNUC_UNUSED GObject *obj, G_GNUC_UNUSED gpointer gdata)
{
	if (debug_state() != DS_INACTIVE && dialogs_show_question(_("Build action activated. "
		"Terminate debugging?")))
	{
		on_debug_terminate(NULL);
	}
}
Esempio n. 4
0
void geanypg_encrypt_cb(GtkMenuItem * menuitem, gpointer user_data)
{
    int sign;
    encrypt_data ed;
    gpgme_error_t err;
    geanypg_init_ed(&ed);
    err = gpgme_new(&ed.ctx);
    if (err && geanypg_show_err_msg(err))
        return;
    gpgme_set_armor(ed.ctx, 1);
    gpgme_set_passphrase_cb(ed.ctx, geanypg_passphrase_cb, NULL);
    if (geanypg_get_keys(&ed) && geanypg_get_secret_keys(&ed))
    {
        gpgme_key_t * recp = NULL;
        if (geanypg_encrypt_selection_dialog(&ed, &recp, &sign))
        {
            int flags = 0;
            int stop = 0;
            gpgme_key_t * key = recp;
            while (*key)
            {
                if ((*key)->owner_trust != GPGME_VALIDITY_ULTIMATE &&
                    (*key)->owner_trust != GPGME_VALIDITY_FULL     &&
                    (*key)->owner_trust != GPGME_VALIDITY_MARGINAL)
                {
                    if (dialogs_show_question(_("The key with user ID \"%s\" has validity \"%s\".\n\n"
                        "WARNING: It is NOT certain that the key belongs to the person named in the user ID.\n\n"
                        "Are you *really* sure you want to use this key anyway?"),
                        (*key)->uids->uid, geanypg_validity((*key)->owner_trust)))
                        flags = GPGME_ENCRYPT_ALWAYS_TRUST;
                    else
                        stop = 1;
                }
                ++key;
            }
            if (*recp && !stop)
                geanypg_encrypt(&ed, recp, sign, flags);
            else if (!stop && dialogs_show_question(_("No recipients were selected,\nuse symmetric cipher?")))
                geanypg_encrypt(&ed, NULL, sign, flags);
        }
        if (recp)
            free(recp);
    }
    geanypg_release_keys(&ed);
    gpgme_release(ed.ctx);
}
Esempio n. 5
0
/*
 * env tree view name changed hadler 
 */
static void on_name_changed(GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer user_data)
{
	GtkTreeIter  iter;
	GtkTreePath *tree_path = gtk_tree_path_new_from_string (path);
	GtkTreePath *empty_path = gtk_tree_row_reference_get_path(empty_row);
    
	gboolean empty = !gtk_tree_path_compare(tree_path, empty_path);

	gtk_tree_model_get_iter (
		 model,
		 &iter,
		 tree_path);
	
	gchar* oldvalue;
	gtk_tree_model_get (
		model,
		&iter,
		NAME, &oldvalue,
       -1);
    
	gchar *striped = g_strstrip(g_strdup(new_text));

	if (!strlen(striped))
	{
		/* if name is empty - offer to delete variable */
		if (!empty && dialogs_show_question(_("Delete variable?")))
		{
			delete_selected_rows();
			config_set_debug_changed();

			gtk_widget_grab_focus(tree);
		}
	}
	else if (strcmp(oldvalue, striped))
    {
		gtk_list_store_set(store, &iter, NAME, striped, -1);
		if (empty)
		{
			/* if it was a new row - move cursor to a value cell */
			entering_new_var = TRUE;
			gtk_tree_view_set_cursor_on_cell(GTK_TREE_VIEW(tree), tree_path, column_value, renderer_value, TRUE);
		}
		if (!empty)
		{
			config_set_debug_changed();
		}
	}
	
	gtk_tree_path_free(tree_path);
	gtk_tree_path_free(empty_path);
	g_free(oldvalue);
	g_free(striped);
}
Esempio n. 6
0
static gboolean check_dialog_path(GtkEntry *entry, gboolean file, int mode)
{
	const gchar *pathname = gtk_entry_get_text(entry);

	if (utils_check_path(pathname, file, mode))
		return TRUE;

	if (errno == ENOENT)
	{
		return dialogs_show_question(_("%s: %s.\n\nContinue?"), pathname,
			g_strerror(errno));
	}

	show_errno(pathname);
	return FALSE;
}
Esempio n. 7
0
/* simple file print using an external tool */
static void print_external(GeanyDocument *doc)
{
	gchar *cmdline;

	if (doc->file_name == NULL)
		return;

	if (! NZV(printing_prefs.external_print_cmd))
	{
		dialogs_show_msgbox(GTK_MESSAGE_ERROR,
			_("Please set a print command in the preferences dialog first."));
		return;
	}

	cmdline = g_strdup(printing_prefs.external_print_cmd);
	utils_str_replace_all(&cmdline, "%f", doc->file_name);

	if (dialogs_show_question(
			_("The file \"%s\" will be printed with the following command:\n\n%s"),
			doc->file_name, cmdline))
	{
		GError *error = NULL;

#ifdef G_OS_WIN32
		gchar *tmp_cmdline = g_strdup(cmdline);
#else
		/* /bin/sh -c emulates the system() call and makes complex commands possible
		 * but only needed on non-win32 systems due to the lack of win32's shell capabilities */
		gchar *tmp_cmdline = g_strconcat("/bin/sh -c \"", cmdline, "\"", NULL);
#endif

		if (! g_spawn_command_line_async(tmp_cmdline, &error))
		{
			dialogs_show_msgbox(GTK_MESSAGE_ERROR,
				_("Printing of \"%s\" failed (return code: %s)."),
				doc->file_name, error->message);
			g_error_free(error);
		}
		else
		{
			msgwin_status_add(_("File %s printed."), doc->file_name);
		}
		g_free(tmp_cmdline);
	}
	g_free(cmdline);
}
Esempio n. 8
0
static PyObject *
Dialogs_show_question(PyObject *self, PyObject *args, PyObject *kwargs)
{
    gchar *text = NULL;
    static gchar *kwlist[] = { "text", NULL };

    if (PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &text))
    {
        if (text != NULL)
        {
            if (dialogs_show_question("%s", text))
                Py_RETURN_TRUE;
            else
                Py_RETURN_FALSE;
        }
    }
    Py_RETURN_NONE;
}
Esempio n. 9
0
/* 
 * watch expression has been changed
 */
static void on_watch_changed(GtkCellRendererText *renderer, gchar *path, gchar *new_text, gpointer user_data)
{
	/* get iterator to the changed row */
	GtkTreeIter  iter;
	GtkTreePath *tree_path = gtk_tree_path_new_from_string (path);
	gtk_tree_model_get_iter (
		 gtk_tree_view_get_model(GTK_TREE_VIEW(wtree)),
		 &iter,
		 tree_path);
	
	/* get oldvalue */
	gchar* oldvalue;
	gtk_tree_model_get (
		wmodel,
		&iter,
		W_NAME, &oldvalue,
       -1);
	gchar *internal = NULL;
		gtk_tree_model_get (
		wmodel,
		&iter,
		W_INTERNAL, &internal,
		-1);

	/* check if it is empty row */
	GtkTreePath *empty_path = wtree_empty_path();
	gboolean is_empty_row = !gtk_tree_path_compare (tree_path, empty_path);
	gtk_tree_path_free(empty_path);

   	gchar *striped = g_strstrip(g_strdup(new_text));
	if (!strlen(striped) &&
		!is_empty_row &&
		dialogs_show_question(_("Delete variable?")))
	{
		/* if new value is empty string on non-empty row
		 * offer to delete watch */
		gtk_tree_store_remove(wstore, &iter);
		if (DBS_STOPPED == debug_state)
			active_module->remove_watch(internal);

		config_set_debug_changed();
	}
	else if (strcmp(oldvalue, striped))
    {
		/* new value is non empty */

		/* insert new row if changing was the last empty row */
		GtkTreeIter newiter;
		if (is_empty_row)
			gtk_tree_store_insert_before(wstore, &newiter, NULL, &iter);
		
		/* set expression */
		variable_set_name_only(wstore, is_empty_row ? &newiter : &iter, striped);

		/* if debug is active - remove old watch and add new one */
		if (DBS_STOPPED == debug_state)
		{
			active_module->remove_watch(internal);
			variable *newvar = active_module->add_watch(striped);
			change_watch(GTK_TREE_VIEW(wtree), is_empty_row ? &newiter : &iter, newvar);
		}
		
		/* if new watch has been added - set selection to the new created row */
		if (is_empty_row)
		{
			GtkTreePath *_path = gtk_tree_model_get_path(wmodel, &newiter);
			GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(wtree));
			gtk_tree_selection_unselect_all(selection);
			gtk_tree_selection_select_path(selection, _path);
			gtk_tree_path_free(_path);
		}

		config_set_debug_changed();
	}
	
	/* free resources */
	gtk_tree_path_free(tree_path);
	g_free(oldvalue);
	g_free(internal);
	g_free(striped);
}
Esempio n. 10
0
/* Called by Geany to initialize the plugin */
void plugin_init(GeanyData G_GNUC_UNUSED *data)
{
	GKeyFile *config = g_key_file_new();
	gchar *config_file_old = NULL;
	gchar *config_dir = NULL;
	gchar *config_dir_old = NULL;
	gchar *kb_label = _("Send file by mail");
	GtkWidget *menu_mail = NULL;
	GeanyKeyGroup *key_group;

	config_file = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S,
		"sendmail", G_DIR_SEPARATOR_S, "mail.conf", NULL);

	#ifndef G_OS_WIN32
	/* We try only to move if we are on not Windows platform */
	config_file_old = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
		"plugins", G_DIR_SEPARATOR_S,
		"geanysendmail", G_DIR_SEPARATOR_S, "mail.conf", NULL);
	config_dir = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
		"plugins", G_DIR_SEPARATOR_S, "sendmail", NULL);
	config_dir_old = g_strconcat(geany->app->configdir, G_DIR_SEPARATOR_S,
		"plugins", G_DIR_SEPARATOR_S, "geanysendmail", NULL);

	if (g_file_test(config_file_old, G_FILE_TEST_EXISTS))
	{
		if (dialogs_show_question(
			_("Renamed plugin detected!\n"
			  "\n"
			  "GeanySendMail has been renamed to sendmail -- you surely have "
			  "already recognised it. \n"
			  "Geany is able to migrate your old plugin configuration by "
			  "moving the old configuration file to new location.\n"
			  "Move now?")))
		{
			if (g_rename(config_dir_old, config_dir) == 0)
			{
				dialogs_show_msgbox(GTK_MESSAGE_INFO,
					_("Your configuration directory has been "
					  "successfully moved from \"%s\" to \"%s\"."),
					config_dir_old, config_dir);
			}
			else
			{
				/* If there was an error on migrating we need
				 * to load from original one.
				 * When saving new configuration it will go to
				 * new folder so migration should
				 * be implicit. */
				g_free(config_file);
				config_file = g_strdup(config_file_old);
				dialogs_show_msgbox(
					GTK_MESSAGE_WARNING,
					_("Your old configuration directory \"%s\" could "
					  "not be moved to \"%s\" (%s). "
					  "Please move manually the directory to the new location."),
					config_dir_old,
					config_dir,
					g_strerror(errno));
			}
		}
	}

	g_free(config_dir_old);
	g_free(config_dir);
	g_free(config_file_old);
	#endif

	/* Initialising options from config file */
	g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
	mailer = g_key_file_get_string(config, "tools", "mailer", NULL);
	address = g_key_file_get_string(config, "tools", "address", NULL);
	use_address_dialog = g_key_file_get_boolean(config, "tools", "address_usage", NULL);
	icon_in_toolbar = g_key_file_get_boolean(config, "icon", "show_icon", NULL);

	g_key_file_free(config);

	add_stock_item();
	if (icon_in_toolbar == TRUE)
	{
		show_icon();
	}

	/* Build up menu entry */
	menu_mail = gtk_menu_item_new_with_mnemonic(_("_Mail document"));
	gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), menu_mail);
	gtk_widget_set_tooltip_text(menu_mail,
		_("Sends the opened file as unzipped attachment by any mailer from your $PATH"));
	g_signal_connect(G_OBJECT(menu_mail), "activate", G_CALLBACK(send_as_attachment), NULL);

	/* setup keybindings */
	key_group = plugin_set_key_group(geany_plugin, "sendmail", COUNT_KB, NULL);
	keybindings_set_item(key_group, SENDMAIL_KB, key_send_as_attachment,
		0, 0, "send_file_as_attachment", kb_label, menu_mail);

	gtk_widget_show_all(menu_mail);
	ui_add_document_sensitive(menu_mail);
	main_menu_item = menu_mail;
}
Esempio n. 11
0
/* Called by Geany to initialize the plugin */
void
plugin_init(G_GNUC_UNUSED GeanyData *data)
{
	GtkWidget *menu_lipsum = NULL;
	GKeyFile *config = g_key_file_new();
	gchar *config_file = NULL;
	gchar *config_file_old = NULL;
	gchar *config_dir = NULL;
	gchar *config_dir_old = NULL;
	GeanyKeyGroup *key_group;


	config_file = g_strconcat(geany->app->configdir,
		G_DIR_SEPARATOR_S, "plugins", G_DIR_SEPARATOR_S,
		"geanylipsum", G_DIR_SEPARATOR_S, "lipsum.conf", NULL);

	#ifndef G_OS_WIN32
	/* We try only to move if we are on not Windows platform */
	config_dir_old = g_build_filename(geany->app->configdir,
		"plugins", "geanylipsum", NULL);
	config_file_old = g_build_filename(config_dir_old,
		"lipsum.conf", NULL);
	config_dir = g_build_filename(geany->app->configdir,
		"plugins", "lipsum", NULL);
	if (g_file_test(config_file_old, G_FILE_TEST_EXISTS))
	{
		if (dialogs_show_question(
			_("Renamed plugin detected!\n"
			  "\n"
			  "As you may have already noticed, GeanyLipsum has been "
			  "renamed to just Lipsum. \n"
			  "Geany is able to migrate your old plugin configuration by "
			  "moving the old configuration file to new location.\n"
			  "Warning: This will not include your keybindings.\n"
			  "Move now?")))
		{
			if (g_rename(config_dir_old, config_dir) == 0)
			{
				dialogs_show_msgbox(GTK_MESSAGE_INFO,
					_("Your configuration directory has been "
					  "successfully moved from \"%s\" to \"%s\"."),
					config_dir_old, config_dir);
			}
			else
			{
				/* If there was an error on migrating we need
				 * to load from original one.
				 * When saving new configuration it will go to
				 * new folder so migration should
				 * be implicit. */
				g_free(config_file);
				config_file = g_strdup(config_file_old);
				dialogs_show_msgbox(
					GTK_MESSAGE_WARNING,
					_("Your old configuration directory \"%s\" could "
					  "not be moved to \"%s\" (%s). "
					  "Please manually move the directory to the new location."),
					config_dir_old,
					config_dir,
					g_strerror(errno));
			}
		}
	}

	g_free(config_dir_old);
	g_free(config_dir);
	g_free(config_file_old);
	#endif

	/* Initialising options from config file  if there is any*/
	g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL);
	lipsum = utils_get_setting_string(config, "snippets", "lipsumtext", default_loremipsum);

	g_key_file_free(config);
	g_free(config_file);

	/* Building menu entry */
	menu_lipsum = gtk_image_menu_item_new_with_mnemonic(_("_Lipsum..."));
	gtk_widget_set_tooltip_text(menu_lipsum, _("Include Pseudotext to your code"));
	gtk_widget_show(menu_lipsum);
	g_signal_connect((gpointer) menu_lipsum, "activate",
			 G_CALLBACK(lipsum_activated), NULL);
	gtk_container_add(GTK_CONTAINER(geany->main_widgets->tools_menu), menu_lipsum);


	ui_add_document_sensitive(menu_lipsum);

	main_menu_item = menu_lipsum;

	/* init keybindings */
	key_group = plugin_set_key_group(geany_plugin, "lipsum", COUNT_KB, NULL);
	keybindings_set_item(key_group, LIPSUM_KB_INSERT, kblipsum_insert,
		0, 0, "insert_lipsum", _("Insert Lipsum text"), menu_lipsum);
}