/* geany_xml_encode_notify * * Display a status notification message saying how many entities were * encoded. */ static void geany_xml_encode_notify(GeanyDocument* document, int count) { assert(document); if (count) { gchar const* file_name = g_path_get_basename(DOC_FILENAME(document)); // Statusbar message for %n replacements in file %s gchar const* msg = g_dngettext( NULL, "%s: replaced %d XML special character with an entity reference.", "%s: replaced %d XML special characters with entity references.", count ); ui_set_statusbar(TRUE, msg, file_name, count); g_free((gchar*)file_name); } else { // Statusbar message when no replacements were done ui_set_statusbar(FALSE, _("No XML special characters found.")); } }
static void print_typing_changed_message(void) { if (sc_info->check_while_typing) ui_set_statusbar(FALSE, _("Spell checking while typing is now enabled")); else ui_set_statusbar(FALSE, _("Spell checking while typing is now disabled")); }
static void backupcopy_document_save_cb(GObject *obj, GeanyDocument *doc, gpointer user_data) { FILE *src, *dst; gchar *locale_filename_src; gchar *locale_filename_dst; gchar *basename_src; gchar *dir_parts_src; gchar *stamp; gchar buf[512]; if (! enable_backupcopy) return; locale_filename_src = utils_get_locale_from_utf8(doc->file_name); if ((src = g_fopen(locale_filename_src, "r")) == NULL) { /* it's unlikely that this happens */ ui_set_statusbar(FALSE, _("Backup Copy: File could not be read (%s)."), g_strerror(errno)); g_free(locale_filename_src); return; } stamp = utils_get_date_time(backupcopy_time_fmt, NULL); basename_src = g_path_get_basename(locale_filename_src); dir_parts_src = backupcopy_create_dir_parts(locale_filename_src); locale_filename_dst = g_strconcat( backupcopy_backup_dir, G_DIR_SEPARATOR_S, dir_parts_src, G_DIR_SEPARATOR_S, basename_src, ".", stamp, NULL); g_free(basename_src); g_free(dir_parts_src); if ((dst = g_fopen(locale_filename_dst, "wb")) == NULL) { ui_set_statusbar(FALSE, _("Backup Copy: File could not be saved (%s)."), g_strerror(errno)); g_free(locale_filename_src); g_free(locale_filename_dst); g_free(stamp); fclose(src); return; } while (fgets(buf, sizeof(buf), src) != NULL) { fputs(buf, dst); } fclose(src); fclose(dst); g_free(locale_filename_src); g_free(locale_filename_dst); g_free(stamp); }
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 on_insert_for_dummies(void) { gboolean enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_items.insert_for_dummies_item)); vi_set_insert_for_dummies(enabled); ui_set_statusbar(FALSE, _("Insert Mode for Dummies: %s"), enabled ? _("ON") : _("OFF")); save_config(); }
/* name should be in UTF-8, and can have a path. */ static void show_output(const gchar * std_output, const gchar * name, const gchar * force_encoding, gint filetype_new_file) { gint page; GtkNotebook *book; GeanyDocument *doc, *cur_doc; if (std_output) { cur_doc = document_get_current(); doc = document_find_by_filename(name); if (doc == NULL) { doc = document_new_file(name, filetypes[filetype_new_file], std_output); } else { sci_set_text(doc->editor->sci, std_output); book = GTK_NOTEBOOK(geany->main_widgets->notebook); page = gtk_notebook_page_num(book, GTK_WIDGET(doc->editor->sci)); gtk_notebook_set_current_page(book, page); } document_set_text_changed(doc, FALSE); document_set_encoding(doc, (force_encoding ? force_encoding : "UTF-8")); navqueue_goto_line(cur_doc, document_get_current(), 1); } else { ui_set_statusbar(FALSE, _("Could not parse the output of command")); } }
static gchar *read_file(const gchar *locale_fname) { gchar *contents; gsize length; GString *str; if (! g_file_get_contents(locale_fname, &contents, &length, NULL)) return NULL; if (! encodings_convert_to_utf8_auto(&contents, &length, NULL, NULL, NULL, NULL)) { gchar *utf8_fname = utils_get_utf8_from_locale(locale_fname); ui_set_statusbar(TRUE, _("Failed to convert template file \"%s\" to UTF-8"), utf8_fname); g_free(utf8_fname); g_free(contents); return NULL; } str = g_string_new(contents); g_free(contents); /* convert to LF endings for consistency in mixing templates */ utils_ensure_same_eol_characters(str, SC_EOL_LF); return g_string_free(str, FALSE); }
static void on_comments_function_activate(GtkMenuItem *menuitem, gpointer user_data) { GeanyDocument *doc = document_get_current(); gchar *text; const gchar *cur_tag = NULL; gint line = -1, pos = 0; if (doc == NULL || doc->file_type == NULL) { ui_set_statusbar(FALSE, _("Please set the filetype for the current file before using this function.")); return; } /* symbols_get_current_function returns -1 on failure, so sci_get_position_from_line * returns the current position, so it should be safe */ line = symbols_get_current_function(doc, &cur_tag); pos = sci_get_position_from_line(doc->editor->sci, line); text = templates_get_template_function(doc, cur_tag); sci_start_undo_action(doc->editor->sci); sci_insert_text(doc->editor->sci, pos, text); sci_end_undo_action(doc->editor->sci); g_free(text); }
/* Changes the current working directory of the VTE to the path of the given filename. * filename is expected to be in UTF-8 encoding. * filename can also be a path, then it is used directly. * If force is set to TRUE, it will always change the cwd */ void vte_cwd(const gchar *filename, gboolean force) { if (vte_info.have_vte && (vc->follow_path || force) && filename != NULL && g_path_is_absolute(filename)) { gchar *path; if (g_file_test(filename, G_FILE_TEST_IS_DIR)) path = g_strdup(filename); else path = g_path_get_dirname(filename); vte_get_working_directory(); /* refresh vte_info.dir */ if (! utils_str_equal(path, vte_info.dir)) { /* use g_shell_quote to avoid problems with spaces, '!' or something else in path */ gchar *quoted_path = g_shell_quote(path); gchar *cmd = g_strconcat(vc->send_cmd_prefix, "cd ", quoted_path, "\n", NULL); if (! vte_send_cmd(cmd)) { ui_set_statusbar(FALSE, _("Could not change the directory in the VTE because it probably contains a command.")); geany_debug( "Could not change the directory in the VTE because it probably contains a command."); } g_free(quoted_path); g_free(cmd); } g_free(path); } }
/* Changes the current working directory of the VTE to the path of the given filename. * filename is expected to be in UTF-8 encoding. * filename can also be a path, then it is used directly. * If force is set to TRUE, it will always change the cwd */ void vte_cwd(const gchar *filename, gboolean force) { if (vte_info.have_vte && (vc->follow_path || force) && filename != NULL && g_path_is_absolute(filename)) { gchar *path; if (g_file_test(filename, G_FILE_TEST_IS_DIR)) path = g_strdup(filename); else path = g_path_get_dirname(filename); vte_get_working_directory(); /* refresh vte_info.dir */ if (! utils_str_equal(path, vte_info.dir)) { /* use g_shell_quote to avoid problems with spaces, '!' or something else in path */ gchar *quoted_path = g_shell_quote(path); gchar *cmd = g_strconcat(vc->send_cmd_prefix, "cd ", quoted_path, "\n", NULL); if (! vte_send_cmd(cmd)) { const gchar *msg = _("Directory not changed because the terminal may contain some input (press Ctrl+C or Enter to clear it)."); ui_set_statusbar(FALSE, "%s", msg); geany_debug("%s", msg); } g_free(quoted_path); g_free(cmd); } g_free(path); } }
void on_save_all1_activate(GtkMenuItem *menuitem, gpointer user_data) { guint i, max = (guint) gtk_notebook_get_n_pages(GTK_NOTEBOOK(main_widgets.notebook)); GeanyDocument *doc, *cur_doc = document_get_current(); guint count = 0; /* iterate over documents in tabs order */ for (i = 0; i < max; i++) { doc = document_get_from_page(i); if (! doc->changed) continue; if (document_save_file(doc, FALSE)) count++; } if (!count) return; ui_set_statusbar(FALSE, ngettext("%d file saved.", "%d files saved.", count), count); /* saving may have changed window title, sidebar for another doc, so update */ document_show_tab(cur_doc); sidebar_update_tag_list(cur_doc, TRUE); ui_set_window_title(cur_doc); }
gboolean msgwin_goto_messages_file_line(gboolean focus_editor) { GtkTreeIter iter; GtkTreeModel *model; GtkTreeSelection *selection; gboolean ret = FALSE; selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(msgwindow.tree_msg)); if (gtk_tree_selection_get_selected(selection, &model, &iter)) { gint line; guint id; gchar *string; GeanyDocument *doc; GeanyDocument *old_doc = document_get_current(); gtk_tree_model_get(model, &iter, MSG_COL_LINE, &line, MSG_COL_DOC_ID, &id, MSG_COL_STRING, &string, -1); if (line >= 0 && id > 0) { /* check doc is still open */ doc = document_find_by_id(id); if (!doc) { ui_set_statusbar(FALSE, _("The document has been closed.")); utils_beep(); } else { line = adjust_line_number(doc, line, msgwindow.line_shifts_msg); ret = navqueue_goto_line(old_doc, doc, line); if (ret && focus_editor) gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); } } else if (line < 0 && string != NULL) { gchar *filename; /* try with a file:line parsing */ msgwin_parse_generic_line(string, &filename, &line); if (filename != NULL) { /* use document_open_file to find an already open file, or open it in place */ doc = document_open_file(filename, FALSE, NULL, NULL); if (doc != NULL) { line = adjust_line_number(doc, line, msgwindow.line_shifts_msg); ret = (line < 0) ? TRUE : navqueue_goto_line(old_doc, doc, line); if (ret && focus_editor) gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); } } g_free(filename); } g_free(string); } return ret; }
/* open_default will make function reload default session files on close */ void project_close(gboolean open_default) { GSList *node; g_return_if_fail(app->project != NULL); ui_set_statusbar(TRUE, _("Project \"%s\" closed."), app->project->name); /* use write_config() to save project session files */ if (!write_config(FALSE)) g_warning("Project file \"%s\" could not be written", app->project->file_name); /* remove project filetypes build entries */ if (app->project->build_filetypes_list != NULL) { g_ptr_array_foreach(app->project->build_filetypes_list, remove_foreach_project_filetype, NULL); g_ptr_array_free(app->project->build_filetypes_list, FALSE); } /* remove project non filetype build menu items */ build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_NON_FT, -1); build_remove_menu_item(GEANY_BCS_PROJ, GEANY_GBG_EXEC, -1); g_free(app->project->name); g_free(app->project->description); g_free(app->project->file_name); g_free(app->project->base_path); g_free(app->project); app->project = NULL; foreach_slist(node, stash_groups) stash_group_free(node->data); g_slist_free(stash_groups); stash_groups = NULL; apply_editor_prefs(); /* ensure that global settings are restored */ if (project_prefs.project_session) { /* close all existing tabs first */ document_close_all(); /* after closing all tabs let's open the tabs found in the default config */ if (open_default && cl_options.load_session) { configuration_reload_default_session(); configuration_open_files(); /* open a new file if no other file was opened */ document_new_file_if_non_open(); ui_focus_current_document(); } } g_signal_emit_by_name(geany_object, "project-close"); update_ui(); }
static gboolean goto_compiler_file_line(const gchar *filename, gint line, gboolean focus_editor) { if (!filename || line <= -1) return FALSE; /* If the path doesn't exist, try the current document. * This happens when we receive build messages in the wrong order - after the * 'Leaving directory' messages */ if (!g_file_test(filename, G_FILE_TEST_EXISTS)) { gchar *cur_dir = utils_get_current_file_dir_utf8(); gchar *name; if (cur_dir) { /* we let the user know we couldn't find the parsed filename from the message window */ setptr(cur_dir, utils_get_locale_from_utf8(cur_dir)); name = g_path_get_basename(filename); setptr(name, g_build_path(G_DIR_SEPARATOR_S, cur_dir, name, NULL)); g_free(cur_dir); if (g_file_test(name, G_FILE_TEST_EXISTS)) { ui_set_statusbar(FALSE, _("Could not find file '%s' - trying the current document path."), filename); filename = name; } else g_free(name); } } { gchar *utf8_filename = utils_get_utf8_from_locale(filename); GeanyDocument *doc = document_find_by_filename(utf8_filename); GeanyDocument *old_doc = document_get_current(); g_free(utf8_filename); if (doc == NULL) /* file not already open */ doc = document_open_file(filename, FALSE, NULL, NULL); if (doc != NULL) { gboolean ret; if (! doc->changed && editor_prefs.use_indicators) /* if modified, line may be wrong */ editor_indicator_set_on_line(doc->editor, GEANY_INDICATOR_ERROR, line - 1); ret = navqueue_goto_line(old_doc, doc, line); if (ret && focus_editor) gtk_widget_grab_focus(GTK_WIDGET(doc->editor->sci)); return ret; } } return FALSE; }
static void on_enable_vim_mode(void) { gboolean enabled = gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_items.enable_vim_item)); vi_set_enabled(enabled); vi_set_mode(start_in_insert ? VI_MODE_INSERT : VI_MODE_COMMAND); if (!enabled) ui_set_statusbar(FALSE, "Vim Mode Disabled"); save_config(); }
static gchar *backupcopy_create_dir_parts(const gchar *filename) { gint cnt_dir_parts = 0; gchar *cp; gchar *dirname; gchar last_char = 0; gint error; gchar *result; gchar *target_dir; if (backupcopy_dir_levels == 0) return g_strdup(""); dirname = g_path_get_dirname(filename); cp = dirname; /* walk to the end of the string */ while (*cp != '\0') cp++; /* walk backwards to find directory parts */ while (cp > dirname) { if (*cp == G_DIR_SEPARATOR && last_char != G_DIR_SEPARATOR) cnt_dir_parts++; if (cnt_dir_parts == backupcopy_dir_levels) break; last_char = *cp; cp--; } result = backupcopy_skip_root(cp); /* skip leading slash/backslash and c:\ */ target_dir = g_build_filename(backupcopy_backup_dir, result, NULL); error = utils_mkdir(target_dir, TRUE); if (error != 0) { ui_set_statusbar(FALSE, _("Backup Copy: Directory could not be created (%s)."), g_strerror(error)); result = g_strdup(""); /* return an empty string in case of an error */ } else result = g_strdup(result); g_free(dirname); g_free(target_dir); return result; }
static void on_recent_menu_item_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, const gchar *name) { GtkTreeIter iter; if (utils_filenamecmp(name, *program_executable ? program_executable : program_load_script) && program_find(&iter, name)) { gint id; char *configfile; GKeyFile *config = g_key_file_new(); GError *gerror = NULL; gchar *message; scp_tree_store_get(recent_programs, &iter, PROGRAM_ID, &id, -1); configfile = recent_file_name(id); if (g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, &gerror)) { scp_tree_store_move(recent_programs, &iter, 0); save_program_settings(); stash_foreach((GFunc) stash_group_load_from_key_file, config); if ((unsigned) option_inspect_expand > EXPAND_MAX) option_inspect_expand = 100; breaks_load(config); watches_load(config); inspects_load(config); registers_load(config); parse_load(config); message = g_strdup_printf(_("Loaded debug settings for %s."), name); program_find(&iter, name); scp_tree_store_move(recent_programs, &iter, 0); recent_menu_create(); program_configure(); } else { message = g_strdup_printf(_("Could not load debug settings file %s: %s."), configfile, gerror->message); g_error_free(gerror); } if (menuitem) ui_set_statusbar(TRUE, "%s", message); else msgwin_status_add("%s", message); g_free(message); g_key_file_free(config); g_free(configfile); } }
gboolean project_load_file(const gchar *locale_file_name) { g_return_val_if_fail(locale_file_name != NULL, FALSE); if (load_config(locale_file_name)) { gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name); ui_set_statusbar(TRUE, _("Project \"%s\" opened."), app->project->name); ui_add_recent_project_file(utf8_filename); g_free(utf8_filename); return TRUE; } else { gchar *utf8_filename = utils_get_utf8_from_locale(locale_file_name); ui_set_statusbar(TRUE, _("Project file \"%s\" could not be loaded."), utf8_filename); g_free(utf8_filename); } return FALSE; }
static gboolean on_editor_notify(GObject *object, GeanyEditor *editor, SCNotification *nt, gpointer data) { /* data == GeanyPlugin because the data member of PluginCallback was set to NULL * and this plugin has called geany_plugin_set_data() with the GeanyPlugin pointer as * data */ GeanyPlugin *plugin = data; GeanyData *geany_data = plugin->geany_data; /* For detailed documentation about the SCNotification struct, please see * http://www.scintilla.org/ScintillaDoc.html#Notifications. */ switch (nt->nmhdr.code) { case SCN_UPDATEUI: /* This notification is sent very often, you should not do time-consuming tasks here */ break; case SCN_CHARADDED: /* For demonstrating purposes simply print the typed character in the status bar */ ui_set_statusbar(FALSE, _("Typed character: %c"), nt->ch); break; case SCN_URIDROPPED: { /* Show a message dialog with the dropped URI list when files (i.e. a list of * filenames) is dropped to the editor widget) */ if (nt->text != NULL) { GtkWidget *dialog; dialog = gtk_message_dialog_new( GTK_WINDOW(geany_data->main_widgets->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, _("The following files were dropped:")); gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), "%s", nt->text); gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); } /* we return TRUE here which prevents Geany from processing the SCN_URIDROPPED * notification, i.e. Geany won't open the passed files */ return TRUE; } } return FALSE; }
static void gdb_exit_cb(G_GNUC_UNUSED GPid pid, gint status, G_GNUC_UNUSED gpointer gdata) { GdbState saved_state = gdb_state; gdb_finalize(); gdb_state = INACTIVE; if (saved_state == ACTIVE) show_error(_("GDB died unexpectedly with status %d."), status); else if (thread_count) ui_set_statusbar(FALSE, _("Program terminated.")); views_clear(); utils_lock_all(FALSE); update_state(DS_INACTIVE); }
void zen_controller_run_action(ZenController *zen, const char *action_name) { PyObject *addr, *result; GeanyDocument *doc; g_return_if_fail(zen != NULL); g_return_if_fail(action_name != NULL); ui_set_statusbar(FALSE, _("Zen Coding: Running '%s' action"), action_name); doc = document_get_current(); if (!DOC_VALID(doc)) { g_warning("No valid document detected."); return; } addr = PyLong_FromVoidPtr((void *) doc); if (addr == NULL) { if (PyErr_Occurred()) PyErr_Print(); g_warning("Unable to convert document pointer to Python object."); return; } result = PyObject_CallMethod(zen->editor, "set_context", "O", addr); Py_DECREF(addr); if (result == NULL) { if (PyErr_Occurred()) PyErr_Print(); g_warning("Unable to call set_context() function."); return; } Py_XDECREF(result); result = PyObject_CallFunction(zen->run_action, "sO", action_name, zen->editor); if (result == NULL) { if (PyErr_Occurred()) PyErr_Print(); g_warning("Call to run_action() failed."); return; } Py_XDECREF(result); }
static void on_recent_menu_item_activate(G_GNUC_UNUSED GtkMenuItem *menuitem, const gchar *name) { RecentProgram *recent = (RecentProgram *) array_find(recent_programs, name, TRUE); if (recent && utils_filenamecmp(recent->name, *program_executable ? program_executable : program_load_script)) { char *configfile = recent_file_name(recent->id); GKeyFile *config = g_key_file_new(); GError *gerror = NULL; gchar *message; if (g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, &gerror)) { save_program_settings(); recent = (RecentProgram *) array_find(recent_programs, name, TRUE); stash_foreach((GFunc) stash_group_load_from_key_file, config); if ((unsigned) option_inspect_expand > EXPAND_MAX) option_inspect_expand = 100; breaks_load(config); watches_load(config); inspects_load(config); parse_load(config); message = g_strdup_printf(_("Loaded debug settings for %s."), recent->name); g_array_insert_vals(recent_programs, 0, ++recent, 1); array_remove(recent_programs, recent); recent_menu_create(); program_configure(); } else { message = g_strdup_printf(_("Could not load debug settings file %s: %s."), configfile, gerror->message); g_error_free(gerror); } if (menuitem) ui_set_statusbar(TRUE, "%s", message); else msgwin_status_add("%s", message); g_free(message); g_key_file_free(config); g_free(configfile); } }
static void insert_multiline_comment(GeanyDocument *doc, gint pos) { g_return_if_fail(doc != NULL); g_return_if_fail(pos == -1 || pos >= 0); if (doc->file_type == NULL) { ui_set_statusbar(FALSE, _("Please set the filetype for the current file before using this function.")); return; } if (doc->file_type->comment_open || doc->file_type->comment_single) { /* editor_insert_multiline_comment() uses editor_info.click_pos */ if (pos == -1) editor_info.click_pos = sci_get_current_position(doc->editor->sci); else editor_info.click_pos = pos; editor_insert_multiline_comment(doc->editor); } else utils_beep(); }
static gboolean auto_save(gpointer data) { GeanyDocument *doc; GeanyDocument *cur_doc = document_get_current(); gint i, max = gtk_notebook_get_n_pages(GTK_NOTEBOOK(geany->main_widgets->notebook)); gint saved_files = 0; if (cur_doc == NULL) return TRUE; if (autosave_save_all) { for (i = 0; i < max; i++) { doc = document_get_from_page(i); /* skip current file (save it last), skip files without name */ if (doc != cur_doc && doc->file_name != NULL) if (document_save_file(doc, FALSE)) saved_files++; } } /* finally save current file, do it after all other files to get correct window title and * symbol list */ if (cur_doc->file_name != NULL) if (document_save_file(cur_doc, FALSE)) saved_files++; if (saved_files > 0 && autosave_print_msg) ui_set_statusbar(FALSE, ngettext( "Autosave: Saved %d file automatically.", "Autosave: Saved %d files automatically.", saved_files), saved_files); return TRUE; }
void backup_document_save_cb(GObject *obj, GeanyDocument *doc, gpointer user_data) { FILE *src, *dst; gchar *locale_filename_src; gchar *locale_filename_dst; gchar *basename_src; gchar *dir_parts_src; gchar *stamp; gchar buf[512]; gint fd_dst = -1; gchar backupcopy_time_fmt[] = "%Y-%m-%d-%H-%M-%S"; locale_filename_src = utils_get_locale_from_utf8(doc->file_name); if ((src = g_fopen(locale_filename_src, "r")) == NULL) { /* it's unlikely that this happens */ ui_set_statusbar ( FALSE, _("Backup Copy: File could not be read.") ); g_free(locale_filename_src); return; } stamp = utils_get_date_time(backupcopy_time_fmt, NULL); basename_src = g_path_get_basename(locale_filename_src); dir_parts_src = backup_create_dir_parts(locale_filename_src); locale_filename_dst = g_strconcat( backupcopy_backup_dir, G_DIR_SEPARATOR_S, dir_parts_src, G_DIR_SEPARATOR_S, basename_src, ".", stamp, NULL); g_free(basename_src); g_free(dir_parts_src); msgwin_status_add ( "Backup into %s", locale_filename_dst ); /* Use g_open() on non-Windows to set file permissions to 600 atomically. * On Windows, seting file permissions would require specific Windows API. */ fd_dst = g_open(locale_filename_dst, O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR); if (fd_dst == -1 || (dst = fdopen(fd_dst, "w")) == NULL) { ui_set_statusbar(FALSE, _("Backup Copy: File could not be saved.") ); g_free(locale_filename_src); g_free(locale_filename_dst); g_free(stamp); fclose(src); if (fd_dst != -1) close(fd_dst); return; } while (fgets(buf, sizeof(buf), src) != NULL) { fputs(buf, dst); } //ui_set_statusbar ( FALSE, _("Backup Copy Saved into %s."), local_filename_dst ); msgwin_status_add ( "Backup created in %s", locale_filename_dst ); fclose(src); fclose(dst); if (fd_dst != -1) close(fd_dst); g_free(locale_filename_src); g_free(locale_filename_dst); g_free(stamp); }
static void show_project_properties(gboolean show_build) { GeanyProject *p = app->project; GtkWidget *widget = NULL; GtkWidget *radio_long_line_custom; static PropertyDialogElements e; GSList *node; g_return_if_fail(app->project != NULL); entries_modified = FALSE; if (e.dialog == NULL) create_properties_dialog(&e); insert_build_page(&e); foreach_slist(node, stash_groups) stash_group_display(node->data, e.dialog); /* fill the elements with the appropriate data */ gtk_entry_set_text(GTK_ENTRY(e.name), p->name); gtk_label_set_text(GTK_LABEL(e.file_name), p->file_name); gtk_entry_set_text(GTK_ENTRY(e.base_path), p->base_path); radio_long_line_custom = ui_lookup_widget(e.dialog, "radio_long_line_custom_project"); switch (p->long_line_behaviour) { case 0: widget = ui_lookup_widget(e.dialog, "radio_long_line_disabled_project"); break; case 1: widget = ui_lookup_widget(e.dialog, "radio_long_line_default_project"); break; case 2: widget = radio_long_line_custom; break; } gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), TRUE); widget = ui_lookup_widget(e.dialog, "spin_long_line_project"); gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), (gdouble)p->long_line_column); on_radio_long_line_custom_toggled(GTK_TOGGLE_BUTTON(radio_long_line_custom), widget); if (p->description != NULL) { /* set text */ GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(e.description)); gtk_text_buffer_set_text(buffer, p->description, -1); } if (p->file_patterns != NULL) { /* set the file patterns */ gchar *str; str = g_strjoinv(" ", p->file_patterns); gtk_entry_set_text(GTK_ENTRY(e.patterns), str); g_free(str); } g_signal_emit_by_name(geany_object, "project-dialog-open", e.notebook); gtk_widget_show_all(e.dialog); /* note: notebook page must be shown before setting current page */ if (show_build) gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), e.build_page_num); else gtk_notebook_set_current_page(GTK_NOTEBOOK(e.notebook), 0); while (gtk_dialog_run(GTK_DIALOG(e.dialog)) == GTK_RESPONSE_OK) { if (update_config(&e, FALSE)) { g_signal_emit_by_name(geany_object, "project-dialog-confirmed", e.notebook); if (!write_config(TRUE)) SHOW_ERR(_("Project file could not be written")); else { ui_set_statusbar(TRUE, _("Project \"%s\" saved."), app->project->name); break; } } } build_free_fields(e.build_properties); g_signal_emit_by_name(geany_object, "project-dialog-close", e.notebook); gtk_notebook_remove_page(GTK_NOTEBOOK(e.notebook), e.build_page_num); gtk_widget_hide(e.dialog); }
static void on_mode_change(ViMode mode) { ui_set_statusbar(FALSE, "Vim Mode: -- %s --", get_mode_name(mode)); }
/* TODO: this should be ported to Glade like the project preferences dialog, * then we can get rid of the PropertyDialogElements struct altogether as * widgets pointers can be accessed through ui_lookup_widget(). */ void project_new(void) { GtkWidget *vbox; GtkWidget *table; GtkWidget *image; GtkWidget *button; GtkWidget *bbox; GtkWidget *label; PropertyDialogElements *e; if (! project_ask_close()) return; g_return_if_fail(app->project == NULL); e = g_new0(PropertyDialogElements, 1); e->dialog = gtk_dialog_new_with_buttons(_("New Project"), GTK_WINDOW(main_widgets.window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, NULL); gtk_widget_set_name(e->dialog, "GeanyDialogProject"); bbox = gtk_hbox_new(FALSE, 0); button = gtk_button_new(); image = gtk_image_new_from_stock(GTK_STOCK_NEW, GTK_ICON_SIZE_BUTTON); label = gtk_label_new_with_mnemonic(_("C_reate")); gtk_box_pack_start(GTK_BOX(bbox), image, FALSE, FALSE, 3); gtk_box_pack_start(GTK_BOX(bbox), label, FALSE, FALSE, 3); gtk_container_add(GTK_CONTAINER(button), bbox); gtk_dialog_add_action_widget(GTK_DIALOG(e->dialog), button, GTK_RESPONSE_OK); vbox = ui_dialog_vbox_new(GTK_DIALOG(e->dialog)); entries_modified = FALSE; table = gtk_table_new(3, 2, FALSE); gtk_table_set_row_spacings(GTK_TABLE(table), 5); gtk_table_set_col_spacings(GTK_TABLE(table), 10); label = gtk_label_new(_("Name:")); gtk_misc_set_alignment(GTK_MISC(label), 1, 0); e->name = gtk_entry_new(); ui_entry_add_clear_icon(GTK_ENTRY(e->name)); gtk_entry_set_max_length(GTK_ENTRY(e->name), MAX_NAME_LEN); ui_table_add_row(GTK_TABLE(table), 0, label, e->name, NULL); label = gtk_label_new(_("Filename:")); gtk_misc_set_alignment(GTK_MISC(label), 1, 0); e->file_name = gtk_entry_new(); ui_entry_add_clear_icon(GTK_ENTRY(e->file_name)); gtk_entry_set_width_chars(GTK_ENTRY(e->file_name), 30); button = gtk_button_new(); g_signal_connect(button, "clicked", G_CALLBACK(on_file_save_button_clicked), e); image = gtk_image_new_from_stock(GTK_STOCK_OPEN, GTK_ICON_SIZE_BUTTON); gtk_container_add(GTK_CONTAINER(button), image); bbox = gtk_hbox_new(FALSE, 6); gtk_box_pack_start_defaults(GTK_BOX(bbox), e->file_name); gtk_box_pack_start(GTK_BOX(bbox), button, FALSE, FALSE, 0); ui_table_add_row(GTK_TABLE(table), 1, label, bbox, NULL); label = gtk_label_new(_("Base path:")); gtk_misc_set_alignment(GTK_MISC(label), 1, 0); e->base_path = gtk_entry_new(); ui_entry_add_clear_icon(GTK_ENTRY(e->base_path)); gtk_widget_set_tooltip_text(e->base_path, _("Base directory of all files that make up the project. " "This can be a new path, or an existing directory tree. " "You can use paths relative to the project filename.")); bbox = ui_path_box_new(_("Choose Project Base Path"), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, GTK_ENTRY(e->base_path)); ui_table_add_row(GTK_TABLE(table), 2, label, bbox, NULL); gtk_container_add(GTK_CONTAINER(vbox), table); /* signals */ g_signal_connect(e->name, "changed", G_CALLBACK(on_name_entry_changed), e); /* run the callback manually to initialise the base_path and file_name fields */ on_name_entry_changed(GTK_EDITABLE(e->name), e); g_signal_connect(e->file_name, "changed", G_CALLBACK(on_entries_changed), e); g_signal_connect(e->base_path, "changed", G_CALLBACK(on_entries_changed), e); gtk_widget_show_all(e->dialog); while (gtk_dialog_run(GTK_DIALOG(e->dialog)) == GTK_RESPONSE_OK) { if (update_config(e, TRUE)) { if (!write_config(TRUE)) SHOW_ERR(_("Project file could not be written")); else { ui_set_statusbar(TRUE, _("Project \"%s\" created."), app->project->name); ui_add_recent_project_file(app->project->file_name); break; } } } gtk_widget_destroy(e->dialog); g_free(e); }
static void quick_find() { gtk_tree_store_clear(list); const gchar *text = gtk_entry_get_text(GTK_ENTRY(entry)); if(strcmp(text, "") == 0) { return; } get_path(); row_pos = 1; gboolean case_sensitive = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check_case)); GError *error = NULL; gint std_out, std_err; gchar **cmd; gchar *command = g_strconcat(executable, " ", case_sensitive ? "" : "-i ", g_shell_quote(text), NULL); if(!g_shell_parse_argv(command, NULL, &cmd, &error)) { ui_set_statusbar(TRUE, _("quick-find failed: %s (%s)"), error->message, command); g_error_free(error); g_free(command); return; } g_free(command); gchar **env = utils_copy_environment( NULL, "GEAN", "running from geany", NULL ); if(g_spawn_async_with_pipes( base_directory, cmd, env, 0, NULL, NULL, NULL, NULL, &std_out, &std_err, &error )) { #ifdef G_OS_WIN32 GIOChannel *err_channel = g_io_channel_win32_new_fd(std_err); GIOChannel *out_channel = g_io_channel_win32_new_fd(std_out); #else GIOChannel *err_channel = g_io_channel_unix_new(std_err); GIOChannel *out_channel = g_io_channel_unix_new(std_out); #endif g_io_channel_set_encoding(out_channel, NULL, NULL); g_io_add_watch(out_channel, G_IO_IN | G_IO_HUP, (GIOFunc)output_out, GUINT_TO_POINTER(0)); g_io_channel_set_encoding(err_channel, NULL, NULL); g_io_add_watch(err_channel, G_IO_IN | G_IO_HUP, (GIOFunc)output_out, GUINT_TO_POINTER(1)); } else { printf("quick-find ERROR %s: %s\n", cmd[0], error->message); ui_set_statusbar(TRUE, _("quick-find ERROR %s: %s"), cmd[0], error->message); g_error_free(error); } g_free(cmd); g_free(env); }
/* Callback for sending file as attachment */ static void send_as_attachment(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer gdata) { GeanyDocument *doc; gchar *locale_filename = NULL; gchar *command = NULL; GError *error = NULL; GString *cmd_str = NULL; gchar *data; doc = document_get_current(); if (doc->file_name == NULL) { dialogs_show_save_as(); } else { document_save_file(doc, FALSE); } if (doc->file_name != NULL) { if (mailer) { locale_filename = utils_get_locale_from_utf8(doc->file_name); cmd_str = g_string_new(mailer); if ((use_address_dialog == TRUE) && (g_strrstr(mailer, "%r") != NULL)) { GKeyFile *config = NULL; gchar *config_dir = NULL; gchar *input = dialogs_show_input(_("Recipient's Address"), GTK_WINDOW(geany->main_widgets->window), _("Enter the recipient's e-mail address:"), address); if (input) { config = g_key_file_new(); g_key_file_load_from_file(config, config_file, G_KEY_FILE_NONE, NULL); g_free(address); address = input; g_key_file_set_string(config, "tools", "address", address); } else { g_string_free(cmd_str, TRUE); g_free(locale_filename); return; } config_dir = g_path_get_dirname(config_file); if (! g_file_test(config_dir, G_FILE_TEST_IS_DIR) && utils_mkdir(config_dir, TRUE) != 0) { dialogs_show_msgbox(GTK_MESSAGE_ERROR, _("Plugin configuration directory could not be created.")); } else { /* write config to file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(config_file, data); g_free(data); } g_key_file_free(config); g_free(config_dir); } if (! utils_string_replace_all(cmd_str, "%f", locale_filename)) ui_set_statusbar(FALSE, _("Filename placeholder not found. The executed command might have failed.")); if (use_address_dialog == TRUE && address != NULL) { if (! utils_string_replace_all(cmd_str, "%r", address)) ui_set_statusbar(FALSE, _("Recipient address placeholder not found. The executed command might have failed.")); } else { /* Removes %r if option was not activ but was included into command */ utils_string_replace_all(cmd_str, "%r", ""); } utils_string_replace_all(cmd_str, "%b", g_path_get_basename(locale_filename)); command = g_string_free(cmd_str, FALSE); g_spawn_command_line_async(command, &error); if (error != NULL) { ui_set_statusbar(FALSE, _("Could not execute mailer. Please check your configuration.")); g_error_free(error); } g_free(locale_filename); g_free(command); } else { ui_set_statusbar(FALSE, _("Please define a mail client first.")); } } else { ui_set_statusbar(FALSE, _("File has to be saved before sending.")); } }