77 const gchar *stock_id = GTK_STOCK_NO;
78 gchar *tooltip =
NULL;
81 stock_id = GTK_STOCK_YES;
84 tooltip = g_strdup_printf(
_(
"Invalid command: %s"), err->message);
97 const gchar *cmd =
NULL;
103 cmd =
ui_prefs.custom_commands[idx];
108 gtk_list_store_append(cc->
store, &iter);
116 gtk_widget_grab_focus(cc->
view);
117 path = gtk_tree_model_get_path(GTK_TREE_MODEL(cc->
store), &iter);
118 gtk_tree_view_set_cursor(GTK_TREE_VIEW(cc->
view), path, cc->
edit_column, TRUE);
119 gtk_tree_path_free(path);
133 GtkTreeViewColumn *column;
135 gtk_tree_view_get_cursor(view, &path, &column);
138 gtk_tree_view_scroll_to_cell(view, path, column, FALSE, 1.0, 1.0);
139 gtk_tree_path_free(path);
147 if (gtk_tree_selection_get_selected(cc->
selection,
NULL, &iter))
149 gtk_list_store_remove(cc->
store, &iter);
159 if (gtk_tree_selection_get_selected(cc->
selection,
NULL, &iter))
164 path = gtk_tree_model_get_path(GTK_TREE_MODEL(cc->
store), &iter);
165 if (gtk_tree_path_prev(path) &&
166 gtk_tree_model_get_iter(GTK_TREE_MODEL(cc->
store), &prev, path))
168 gtk_list_store_move_before(cc->
store, &iter, &prev);
171 gtk_tree_path_free(path);
180 if (gtk_tree_selection_get_selected(cc->
selection,
NULL, &iter))
182 GtkTreeIter next = iter;
184 if (gtk_tree_model_iter_next(GTK_TREE_MODEL(cc->
store), &next))
186 gtk_list_store_move_after(cc->
store, &iter, &next);
212 input.
size = strlen(sel);
213 output = g_string_sized_new(256);
214 errors = g_string_new(
NULL);
221 g_warning(
"%s: %s\n",
command, errors->str);
223 _(
"The executed custom command returned an error. "
224 "Your selection was not changed. Error message: %s"),
231 _(
"The executed custom command exited with an unsuccessful exit code."));
241 "Check the path setting in Custom Commands."),
command,
error->message);
245 g_string_free(output, TRUE);
246 g_string_free(errors, TRUE);
256 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(cc->
store), &iter, path);
267 gtk_tree_model_get_iter_from_string(GTK_TREE_MODEL(cc->
store), &iter, path);
278 if (! gtk_tree_model_get_iter_first(GTK_TREE_MODEL(cc->
store), &iter))
286 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(cc->
store), &iter));
294 gboolean has_selection = FALSE;
295 gboolean first_selected = FALSE;
296 gboolean last_selected = FALSE;
298 if ((has_selection = gtk_tree_selection_get_selected(cc->
selection,
NULL, &iter)))
303 path = gtk_tree_model_get_path(GTK_TREE_MODEL(cc->
store), &iter);
304 copy = gtk_tree_path_copy(path);
305 first_selected = ! gtk_tree_path_prev(copy);
306 gtk_tree_path_free(copy);
307 gtk_tree_path_next(path);
308 last_selected = ! gtk_tree_model_get_iter(GTK_TREE_MODEL(cc->
store), &iter, path);
309 gtk_tree_path_free(path);
313 gtk_widget_set_sensitive(cc->
button_up, has_selection && ! first_selected);
314 gtk_widget_set_sensitive(cc->
button_down, has_selection && ! last_selected);
340 gpointer new_order,
struct cc_dialog *cc)
349 GtkWidget *
dialog, *
label, *vbox, *scroll, *buttonbox;
350 GtkCellRenderer *renderer;
351 GtkTreeViewColumn *column;
356 GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
357 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
NULL);
358 gtk_window_set_default_size(GTK_WINDOW(
dialog), 300, 300);
360 gtk_box_set_spacing(GTK_BOX(vbox), 6);
361 gtk_widget_set_name(
dialog,
"GeanyDialog");
363 label = gtk_label_new(
_(
"You can send the current selection to any of these commands and the output of the command replaces the current selection."));
364 gtk_label_set_line_wrap(GTK_LABEL(
label), TRUE);
365 gtk_misc_set_alignment(GTK_MISC(
label), 0, 0.5);
366 gtk_box_pack_start(GTK_BOX(vbox),
label, FALSE, FALSE, 0);
370 G_TYPE_STRING, G_TYPE_STRING);
371 cc.
view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(cc.
store));
373 gtk_tree_view_set_reorderable(GTK_TREE_VIEW(cc.
view), TRUE);
374 cc.
selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(cc.
view));
376 renderer = gtk_cell_renderer_text_new();
377 column = gtk_tree_view_column_new_with_attributes(
_(
"ID"), renderer,
"text",
CC_COLUMN_ID,
NULL);
378 gtk_tree_view_append_column(GTK_TREE_VIEW(cc.
view), column);
380 column = g_object_new(GTK_TYPE_TREE_VIEW_COLUMN,
"title",
_(
"Command"),
"expand", TRUE,
"resizable", TRUE,
NULL);
381 renderer = gtk_cell_renderer_pixbuf_new();
382 gtk_tree_view_column_pack_start(column, renderer, FALSE);
384 renderer = gtk_cell_renderer_text_new();
385 g_object_set(renderer,
"editable", TRUE,
"ellipsize", PANGO_ELLIPSIZE_END,
NULL);
387 gtk_tree_view_column_pack_start(column, renderer, TRUE);
388 gtk_tree_view_column_set_attributes(column, renderer,
"text",
CC_COLUMN_CMD,
NULL);
390 gtk_tree_view_append_column(GTK_TREE_VIEW(cc.
view), column);
392 renderer = gtk_cell_renderer_text_new();
393 g_object_set(renderer,
"editable", TRUE,
"ellipsize", PANGO_ELLIPSIZE_END,
NULL);
395 column = gtk_tree_view_column_new_with_attributes(
_(
"Label"), renderer,
"text",
CC_COLUMN_LABEL,
NULL);
396 g_object_set(column,
"expand", TRUE,
"resizable", TRUE,
NULL);
397 gtk_tree_view_append_column(GTK_TREE_VIEW(cc.
view), column);
399 scroll = gtk_scrolled_window_new(
NULL,
NULL);
400 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC,
401 GTK_POLICY_AUTOMATIC);
402 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN);
404 gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
409 guint len = g_strv_length(
ui_prefs.custom_commands);
411 for (i = 0; i < len; i++)
420 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(cc.
store), &iter))
422 GtkTreePath *path = gtk_tree_model_get_path(GTK_TREE_MODEL(cc.
store), &iter);
424 gtk_tree_view_set_cursor(GTK_TREE_VIEW(cc.
view), path, cc.
edit_column, FALSE);
425 gtk_tree_path_free(path);
429 buttonbox = gtk_button_box_new(GTK_ORIENTATION_HORIZONTAL);
430 gtk_box_set_spacing(GTK_BOX(buttonbox), 6);
431 gtk_box_pack_start(GTK_BOX(vbox), buttonbox, FALSE, FALSE, 0);
432 cc.
button_add = gtk_button_new_from_stock(GTK_STOCK_ADD);
435 cc.
button_remove = gtk_button_new_from_stock(GTK_STOCK_REMOVE);
438 cc.
button_up = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
441 cc.
button_down = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
455 if (gtk_dialog_run(GTK_DIALOG(
dialog)) == GTK_RESPONSE_ACCEPT)
457 GSList *cmd_list =
NULL;
458 GSList *lbl_list =
NULL;
460 gchar **commands =
NULL;
461 gchar **labels =
NULL;
464 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(cc.
store), &iter))
474 cmd_list = g_slist_prepend(cmd_list, cmd);
475 lbl_list = g_slist_prepend(lbl_list, lbl);
484 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(cc.
store), &iter));
486 cmd_list = g_slist_reverse(cmd_list);
487 lbl_list = g_slist_reverse(lbl_list);
492 GSList *cmd_node, *lbl_node;
494 commands = g_new(gchar*, len + 1);
495 labels = g_new(gchar*, len + 1);
497 for (cmd_node = cmd_list, lbl_node = lbl_list; cmd_node !=
NULL; cmd_node = cmd_node->next, lbl_node = lbl_node->next)
499 commands[j] = (gchar*) cmd_node->data;
500 labels[j] = (gchar*) lbl_node->data;
508 g_strfreev(
ui_prefs.custom_commands);
509 ui_prefs.custom_commands = commands;
510 g_strfreev(
ui_prefs.custom_commands_labels);
511 ui_prefs.custom_commands_labels = labels;
515 g_slist_free(cmd_list);
516 g_slist_free(lbl_list);
518 gtk_widget_destroy(
dialog);
529 command_idx = GPOINTER_TO_INT(user_data);
532 command_idx < 0 || command_idx > (gint) g_strv_length(
ui_prefs.custom_commands))
562 item = gtk_menu_item_new_with_label(
label);
563 gtk_widget_set_tooltip_text(item, tooltip);
570 gtk_widget_add_accelerator(item,
"activate", gtk_accel_group_new(),
571 kb->
key, kb->
mods, GTK_ACCEL_VISIBLE);
575 gtk_widget_show(item);
577 GINT_TO_POINTER(idx));
585 GList *me_children, *node;
588 me_children = gtk_container_get_children(GTK_CONTAINER(menu_edit));
590 gtk_widget_destroy(GTK_WIDGET(node->data));
591 g_list_free(me_children);
595 item = gtk_menu_item_new_with_label(
_(
"No custom commands defined."));
597 gtk_widget_set_sensitive(item, FALSE);
598 gtk_widget_show(item);
604 len = g_strv_length(
ui_prefs.custom_commands);
605 for (i = 0; i < len; i++)
620 item = gtk_separator_menu_item_new();
622 gtk_widget_show(item);
641 while (*
text !=
'\0')
663 utext = g_utf8_get_char_validated(
text, 2);
664 if (g_unichar_isspace(utext))
665 goto mb_word_separator;
666 if (g_unichar_isgraph(utext))
692 g_return_if_fail(doc !=
NULL);
695 GTK_DIALOG_DESTROY_WITH_PARENT,
696 GTK_STOCK_CLOSE, GTK_RESPONSE_CANCEL,
NULL);
698 gtk_widget_set_name(
dialog,
"GeanyDialog");
703 range =
_(
"selection");
708 range =
_(
"whole document");
713 table = gtk_table_new(4, 2, FALSE);
714 gtk_table_set_row_spacings(GTK_TABLE(table), 5);
715 gtk_table_set_col_spacings(GTK_TABLE(table), 10);
717 label = gtk_label_new(
_(
"Range:"));
718 gtk_table_attach(GTK_TABLE(table),
label, 0, 1, 0, 1,
719 (GtkAttachOptions) (GTK_FILL),
720 (GtkAttachOptions) (0), 0, 0);
721 gtk_misc_set_alignment(GTK_MISC(
label), 1, 0);
723 label = gtk_label_new(range);
724 gtk_table_attach(GTK_TABLE(table),
label, 1, 2, 0, 1,
725 (GtkAttachOptions) (GTK_FILL),
726 (GtkAttachOptions) (0), 20, 0);
727 gtk_misc_set_alignment(GTK_MISC(
label), 0, 0);
729 label = gtk_label_new(
_(
"Lines:"));
730 gtk_table_attach(GTK_TABLE(table),
label, 0, 1, 1, 2,
731 (GtkAttachOptions) (GTK_FILL),
732 (GtkAttachOptions) (0), 0, 0);
733 gtk_misc_set_alignment(GTK_MISC(
label), 1, 0);
737 gtk_table_attach(GTK_TABLE(table),
label, 1, 2, 1, 2,
738 (GtkAttachOptions) (GTK_FILL),
739 (GtkAttachOptions) (0), 20, 0);
740 gtk_misc_set_alignment(GTK_MISC(
label), 0, 0);
743 label = gtk_label_new(
_(
"Words:"));
744 gtk_table_attach(GTK_TABLE(table),
label, 0, 1, 2, 3,
745 (GtkAttachOptions) (GTK_FILL),
746 (GtkAttachOptions) (0), 0, 0);
747 gtk_misc_set_alignment(GTK_MISC(
label), 1, 0);
749 text = g_strdup_printf(
"%d", words);
751 gtk_table_attach(GTK_TABLE(table),
label, 1, 2, 2, 3,
752 (GtkAttachOptions) (GTK_FILL),
753 (GtkAttachOptions) (0), 20, 0);
754 gtk_misc_set_alignment(GTK_MISC(
label), 0, 0);
757 label = gtk_label_new(
_(
"Characters:"));
758 gtk_table_attach(GTK_TABLE(table),
label, 0, 1, 3, 4,
759 (GtkAttachOptions) (GTK_FILL),
760 (GtkAttachOptions) (0), 0, 0);
761 gtk_misc_set_alignment(GTK_MISC(
label), 1, 0);
765 gtk_table_attach(GTK_TABLE(table),
label, 1, 2, 3, 4,
766 (GtkAttachOptions) (GTK_FILL),
767 (GtkAttachOptions) (0), 20, 0);
768 gtk_misc_set_alignment(GTK_MISC(
label), 0, 0);
773 g_signal_connect(
dialog,
"response", G_CALLBACK(gtk_widget_destroy),
dialog);
774 g_signal_connect(
dialog,
"delete-event", G_CALLBACK(gtk_widget_destroy),
dialog);
787 case GTK_RESPONSE_OK:
790 case GTK_RESPONSE_APPLY:
797 g_return_if_fail(doc !=
NULL);
799 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(
ui_widgets.open_colorsel));
800 gtk_color_selection_get_current_color(GTK_COLOR_SELECTION(colorsel), &
color);
819 g_free(
ui_prefs.color_picker_palette);
820 ui_prefs.color_picker_palette = gtk_color_selection_palette_to_string(colors, n_colors);
823 settings = gtk_settings_get_for_screen(screen);
837 win32_show_color_dialog(
color);
844 ui_widgets.open_colorsel = gtk_color_selection_dialog_new(
_(
"Color Chooser"));
845 gtk_dialog_add_button(GTK_DIALOG(
ui_widgets.open_colorsel), GTK_STOCK_APPLY, GTK_RESPONSE_APPLY);
847 GTK_RESPONSE_APPLY, GTK_RESPONSE_CANCEL, GTK_RESPONSE_OK, -1);
848 gtk_widget_set_name(
ui_widgets.open_colorsel,
"GeanyDialog");
850 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(
ui_widgets.open_colorsel));
851 gtk_color_selection_set_has_palette(GTK_COLOR_SELECTION(colorsel), TRUE);
854 g_signal_connect(
ui_widgets.open_colorsel,
"response",
856 g_signal_connect(
ui_widgets.open_colorsel,
"delete-event",
857 G_CALLBACK(gtk_widget_hide_on_delete),
NULL);
860 colorsel = gtk_color_selection_dialog_get_color_selection(GTK_COLOR_SELECTION_DIALOG(
ui_widgets.open_colorsel));
864 gtk_color_selection_set_current_color(GTK_COLOR_SELECTION(colorsel), &gc);
865 gtk_color_selection_set_previous_color(GTK_COLOR_SELECTION(colorsel), &gc);
869 gtk_window_present(GTK_WINDOW(
ui_widgets.open_colorsel));
GeanyDocument * document_get_current(void)
Finds the current document.
Document related actions: new, save, open, etc.
#define DOC_VALID(doc_ptr)
Null-safe way to check GeanyDocument::is_valid.
void editor_insert_color(GeanyEditor *editor, const gchar *colour)
void editor_select_lines(GeanyEditor *editor, gboolean extra_line)
void error(const errorSelection selection, const char *const format,...)
GeanyKeyBinding * keybindings_lookup_item(guint group_id, guint key_id)
Configurable keyboard shortcuts.
@ GEANY_KEY_GROUP_FORMAT
Group.
@ GEANY_KEYS_FORMAT_SENDTOCMD5
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD7
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD3
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD4
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD9
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD8
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD6
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD2
Keybinding.
@ GEANY_KEYS_FORMAT_SENDTOCMD1
Keybinding.
static GtkPrintSettings * settings
gchar * sci_get_selection_contents(ScintillaObject *sci)
Gets selected text.
void sci_replace_sel(ScintillaObject *sci, const gchar *text)
Replaces selection.
gboolean sci_has_selection(ScintillaObject *sci)
Checks if there's a selection.
gchar * sci_get_contents(ScintillaObject *sci, gint buffer_len)
Allocates and fills a buffer with text from the start of the document.
Wrapper functions for the Scintilla editor widget SCI_* messages.
gboolean spawn_check_command(const gchar *command_line, gboolean execute, GError **error)
Checks whether a command line is valid.
gboolean spawn_sync(const gchar *working_directory, const gchar *command_line, gchar **argv, gchar **envp, SpawnWriteData *stdin_data, GString *stdout_data, GString *stderr_data, gint *exit_status, GError **error)
Executes a child synchronously.
Portable and convenient process spawning and communication.
#define SPAWN_WIFEXITED(status)
non-zero if the child exited normally
#define SPAWN_WEXITSTATUS(status)
exit status of a child if exited normally
gtk_container_add(GTK_CONTAINER(dialog->vbox), check_button)
gtk_widget_show_all(dialog)
Structure for representing an open tab with all its properties.
GeanyEditor * editor
The editor associated with the document.
ScintillaObject * sci
The Scintilla editor GtkWidget.
gboolean use_native_windows_dialogs
whether to use native Windows' dialogs (only used on Windows)
Represents a single keybinding action.
GdkModifierType mods
Modifier keys, such as GDK_CONTROL_MASK or 0.
guint key
Key value in lower-case, such as GDK_KEY_a or 0.
GtkWidget * window
Main window.
A simple structure used by spawn_write_data() to write data to a channel.
gsize size
Size of the data.
const gchar * ptr
Pointer to the data.
GtkTreeSelection * selection
GtkTreeViewColumn * edit_column
GtkWidget * button_remove
Defines internationalization macros.
void ui_dialog_set_primary_button_order(GtkDialog *dialog, gint response,...)
GtkWidget * ui_dialog_vbox_new(GtkDialog *dialog)
Makes a fixed border for dialogs without increasing the button box border.
GeanyMainWidgets main_widgets
void ui_set_statusbar(gboolean log, const gchar *format,...)
Displays text on the statusbar.
GtkWidget * ui_lookup_widget(GtkWidget *widget, const gchar *widget_name)
Returns a widget from a name in a component, usually created by Glade.
void ui_tree_view_set_tooltip_text_column(GtkTreeView *tree_view, gint column)
Adds text tooltips to a tree view.
GeanyInterfacePrefs interface_prefs
User Interface general utility functions.
gboolean utils_parse_color(const gchar *spec, GdkColor *color)
gchar * utils_get_hex_from_color(GdkColor *color)
General utility functions, non-GTK related.
#define foreach_list(node, list)
Iterates all the nodes in list.
#define EMPTY(ptr)
Returns TRUE if ptr is NULL or *ptr is FALSE.