lists.geany.org
Sign In
Sign Up
Sign In
Sign Up
Manage this list
×
Keyboard Shortcuts
Thread View
j
: Next unread message
k
: Previous unread message
j a
: Jump to all threads
j l
: Jump to MailingList overview
2024
December
November
October
September
August
July
June
May
April
March
February
January
2023
December
November
October
September
August
July
June
May
April
March
February
January
2022
December
November
October
September
August
July
June
May
April
March
February
January
2021
December
November
October
September
August
July
June
May
April
March
February
January
2020
December
November
October
September
August
July
June
May
April
March
February
January
2019
December
November
October
September
August
July
June
May
April
March
February
January
2018
December
November
October
September
August
July
June
May
April
March
February
January
2017
December
November
October
September
August
July
June
May
April
March
February
January
2016
December
November
October
September
August
July
June
May
April
March
February
January
2015
December
November
October
September
August
July
June
May
April
March
February
January
2014
December
November
October
September
August
July
June
May
April
March
February
January
2013
December
November
October
September
August
July
June
May
April
March
February
January
2012
December
November
October
September
August
July
June
May
April
March
February
January
2011
December
November
October
September
August
July
June
May
April
March
February
January
2010
December
November
October
September
August
July
June
May
April
March
February
January
2009
December
November
October
September
August
July
June
May
April
March
February
January
2008
December
November
October
September
August
July
June
May
April
List overview
Plugins-Commits
July 2019
----- 2024 -----
December 2024
November 2024
October 2024
September 2024
August 2024
July 2024
June 2024
May 2024
April 2024
March 2024
February 2024
January 2024
----- 2023 -----
December 2023
November 2023
October 2023
September 2023
August 2023
July 2023
June 2023
May 2023
April 2023
March 2023
February 2023
January 2023
----- 2022 -----
December 2022
November 2022
October 2022
September 2022
August 2022
July 2022
June 2022
May 2022
April 2022
March 2022
February 2022
January 2022
----- 2021 -----
December 2021
November 2021
October 2021
September 2021
August 2021
July 2021
June 2021
May 2021
April 2021
March 2021
February 2021
January 2021
----- 2020 -----
December 2020
November 2020
October 2020
September 2020
August 2020
July 2020
June 2020
May 2020
April 2020
March 2020
February 2020
January 2020
----- 2019 -----
December 2019
November 2019
October 2019
September 2019
August 2019
July 2019
June 2019
May 2019
April 2019
March 2019
February 2019
January 2019
----- 2018 -----
December 2018
November 2018
October 2018
September 2018
August 2018
July 2018
June 2018
May 2018
April 2018
March 2018
February 2018
January 2018
----- 2017 -----
December 2017
November 2017
October 2017
September 2017
August 2017
July 2017
June 2017
May 2017
April 2017
March 2017
February 2017
January 2017
----- 2016 -----
December 2016
November 2016
October 2016
September 2016
August 2016
July 2016
June 2016
May 2016
April 2016
March 2016
February 2016
January 2016
----- 2015 -----
December 2015
November 2015
October 2015
September 2015
August 2015
July 2015
June 2015
May 2015
April 2015
March 2015
February 2015
January 2015
----- 2014 -----
December 2014
November 2014
October 2014
September 2014
August 2014
July 2014
June 2014
May 2014
April 2014
March 2014
February 2014
January 2014
----- 2013 -----
December 2013
November 2013
October 2013
September 2013
August 2013
July 2013
June 2013
May 2013
April 2013
March 2013
February 2013
January 2013
----- 2012 -----
December 2012
November 2012
October 2012
September 2012
August 2012
July 2012
June 2012
May 2012
April 2012
March 2012
February 2012
January 2012
----- 2011 -----
December 2011
November 2011
October 2011
September 2011
August 2011
July 2011
June 2011
May 2011
April 2011
March 2011
February 2011
January 2011
----- 2010 -----
December 2010
November 2010
October 2010
September 2010
August 2010
July 2010
June 2010
May 2010
April 2010
March 2010
February 2010
January 2010
----- 2009 -----
December 2009
November 2009
October 2009
September 2009
August 2009
July 2009
June 2009
May 2009
April 2009
March 2009
February 2009
January 2009
----- 2008 -----
December 2008
November 2008
October 2008
September 2008
August 2008
July 2008
June 2008
May 2008
April 2008
plugins-commits@lists.geany.org
1 participants
35 discussions
Start a n
N
ew thread
[geany/geany-plugins] 0cd74f: Merge pull request #860 from LarsGit223/lineops-rm-every-n
by Frank Lanitz
12 Jul '19
12 Jul '19
Branch: refs/heads/master Author: Frank Lanitz <frank(a)frank.uvena.de> Committer: GitHub <noreply(a)github.com> Date: Fri, 12 Jul 2019 07:20:11 UTC Commit: 0cd74f5fcee2adca89b686c342b147e38b3496cc
https://github.com/geany/geany-plugins/commit/0cd74f5fcee2adca89b686c342b14…
Log Message: ----------- Merge pull request #860 from LarsGit223/lineops-rm-every-n lineoperations: remove every n-th line Modified Paths: -------------- lineoperations/README lineoperations/src/linefunctions.c lineoperations/src/linefunctions.h lineoperations/src/lineoperations.c po/POTFILES.in Modified: lineoperations/README 25 lines changed, 25 insertions(+), 0 deletions(-) =================================================================== @@ -19,6 +19,7 @@ Features * Keep Unique Lines * Remove Empty Lines * Remove Whitespace Lines +* Remove Every Nth Line * Sort Lines Ascending * Sort Lines Descending @@ -197,6 +198,30 @@ Removes all lines that have only whitespace characters. Line 1\n Line 2\n +Remove Every Nth Line +--------------------- + +The user can enter a number N. Every Nth line will be removed then. + + Example: Suppose a file has the following lines and the user enters the + value 2 for N. (#comments added for clarity) + + :: + + Line 1 + Line 2 #removed + Line 3 + Line 4 #removed + Line 5 + + The **Remove Every Nth Line** (N=2) will change the file into this: + + :: + + Line 1 + Line 3 + Line 5 + Sort Lines ---------- Modified: lineoperations/src/linefunctions.c 42 lines changed, 42 insertions(+), 0 deletions(-) =================================================================== @@ -301,3 +301,45 @@ sortlndesc(gchar **lines, gint num_lines, gchar *new_file) return num_lines; } + + +/* Remove Every Nth Line */ +gint +rmnthln(ScintillaObject *sci, gint line_num, gint end_line_num) +{ + gboolean ok; + gdouble n; + gint count; + gint changed = 0; /* number of lines removed */ + + ok = dialogs_show_input_numeric(_("Remove every Nth line"), + _("Value of N"), &n, 1, 1000, 1); + if (ok == FALSE) + { + return 0; + } + + count = n; + while(line_num <= end_line_num) /* loop through lines */ + { + count--; + + /* check if this is the nth line. */ + if(count == 0) + { + scintilla_send_message(sci, + SCI_DELETERANGE, + sci_get_position_from_line(sci, line_num), + sci_get_line_length(sci, line_num)); + + line_num--; + end_line_num--; + changed++; + count = n; + } + line_num++; + } + + /* return the number of lines deleted */ + return -changed; +} Modified: lineoperations/src/linefunctions.h 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -69,4 +69,9 @@ sortlnsasc(gchar **lines, gint num_lines, gchar *new_file); gint sortlndesc(gchar **lines, gint num_lines, gchar *new_file); + +/* Remove Every Nth Line */ +gint +rmnthln(ScintillaObject *sci, gint line_num, gint end_line_num); + #endif Modified: lineoperations/src/lineoperations.c 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -264,6 +264,9 @@ lo_init(GeanyPlugin *plugin, gpointer gdata) { N_("Remove _Whitespace Lines"), G_CALLBACK(action_sci_manip_item), (gpointer) rmwhspln }, { NULL }, + { N_("Remove Every _Nth Line"), + G_CALLBACK(action_sci_manip_item), (gpointer) rmnthln }, + { NULL }, { N_("Sort Lines _Ascending"), G_CALLBACK(action_indir_manip_item), (gpointer) sortlnsasc }, { N_("Sort Lines _Descending"), Modified: po/POTFILES.in 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -220,6 +220,7 @@ keyrecord/src/keyrecord.c # LineOperations lineoperations/src/lineoperations.c +lineoperations/src/linefunctions.c # lipsum lipsum/src/lipsum.c -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 0cd74f: Merge pull request #860 from LarsGit223/lineops-rm-every-n
by Frank Lanitz
12 Jul '19
12 Jul '19
Branch: refs/heads/master Author: Frank Lanitz <frank(a)frank.uvena.de> Committer: GitHub <noreply(a)github.com> Date: Fri, 12 Jul 2019 07:20:11 UTC Commit: 0cd74f5fcee2adca89b686c342b147e38b3496cc
https://github.com/geany/geany-plugins/commit/0cd74f5fcee2adca89b686c342b14…
Log Message: ----------- Merge pull request #860 from LarsGit223/lineops-rm-every-n lineoperations: remove every n-th line Modified Paths: -------------- lineoperations/README lineoperations/src/linefunctions.c lineoperations/src/linefunctions.h lineoperations/src/lineoperations.c po/POTFILES.in Modified: lineoperations/README 25 lines changed, 25 insertions(+), 0 deletions(-) =================================================================== @@ -19,6 +19,7 @@ Features * Keep Unique Lines * Remove Empty Lines * Remove Whitespace Lines +* Remove Every Nth Line * Sort Lines Ascending * Sort Lines Descending @@ -197,6 +198,30 @@ Removes all lines that have only whitespace characters. Line 1\n Line 2\n +Remove Every Nth Line +--------------------- + +The user can enter a number N. Every Nth line will be removed then. + + Example: Suppose a file has the following lines and the user enters the + value 2 for N. (#comments added for clarity) + + :: + + Line 1 + Line 2 #removed + Line 3 + Line 4 #removed + Line 5 + + The **Remove Every Nth Line** (N=2) will change the file into this: + + :: + + Line 1 + Line 3 + Line 5 + Sort Lines ---------- Modified: lineoperations/src/linefunctions.c 42 lines changed, 42 insertions(+), 0 deletions(-) =================================================================== @@ -301,3 +301,45 @@ sortlndesc(gchar **lines, gint num_lines, gchar *new_file) return num_lines; } + + +/* Remove Every Nth Line */ +gint +rmnthln(ScintillaObject *sci, gint line_num, gint end_line_num) +{ + gboolean ok; + gdouble n; + gint count; + gint changed = 0; /* number of lines removed */ + + ok = dialogs_show_input_numeric(_("Remove every Nth line"), + _("Value of N"), &n, 1, 1000, 1); + if (ok == FALSE) + { + return 0; + } + + count = n; + while(line_num <= end_line_num) /* loop through lines */ + { + count--; + + /* check if this is the nth line. */ + if(count == 0) + { + scintilla_send_message(sci, + SCI_DELETERANGE, + sci_get_position_from_line(sci, line_num), + sci_get_line_length(sci, line_num)); + + line_num--; + end_line_num--; + changed++; + count = n; + } + line_num++; + } + + /* return the number of lines deleted */ + return -changed; +} Modified: lineoperations/src/linefunctions.h 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -69,4 +69,9 @@ sortlnsasc(gchar **lines, gint num_lines, gchar *new_file); gint sortlndesc(gchar **lines, gint num_lines, gchar *new_file); + +/* Remove Every Nth Line */ +gint +rmnthln(ScintillaObject *sci, gint line_num, gint end_line_num); + #endif Modified: lineoperations/src/lineoperations.c 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -264,6 +264,9 @@ lo_init(GeanyPlugin *plugin, gpointer gdata) { N_("Remove _Whitespace Lines"), G_CALLBACK(action_sci_manip_item), (gpointer) rmwhspln }, { NULL }, + { N_("Remove Every _Nth Line"), + G_CALLBACK(action_sci_manip_item), (gpointer) rmnthln }, + { NULL }, { N_("Sort Lines _Ascending"), G_CALLBACK(action_indir_manip_item), (gpointer) sortlnsasc }, { N_("Sort Lines _Descending"), Modified: po/POTFILES.in 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -220,6 +220,7 @@ keyrecord/src/keyrecord.c # LineOperations lineoperations/src/lineoperations.c +lineoperations/src/linefunctions.c # lipsum lipsum/src/lipsum.c -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 7058a5: scope: prevent usage of invalid iters (GtkTreeeIter)
by LarsGit223
12 Jul '19
12 Jul '19
Branch: refs/heads/master Author: LarsGit223 <lars_paulsen(a)web.de> Committer: LarsGit223 <lars_paulsen(a)web.de> Date: Wed, 20 Feb 2019 20:18:03 UTC Commit: 7058a5dd8f086ae762abb2cb9f689951125f96cd
https://github.com/geany/geany-plugins/commit/7058a5dd8f086ae762abb2cb9f689…
Log Message: ----------- scope: prevent usage of invalid iters (GtkTreeeIter) This is done by checking all results from calls to 'gtk_tree_selection_get_selected()'. Additionally some initializations have been moved behind parameter checks in 'scptreestore.c' to prevent crashes in case (still) an invalid iter would be passed as an argument. The changes in function 'stack_entry()' fixed #824. Modified Paths: -------------- scope/src/break.c scope/src/inspect.c scope/src/local.c scope/src/memory.c scope/src/menu.c scope/src/register.c scope/src/stack.c scope/src/store/scptreestore.c scope/src/thread.c Modified: scope/src/break.c 20 lines changed, 13 insertions(+), 7 deletions(-) =================================================================== @@ -1332,8 +1332,10 @@ static void on_break_apply(const MenuItem *menu_item) if (menu_item || thread_id) { GtkTreeIter iter; - gtk_tree_selection_get_selected(selection, NULL, &iter); - break_apply(&iter, !menu_item); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + break_apply(&iter, !menu_item); + } } else plugin_beep(); @@ -1343,16 +1345,20 @@ static void on_break_run_apply(const MenuItem *menu_item) { GtkTreeIter iter; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_set(store, &iter, BREAK_RUN_APPLY, - gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item->widget)), -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_set(store, &iter, BREAK_RUN_APPLY, + gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item->widget)), -1); + } } static void on_break_delete(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - gtk_tree_selection_get_selected(selection, NULL, &iter); - break_delete(&iter); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + break_delete(&iter); + } } static void break_seek_selected(gboolean focus) Modified: scope/src/inspect.c 156 lines changed, 92 insertions(+), 64 deletions(-) =================================================================== @@ -815,25 +815,29 @@ static void on_inspect_edit(G_GNUC_UNUSED const MenuItem *menu_item) const char *name, *frame; gboolean run_apply; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, - INSPECT_FRAME, &frame, INSPECT_RUN_APPLY, &run_apply, -1); - scp_tree_store_set(store, &iter, INSPECT_NAME, "-", -1); /* for duplicate name check */ - - gtk_entry_set_text(inspect_expr, expr); - gtk_entry_set_text(inspect_name, name); - gtk_entry_set_text(inspect_frame, frame); - gtk_toggle_button_set_active(inspect_run_apply, run_apply); - on_inspect_entry_changed(NULL, NULL); - - if (gtk_dialog_run(GTK_DIALOG(inspect_dialog)) == GTK_RESPONSE_ACCEPT) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - g_free(jump_to_expr); - jump_to_expr = NULL; - inspect_dialog_store(&iter); + scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, + INSPECT_FRAME, &frame, INSPECT_RUN_APPLY, &run_apply, -1); + scp_tree_store_set(store, &iter, INSPECT_NAME, "-", -1); /* for duplicate name check */ + + gtk_entry_set_text(inspect_expr, expr); + gtk_entry_set_text(inspect_name, name); + gtk_entry_set_text(inspect_frame, frame); + gtk_toggle_button_set_active(inspect_run_apply, run_apply); + on_inspect_entry_changed(NULL, NULL); + + if (gtk_dialog_run(GTK_DIALOG(inspect_dialog)) == GTK_RESPONSE_ACCEPT) + { + g_free(jump_to_expr); + jump_to_expr = NULL; + inspect_dialog_store(&iter); + } + else + { + scp_tree_store_set(store, &iter, INSPECT_NAME, name, -1); + } } - else - scp_tree_store_set(store, &iter, INSPECT_NAME, name, -1); } static void on_inspect_apply(G_GNUC_UNUSED const MenuItem *menu_item) @@ -842,13 +846,19 @@ static void on_inspect_apply(G_GNUC_UNUSED const MenuItem *menu_item) const char *var1; gint scid; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_SCID, &scid, INSPECT_VAR1, &var1, -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, INSPECT_SCID, &scid, INSPECT_VAR1, &var1, -1); - if (var1) - debug_send_format(N, "070%d-var-delete %s", scid, var1); - else - inspect_apply(&iter); + if (var1) + { + debug_send_format(N, "070%d-var-delete %s", scid, var1); + } + else + { + inspect_apply(&iter); + } + } } static GtkWidget *expand_dialog; @@ -863,25 +873,31 @@ static void on_inspect_expand(G_GNUC_UNUSED const MenuItem *menu_item) gint start, count; gboolean expand; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_NAME, &name, INSPECT_START, &start, - INSPECT_COUNT, &count, INSPECT_EXPAND, &expand, -1); - gtk_spin_button_set_value(expand_start, start); - gtk_spin_button_set_value(expand_count, count); - gtk_toggle_button_set_active(expand_automatic, expand); - gtk_widget_set_sensitive(GTK_WIDGET(expand_automatic), name != NULL); - - if (gtk_dialog_run(GTK_DIALOG(expand_dialog)) == GTK_RESPONSE_ACCEPT) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - scp_tree_store_set(store, &iter, - INSPECT_START, gtk_spin_button_get_value_as_int(expand_start), - INSPECT_COUNT, gtk_spin_button_get_value_as_int(expand_count), - INSPECT_EXPAND, gtk_toggle_button_get_active(expand_automatic), -1); + scp_tree_store_get(store, &iter, INSPECT_NAME, &name, INSPECT_START, &start, + INSPECT_COUNT, &count, INSPECT_EXPAND, &expand, -1); + gtk_spin_button_set_value(expand_start, start); + gtk_spin_button_set_value(expand_count, count); + gtk_toggle_button_set_active(expand_automatic, expand); + gtk_widget_set_sensitive(GTK_WIDGET(expand_automatic), name != NULL); + + if (gtk_dialog_run(GTK_DIALOG(expand_dialog)) == GTK_RESPONSE_ACCEPT) + { + scp_tree_store_set(store, &iter, + INSPECT_START, gtk_spin_button_get_value_as_int(expand_start), + INSPECT_COUNT, gtk_spin_button_get_value_as_int(expand_count), + INSPECT_EXPAND, gtk_toggle_button_get_active(expand_automatic), -1); - if (debug_state() & DS_VARIABLE) - inspect_expand(&iter); - else - plugin_beep(); + if (debug_state() & DS_VARIABLE) + { + inspect_expand(&iter); + } + else + { + plugin_beep(); + } + } } } @@ -901,16 +917,20 @@ static void on_inspect_format_update(const MenuItem *menu_item) gint format = GPOINTER_TO_INT(menu_item->gdata); const char *var1; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); - - if (var1) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - debug_send_format(N, "07%d-var-set-format %s %s", inspect_get_scid(&iter), var1, - inspect_formats[format]); + scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); + + if (var1) + { + debug_send_format(N, "07%d-var-set-format %s %s", inspect_get_scid(&iter), var1, + inspect_formats[format]); + } + else + { + scp_tree_store_set(store, &iter, INSPECT_FORMAT, format, -1); + } } - else - scp_tree_store_set(store, &iter, INSPECT_FORMAT, format, -1); } static void on_inspect_hbit_display(const MenuItem *menu_item) @@ -939,18 +959,20 @@ static void on_inspect_hbit_update(const MenuItem *menu_item) const char *expr, *name; gint hb_mode = GPOINTER_TO_INT(menu_item->gdata); - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, -1); - inspect_hbit_update_iter(&iter, hb_mode); - parse_mode_update(expr, MODE_HBIT, hb_mode); - - if (name) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - char *reverse = parse_mode_reentry(expr); + scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, -1); + inspect_hbit_update_iter(&iter, hb_mode); + parse_mode_update(expr, MODE_HBIT, hb_mode); + + if (name) + { + char *reverse = parse_mode_reentry(expr); - if (store_find(store, &iter, INSPECT_EXPR, reverse)) - inspect_hbit_update_iter(&iter, hb_mode); - g_free(reverse); + if (store_find(store, &iter, INSPECT_EXPR, reverse)) + inspect_hbit_update_iter(&iter, hb_mode); + g_free(reverse); + } } } @@ -959,13 +981,19 @@ static void on_inspect_delete(G_GNUC_UNUSED const MenuItem *menu_item) GtkTreeIter iter; const char *var1; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); - if (var1) - debug_send_format(N, "071%d-var-delete %s", inspect_get_scid(&iter), var1); - else - scp_tree_store_remove(store, &iter); + if (var1) + { + debug_send_format(N, "071%d-var-delete %s", inspect_get_scid(&iter), var1); + } + else + { + scp_tree_store_remove(store, &iter); + } + } } #define DS_EDITABLE (DS_BASICS | DS_EXTRA_2) Modified: scope/src/local.c 8 lines changed, 5 insertions(+), 3 deletions(-) =================================================================== @@ -152,9 +152,11 @@ static void on_local_watch(G_GNUC_UNUSED const MenuItem *menu_item) GtkTreeIter iter; const char *name; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, LOCAL_NAME, &name, -1); - watch_add(name); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, LOCAL_NAME, &name, -1); + watch_add(name); + } } static void on_local_inspect(G_GNUC_UNUSED const MenuItem *menu_item) Modified: scope/src/memory.c 16 lines changed, 9 insertions(+), 7 deletions(-) =================================================================== @@ -304,13 +304,15 @@ static void on_memory_copy(G_GNUC_UNUSED const MenuItem *menu_item) const gchar *ascii; gchar *string; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, MEMORY_ADDR, &addr, MEMORY_BYTES, &bytes, - MEMORY_ASCII, &ascii, -1); - string = g_strdup_printf("%s%s%s", addr, bytes, ascii); - gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, - GDK_SELECTION_CLIPBOARD), string, -1); - g_free(string); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, MEMORY_ADDR, &addr, MEMORY_BYTES, &bytes, + MEMORY_ASCII, &ascii, -1); + string = g_strdup_printf("%s%s%s", addr, bytes, ascii); + gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, + GDK_SELECTION_CLIPBOARD), string, -1); + g_free(string); + } } static void on_memory_clear(G_GNUC_UNUSED const MenuItem *menu_item) Modified: scope/src/menu.c 70 lines changed, 40 insertions(+), 30 deletions(-) =================================================================== @@ -203,9 +203,11 @@ void menu_mode_display(GtkTreeSelection *selection, const MenuItem *menu_item, g GtkTreeIter iter; gint mode; - gtk_tree_selection_get_selected(selection, &model, &iter); - gtk_tree_model_get(model, &iter, column, &mode, -1); - menu_item_set_active(menu_item + mode + 1, TRUE); + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + { + gtk_tree_model_get(model, &iter, column, &mode, -1); + menu_item_set_active(menu_item + mode + 1, TRUE); + } } static void menu_mode_update_iter(ScpTreeStore *store, GtkTreeIter *iter, gint new_mode, @@ -235,18 +237,20 @@ void menu_mode_update(GtkTreeSelection *selection, gint new_mode, gboolean hbit) GtkTreeIter iter; const char *name; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); - menu_mode_update_iter(store, &iter, new_mode, hbit); - parse_mode_update(name, hbit ? MODE_HBIT : MODE_MEMBER, new_mode); - - if (hbit) + if (scp_tree_selection_get_selected(selection, &store, &iter)) { - char *reverse = parse_mode_reentry(name); + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); + menu_mode_update_iter(store, &iter, new_mode, hbit); + parse_mode_update(name, hbit ? MODE_HBIT : MODE_MEMBER, new_mode); + + if (hbit) + { + char *reverse = parse_mode_reentry(name); - if (store_find(store, &iter, COLUMN_NAME, reverse)) - menu_mode_update_iter(store, &iter, new_mode, TRUE); - g_free(reverse); + if (store_find(store, &iter, COLUMN_NAME, reverse)) + menu_mode_update_iter(store, &iter, new_mode, TRUE); + g_free(reverse); + } } } @@ -306,18 +310,20 @@ void menu_copy(GtkTreeSelection *selection, const MenuItem *menu_item) const char *value; GString *string; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_DISPLAY, &display, - COLUMN_VALUE, &value, -1); - string = g_string_new(name); + if (scp_tree_selection_get_selected(selection, &store, &iter)) + { + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_DISPLAY, &display, + COLUMN_VALUE, &value, -1); + string = g_string_new(name); - if (value) - g_string_append_printf(string, " = %s", display); + if (value) + g_string_append_printf(string, " = %s", display); - gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, - GDK_SELECTION_CLIPBOARD), string->str, string->len); + gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, + GDK_SELECTION_CLIPBOARD), string->str, string->len); - g_string_free(string, TRUE); + g_string_free(string, TRUE); + } } static GtkWidget *modify_dialog; @@ -373,11 +379,13 @@ void menu_modify(GtkTreeSelection *selection, const MenuItem *menu_item) const char *value; gint hb_mode; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_VALUE, &value, COLUMN_HB_MODE, - &hb_mode, -1); - menu_evaluate_modify(name, value, _("Modify"), hb_mode, menu_item ? MR_MODIFY : MR_MODSTR, - "07"); + if (scp_tree_selection_get_selected(selection, &store, &iter)) + { + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_VALUE, &value, COLUMN_HB_MODE, + &hb_mode, -1); + menu_evaluate_modify(name, value, _("Modify"), hb_mode, menu_item ? MR_MODIFY : MR_MODSTR, + "07"); + } } void menu_inspect(GtkTreeSelection *selection) @@ -386,9 +394,11 @@ void menu_inspect(GtkTreeSelection *selection) GtkTreeIter iter; const char *name; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); - inspect_add(name); + if (scp_tree_selection_get_selected(selection, &store, &iter)) + { + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); + inspect_add(name); + } } void on_menu_display_booleans(const MenuItem *menu_item) Modified: scope/src/register.c 20 lines changed, 12 insertions(+), 8 deletions(-) =================================================================== @@ -459,16 +459,20 @@ static void on_register_format_update(const MenuItem *menu_item) gint format = GPOINTER_TO_INT(menu_item->gdata); gint id; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, REGISTER_ID, &id, -1); - - if (debug_state() & DS_DEBUG) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - debug_send_format(N, "02%d%c%s%s-data-list-register-values %c %d", format, - FRAME_ARGS, register_formats[format], id); + scp_tree_store_get(store, &iter, REGISTER_ID, &id, -1); + + if (debug_state() & DS_DEBUG) + { + debug_send_format(N, "02%d%c%s%s-data-list-register-values %c %d", format, + FRAME_ARGS, register_formats[format], id); + } + else + { + scp_tree_store_set(store, &iter, REGISTER_FORMAT, format, -1); + } } - else - scp_tree_store_set(store, &iter, REGISTER_FORMAT, format, -1); } static void on_register_query(G_GNUC_UNUSED const MenuItem *menu_item) Modified: scope/src/stack.c 32 lines changed, 19 insertions(+), 13 deletions(-) =================================================================== @@ -165,10 +165,12 @@ void on_stack_follow(GArray *nodes) gboolean stack_entry(void) { GtkTreeIter iter; - gboolean entry; + gboolean entry = NULL; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, STACK_ENTRY, &entry, -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, STACK_ENTRY, &entry, -1); + } return entry; } @@ -268,18 +270,22 @@ static void on_stack_show_entry(const MenuItem *menu_item) GtkTreeIter iter; view_dirty(VIEW_LOCALS); - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, STACK_FUNC, &ed.func, -1); - parse_mode_update(ed.func, MODE_ENTRY, ed.entry); - store_foreach(store, (GFunc) stack_iter_show_entry, &ed); - - if (ed.count == 1) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - debug_send_format(T, "04%s-stack-list-arguments 1 %s %s", thread_id, frame_id, - frame_id); + scp_tree_store_get(store, &iter, STACK_FUNC, &ed.func, -1); + parse_mode_update(ed.func, MODE_ENTRY, ed.entry); + store_foreach(store, (GFunc) stack_iter_show_entry, &ed); + + if (ed.count == 1) + { + debug_send_format(T, "04%s-stack-list-arguments 1 %s %s", thread_id, frame_id, + frame_id); + } + else + { + debug_send_format(T, "04%s-stack-list-arguments 1", thread_id); + } } - else - debug_send_format(T, "04%s-stack-list-arguments 1", thread_id); } #define DS_VIEWABLE (DS_ACTIVE | DS_EXTRA_2) Modified: scope/src/store/scptreestore.c 15 lines changed, 10 insertions(+), 5 deletions(-) =================================================================== @@ -527,16 +527,19 @@ static void validate_store(ScpTreeStore *store) static gboolean scp_insert_element(ScpTreeStore *store, GtkTreeIter *iter, AElem *elem, gint position, GtkTreeIter *parent_iter) { - ScpTreeStorePrivate *priv = store->priv; - AElem *parent = parent_iter ? ITER_ELEM(parent_iter) : priv->root; - GPtrArray *array = parent->children; + ScpTreeStorePrivate *priv; + AElem *parent; + GPtrArray *array; GtkTreePath *path; g_return_val_if_fail(SCP_IS_TREE_STORE(store), FALSE); g_return_val_if_fail(iter != NULL, FALSE); + priv = store->priv; g_return_val_if_fail(priv->sublevels == TRUE || parent_iter == NULL, FALSE); g_return_val_if_fail(VALID_ITER_OR_NULL(parent_iter, store), FALSE); + parent = parent_iter ? ITER_ELEM(parent_iter) : priv->root; + array = parent->children; if (array) { if (position == -1) @@ -624,12 +627,13 @@ void scp_tree_store_insert_with_values(ScpTreeStore *store, GtkTreeIter *iter, void scp_tree_store_get_valist(ScpTreeStore *store, GtkTreeIter *iter, va_list ap) { ScpTreeStorePrivate *priv = store->priv; - AElem *elem = ITER_ELEM(iter); + AElem *elem; gint column; g_return_if_fail(SCP_IS_TREE_STORE(store)); g_return_if_fail(VALID_ITER(iter, store)); + elem = ITER_ELEM(iter); while ((column = va_arg(ap, int)) != -1) { gpointer dest; @@ -896,12 +900,13 @@ gboolean scp_tree_store_get_iter(ScpTreeStore *store, GtkTreeIter *iter, GtkTree GtkTreePath *scp_tree_store_get_path(VALIDATE_ONLY ScpTreeStore *store, GtkTreeIter *iter) { - AElem *elem = ITER_ELEM(iter); + AElem *elem; GtkTreePath *path; g_return_val_if_fail(VALID_ITER(iter, store), NULL); path = gtk_tree_path_new(); + elem = ITER_ELEM(iter); if (elem->parent) { gtk_tree_path_append_index(path, ITER_INDEX(iter)); Modified: scope/src/thread.c 16 lines changed, 9 insertions(+), 7 deletions(-) =================================================================== @@ -775,14 +775,16 @@ static void on_thread_interrupt(G_GNUC_UNUSED const MenuItem *menu_item) GtkTreeIter iter; HANDLE hid; - gtk_tree_selection_get_selected(selection, NULL, &iter); - hid = iter_to_handle(&iter); - - if (hid) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - if (!DebugBreakProcess(hid)) - show_errno("DebugBreakProcess"); - CloseHandle(hid); + hid = iter_to_handle(&iter); + + if (hid) + { + if (!DebugBreakProcess(hid)) + show_errno("DebugBreakProcess"); + CloseHandle(hid); + } } } -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] b877d9: Merge pull request #827 from LarsGit223/issue824
by Frank Lanitz
12 Jul '19
12 Jul '19
Branch: refs/heads/master Author: Frank Lanitz <frank(a)frank.uvena.de> Committer: GitHub <noreply(a)github.com> Date: Fri, 12 Jul 2019 07:18:34 UTC Commit: b877d94ee079fe368b3492d23435d3c089a70f9a
https://github.com/geany/geany-plugins/commit/b877d94ee079fe368b3492d23435d…
Log Message: ----------- Merge pull request #827 from LarsGit223/issue824 scope: prevent usage of invalid iters (GtkTreeeIter) Modified Paths: -------------- scope/src/break.c scope/src/inspect.c scope/src/local.c scope/src/memory.c scope/src/menu.c scope/src/register.c scope/src/stack.c scope/src/store/scptreestore.c scope/src/thread.c Modified: scope/src/break.c 20 lines changed, 13 insertions(+), 7 deletions(-) =================================================================== @@ -1332,8 +1332,10 @@ static void on_break_apply(const MenuItem *menu_item) if (menu_item || thread_id) { GtkTreeIter iter; - gtk_tree_selection_get_selected(selection, NULL, &iter); - break_apply(&iter, !menu_item); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + break_apply(&iter, !menu_item); + } } else plugin_beep(); @@ -1343,16 +1345,20 @@ static void on_break_run_apply(const MenuItem *menu_item) { GtkTreeIter iter; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_set(store, &iter, BREAK_RUN_APPLY, - gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item->widget)), -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_set(store, &iter, BREAK_RUN_APPLY, + gtk_check_menu_item_get_active(GTK_CHECK_MENU_ITEM(menu_item->widget)), -1); + } } static void on_break_delete(G_GNUC_UNUSED const MenuItem *menu_item) { GtkTreeIter iter; - gtk_tree_selection_get_selected(selection, NULL, &iter); - break_delete(&iter); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + break_delete(&iter); + } } static void break_seek_selected(gboolean focus) Modified: scope/src/inspect.c 156 lines changed, 92 insertions(+), 64 deletions(-) =================================================================== @@ -815,25 +815,29 @@ static void on_inspect_edit(G_GNUC_UNUSED const MenuItem *menu_item) const char *name, *frame; gboolean run_apply; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, - INSPECT_FRAME, &frame, INSPECT_RUN_APPLY, &run_apply, -1); - scp_tree_store_set(store, &iter, INSPECT_NAME, "-", -1); /* for duplicate name check */ - - gtk_entry_set_text(inspect_expr, expr); - gtk_entry_set_text(inspect_name, name); - gtk_entry_set_text(inspect_frame, frame); - gtk_toggle_button_set_active(inspect_run_apply, run_apply); - on_inspect_entry_changed(NULL, NULL); - - if (gtk_dialog_run(GTK_DIALOG(inspect_dialog)) == GTK_RESPONSE_ACCEPT) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - g_free(jump_to_expr); - jump_to_expr = NULL; - inspect_dialog_store(&iter); + scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, + INSPECT_FRAME, &frame, INSPECT_RUN_APPLY, &run_apply, -1); + scp_tree_store_set(store, &iter, INSPECT_NAME, "-", -1); /* for duplicate name check */ + + gtk_entry_set_text(inspect_expr, expr); + gtk_entry_set_text(inspect_name, name); + gtk_entry_set_text(inspect_frame, frame); + gtk_toggle_button_set_active(inspect_run_apply, run_apply); + on_inspect_entry_changed(NULL, NULL); + + if (gtk_dialog_run(GTK_DIALOG(inspect_dialog)) == GTK_RESPONSE_ACCEPT) + { + g_free(jump_to_expr); + jump_to_expr = NULL; + inspect_dialog_store(&iter); + } + else + { + scp_tree_store_set(store, &iter, INSPECT_NAME, name, -1); + } } - else - scp_tree_store_set(store, &iter, INSPECT_NAME, name, -1); } static void on_inspect_apply(G_GNUC_UNUSED const MenuItem *menu_item) @@ -842,13 +846,19 @@ static void on_inspect_apply(G_GNUC_UNUSED const MenuItem *menu_item) const char *var1; gint scid; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_SCID, &scid, INSPECT_VAR1, &var1, -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, INSPECT_SCID, &scid, INSPECT_VAR1, &var1, -1); - if (var1) - debug_send_format(N, "070%d-var-delete %s", scid, var1); - else - inspect_apply(&iter); + if (var1) + { + debug_send_format(N, "070%d-var-delete %s", scid, var1); + } + else + { + inspect_apply(&iter); + } + } } static GtkWidget *expand_dialog; @@ -863,25 +873,31 @@ static void on_inspect_expand(G_GNUC_UNUSED const MenuItem *menu_item) gint start, count; gboolean expand; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_NAME, &name, INSPECT_START, &start, - INSPECT_COUNT, &count, INSPECT_EXPAND, &expand, -1); - gtk_spin_button_set_value(expand_start, start); - gtk_spin_button_set_value(expand_count, count); - gtk_toggle_button_set_active(expand_automatic, expand); - gtk_widget_set_sensitive(GTK_WIDGET(expand_automatic), name != NULL); - - if (gtk_dialog_run(GTK_DIALOG(expand_dialog)) == GTK_RESPONSE_ACCEPT) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - scp_tree_store_set(store, &iter, - INSPECT_START, gtk_spin_button_get_value_as_int(expand_start), - INSPECT_COUNT, gtk_spin_button_get_value_as_int(expand_count), - INSPECT_EXPAND, gtk_toggle_button_get_active(expand_automatic), -1); + scp_tree_store_get(store, &iter, INSPECT_NAME, &name, INSPECT_START, &start, + INSPECT_COUNT, &count, INSPECT_EXPAND, &expand, -1); + gtk_spin_button_set_value(expand_start, start); + gtk_spin_button_set_value(expand_count, count); + gtk_toggle_button_set_active(expand_automatic, expand); + gtk_widget_set_sensitive(GTK_WIDGET(expand_automatic), name != NULL); + + if (gtk_dialog_run(GTK_DIALOG(expand_dialog)) == GTK_RESPONSE_ACCEPT) + { + scp_tree_store_set(store, &iter, + INSPECT_START, gtk_spin_button_get_value_as_int(expand_start), + INSPECT_COUNT, gtk_spin_button_get_value_as_int(expand_count), + INSPECT_EXPAND, gtk_toggle_button_get_active(expand_automatic), -1); - if (debug_state() & DS_VARIABLE) - inspect_expand(&iter); - else - plugin_beep(); + if (debug_state() & DS_VARIABLE) + { + inspect_expand(&iter); + } + else + { + plugin_beep(); + } + } } } @@ -901,16 +917,20 @@ static void on_inspect_format_update(const MenuItem *menu_item) gint format = GPOINTER_TO_INT(menu_item->gdata); const char *var1; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); - - if (var1) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - debug_send_format(N, "07%d-var-set-format %s %s", inspect_get_scid(&iter), var1, - inspect_formats[format]); + scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); + + if (var1) + { + debug_send_format(N, "07%d-var-set-format %s %s", inspect_get_scid(&iter), var1, + inspect_formats[format]); + } + else + { + scp_tree_store_set(store, &iter, INSPECT_FORMAT, format, -1); + } } - else - scp_tree_store_set(store, &iter, INSPECT_FORMAT, format, -1); } static void on_inspect_hbit_display(const MenuItem *menu_item) @@ -939,18 +959,20 @@ static void on_inspect_hbit_update(const MenuItem *menu_item) const char *expr, *name; gint hb_mode = GPOINTER_TO_INT(menu_item->gdata); - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, -1); - inspect_hbit_update_iter(&iter, hb_mode); - parse_mode_update(expr, MODE_HBIT, hb_mode); - - if (name) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - char *reverse = parse_mode_reentry(expr); + scp_tree_store_get(store, &iter, INSPECT_EXPR, &expr, INSPECT_NAME, &name, -1); + inspect_hbit_update_iter(&iter, hb_mode); + parse_mode_update(expr, MODE_HBIT, hb_mode); + + if (name) + { + char *reverse = parse_mode_reentry(expr); - if (store_find(store, &iter, INSPECT_EXPR, reverse)) - inspect_hbit_update_iter(&iter, hb_mode); - g_free(reverse); + if (store_find(store, &iter, INSPECT_EXPR, reverse)) + inspect_hbit_update_iter(&iter, hb_mode); + g_free(reverse); + } } } @@ -959,13 +981,19 @@ static void on_inspect_delete(G_GNUC_UNUSED const MenuItem *menu_item) GtkTreeIter iter; const char *var1; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, INSPECT_VAR1, &var1, -1); - if (var1) - debug_send_format(N, "071%d-var-delete %s", inspect_get_scid(&iter), var1); - else - scp_tree_store_remove(store, &iter); + if (var1) + { + debug_send_format(N, "071%d-var-delete %s", inspect_get_scid(&iter), var1); + } + else + { + scp_tree_store_remove(store, &iter); + } + } } #define DS_EDITABLE (DS_BASICS | DS_EXTRA_2) Modified: scope/src/local.c 8 lines changed, 5 insertions(+), 3 deletions(-) =================================================================== @@ -152,9 +152,11 @@ static void on_local_watch(G_GNUC_UNUSED const MenuItem *menu_item) GtkTreeIter iter; const char *name; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, LOCAL_NAME, &name, -1); - watch_add(name); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, LOCAL_NAME, &name, -1); + watch_add(name); + } } static void on_local_inspect(G_GNUC_UNUSED const MenuItem *menu_item) Modified: scope/src/memory.c 16 lines changed, 9 insertions(+), 7 deletions(-) =================================================================== @@ -304,13 +304,15 @@ static void on_memory_copy(G_GNUC_UNUSED const MenuItem *menu_item) const gchar *ascii; gchar *string; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, MEMORY_ADDR, &addr, MEMORY_BYTES, &bytes, - MEMORY_ASCII, &ascii, -1); - string = g_strdup_printf("%s%s%s", addr, bytes, ascii); - gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, - GDK_SELECTION_CLIPBOARD), string, -1); - g_free(string); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, MEMORY_ADDR, &addr, MEMORY_BYTES, &bytes, + MEMORY_ASCII, &ascii, -1); + string = g_strdup_printf("%s%s%s", addr, bytes, ascii); + gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, + GDK_SELECTION_CLIPBOARD), string, -1); + g_free(string); + } } static void on_memory_clear(G_GNUC_UNUSED const MenuItem *menu_item) Modified: scope/src/menu.c 70 lines changed, 40 insertions(+), 30 deletions(-) =================================================================== @@ -203,9 +203,11 @@ void menu_mode_display(GtkTreeSelection *selection, const MenuItem *menu_item, g GtkTreeIter iter; gint mode; - gtk_tree_selection_get_selected(selection, &model, &iter); - gtk_tree_model_get(model, &iter, column, &mode, -1); - menu_item_set_active(menu_item + mode + 1, TRUE); + if (gtk_tree_selection_get_selected(selection, &model, &iter)) + { + gtk_tree_model_get(model, &iter, column, &mode, -1); + menu_item_set_active(menu_item + mode + 1, TRUE); + } } static void menu_mode_update_iter(ScpTreeStore *store, GtkTreeIter *iter, gint new_mode, @@ -235,18 +237,20 @@ void menu_mode_update(GtkTreeSelection *selection, gint new_mode, gboolean hbit) GtkTreeIter iter; const char *name; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); - menu_mode_update_iter(store, &iter, new_mode, hbit); - parse_mode_update(name, hbit ? MODE_HBIT : MODE_MEMBER, new_mode); - - if (hbit) + if (scp_tree_selection_get_selected(selection, &store, &iter)) { - char *reverse = parse_mode_reentry(name); + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); + menu_mode_update_iter(store, &iter, new_mode, hbit); + parse_mode_update(name, hbit ? MODE_HBIT : MODE_MEMBER, new_mode); + + if (hbit) + { + char *reverse = parse_mode_reentry(name); - if (store_find(store, &iter, COLUMN_NAME, reverse)) - menu_mode_update_iter(store, &iter, new_mode, TRUE); - g_free(reverse); + if (store_find(store, &iter, COLUMN_NAME, reverse)) + menu_mode_update_iter(store, &iter, new_mode, TRUE); + g_free(reverse); + } } } @@ -306,18 +310,20 @@ void menu_copy(GtkTreeSelection *selection, const MenuItem *menu_item) const char *value; GString *string; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_DISPLAY, &display, - COLUMN_VALUE, &value, -1); - string = g_string_new(name); + if (scp_tree_selection_get_selected(selection, &store, &iter)) + { + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_DISPLAY, &display, + COLUMN_VALUE, &value, -1); + string = g_string_new(name); - if (value) - g_string_append_printf(string, " = %s", display); + if (value) + g_string_append_printf(string, " = %s", display); - gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, - GDK_SELECTION_CLIPBOARD), string->str, string->len); + gtk_clipboard_set_text(gtk_widget_get_clipboard(menu_item->widget, + GDK_SELECTION_CLIPBOARD), string->str, string->len); - g_string_free(string, TRUE); + g_string_free(string, TRUE); + } } static GtkWidget *modify_dialog; @@ -373,11 +379,13 @@ void menu_modify(GtkTreeSelection *selection, const MenuItem *menu_item) const char *value; gint hb_mode; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_VALUE, &value, COLUMN_HB_MODE, - &hb_mode, -1); - menu_evaluate_modify(name, value, _("Modify"), hb_mode, menu_item ? MR_MODIFY : MR_MODSTR, - "07"); + if (scp_tree_selection_get_selected(selection, &store, &iter)) + { + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, COLUMN_VALUE, &value, COLUMN_HB_MODE, + &hb_mode, -1); + menu_evaluate_modify(name, value, _("Modify"), hb_mode, menu_item ? MR_MODIFY : MR_MODSTR, + "07"); + } } void menu_inspect(GtkTreeSelection *selection) @@ -386,9 +394,11 @@ void menu_inspect(GtkTreeSelection *selection) GtkTreeIter iter; const char *name; - scp_tree_selection_get_selected(selection, &store, &iter); - scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); - inspect_add(name); + if (scp_tree_selection_get_selected(selection, &store, &iter)) + { + scp_tree_store_get(store, &iter, COLUMN_NAME, &name, -1); + inspect_add(name); + } } void on_menu_display_booleans(const MenuItem *menu_item) Modified: scope/src/register.c 20 lines changed, 12 insertions(+), 8 deletions(-) =================================================================== @@ -459,16 +459,20 @@ static void on_register_format_update(const MenuItem *menu_item) gint format = GPOINTER_TO_INT(menu_item->gdata); gint id; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, REGISTER_ID, &id, -1); - - if (debug_state() & DS_DEBUG) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - debug_send_format(N, "02%d%c%s%s-data-list-register-values %c %d", format, - FRAME_ARGS, register_formats[format], id); + scp_tree_store_get(store, &iter, REGISTER_ID, &id, -1); + + if (debug_state() & DS_DEBUG) + { + debug_send_format(N, "02%d%c%s%s-data-list-register-values %c %d", format, + FRAME_ARGS, register_formats[format], id); + } + else + { + scp_tree_store_set(store, &iter, REGISTER_FORMAT, format, -1); + } } - else - scp_tree_store_set(store, &iter, REGISTER_FORMAT, format, -1); } static void on_register_query(G_GNUC_UNUSED const MenuItem *menu_item) Modified: scope/src/stack.c 32 lines changed, 19 insertions(+), 13 deletions(-) =================================================================== @@ -165,10 +165,12 @@ void on_stack_follow(GArray *nodes) gboolean stack_entry(void) { GtkTreeIter iter; - gboolean entry; + gboolean entry = NULL; - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, STACK_ENTRY, &entry, -1); + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) + { + scp_tree_store_get(store, &iter, STACK_ENTRY, &entry, -1); + } return entry; } @@ -268,18 +270,22 @@ static void on_stack_show_entry(const MenuItem *menu_item) GtkTreeIter iter; view_dirty(VIEW_LOCALS); - gtk_tree_selection_get_selected(selection, NULL, &iter); - scp_tree_store_get(store, &iter, STACK_FUNC, &ed.func, -1); - parse_mode_update(ed.func, MODE_ENTRY, ed.entry); - store_foreach(store, (GFunc) stack_iter_show_entry, &ed); - - if (ed.count == 1) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - debug_send_format(T, "04%s-stack-list-arguments 1 %s %s", thread_id, frame_id, - frame_id); + scp_tree_store_get(store, &iter, STACK_FUNC, &ed.func, -1); + parse_mode_update(ed.func, MODE_ENTRY, ed.entry); + store_foreach(store, (GFunc) stack_iter_show_entry, &ed); + + if (ed.count == 1) + { + debug_send_format(T, "04%s-stack-list-arguments 1 %s %s", thread_id, frame_id, + frame_id); + } + else + { + debug_send_format(T, "04%s-stack-list-arguments 1", thread_id); + } } - else - debug_send_format(T, "04%s-stack-list-arguments 1", thread_id); } #define DS_VIEWABLE (DS_ACTIVE | DS_EXTRA_2) Modified: scope/src/store/scptreestore.c 15 lines changed, 10 insertions(+), 5 deletions(-) =================================================================== @@ -527,16 +527,19 @@ static void validate_store(ScpTreeStore *store) static gboolean scp_insert_element(ScpTreeStore *store, GtkTreeIter *iter, AElem *elem, gint position, GtkTreeIter *parent_iter) { - ScpTreeStorePrivate *priv = store->priv; - AElem *parent = parent_iter ? ITER_ELEM(parent_iter) : priv->root; - GPtrArray *array = parent->children; + ScpTreeStorePrivate *priv; + AElem *parent; + GPtrArray *array; GtkTreePath *path; g_return_val_if_fail(SCP_IS_TREE_STORE(store), FALSE); g_return_val_if_fail(iter != NULL, FALSE); + priv = store->priv; g_return_val_if_fail(priv->sublevels == TRUE || parent_iter == NULL, FALSE); g_return_val_if_fail(VALID_ITER_OR_NULL(parent_iter, store), FALSE); + parent = parent_iter ? ITER_ELEM(parent_iter) : priv->root; + array = parent->children; if (array) { if (position == -1) @@ -624,12 +627,13 @@ void scp_tree_store_insert_with_values(ScpTreeStore *store, GtkTreeIter *iter, void scp_tree_store_get_valist(ScpTreeStore *store, GtkTreeIter *iter, va_list ap) { ScpTreeStorePrivate *priv = store->priv; - AElem *elem = ITER_ELEM(iter); + AElem *elem; gint column; g_return_if_fail(SCP_IS_TREE_STORE(store)); g_return_if_fail(VALID_ITER(iter, store)); + elem = ITER_ELEM(iter); while ((column = va_arg(ap, int)) != -1) { gpointer dest; @@ -896,12 +900,13 @@ gboolean scp_tree_store_get_iter(ScpTreeStore *store, GtkTreeIter *iter, GtkTree GtkTreePath *scp_tree_store_get_path(VALIDATE_ONLY ScpTreeStore *store, GtkTreeIter *iter) { - AElem *elem = ITER_ELEM(iter); + AElem *elem; GtkTreePath *path; g_return_val_if_fail(VALID_ITER(iter, store), NULL); path = gtk_tree_path_new(); + elem = ITER_ELEM(iter); if (elem->parent) { gtk_tree_path_append_index(path, ITER_INDEX(iter)); Modified: scope/src/thread.c 16 lines changed, 9 insertions(+), 7 deletions(-) =================================================================== @@ -775,14 +775,16 @@ static void on_thread_interrupt(G_GNUC_UNUSED const MenuItem *menu_item) GtkTreeIter iter; HANDLE hid; - gtk_tree_selection_get_selected(selection, NULL, &iter); - hid = iter_to_handle(&iter); - - if (hid) + if (gtk_tree_selection_get_selected(selection, NULL, &iter)) { - if (!DebugBreakProcess(hid)) - show_errno("DebugBreakProcess"); - CloseHandle(hid); + hid = iter_to_handle(&iter); + + if (hid) + { + if (!DebugBreakProcess(hid)) + show_errno("DebugBreakProcess"); + CloseHandle(hid); + } } } -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] f03977: workbench: added new feature "Search projects"
by LarsGit223
11 Jul '19
11 Jul '19
Branch: refs/heads/master Author: LarsGit223 <lars_paulsen(a)web.de> Committer: LarsGit223 <lars_paulsen(a)web.de> Date: Wed, 12 Jun 2019 13:56:16 UTC Commit: f03977145f79269571a7480b664e4188cb5082ca
https://github.com/geany/geany-plugins/commit/f03977145f79269571a7480b664e4…
Log Message: ----------- workbench: added new feature "Search projects" The feature lets the user search for projects to add them to the Workbench. After selecting the menu item, the user can select a directory to search through. The directory and it's sub-directories are scanned for project files (".geany"). All found files are listed and after scanning is done the user can select the projects which shall be added to the Workbench. The dialog is not modal - the user can do other work during the scanning of the directory. Modified Paths: -------------- po/POTFILES.in workbench/README workbench/src/Makefile.am workbench/src/menu.c workbench/src/menu.h workbench/src/plugin_main.c workbench/src/search_projects.c workbench/src/search_projects.h workbench/src/sidebar.c workbench/src/workbench.c Modified: po/POTFILES.in 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -321,6 +321,7 @@ workbench/src/dialogs.c workbench/src/menu.c workbench/src/plugin_main.c workbench/src/popup_menu.c +workbench/src/search_projects.c workbench/src/sidebar.c workbench/src/utils.c workbench/src/wb_globals.c Modified: workbench/README 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -39,6 +39,12 @@ menu: Open the Workbench settings dialog. After the settings have been confirmed with "OK" they will be written back to the workbench file (if any value was changed). +**Item "Search projects"** + Search for projects to add them to the Workbench. This lets the user + select a directory to search through. The directory and it's sub-directories + are scanned for project files (".geany"). All found files are listed and + after scanning is done the user can select the projects which shall be + added to the Workbench. **Item "Close"** Closes the opened Workbench. Modified: workbench/src/Makefile.am 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -15,6 +15,8 @@ workbench_la_SOURCES = \ wb_monitor.c \ dialogs.h \ dialogs.c \ + search_projects.h \ + search_projects.c \ menu.h \ menu.c \ popup_menu.h \ Modified: workbench/src/menu.c 29 lines changed, 29 insertions(+), 0 deletions(-) =================================================================== @@ -27,6 +27,7 @@ #include "dialogs.h" #include "menu.h" #include "sidebar.h" +#include "search_projects.h" extern GeanyPlugin *geany_plugin; @@ -37,6 +38,7 @@ typedef struct GtkWidget *item_new; GtkWidget *item_open; GtkWidget *item_settings; + GtkWidget *item_search_projects; GtkWidget *item_close; }WB_MENU_DATA; static WB_MENU_DATA menu_data; @@ -58,12 +60,21 @@ void menu_set_context(MENU_CONTEXT context) gtk_widget_set_sensitive(menu_data.item_new, FALSE); gtk_widget_set_sensitive(menu_data.item_open, FALSE); gtk_widget_set_sensitive(menu_data.item_settings, TRUE); + gtk_widget_set_sensitive(menu_data.item_search_projects, TRUE); gtk_widget_set_sensitive(menu_data.item_close, TRUE); break; + case MENU_CONTEXT_SEARCH_PROJECTS_SCANING: + gtk_widget_set_sensitive(menu_data.item_new, FALSE); + gtk_widget_set_sensitive(menu_data.item_open, FALSE); + gtk_widget_set_sensitive(menu_data.item_settings, TRUE); + gtk_widget_set_sensitive(menu_data.item_search_projects, FALSE); + gtk_widget_set_sensitive(menu_data.item_close, FALSE); + break; case MENU_CONTEXT_WB_CLOSED: gtk_widget_set_sensitive(menu_data.item_new, TRUE); gtk_widget_set_sensitive(menu_data.item_open, TRUE); gtk_widget_set_sensitive(menu_data.item_settings, FALSE); + gtk_widget_set_sensitive(menu_data.item_search_projects, FALSE); gtk_widget_set_sensitive(menu_data.item_close, FALSE); break; } @@ -164,6 +175,17 @@ static void item_workbench_settings_activate_cb(G_GNUC_UNUSED GtkMenuItem *menui } +/* The function handles the menu item "Search projects" */ +static void item_workbench_search_projects_activate_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + if (wb_globals.opened_wb != NULL) + { + search_projects(wb_globals.opened_wb); + } + sidebar_update(SIDEBAR_CONTEXT_PROJECT_ADDED, NULL); +} + + /* The function handles the menu item "Close workbench" */ static void item_close_workbench_activate_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) { @@ -206,6 +228,13 @@ gboolean menu_init(void) g_signal_connect(menu_data.item_settings, "activate", G_CALLBACK(item_workbench_settings_activate_cb), NULL); + /* Create new menu item "Search Projects" */ + menu_data.item_search_projects = gtk_menu_item_new_with_mnemonic(_("Search _projects")); + gtk_widget_show(menu_data.item_search_projects); + gtk_menu_shell_append(GTK_MENU_SHELL (menu_data.menu), menu_data.item_search_projects); + g_signal_connect(menu_data.item_search_projects, "activate", + G_CALLBACK(item_workbench_search_projects_activate_cb), NULL); + /* Create new menu item "Close Workbench" */ menu_data.item_close = gtk_menu_item_new_with_mnemonic(_("_Close")); gtk_widget_show(menu_data.item_close); Modified: workbench/src/menu.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -24,6 +24,7 @@ typedef enum MENU_CONTEXT_WB_CREATED, MENU_CONTEXT_WB_OPENED, MENU_CONTEXT_WB_CLOSED, + MENU_CONTEXT_SEARCH_PROJECTS_SCANING, }MENU_CONTEXT; void menu_set_context(MENU_CONTEXT context); Modified: workbench/src/plugin_main.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -117,7 +117,7 @@ void geany_load_module(GeanyPlugin *plugin) /* Set metadata */ plugin->info->name = _("Workbench"); plugin->info->description = _("Manage and customize multiple projects."); - plugin->info->version = "1.07"; + plugin->info->version = "1.08"; plugin->info->author = "LarsGit223"; /* Set functions */ Modified: workbench/src/search_projects.c 537 lines changed, 537 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,537 @@ +/* + * Copyright 2017 LarsGit223 + * + * 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. + */ + +/* + * This file contains all the code for handling the "Search projects" + * menu item/action. + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "wb_globals.h" +#include "dialogs.h" +#include "sidebar.h" +#include "menu.h" + + +typedef enum +{ + SCAN_DIR_STATE_ENTER, + SCAN_DIR_STATE_CONTINUE, +}SCAN_DIR_STATE; + + +enum +{ + SEARCH_PROJECTS_COLUMN_IMPORT, + SEARCH_PROJECTS_COLUMN_PATH, + SEARCH_PROJECTS_N_COLUMNS, +}; + + +typedef struct +{ + gchar *path; + gchar *locale_path; + gchar *real_path; + GDir *dir; +}SCAN_DIR_STATE_DATA; + + +typedef struct +{ + SCAN_DIR_STATE state; + gchar *searchdir; + glong prj_count; + GHashTable *visited_paths; + GPtrArray *data; +}SCAN_DIR_PARAMS; + + +typedef struct S_SEARCH_PROJECTS_DIALOG +{ + gboolean stopped; + GtkWidget *dialog; + GtkWidget *vbox; + GtkWidget *label; + GtkWidget *label_dir; + GtkWidget *list_vbox; + GtkWidget *list_view; + GtkListStore *list_store; + SCAN_DIR_PARAMS *params; +}SEARCH_PROJECTS_DIALOG; + + +/** Shows the dialog "Select search directory". + * + * The dialog lets the user choose an existing folder. + * + * @return The filename + * + **/ +static gchar *dialogs_select_search_directory(void) +{ + gchar *filename = NULL; + GtkWidget *dialog; + + dialog = gtk_file_chooser_dialog_new(_("Select search directory"), + GTK_WINDOW(wb_globals.geany_plugin->geany_data->main_widgets->window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Add"), GTK_RESPONSE_ACCEPT, NULL); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) + { + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + } + + gtk_widget_destroy(dialog); + + return filename; +} + + +/* Free data used during searching. + Freeing the widgets is done by gtk through calling 'destroy()'. */ +static void search_projects_free_data(SEARCH_PROJECTS_DIALOG *data) +{ + if (data->params != NULL) + { + g_free(data->params->searchdir); + g_hash_table_destroy(data->params->visited_paths); + g_ptr_array_free(data->params->data, FALSE); + g_free(data->params); + data->params = NULL; + } + + g_free(data); +} + + +/* Callback function for clicking on a list item */ +static void list_view_on_row_activated (GtkTreeView *treeview, + GtkTreePath *path, G_GNUC_UNUSED GtkTreeViewColumn *col, G_GNUC_UNUSED gpointer userdata) +{ + gboolean value; + GtkTreeModel *model; + GtkTreeIter iter; + SEARCH_PROJECTS_DIALOG *data = userdata; + + model = gtk_tree_view_get_model(treeview); + + if (gtk_tree_model_get_iter(model, &iter, path)) + { + gtk_tree_model_get(model, &iter, SEARCH_PROJECTS_COLUMN_IMPORT, &value, -1); + gtk_list_store_set(data->list_store, &iter, + SEARCH_PROJECTS_COLUMN_IMPORT, !value, + -1); + } +} + +static void search_projects_shutdown(SEARCH_PROJECTS_DIALOG *data) +{ + /* Close and free dialog. */ + gtk_widget_destroy(GTK_WIDGET(data->dialog)); + + menu_set_context(MENU_CONTEXT_WB_OPENED); + + /* Free data. */ + search_projects_free_data(data); +} + + +/* Handle "OK" and "Cancel" button. */ +static void dialog_on_button_pressed(GtkDialog *dialog, gint response_id, + gpointer user_data) +{ + gboolean value; + gchar *filename; + GtkTreeModel *model; + GtkTreeIter iter; + GError *error = NULL; + SEARCH_PROJECTS_DIALOG *data = user_data; + + if (response_id == GTK_RESPONSE_ACCEPT) + { + model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->list_view)); + if (gtk_tree_model_get_iter_first(model, &iter)) + { + do + { + gtk_tree_model_get(model, &iter, SEARCH_PROJECTS_COLUMN_IMPORT, &value, -1); + if (value == TRUE) + { + gtk_tree_model_get(model, &iter, SEARCH_PROJECTS_COLUMN_PATH, &filename, -1); + workbench_add_project(wb_globals.opened_wb, filename); + } + }while (gtk_tree_model_iter_next(model, &iter)); + } + + /* Save the workbench file (.geanywb). */ + if (!workbench_save(wb_globals.opened_wb, &error)) + { + dialogs_show_msgbox(GTK_MESSAGE_INFO, _("Could not save workbench file: %s"), error->message); + } + sidebar_update(SIDEBAR_CONTEXT_PROJECT_ADDED, NULL); + } + + + if (response_id == GTK_RESPONSE_ACCEPT || + response_id == GTK_RESPONSE_CANCEL || + data->stopped == TRUE) + { + search_projects_shutdown(data); + } + else + { + /* Set stop marker (scanning might still be in progress). */ + data->stopped = TRUE; + } +} + + +/* Push scan data on the stack. */ +static void scan_dir_data_push(SCAN_DIR_PARAMS *params, gchar *path, + gchar *locale_path, gchar *real_path, GDir *dir) +{ + SCAN_DIR_STATE_DATA *state_data; + + state_data = g_new0(SCAN_DIR_STATE_DATA, 1); + state_data->path = path; + state_data->locale_path = locale_path; + state_data->real_path = real_path; + state_data->dir = dir; + + g_ptr_array_add(params->data, state_data); +} + + +/* Pop scan data from the stack. */ +static void scan_dir_data_pop(SCAN_DIR_PARAMS *params) +{ + SCAN_DIR_STATE_DATA *state_data; + + if (params->data->len > 0) + { + state_data = params->data->pdata[params->data->len - 1]; + g_free(state_data->path); + g_free(state_data->locale_path); + g_free(state_data->real_path); + + g_ptr_array_remove_index(params->data, params->data->len - 1); + } +} + + +/* The function needs to be called if scanning comes to an end (scanning + done or an error occurred. */ +static void search_projects_scan_directory_end (SEARCH_PROJECTS_DIALOG *data) +{ + gchar *text; + + if (data->stopped == FALSE) + { + text = g_strdup_printf(_("Found %lu project files in directory \"%s\".\nPlease select the projects to add to the workbench."), + data->params->prj_count, data->params->searchdir); + gtk_label_set_text((GtkLabel *)data->label, text); + g_free(text); + + gtk_widget_destroy(data->label_dir); + gtk_widget_set_sensitive(data->dialog, TRUE); + + data->stopped = TRUE; + } + else + { + /* Dialog has been deleted as timer was running. */ + search_projects_shutdown(data); + } +} + + +/* Start/continue scanning of the directory. This is a timer callback + function to enable working with geany during long scans instead of + blocking everything. */ +static gboolean search_projects_scan_directory_do_work (gpointer user_data) +{ + SEARCH_PROJECTS_DIALOG *data = user_data; + SCAN_DIR_STATE_DATA *state_data; + gchar *text; + guint repeats = 0; + + if (data->stopped == TRUE || + data->params->data->len == 0) + { + /* Abort. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + while (repeats < 50) + { + const gchar *locale_name; + gchar *locale_filename, *utf8_filename, *utf8_name; + GtkTreeIter iter; + + if (data->stopped == TRUE) + { + /* Abort. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + repeats++; + state_data = data->params->data->pdata[data->params->data->len - 1]; + + if (data->params->state == SCAN_DIR_STATE_ENTER) + { + /* Data must already be on the stack. */ + + /* Add missing state data. */ + state_data->locale_path = utils_get_locale_from_utf8(state_data->path); + state_data->real_path = utils_get_real_path(state_data->locale_path); + + if (state_data->real_path && + g_hash_table_lookup(data->params->visited_paths, state_data->real_path)) + { + /* Seen this already. Leave dir. */ + scan_dir_data_pop(data->params); + data->params->state = SCAN_DIR_STATE_CONTINUE; + return TRUE; + } + + state_data->dir = g_dir_open(state_data->locale_path, 0, NULL); + if (!state_data->dir || !state_data->real_path) + { + if (state_data->dir != NULL) + { + g_dir_close(state_data->dir); + } + + /* Abort on error. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + g_hash_table_insert(data->params->visited_paths, g_strdup(state_data->real_path), GINT_TO_POINTER(1)); + + text = g_strdup_printf("%s", state_data->locale_path); + gtk_label_set_text((GtkLabel *)data->label_dir, text); + g_free(text); + } + + + if (data->params->data->len == 0) + { + /* Internal error. Abort. */ + search_projects_scan_directory_end(data); + return FALSE; + } + data->params->state = SCAN_DIR_STATE_CONTINUE; + state_data = data->params->data->pdata[data->params->data->len - 1]; + + /* Get next directory entry. */ + locale_name = g_dir_read_name(state_data->dir); + if (!locale_name) + { + g_dir_close(state_data->dir); + scan_dir_data_pop(data->params); + break; + } + + utf8_name = utils_get_utf8_from_locale(locale_name); + locale_filename = g_build_filename(state_data->locale_path, locale_name, NULL); + utf8_filename = utils_get_utf8_from_locale(locale_filename); + + if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR)) + { + scan_dir_data_push(data->params, g_strdup(locale_filename), NULL, NULL, NULL); + data->params->state = SCAN_DIR_STATE_ENTER; + } + else if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR)) + { + if (g_str_has_suffix(utf8_name, ".geany")) + { + data->params->prj_count++; + gtk_list_store_append (data->list_store, &iter); + gtk_list_store_set (data->list_store, &iter, + SEARCH_PROJECTS_COLUMN_PATH, locale_filename, + SEARCH_PROJECTS_COLUMN_IMPORT, FALSE, + -1); + } + } + + g_free(utf8_filename); + g_free(locale_filename); + g_free(utf8_name); + } + + if (data->params->data->len == 0) + { + /* Finished. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + /* Continue. */ + return TRUE; +} + + +/* The function prepares the required data for scaning and starts a timer + for calling 'search_projects_scan_directory_do_work()' periodically + until work is done. */ +static void search_projects_scan_directory_start (const gchar *searchdir, SEARCH_PROJECTS_DIALOG *data) +{ + SCAN_DIR_PARAMS *params; + + params = g_new0(SCAN_DIR_PARAMS, 1); + + params->state = SCAN_DIR_STATE_ENTER; + params->searchdir = g_strdup(searchdir); + params->prj_count = 0; + params->visited_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + params->data = g_ptr_array_new(); + + scan_dir_data_push(params, g_strdup(searchdir), NULL, NULL, NULL); + data->params = params; + + menu_set_context(MENU_CONTEXT_SEARCH_PROJECTS_SCANING); + plugin_timeout_add(wb_globals.geany_plugin, 1, search_projects_scan_directory_do_work, data); +} + + +/** Search for projects. + * + * Search for projects to be added to the workbench. First the function + * 'dialogs_select_search_directory()' is called to open the dialog + * "Select search directory". Scanning then started by calling + * 'search_projects_scan_directory_start()'. The dialog shows a list + * of found project files ("*.geany") and is held insenstive until search + * has finished. Then the user can check the projects we likes to add. + * Clicking "OK" then makes the projects being added to the workbench. + * Clicking "Cancel" or closing the dialog aborts everything and the + * workbench is un-changed. + * + * @param wb The workbench to add the found/selected projects to. + * + **/ +void search_projects(WORKBENCH *wb) +{ + gchar *directory; + GtkWidget *content_area; + GtkDialogFlags flags; + GtkWidget *scrollwin; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkTreeSelection *sel; + GList *focus_chain = NULL; + SEARCH_PROJECTS_DIALOG *search_projects; + + /* First, the user needs to select a directory to scan. */ + directory = dialogs_select_search_directory(); + if (directory == NULL) + { + return; + } + + search_projects = g_new0(SEARCH_PROJECTS_DIALOG, 1); + + /* Create the widgets */ + flags = GTK_DIALOG_DESTROY_WITH_PARENT; + search_projects->dialog = gtk_dialog_new_with_buttons(_("Search projects"), + GTK_WINDOW(wb_globals.geany_plugin->geany_data->main_widgets->window), + flags, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_OK"), GTK_RESPONSE_ACCEPT, + NULL); + g_signal_connect(search_projects->dialog, "response", G_CALLBACK(dialog_on_button_pressed), search_projects); + content_area = gtk_dialog_get_content_area(GTK_DIALOG (search_projects->dialog)); + gtk_widget_set_sensitive(search_projects->dialog, FALSE); + + /* VBox for the list view */ + search_projects->vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(search_projects->vbox), 12); + + + /* List view */ + search_projects->list_view = gtk_tree_view_new(); + g_signal_connect(search_projects->list_view, "row-activated", (GCallback)list_view_on_row_activated, search_projects); + + search_projects->list_store = gtk_list_store_new(SEARCH_PROJECTS_N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING); + gtk_tree_view_set_model(GTK_TREE_VIEW(search_projects->list_view), GTK_TREE_MODEL(search_projects->list_store)); + + column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_spacing(column, 10); + gtk_tree_view_column_set_resizable(column, FALSE); + gtk_tree_view_column_set_title(column, _("Add to workbench?")); + renderer = gtk_cell_renderer_toggle_new(); + gtk_tree_view_column_pack_start(column, renderer, FALSE); + gtk_tree_view_column_add_attribute(column, renderer, "active", SEARCH_PROJECTS_COLUMN_IMPORT); + gtk_tree_view_append_column(GTK_TREE_VIEW(search_projects->list_view), column); + + column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_spacing(column, 10); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_column_set_title(column, _("Project path")); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start(column, renderer, TRUE); + gtk_tree_view_column_add_attribute(column, renderer, "text", SEARCH_PROJECTS_COLUMN_PATH); + gtk_tree_view_append_column(GTK_TREE_VIEW(search_projects->list_view), column); + + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(search_projects->list_view), TRUE); + gtk_tree_view_set_enable_search(GTK_TREE_VIEW(search_projects->list_view), FALSE); + + ui_widget_modify_font_from_string(search_projects->list_view, + wb_globals.geany_plugin->geany_data->interface_prefs->tagbar_font); + + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(search_projects->list_view)); + gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE); + + /*Add label to vbox */ + search_projects->label = gtk_label_new (_("Scanning directory:")); + gtk_box_pack_start(GTK_BOX(search_projects->vbox), search_projects->label, FALSE, FALSE, 6); + + /*Add label for current directory to vbox */ + search_projects->label_dir = gtk_label_new (NULL); + gtk_box_pack_start(GTK_BOX(search_projects->vbox), search_projects->label_dir, FALSE, FALSE, 6); + + /*Add list view to vbox */ + focus_chain = g_list_prepend(focus_chain, search_projects->list_view); + gtk_container_set_focus_chain(GTK_CONTAINER(search_projects->vbox), focus_chain); + g_list_free(focus_chain); + scrollwin = gtk_scrolled_window_new(NULL, NULL); + gtk_widget_set_size_request(scrollwin, 400, 200); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_set_vexpand(scrollwin, TRUE); +#endif + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_container_add(GTK_CONTAINER(scrollwin), search_projects->list_view); + gtk_box_pack_start(GTK_BOX(search_projects->vbox), scrollwin, TRUE, TRUE, 0); + + gtk_widget_show_all(search_projects->vbox); + + gtk_container_add(GTK_CONTAINER (content_area), search_projects->vbox); + gtk_widget_show_all(search_projects->dialog); + + search_projects_scan_directory_start(directory, search_projects); + g_free(directory); + + return; +} Modified: workbench/src/search_projects.h 24 lines changed, 24 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,24 @@ +/* + * Copyright 2019 LarsGit223 + * + * 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. + */ + +#ifndef __WB_SEARCH_PROJECTS_H__ +#define __WB_SEARCH_PROJECTS_H__ + +void search_projects(WORKBENCH *wb); + +#endif Modified: workbench/src/sidebar.c 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -883,7 +883,8 @@ static void sidebar_update_workbench(GtkTreeIter *iter, gint *position) if (count == 0) { gtk_tree_store_clear(sidebar.file_store); - sidebar_show_intro_message(_("Add a project\nusing the context menu."), TRUE); + sidebar_show_intro_message(_("Add a project using the context menu\n" + "or select \"Search projects\" from the menu."), TRUE); } else { Modified: workbench/src/workbench.c 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -534,6 +534,12 @@ gboolean workbench_add_project(WORKBENCH *wb, const gchar *filename) /* Load project to import base path. */ wb_project_load(project, filename, NULL); + /* Start immediate scan if enabled. */ + if (wb->rescan_projects_on_open == TRUE) + { + wb_project_rescan(project); + } + wb->modified = TRUE; return TRUE; } -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] b45615: Merge pull request #875 from LarsGit223/wb-search-projects
by LarsGit223
11 Jul '19
11 Jul '19
Branch: refs/heads/master Author: LarsGit223 <LarsGit223(a)users.noreply.github.com> Committer: GitHub <noreply(a)github.com> Date: Thu, 11 Jul 2019 17:42:49 UTC Commit: b456154457195ed686b97748e626d8eda6112387
https://github.com/geany/geany-plugins/commit/b456154457195ed686b97748e626d…
Log Message: ----------- Merge pull request #875 from LarsGit223/wb-search-projects workbench: added new feature "Search projects" Modified Paths: -------------- po/POTFILES.in workbench/README workbench/src/Makefile.am workbench/src/menu.c workbench/src/menu.h workbench/src/search_projects.c workbench/src/search_projects.h workbench/src/sidebar.c workbench/src/workbench.c Modified: po/POTFILES.in 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -321,6 +321,7 @@ workbench/src/dialogs.c workbench/src/menu.c workbench/src/plugin_main.c workbench/src/popup_menu.c +workbench/src/search_projects.c workbench/src/sidebar.c workbench/src/utils.c workbench/src/wb_globals.c Modified: workbench/README 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -39,6 +39,12 @@ menu: Open the Workbench settings dialog. After the settings have been confirmed with "OK" they will be written back to the workbench file (if any value was changed). +**Item "Search projects"** + Search for projects to add them to the Workbench. This lets the user + select a directory to search through. The directory and it's sub-directories + are scanned for project files (".geany"). All found files are listed and + after scanning is done the user can select the projects which shall be + added to the Workbench. **Item "Close"** Closes the opened Workbench. Modified: workbench/src/Makefile.am 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -15,6 +15,8 @@ workbench_la_SOURCES = \ wb_monitor.c \ dialogs.h \ dialogs.c \ + search_projects.h \ + search_projects.c \ menu.h \ menu.c \ popup_menu.h \ Modified: workbench/src/menu.c 29 lines changed, 29 insertions(+), 0 deletions(-) =================================================================== @@ -27,6 +27,7 @@ #include "dialogs.h" #include "menu.h" #include "sidebar.h" +#include "search_projects.h" extern GeanyPlugin *geany_plugin; @@ -37,6 +38,7 @@ typedef struct GtkWidget *item_new; GtkWidget *item_open; GtkWidget *item_settings; + GtkWidget *item_search_projects; GtkWidget *item_close; }WB_MENU_DATA; static WB_MENU_DATA menu_data; @@ -58,12 +60,21 @@ void menu_set_context(MENU_CONTEXT context) gtk_widget_set_sensitive(menu_data.item_new, FALSE); gtk_widget_set_sensitive(menu_data.item_open, FALSE); gtk_widget_set_sensitive(menu_data.item_settings, TRUE); + gtk_widget_set_sensitive(menu_data.item_search_projects, TRUE); gtk_widget_set_sensitive(menu_data.item_close, TRUE); break; + case MENU_CONTEXT_SEARCH_PROJECTS_SCANING: + gtk_widget_set_sensitive(menu_data.item_new, FALSE); + gtk_widget_set_sensitive(menu_data.item_open, FALSE); + gtk_widget_set_sensitive(menu_data.item_settings, TRUE); + gtk_widget_set_sensitive(menu_data.item_search_projects, FALSE); + gtk_widget_set_sensitive(menu_data.item_close, FALSE); + break; case MENU_CONTEXT_WB_CLOSED: gtk_widget_set_sensitive(menu_data.item_new, TRUE); gtk_widget_set_sensitive(menu_data.item_open, TRUE); gtk_widget_set_sensitive(menu_data.item_settings, FALSE); + gtk_widget_set_sensitive(menu_data.item_search_projects, FALSE); gtk_widget_set_sensitive(menu_data.item_close, FALSE); break; } @@ -164,6 +175,17 @@ static void item_workbench_settings_activate_cb(G_GNUC_UNUSED GtkMenuItem *menui } +/* The function handles the menu item "Search projects" */ +static void item_workbench_search_projects_activate_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) +{ + if (wb_globals.opened_wb != NULL) + { + search_projects(wb_globals.opened_wb); + } + sidebar_update(SIDEBAR_CONTEXT_PROJECT_ADDED, NULL); +} + + /* The function handles the menu item "Close workbench" */ static void item_close_workbench_activate_cb(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) { @@ -206,6 +228,13 @@ gboolean menu_init(void) g_signal_connect(menu_data.item_settings, "activate", G_CALLBACK(item_workbench_settings_activate_cb), NULL); + /* Create new menu item "Search Projects" */ + menu_data.item_search_projects = gtk_menu_item_new_with_mnemonic(_("Search _projects")); + gtk_widget_show(menu_data.item_search_projects); + gtk_menu_shell_append(GTK_MENU_SHELL (menu_data.menu), menu_data.item_search_projects); + g_signal_connect(menu_data.item_search_projects, "activate", + G_CALLBACK(item_workbench_search_projects_activate_cb), NULL); + /* Create new menu item "Close Workbench" */ menu_data.item_close = gtk_menu_item_new_with_mnemonic(_("_Close")); gtk_widget_show(menu_data.item_close); Modified: workbench/src/menu.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -24,6 +24,7 @@ typedef enum MENU_CONTEXT_WB_CREATED, MENU_CONTEXT_WB_OPENED, MENU_CONTEXT_WB_CLOSED, + MENU_CONTEXT_SEARCH_PROJECTS_SCANING, }MENU_CONTEXT; void menu_set_context(MENU_CONTEXT context); Modified: workbench/src/search_projects.c 537 lines changed, 537 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,537 @@ +/* + * Copyright 2017 LarsGit223 + * + * 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. + */ + +/* + * This file contains all the code for handling the "Search projects" + * menu item/action. + */ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include "wb_globals.h" +#include "dialogs.h" +#include "sidebar.h" +#include "menu.h" + + +typedef enum +{ + SCAN_DIR_STATE_ENTER, + SCAN_DIR_STATE_CONTINUE, +}SCAN_DIR_STATE; + + +enum +{ + SEARCH_PROJECTS_COLUMN_IMPORT, + SEARCH_PROJECTS_COLUMN_PATH, + SEARCH_PROJECTS_N_COLUMNS, +}; + + +typedef struct +{ + gchar *path; + gchar *locale_path; + gchar *real_path; + GDir *dir; +}SCAN_DIR_STATE_DATA; + + +typedef struct +{ + SCAN_DIR_STATE state; + gchar *searchdir; + glong prj_count; + GHashTable *visited_paths; + GPtrArray *data; +}SCAN_DIR_PARAMS; + + +typedef struct S_SEARCH_PROJECTS_DIALOG +{ + gboolean stopped; + GtkWidget *dialog; + GtkWidget *vbox; + GtkWidget *label; + GtkWidget *label_dir; + GtkWidget *list_vbox; + GtkWidget *list_view; + GtkListStore *list_store; + SCAN_DIR_PARAMS *params; +}SEARCH_PROJECTS_DIALOG; + + +/** Shows the dialog "Select search directory". + * + * The dialog lets the user choose an existing folder. + * + * @return The filename + * + **/ +static gchar *dialogs_select_search_directory(void) +{ + gchar *filename = NULL; + GtkWidget *dialog; + + dialog = gtk_file_chooser_dialog_new(_("Select search directory"), + GTK_WINDOW(wb_globals.geany_plugin->geany_data->main_widgets->window), GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Add"), GTK_RESPONSE_ACCEPT, NULL); + + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) + { + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + } + + gtk_widget_destroy(dialog); + + return filename; +} + + +/* Free data used during searching. + Freeing the widgets is done by gtk through calling 'destroy()'. */ +static void search_projects_free_data(SEARCH_PROJECTS_DIALOG *data) +{ + if (data->params != NULL) + { + g_free(data->params->searchdir); + g_hash_table_destroy(data->params->visited_paths); + g_ptr_array_free(data->params->data, FALSE); + g_free(data->params); + data->params = NULL; + } + + g_free(data); +} + + +/* Callback function for clicking on a list item */ +static void list_view_on_row_activated (GtkTreeView *treeview, + GtkTreePath *path, G_GNUC_UNUSED GtkTreeViewColumn *col, G_GNUC_UNUSED gpointer userdata) +{ + gboolean value; + GtkTreeModel *model; + GtkTreeIter iter; + SEARCH_PROJECTS_DIALOG *data = userdata; + + model = gtk_tree_view_get_model(treeview); + + if (gtk_tree_model_get_iter(model, &iter, path)) + { + gtk_tree_model_get(model, &iter, SEARCH_PROJECTS_COLUMN_IMPORT, &value, -1); + gtk_list_store_set(data->list_store, &iter, + SEARCH_PROJECTS_COLUMN_IMPORT, !value, + -1); + } +} + +static void search_projects_shutdown(SEARCH_PROJECTS_DIALOG *data) +{ + /* Close and free dialog. */ + gtk_widget_destroy(GTK_WIDGET(data->dialog)); + + menu_set_context(MENU_CONTEXT_WB_OPENED); + + /* Free data. */ + search_projects_free_data(data); +} + + +/* Handle "OK" and "Cancel" button. */ +static void dialog_on_button_pressed(GtkDialog *dialog, gint response_id, + gpointer user_data) +{ + gboolean value; + gchar *filename; + GtkTreeModel *model; + GtkTreeIter iter; + GError *error = NULL; + SEARCH_PROJECTS_DIALOG *data = user_data; + + if (response_id == GTK_RESPONSE_ACCEPT) + { + model = gtk_tree_view_get_model(GTK_TREE_VIEW(data->list_view)); + if (gtk_tree_model_get_iter_first(model, &iter)) + { + do + { + gtk_tree_model_get(model, &iter, SEARCH_PROJECTS_COLUMN_IMPORT, &value, -1); + if (value == TRUE) + { + gtk_tree_model_get(model, &iter, SEARCH_PROJECTS_COLUMN_PATH, &filename, -1); + workbench_add_project(wb_globals.opened_wb, filename); + } + }while (gtk_tree_model_iter_next(model, &iter)); + } + + /* Save the workbench file (.geanywb). */ + if (!workbench_save(wb_globals.opened_wb, &error)) + { + dialogs_show_msgbox(GTK_MESSAGE_INFO, _("Could not save workbench file: %s"), error->message); + } + sidebar_update(SIDEBAR_CONTEXT_PROJECT_ADDED, NULL); + } + + + if (response_id == GTK_RESPONSE_ACCEPT || + response_id == GTK_RESPONSE_CANCEL || + data->stopped == TRUE) + { + search_projects_shutdown(data); + } + else + { + /* Set stop marker (scanning might still be in progress). */ + data->stopped = TRUE; + } +} + + +/* Push scan data on the stack. */ +static void scan_dir_data_push(SCAN_DIR_PARAMS *params, gchar *path, + gchar *locale_path, gchar *real_path, GDir *dir) +{ + SCAN_DIR_STATE_DATA *state_data; + + state_data = g_new0(SCAN_DIR_STATE_DATA, 1); + state_data->path = path; + state_data->locale_path = locale_path; + state_data->real_path = real_path; + state_data->dir = dir; + + g_ptr_array_add(params->data, state_data); +} + + +/* Pop scan data from the stack. */ +static void scan_dir_data_pop(SCAN_DIR_PARAMS *params) +{ + SCAN_DIR_STATE_DATA *state_data; + + if (params->data->len > 0) + { + state_data = params->data->pdata[params->data->len - 1]; + g_free(state_data->path); + g_free(state_data->locale_path); + g_free(state_data->real_path); + + g_ptr_array_remove_index(params->data, params->data->len - 1); + } +} + + +/* The function needs to be called if scanning comes to an end (scanning + done or an error occurred. */ +static void search_projects_scan_directory_end (SEARCH_PROJECTS_DIALOG *data) +{ + gchar *text; + + if (data->stopped == FALSE) + { + text = g_strdup_printf(_("Found %lu project files in directory \"%s\".\nPlease select the projects to add to the workbench."), + data->params->prj_count, data->params->searchdir); + gtk_label_set_text((GtkLabel *)data->label, text); + g_free(text); + + gtk_widget_destroy(data->label_dir); + gtk_widget_set_sensitive(data->dialog, TRUE); + + data->stopped = TRUE; + } + else + { + /* Dialog has been deleted as timer was running. */ + search_projects_shutdown(data); + } +} + + +/* Start/continue scanning of the directory. This is a timer callback + function to enable working with geany during long scans instead of + blocking everything. */ +static gboolean search_projects_scan_directory_do_work (gpointer user_data) +{ + SEARCH_PROJECTS_DIALOG *data = user_data; + SCAN_DIR_STATE_DATA *state_data; + gchar *text; + guint repeats = 0; + + if (data->stopped == TRUE || + data->params->data->len == 0) + { + /* Abort. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + while (repeats < 50) + { + const gchar *locale_name; + gchar *locale_filename, *utf8_filename, *utf8_name; + GtkTreeIter iter; + + if (data->stopped == TRUE) + { + /* Abort. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + repeats++; + state_data = data->params->data->pdata[data->params->data->len - 1]; + + if (data->params->state == SCAN_DIR_STATE_ENTER) + { + /* Data must already be on the stack. */ + + /* Add missing state data. */ + state_data->locale_path = utils_get_locale_from_utf8(state_data->path); + state_data->real_path = utils_get_real_path(state_data->locale_path); + + if (state_data->real_path && + g_hash_table_lookup(data->params->visited_paths, state_data->real_path)) + { + /* Seen this already. Leave dir. */ + scan_dir_data_pop(data->params); + data->params->state = SCAN_DIR_STATE_CONTINUE; + return TRUE; + } + + state_data->dir = g_dir_open(state_data->locale_path, 0, NULL); + if (!state_data->dir || !state_data->real_path) + { + if (state_data->dir != NULL) + { + g_dir_close(state_data->dir); + } + + /* Abort on error. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + g_hash_table_insert(data->params->visited_paths, g_strdup(state_data->real_path), GINT_TO_POINTER(1)); + + text = g_strdup_printf("%s", state_data->locale_path); + gtk_label_set_text((GtkLabel *)data->label_dir, text); + g_free(text); + } + + + if (data->params->data->len == 0) + { + /* Internal error. Abort. */ + search_projects_scan_directory_end(data); + return FALSE; + } + data->params->state = SCAN_DIR_STATE_CONTINUE; + state_data = data->params->data->pdata[data->params->data->len - 1]; + + /* Get next directory entry. */ + locale_name = g_dir_read_name(state_data->dir); + if (!locale_name) + { + g_dir_close(state_data->dir); + scan_dir_data_pop(data->params); + break; + } + + utf8_name = utils_get_utf8_from_locale(locale_name); + locale_filename = g_build_filename(state_data->locale_path, locale_name, NULL); + utf8_filename = utils_get_utf8_from_locale(locale_filename); + + if (g_file_test(locale_filename, G_FILE_TEST_IS_DIR)) + { + scan_dir_data_push(data->params, g_strdup(locale_filename), NULL, NULL, NULL); + data->params->state = SCAN_DIR_STATE_ENTER; + } + else if (g_file_test(locale_filename, G_FILE_TEST_IS_REGULAR)) + { + if (g_str_has_suffix(utf8_name, ".geany")) + { + data->params->prj_count++; + gtk_list_store_append (data->list_store, &iter); + gtk_list_store_set (data->list_store, &iter, + SEARCH_PROJECTS_COLUMN_PATH, locale_filename, + SEARCH_PROJECTS_COLUMN_IMPORT, FALSE, + -1); + } + } + + g_free(utf8_filename); + g_free(locale_filename); + g_free(utf8_name); + } + + if (data->params->data->len == 0) + { + /* Finished. */ + search_projects_scan_directory_end(data); + return FALSE; + } + + /* Continue. */ + return TRUE; +} + + +/* The function prepares the required data for scaning and starts a timer + for calling 'search_projects_scan_directory_do_work()' periodically + until work is done. */ +static void search_projects_scan_directory_start (const gchar *searchdir, SEARCH_PROJECTS_DIALOG *data) +{ + SCAN_DIR_PARAMS *params; + + params = g_new0(SCAN_DIR_PARAMS, 1); + + params->state = SCAN_DIR_STATE_ENTER; + params->searchdir = g_strdup(searchdir); + params->prj_count = 0; + params->visited_paths = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL); + params->data = g_ptr_array_new(); + + scan_dir_data_push(params, g_strdup(searchdir), NULL, NULL, NULL); + data->params = params; + + menu_set_context(MENU_CONTEXT_SEARCH_PROJECTS_SCANING); + plugin_timeout_add(wb_globals.geany_plugin, 1, search_projects_scan_directory_do_work, data); +} + + +/** Search for projects. + * + * Search for projects to be added to the workbench. First the function + * 'dialogs_select_search_directory()' is called to open the dialog + * "Select search directory". Scanning then started by calling + * 'search_projects_scan_directory_start()'. The dialog shows a list + * of found project files ("*.geany") and is held insenstive until search + * has finished. Then the user can check the projects we likes to add. + * Clicking "OK" then makes the projects being added to the workbench. + * Clicking "Cancel" or closing the dialog aborts everything and the + * workbench is un-changed. + * + * @param wb The workbench to add the found/selected projects to. + * + **/ +void search_projects(WORKBENCH *wb) +{ + gchar *directory; + GtkWidget *content_area; + GtkDialogFlags flags; + GtkWidget *scrollwin; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; + GtkTreeSelection *sel; + GList *focus_chain = NULL; + SEARCH_PROJECTS_DIALOG *search_projects; + + /* First, the user needs to select a directory to scan. */ + directory = dialogs_select_search_directory(); + if (directory == NULL) + { + return; + } + + search_projects = g_new0(SEARCH_PROJECTS_DIALOG, 1); + + /* Create the widgets */ + flags = GTK_DIALOG_DESTROY_WITH_PARENT; + search_projects->dialog = gtk_dialog_new_with_buttons(_("Search projects"), + GTK_WINDOW(wb_globals.geany_plugin->geany_data->main_widgets->window), + flags, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_OK"), GTK_RESPONSE_ACCEPT, + NULL); + g_signal_connect(search_projects->dialog, "response", G_CALLBACK(dialog_on_button_pressed), search_projects); + content_area = gtk_dialog_get_content_area(GTK_DIALOG (search_projects->dialog)); + gtk_widget_set_sensitive(search_projects->dialog, FALSE); + + /* VBox for the list view */ + search_projects->vbox = gtk_vbox_new(FALSE, 0); + gtk_container_set_border_width(GTK_CONTAINER(search_projects->vbox), 12); + + + /* List view */ + search_projects->list_view = gtk_tree_view_new(); + g_signal_connect(search_projects->list_view, "row-activated", (GCallback)list_view_on_row_activated, search_projects); + + search_projects->list_store = gtk_list_store_new(SEARCH_PROJECTS_N_COLUMNS, G_TYPE_BOOLEAN, G_TYPE_STRING); + gtk_tree_view_set_model(GTK_TREE_VIEW(search_projects->list_view), GTK_TREE_MODEL(search_projects->list_store)); + + column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_spacing(column, 10); + gtk_tree_view_column_set_resizable(column, FALSE); + gtk_tree_view_column_set_title(column, _("Add to workbench?")); + renderer = gtk_cell_renderer_toggle_new(); + gtk_tree_view_column_pack_start(column, renderer, FALSE); + gtk_tree_view_column_add_attribute(column, renderer, "active", SEARCH_PROJECTS_COLUMN_IMPORT); + gtk_tree_view_append_column(GTK_TREE_VIEW(search_projects->list_view), column); + + column = gtk_tree_view_column_new(); + gtk_tree_view_column_set_spacing(column, 10); + gtk_tree_view_column_set_resizable (column, TRUE); + gtk_tree_view_column_set_title(column, _("Project path")); + renderer = gtk_cell_renderer_text_new(); + gtk_tree_view_column_pack_start(column, renderer, TRUE); + gtk_tree_view_column_add_attribute(column, renderer, "text", SEARCH_PROJECTS_COLUMN_PATH); + gtk_tree_view_append_column(GTK_TREE_VIEW(search_projects->list_view), column); + + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(search_projects->list_view), TRUE); + gtk_tree_view_set_enable_search(GTK_TREE_VIEW(search_projects->list_view), FALSE); + + ui_widget_modify_font_from_string(search_projects->list_view, + wb_globals.geany_plugin->geany_data->interface_prefs->tagbar_font); + + sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(search_projects->list_view)); + gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE); + + /*Add label to vbox */ + search_projects->label = gtk_label_new (_("Scanning directory:")); + gtk_box_pack_start(GTK_BOX(search_projects->vbox), search_projects->label, FALSE, FALSE, 6); + + /*Add label for current directory to vbox */ + search_projects->label_dir = gtk_label_new (NULL); + gtk_box_pack_start(GTK_BOX(search_projects->vbox), search_projects->label_dir, FALSE, FALSE, 6); + + /*Add list view to vbox */ + focus_chain = g_list_prepend(focus_chain, search_projects->list_view); + gtk_container_set_focus_chain(GTK_CONTAINER(search_projects->vbox), focus_chain); + g_list_free(focus_chain); + scrollwin = gtk_scrolled_window_new(NULL, NULL); + gtk_widget_set_size_request(scrollwin, 400, 200); +#if GTK_CHECK_VERSION(3, 0, 0) + gtk_widget_set_vexpand(scrollwin, TRUE); +#endif + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrollwin), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_container_add(GTK_CONTAINER(scrollwin), search_projects->list_view); + gtk_box_pack_start(GTK_BOX(search_projects->vbox), scrollwin, TRUE, TRUE, 0); + + gtk_widget_show_all(search_projects->vbox); + + gtk_container_add(GTK_CONTAINER (content_area), search_projects->vbox); + gtk_widget_show_all(search_projects->dialog); + + search_projects_scan_directory_start(directory, search_projects); + g_free(directory); + + return; +} Modified: workbench/src/search_projects.h 24 lines changed, 24 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,24 @@ +/* + * Copyright 2019 LarsGit223 + * + * 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. + */ + +#ifndef __WB_SEARCH_PROJECTS_H__ +#define __WB_SEARCH_PROJECTS_H__ + +void search_projects(WORKBENCH *wb); + +#endif Modified: workbench/src/sidebar.c 3 lines changed, 2 insertions(+), 1 deletions(-) =================================================================== @@ -883,7 +883,8 @@ static void sidebar_update_workbench(GtkTreeIter *iter, gint *position) if (count == 0) { gtk_tree_store_clear(sidebar.file_store); - sidebar_show_intro_message(_("Add a project\nusing the context menu."), TRUE); + sidebar_show_intro_message(_("Add a project using the context menu\n" + "or select \"Search projects\" from the menu."), TRUE); } else { Modified: workbench/src/workbench.c 6 lines changed, 6 insertions(+), 0 deletions(-) =================================================================== @@ -534,6 +534,12 @@ gboolean workbench_add_project(WORKBENCH *wb, const gchar *filename) /* Load project to import base path. */ wb_project_load(project, filename, NULL); + /* Start immediate scan if enabled. */ + if (wb->rescan_projects_on_open == TRUE) + { + wb_project_rescan(project); + } + wb->modified = TRUE; return TRUE; } -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 648224: scope: Improved evaluation on-hover
by LarsGit223
11 Jul '19
11 Jul '19
Branch: refs/heads/master Author: LarsGit223 <lars_paulsen(a)web.de> Committer: LarsGit223 <lars_paulsen(a)web.de> Date: Wed, 08 May 2019 19:27:32 UTC Commit: 648224ab17c938db374bdba5a0bfc5dfae5c1033
https://github.com/geany/geany-plugins/commit/648224ab17c938db374bdba5a0bfc…
Log Message: ----------- scope: Improved evaluation on-hover Scope automatically evaluates an expression if the mouse pointer is hovered over it. But before this change it only evaluated words. E.g. if the mouse was hovered over "structa->item1" then scope would have evaluated "structa" or "item1" depending on the exact position of the mouse pointer. With this change it will instead evaluate the value of "structa" if the mouse pointer is over "structa". If the mouse pointer is over "item1" then the expression "structa->item1" will be evaluated. Modified Paths: -------------- scope/src/Makefile.am scope/src/tests/unittests.c scope/src/tests/utils_test.c scope/src/tooltip.c scope/src/utils.c scope/src/utils.h Modified: scope/src/Makefile.am 14 lines changed, 14 insertions(+), 0 deletions(-) =================================================================== @@ -61,3 +61,17 @@ scope_la_CFLAGS = $(AM_CFLAGS) $(VTE_CFLAGS) \ -I$(top_srcdir)/utils/src include $(top_srcdir)/build/cppcheck.mk + +if UNITTESTS + +TESTS = unittests +check_PROGRAMS = unittests + +unittests_SOURCES = tests/unittests.c tests/utils_test.c \ + $(scope_la_SOURCES) +unittests_CPPFLAGS = -DTEST $(scope_la_CPPFLAGS) +unittests_CFLAGS = $(GEANY_CFLAGS) -DUNITTESTS $(scope_la_CFLAGS) +unittests_LDADD = @GEANY_LIBS@ $(INTLLIBS) @CHECK_LIBS@ \ + $(scope_la_LIBADD) + +endif Modified: scope/src/tests/unittests.c 28 lines changed, 28 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,28 @@ +#include <stdlib.h> +#include <stdio.h> +#include <check.h> + +#include <gtk/gtk.h> +#include "geany.h" + +TCase *utils_create_tests(void); + +Suite * +my_suite(void) +{ + Suite *s = suite_create("Scope"); + suite_add_tcase(s, utils_create_tests()); + return s; +} + +int +main(void) +{ + int nf; + Suite *s = my_suite(); + SRunner *sr = srunner_create(s); + srunner_run_all(sr, CK_NORMAL); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} Modified: scope/src/tests/utils_test.c 73 lines changed, 73 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,73 @@ +#include <check.h> +#include "../src/common.h" +#include "../src/utils.h" + +typedef struct S_EXPR_TEST_ITEM +{ + const gchar *input; + guint peek_index; + const gchar *expected; +}EXPR_TEST_ITEM; + +EXPR_TEST_ITEM expr_test_items [] = +{ + { " variable ", sizeof(" var")-1, "variable" }, + { " (variable) ", sizeof(" (var")-1, "variable" }, + { "struct.item", sizeof("str")-1, "struct" }, + { "struct.item", sizeof("str")-1, "struct" }, + { "struct.item", sizeof("struct.it")-1, "struct.item" }, + { "struct->item", sizeof("str")-1, "struct" }, + { "struct->item", sizeof("struct->it")-1, "struct->item" }, + { "&(struct->item)", sizeof("&(str")-1, "struct" }, + { "&(struct->item)", sizeof("&(struct->it")-1, "struct->item" }, + { "foobar(item)", sizeof("foobar(it")-1, "item" }, + { "sizeof(item)", sizeof("sizeof(it")-1, "sizeof(item)" }, + { "array[5]", sizeof("arr")-1, "array" }, + { "array[5]", sizeof("array[")-1, "array[5]" }, + { "*pointer", sizeof("*poi")-1, "pointer" }, + { "*pointer", 0, "*pointer" }, + { "&variable", sizeof("&var")-1, "variable" }, + { "&variable", 0, "&variable" }, + { "foo variable", sizeof("foo var")-1, "variable" }, + { "variable foo", sizeof("var")-1, "variable" }, + { "int var_a, var_b;", sizeof("int var")-1, "var_a" }, + { "int var_a, var_b;", sizeof("int var_a, va")-1, "var_b" }, + { "foo(var_a, var_b);", sizeof("foo(var")-1, "var_a" }, + { "foo(var_a, var_b);", sizeof("foo(var_a, va")-1, "var_b" }, + { "array[index].item", sizeof("array[index].i")-1, "array[index].item" }, + { "array[index]->item", sizeof("array[index]->i")-1, "array[index]->item" }, + { NULL, 0, NULL }, +}; + +START_TEST(test_parser_for_evaluate) +{ + EXPR_TEST_ITEM *test_item; + guint index = 0; + gchar *expr, *chunk; + + test_item = &(expr_test_items[index]); + while (test_item->input != NULL) + { + chunk = g_strdup(test_item->input); + expr = utils_evaluate_expr_from_string (chunk, test_item->peek_index); + ck_assert_ptr_ne(expr, NULL); + if (g_strcmp0(expr, test_item->expected) != 0) + { + ck_abort_msg("Index #%lu: Input: '%s', Peek-Ind.: %lu, Result: '%s' != '%s' (expected)", + index, test_item->input, test_item->peek_index, expr, test_item->expected); + } + g_free(chunk); + g_free(expr); + + index++; + test_item = &(expr_test_items[index]); + } +} +END_TEST; + +TCase *utils_create_tests(void) +{ + TCase *tc_utils = tcase_create("utils"); + tcase_add_test(tc_utils, test_parser_for_evaluate); + return tc_utils; +} Modified: scope/src/tooltip.c 40 lines changed, 34 insertions(+), 6 deletions(-) =================================================================== @@ -22,6 +22,9 @@ #include "common.h" +/* Wordchars defining possible signs in an expression. */ +#define SCOPE_EXPR_WORDCHARS "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.->[]" + static void tooltip_trigger(void) { GdkDisplay *display = gdk_display_get_default(); @@ -48,6 +51,7 @@ static void tooltip_trigger(void) } } +static gchar *last_expr = NULL; static gchar *output = NULL; static gint last_pos = -1; static gint peek_pos = -1; @@ -69,6 +73,24 @@ static void tooltip_set(gchar *text) } } +static void tooltip_set_expr(gchar *expr, gchar *text) +{ + show = text != NULL; + g_free(output); + output = g_strdup_printf ("%s =\n %s", expr, text); + g_free(text); + g_free(expr); + last_pos = peek_pos; + + if (show) + { + if (pref_tooltips_length && strlen(output) > (size_t) pref_tooltips_length + 3) + strcpy(output + pref_tooltips_length, "..."); + + tooltip_trigger(); + } +} + static gint scid_gen = 0; void on_tooltip_error(GArray *nodes) @@ -92,7 +114,7 @@ void on_tooltip_value(GArray *nodes) { if (atoi(parse_grab_token(nodes)) == scid_gen) { - tooltip_set(parse_get_display_from_7bit(parse_lead_value(nodes), + tooltip_set_expr(last_expr, parse_get_display_from_7bit(parse_lead_value(nodes), parse_mode_get(input, MODE_HBIT), parse_mode_get(input, MODE_MEMBER))); } } @@ -107,17 +129,23 @@ static gboolean tooltip_launch(gpointer gdata) (debug_state() & DS_SENDABLE)) { ScintillaObject *sci = doc->editor->sci; - gchar *expr = sci_get_selection_mode(sci) == SC_SEL_STREAM && + gchar *expr; + if (sci_get_selection_mode(sci) == SC_SEL_STREAM && peek_pos >= sci_get_selection_start(sci) && - peek_pos < sci_get_selection_end(sci) ? - editor_get_default_selection(doc->editor, FALSE, NULL) : - editor_get_word_at_pos(doc->editor, peek_pos, NULL); + peek_pos < sci_get_selection_end(sci)) + { + expr = editor_get_default_selection(doc->editor, FALSE, NULL); + } + else + { + expr = utils_read_evaluate_expr(doc->editor, peek_pos); + } if ((expr = utils_verify_selection(expr)) != NULL) { g_free(input); input = debug_send_evaluate('3', scid_gen, expr); - g_free(expr); + last_expr = expr; } else tooltip_set(NULL); Modified: scope/src/utils.c 347 lines changed, 347 insertions(+), 0 deletions(-) =================================================================== @@ -36,6 +36,10 @@ #ifdef G_OS_UNIX #include <fcntl.h> +/* The maximum length of an expression for evaluating the value. + (Including the string terminator '\0') */ +#define SCOPE_MAX_EVALUATE_EXPR_LENGTH 256 + void show_errno(const char *prefix) { show_error(_("%s: %s."), prefix, g_strerror(errno)); @@ -753,3 +757,346 @@ void utils_finalize(void) utils_unlock(documents[i]); } } + +/* checks whether @p c is an ASCII character (e.g. < 0x80) */ +#define IS_ASCII(c) (((unsigned char)(c)) < 0x80) + +/* This function is doing the parsing for 'utils_read_evaluate_expr()'. + It was mainly separated from it to support easy unit testing. */ +gchar *utils_evaluate_expr_from_string(gchar *chunk, guint peek_index) +{ + static const gchar *keep_prefix_list[] = + { "sizeof", NULL }; + static gchar expr[SCOPE_MAX_EVALUATE_EXPR_LENGTH]; + static const gchar *wchars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static const gchar *wspace = " \t"; + gint startword, endword, temp_pos, round_brackets; + gint pos, left_bracket, cmp; + gboolean stop, oper, whitespace, brackets_exist; + gchar *expr_copy; + + g_return_val_if_fail(chunk != NULL, NULL); + + startword = peek_index; + endword = peek_index; + expr[0] = '\0'; + + if (chunk[startword] == ' ') + { + return NULL; + } + + /* Find the left boundary of the expression. If the current sign + is a '*' or a '&' then we already are at the left boundary. */ + round_brackets = 0; + if (chunk[startword] != '*' && chunk[startword] != '&') + { + stop = FALSE; + oper = FALSE; + whitespace = FALSE; + while (startword > 0 && stop == FALSE) + { + /* the checks for "c < 0" are to allow any Unicode character which should make the code + * a little bit more Unicode safe, anyway, this allows also any Unicode punctuation */ + if (strchr(wchars, chunk[startword]) || ! IS_ASCII(chunk[startword])) + { + if (whitespace == TRUE && oper == FALSE) + { + startword++; + stop = TRUE; + } + else + { + startword--; + oper = FALSE; + whitespace = FALSE; + } + } + else + { + switch (chunk[startword]) + { + case ' ': + case '\t': + startword--; + whitespace = TRUE; + break; + + case '(': + round_brackets++; + startword--; + break; + + case ')': + round_brackets--; + startword--; + break; + + case '[': + case ']': + startword--; + break; + + case '.': + /* Stop if there are no more signs before the current position, + or if we already have seen an operator, or the sign before + the operator is not a valid variable-name-char or whitespace. */ + if (startword == 0 || oper == TRUE || + (strchr(wchars, chunk[startword - 1]) == NULL && + strchr(wspace, chunk[startword - 1]) == NULL && + chunk[startword - 1] != ']')) + { + stop = TRUE; + break; + } + oper = TRUE; + startword--; + break; + + case '>': + /* Stop if there are no more signs before the current position, + or if we already have seen an operator, or the sign before + the current sign is not a '-' (we expect a "->" here) */ + if (startword < 2 || oper == TRUE || chunk[startword - 1] != '-') + { + stop = TRUE; + break; + } + oper = TRUE; + startword -= 2; + break; + + case ':': + /* Stop if there are no more signs before the current position, + or if we already have seen an operator, or the sign before + the current sign is not a ':' (we expect a "::" here) */ + if (startword < 2 || oper == TRUE || chunk[startword - 1] != ':') + { + stop = TRUE; + break; + } + oper = TRUE; + startword -= 2; + break; + + default: + /* Not a valid variable-name-char or whitespace or operator. */ + stop = TRUE; + if (whitespace == TRUE) + { + startword += 2; + } + break; + } + } + } + if (chunk[startword] == '*' || chunk[startword] == '&') + { + startword++; + } + } + + /* Find the right boundary of the expression. */ + stop = FALSE; + while (chunk[endword] != 0 && stop == FALSE) + { + /* the checks for "c < 0" are to allow any Unicode character which should make the code + * a little bit more Unicode safe, anyway, this allows also any Unicode punctuation */ + if (strchr(wchars, chunk[endword]) || ! IS_ASCII(chunk[endword])) + { + endword++; + } + else + { + switch (chunk[endword]) + { + case ')': + round_brackets--; + if (round_brackets < 1) + { + /* We stop here in any case. 0 would be the normal case. + If the value is below zero something went wrong in the + loop above. Maybe this is just not a valid expression. */ + stop = TRUE; + } + break; + + case ']': + case '*': + case '&': + endword++; + break; + + case ' ': + case '\t': + /* We should usually stop here. But we need to continue + if the whitespace is followed by an array index "[...]"! */ + temp_pos = endword + 1; + while (chunk[temp_pos] != 0 && + (chunk[temp_pos] == ' ' || chunk[temp_pos] == '\t')) + { + temp_pos++; + } + if (chunk[temp_pos] == '[' && chunk[temp_pos+1] != ']') + { + endword = temp_pos + 1; + } + else + { + stop = TRUE; + } + break; + + default: + endword--; + stop = TRUE; + break; + } + } + } + + /* Skip leading whitespace. */ + while ((chunk[startword] == ' ' || chunk[startword] == '\t') && + startword < endword) + { + startword++; + } + + /* Skip trailing whitespace. */ + while (endword > 0 && + (chunk[endword] == ' ' || chunk[endword] == '\t') && + startword < endword) + { + endword--; + } + + /* Validate/ensure balanced round brackets. */ + round_brackets = 0; + left_bracket = 0; + stop = FALSE; + brackets_exist = FALSE; + for (pos = startword ; pos <= endword && stop == FALSE ; pos++) + { + switch (chunk[pos]) + { + case '(': + round_brackets++; + brackets_exist = TRUE; + left_bracket = pos; + break; + + case ')': + round_brackets--; + if (round_brackets == 0) + { + endword = pos; + stop = TRUE; + } + else if (round_brackets < 0) + { + endword = pos - 1; + stop = TRUE; + } + break; + + case ' ': + case '\t': + break; + + default: + temp_pos = pos; + break; + } + } + + /* If brackets exist and the left-most sign is not a bracket itself, + then it could be a function name or an operator (sizeof). We + want to exclude the function name but include an operator name. */ + if (brackets_exist == TRUE && chunk[startword] != '(') + { + pos = 0; + oper = FALSE; + while (keep_prefix_list[pos] != NULL) + { + cmp = strncmp(keep_prefix_list[pos], &(chunk[startword]), + strlen(keep_prefix_list[pos])); + if (cmp == 0) + { + /* Match with allowed operator/prefix. Keep it. */ + oper = TRUE; + break; + } + pos++; + } + + /* Did we find a wanted prefix? */ + if (oper == FALSE) + { + /* No! Move startword back to position of left-most valid + round bracket. */ + startword = left_bracket; + } + } + + /* Skip useless surrounding brackets if present. */ + if (startword < endword) + { + guint skipped = 0; + + while (chunk[startword] == '(' && startword < endword) + { + skipped++; + startword++; + } + while (chunk[endword] == ')' && skipped > 0) + { + skipped--; + endword--; + } + } + + expr_copy = NULL; + if (startword < endword) + { + if (chunk[endword] != '\0') + { + chunk[endword+1] = '\0'; + } + + /* ensure null terminated */ + g_strlcpy(expr, &(chunk[startword]), sizeof(expr)); + expr_copy = g_strdup(expr); + } + + return expr_copy; +} + +/* Reads the expression for evaluate at the given cursor position and writes + * it into the given buffer. The buffer will be NULL terminated in any case, + * even when the word is truncated because wordlen is too small. + * Position can be -1, then the current position is used. */ +gchar *utils_read_evaluate_expr(GeanyEditor *editor, gint peek_pos) +{ + gint line, line_start; + gchar *chunk, *expr; + ScintillaObject *sci; + + g_return_val_if_fail(editor != NULL, NULL); + sci = editor->sci; + + if (peek_pos == -1) + { + peek_pos = sci_get_current_position(sci); + } + + line = sci_get_line_from_position(sci, peek_pos); + line_start = sci_get_position_from_line(sci, line); + chunk = sci_get_line(sci, line); + + /* Now that we got the content, let's parse it. */ + expr = utils_evaluate_expr_from_string (chunk, peek_pos - line_start); + + g_free(chunk); + + return expr; +} Modified: scope/src/utils.h 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -107,5 +107,8 @@ void utils_tree_set_cursor(GtkTreeSelection *selection, GtkTreeIter *iter, gdoub void utils_init(void); void utils_finalize(void); +gchar *utils_evaluate_expr_from_string(gchar *chunk, guint peek_index); +gchar *utils_read_evaluate_expr(GeanyEditor *editor, gint pos); + #define UTILS_H 1 #endif -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 42f0fc: Merge pull request #823 from LarsGit223/scope-improve-on-hover-evaluate
by LarsGit223
11 Jul '19
11 Jul '19
Branch: refs/heads/master Author: LarsGit223 <LarsGit223(a)users.noreply.github.com> Committer: GitHub <noreply(a)github.com> Date: Thu, 11 Jul 2019 17:37:35 UTC Commit: 42f0fc9a3adf5a79e8077406f87a42f0154af1a6
https://github.com/geany/geany-plugins/commit/42f0fc9a3adf5a79e8077406f87a4…
Log Message: ----------- Merge pull request #823 from LarsGit223/scope-improve-on-hover-evaluate scope: Improved evaluation on-hover Modified Paths: -------------- scope/src/Makefile.am scope/src/tests/unittests.c scope/src/tests/utils_test.c scope/src/tooltip.c scope/src/utils.c scope/src/utils.h Modified: scope/src/Makefile.am 14 lines changed, 14 insertions(+), 0 deletions(-) =================================================================== @@ -61,3 +61,17 @@ scope_la_CFLAGS = $(AM_CFLAGS) $(VTE_CFLAGS) \ -I$(top_srcdir)/utils/src include $(top_srcdir)/build/cppcheck.mk + +if UNITTESTS + +TESTS = unittests +check_PROGRAMS = unittests + +unittests_SOURCES = tests/unittests.c tests/utils_test.c \ + $(scope_la_SOURCES) +unittests_CPPFLAGS = -DTEST $(scope_la_CPPFLAGS) +unittests_CFLAGS = $(GEANY_CFLAGS) -DUNITTESTS $(scope_la_CFLAGS) +unittests_LDADD = @GEANY_LIBS@ $(INTLLIBS) @CHECK_LIBS@ \ + $(scope_la_LIBADD) + +endif Modified: scope/src/tests/unittests.c 28 lines changed, 28 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,28 @@ +#include <stdlib.h> +#include <stdio.h> +#include <check.h> + +#include <gtk/gtk.h> +#include "geany.h" + +TCase *utils_create_tests(void); + +Suite * +my_suite(void) +{ + Suite *s = suite_create("Scope"); + suite_add_tcase(s, utils_create_tests()); + return s; +} + +int +main(void) +{ + int nf; + Suite *s = my_suite(); + SRunner *sr = srunner_create(s); + srunner_run_all(sr, CK_NORMAL); + nf = srunner_ntests_failed(sr); + srunner_free(sr); + return (nf == 0) ? EXIT_SUCCESS : EXIT_FAILURE; +} Modified: scope/src/tests/utils_test.c 73 lines changed, 73 insertions(+), 0 deletions(-) =================================================================== @@ -0,0 +1,73 @@ +#include <check.h> +#include "../src/common.h" +#include "../src/utils.h" + +typedef struct S_EXPR_TEST_ITEM +{ + const gchar *input; + guint peek_index; + const gchar *expected; +}EXPR_TEST_ITEM; + +EXPR_TEST_ITEM expr_test_items [] = +{ + { " variable ", sizeof(" var")-1, "variable" }, + { " (variable) ", sizeof(" (var")-1, "variable" }, + { "struct.item", sizeof("str")-1, "struct" }, + { "struct.item", sizeof("str")-1, "struct" }, + { "struct.item", sizeof("struct.it")-1, "struct.item" }, + { "struct->item", sizeof("str")-1, "struct" }, + { "struct->item", sizeof("struct->it")-1, "struct->item" }, + { "&(struct->item)", sizeof("&(str")-1, "struct" }, + { "&(struct->item)", sizeof("&(struct->it")-1, "struct->item" }, + { "foobar(item)", sizeof("foobar(it")-1, "item" }, + { "sizeof(item)", sizeof("sizeof(it")-1, "sizeof(item)" }, + { "array[5]", sizeof("arr")-1, "array" }, + { "array[5]", sizeof("array[")-1, "array[5]" }, + { "*pointer", sizeof("*poi")-1, "pointer" }, + { "*pointer", 0, "*pointer" }, + { "&variable", sizeof("&var")-1, "variable" }, + { "&variable", 0, "&variable" }, + { "foo variable", sizeof("foo var")-1, "variable" }, + { "variable foo", sizeof("var")-1, "variable" }, + { "int var_a, var_b;", sizeof("int var")-1, "var_a" }, + { "int var_a, var_b;", sizeof("int var_a, va")-1, "var_b" }, + { "foo(var_a, var_b);", sizeof("foo(var")-1, "var_a" }, + { "foo(var_a, var_b);", sizeof("foo(var_a, va")-1, "var_b" }, + { "array[index].item", sizeof("array[index].i")-1, "array[index].item" }, + { "array[index]->item", sizeof("array[index]->i")-1, "array[index]->item" }, + { NULL, 0, NULL }, +}; + +START_TEST(test_parser_for_evaluate) +{ + EXPR_TEST_ITEM *test_item; + guint index = 0; + gchar *expr, *chunk; + + test_item = &(expr_test_items[index]); + while (test_item->input != NULL) + { + chunk = g_strdup(test_item->input); + expr = utils_evaluate_expr_from_string (chunk, test_item->peek_index); + ck_assert_ptr_ne(expr, NULL); + if (g_strcmp0(expr, test_item->expected) != 0) + { + ck_abort_msg("Index #%lu: Input: '%s', Peek-Ind.: %lu, Result: '%s' != '%s' (expected)", + index, test_item->input, test_item->peek_index, expr, test_item->expected); + } + g_free(chunk); + g_free(expr); + + index++; + test_item = &(expr_test_items[index]); + } +} +END_TEST; + +TCase *utils_create_tests(void) +{ + TCase *tc_utils = tcase_create("utils"); + tcase_add_test(tc_utils, test_parser_for_evaluate); + return tc_utils; +} Modified: scope/src/tooltip.c 40 lines changed, 34 insertions(+), 6 deletions(-) =================================================================== @@ -22,6 +22,9 @@ #include "common.h" +/* Wordchars defining possible signs in an expression. */ +#define SCOPE_EXPR_WORDCHARS "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.->[]" + static void tooltip_trigger(void) { GdkDisplay *display = gdk_display_get_default(); @@ -48,6 +51,7 @@ static void tooltip_trigger(void) } } +static gchar *last_expr = NULL; static gchar *output = NULL; static gint last_pos = -1; static gint peek_pos = -1; @@ -69,6 +73,24 @@ static void tooltip_set(gchar *text) } } +static void tooltip_set_expr(gchar *expr, gchar *text) +{ + show = text != NULL; + g_free(output); + output = g_strdup_printf ("%s =\n %s", expr, text); + g_free(text); + g_free(expr); + last_pos = peek_pos; + + if (show) + { + if (pref_tooltips_length && strlen(output) > (size_t) pref_tooltips_length + 3) + strcpy(output + pref_tooltips_length, "..."); + + tooltip_trigger(); + } +} + static gint scid_gen = 0; void on_tooltip_error(GArray *nodes) @@ -92,7 +114,7 @@ void on_tooltip_value(GArray *nodes) { if (atoi(parse_grab_token(nodes)) == scid_gen) { - tooltip_set(parse_get_display_from_7bit(parse_lead_value(nodes), + tooltip_set_expr(last_expr, parse_get_display_from_7bit(parse_lead_value(nodes), parse_mode_get(input, MODE_HBIT), parse_mode_get(input, MODE_MEMBER))); } } @@ -107,17 +129,23 @@ static gboolean tooltip_launch(gpointer gdata) (debug_state() & DS_SENDABLE)) { ScintillaObject *sci = doc->editor->sci; - gchar *expr = sci_get_selection_mode(sci) == SC_SEL_STREAM && + gchar *expr; + if (sci_get_selection_mode(sci) == SC_SEL_STREAM && peek_pos >= sci_get_selection_start(sci) && - peek_pos < sci_get_selection_end(sci) ? - editor_get_default_selection(doc->editor, FALSE, NULL) : - editor_get_word_at_pos(doc->editor, peek_pos, NULL); + peek_pos < sci_get_selection_end(sci)) + { + expr = editor_get_default_selection(doc->editor, FALSE, NULL); + } + else + { + expr = utils_read_evaluate_expr(doc->editor, peek_pos); + } if ((expr = utils_verify_selection(expr)) != NULL) { g_free(input); input = debug_send_evaluate('3', scid_gen, expr); - g_free(expr); + last_expr = expr; } else tooltip_set(NULL); Modified: scope/src/utils.c 347 lines changed, 347 insertions(+), 0 deletions(-) =================================================================== @@ -36,6 +36,10 @@ #ifdef G_OS_UNIX #include <fcntl.h> +/* The maximum length of an expression for evaluating the value. + (Including the string terminator '\0') */ +#define SCOPE_MAX_EVALUATE_EXPR_LENGTH 256 + void show_errno(const char *prefix) { show_error(_("%s: %s."), prefix, g_strerror(errno)); @@ -753,3 +757,346 @@ void utils_finalize(void) utils_unlock(documents[i]); } } + +/* checks whether @p c is an ASCII character (e.g. < 0x80) */ +#define IS_ASCII(c) (((unsigned char)(c)) < 0x80) + +/* This function is doing the parsing for 'utils_read_evaluate_expr()'. + It was mainly separated from it to support easy unit testing. */ +gchar *utils_evaluate_expr_from_string(gchar *chunk, guint peek_index) +{ + static const gchar *keep_prefix_list[] = + { "sizeof", NULL }; + static gchar expr[SCOPE_MAX_EVALUATE_EXPR_LENGTH]; + static const gchar *wchars = "_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; + static const gchar *wspace = " \t"; + gint startword, endword, temp_pos, round_brackets; + gint pos, left_bracket, cmp; + gboolean stop, oper, whitespace, brackets_exist; + gchar *expr_copy; + + g_return_val_if_fail(chunk != NULL, NULL); + + startword = peek_index; + endword = peek_index; + expr[0] = '\0'; + + if (chunk[startword] == ' ') + { + return NULL; + } + + /* Find the left boundary of the expression. If the current sign + is a '*' or a '&' then we already are at the left boundary. */ + round_brackets = 0; + if (chunk[startword] != '*' && chunk[startword] != '&') + { + stop = FALSE; + oper = FALSE; + whitespace = FALSE; + while (startword > 0 && stop == FALSE) + { + /* the checks for "c < 0" are to allow any Unicode character which should make the code + * a little bit more Unicode safe, anyway, this allows also any Unicode punctuation */ + if (strchr(wchars, chunk[startword]) || ! IS_ASCII(chunk[startword])) + { + if (whitespace == TRUE && oper == FALSE) + { + startword++; + stop = TRUE; + } + else + { + startword--; + oper = FALSE; + whitespace = FALSE; + } + } + else + { + switch (chunk[startword]) + { + case ' ': + case '\t': + startword--; + whitespace = TRUE; + break; + + case '(': + round_brackets++; + startword--; + break; + + case ')': + round_brackets--; + startword--; + break; + + case '[': + case ']': + startword--; + break; + + case '.': + /* Stop if there are no more signs before the current position, + or if we already have seen an operator, or the sign before + the operator is not a valid variable-name-char or whitespace. */ + if (startword == 0 || oper == TRUE || + (strchr(wchars, chunk[startword - 1]) == NULL && + strchr(wspace, chunk[startword - 1]) == NULL && + chunk[startword - 1] != ']')) + { + stop = TRUE; + break; + } + oper = TRUE; + startword--; + break; + + case '>': + /* Stop if there are no more signs before the current position, + or if we already have seen an operator, or the sign before + the current sign is not a '-' (we expect a "->" here) */ + if (startword < 2 || oper == TRUE || chunk[startword - 1] != '-') + { + stop = TRUE; + break; + } + oper = TRUE; + startword -= 2; + break; + + case ':': + /* Stop if there are no more signs before the current position, + or if we already have seen an operator, or the sign before + the current sign is not a ':' (we expect a "::" here) */ + if (startword < 2 || oper == TRUE || chunk[startword - 1] != ':') + { + stop = TRUE; + break; + } + oper = TRUE; + startword -= 2; + break; + + default: + /* Not a valid variable-name-char or whitespace or operator. */ + stop = TRUE; + if (whitespace == TRUE) + { + startword += 2; + } + break; + } + } + } + if (chunk[startword] == '*' || chunk[startword] == '&') + { + startword++; + } + } + + /* Find the right boundary of the expression. */ + stop = FALSE; + while (chunk[endword] != 0 && stop == FALSE) + { + /* the checks for "c < 0" are to allow any Unicode character which should make the code + * a little bit more Unicode safe, anyway, this allows also any Unicode punctuation */ + if (strchr(wchars, chunk[endword]) || ! IS_ASCII(chunk[endword])) + { + endword++; + } + else + { + switch (chunk[endword]) + { + case ')': + round_brackets--; + if (round_brackets < 1) + { + /* We stop here in any case. 0 would be the normal case. + If the value is below zero something went wrong in the + loop above. Maybe this is just not a valid expression. */ + stop = TRUE; + } + break; + + case ']': + case '*': + case '&': + endword++; + break; + + case ' ': + case '\t': + /* We should usually stop here. But we need to continue + if the whitespace is followed by an array index "[...]"! */ + temp_pos = endword + 1; + while (chunk[temp_pos] != 0 && + (chunk[temp_pos] == ' ' || chunk[temp_pos] == '\t')) + { + temp_pos++; + } + if (chunk[temp_pos] == '[' && chunk[temp_pos+1] != ']') + { + endword = temp_pos + 1; + } + else + { + stop = TRUE; + } + break; + + default: + endword--; + stop = TRUE; + break; + } + } + } + + /* Skip leading whitespace. */ + while ((chunk[startword] == ' ' || chunk[startword] == '\t') && + startword < endword) + { + startword++; + } + + /* Skip trailing whitespace. */ + while (endword > 0 && + (chunk[endword] == ' ' || chunk[endword] == '\t') && + startword < endword) + { + endword--; + } + + /* Validate/ensure balanced round brackets. */ + round_brackets = 0; + left_bracket = 0; + stop = FALSE; + brackets_exist = FALSE; + for (pos = startword ; pos <= endword && stop == FALSE ; pos++) + { + switch (chunk[pos]) + { + case '(': + round_brackets++; + brackets_exist = TRUE; + left_bracket = pos; + break; + + case ')': + round_brackets--; + if (round_brackets == 0) + { + endword = pos; + stop = TRUE; + } + else if (round_brackets < 0) + { + endword = pos - 1; + stop = TRUE; + } + break; + + case ' ': + case '\t': + break; + + default: + temp_pos = pos; + break; + } + } + + /* If brackets exist and the left-most sign is not a bracket itself, + then it could be a function name or an operator (sizeof). We + want to exclude the function name but include an operator name. */ + if (brackets_exist == TRUE && chunk[startword] != '(') + { + pos = 0; + oper = FALSE; + while (keep_prefix_list[pos] != NULL) + { + cmp = strncmp(keep_prefix_list[pos], &(chunk[startword]), + strlen(keep_prefix_list[pos])); + if (cmp == 0) + { + /* Match with allowed operator/prefix. Keep it. */ + oper = TRUE; + break; + } + pos++; + } + + /* Did we find a wanted prefix? */ + if (oper == FALSE) + { + /* No! Move startword back to position of left-most valid + round bracket. */ + startword = left_bracket; + } + } + + /* Skip useless surrounding brackets if present. */ + if (startword < endword) + { + guint skipped = 0; + + while (chunk[startword] == '(' && startword < endword) + { + skipped++; + startword++; + } + while (chunk[endword] == ')' && skipped > 0) + { + skipped--; + endword--; + } + } + + expr_copy = NULL; + if (startword < endword) + { + if (chunk[endword] != '\0') + { + chunk[endword+1] = '\0'; + } + + /* ensure null terminated */ + g_strlcpy(expr, &(chunk[startword]), sizeof(expr)); + expr_copy = g_strdup(expr); + } + + return expr_copy; +} + +/* Reads the expression for evaluate at the given cursor position and writes + * it into the given buffer. The buffer will be NULL terminated in any case, + * even when the word is truncated because wordlen is too small. + * Position can be -1, then the current position is used. */ +gchar *utils_read_evaluate_expr(GeanyEditor *editor, gint peek_pos) +{ + gint line, line_start; + gchar *chunk, *expr; + ScintillaObject *sci; + + g_return_val_if_fail(editor != NULL, NULL); + sci = editor->sci; + + if (peek_pos == -1) + { + peek_pos = sci_get_current_position(sci); + } + + line = sci_get_line_from_position(sci, peek_pos); + line_start = sci_get_position_from_line(sci, line); + chunk = sci_get_line(sci, line); + + /* Now that we got the content, let's parse it. */ + expr = utils_evaluate_expr_from_string (chunk, peek_pos - line_start); + + g_free(chunk); + + return expr; +} Modified: scope/src/utils.h 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -107,5 +107,8 @@ void utils_tree_set_cursor(GtkTreeSelection *selection, GtkTreeIter *iter, gdoub void utils_init(void); void utils_finalize(void); +gchar *utils_evaluate_expr_from_string(gchar *chunk, guint peek_index); +gchar *utils_read_evaluate_expr(GeanyEditor *editor, gint pos); + #define UTILS_H 1 #endif -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] e2526f: Merge pull request #880 from eht16/updatechecker_new_service_url
by Frank Lanitz
02 Jul '19
02 Jul '19
Branch: refs/heads/master Author: Frank Lanitz <frank(a)frank.uvena.de> Committer: GitHub <noreply(a)github.com> Date: Tue, 02 Jul 2019 11:08:44 UTC Commit: e2526f8359850961b8c6066f06bf88bd9be6fef9
https://github.com/geany/geany-plugins/commit/e2526f8359850961b8c6066f06bf8…
Log Message: ----------- Merge pull request #880 from eht16/updatechecker_new_service_url UpdateChecker: Use new service URL Modified Paths: -------------- updatechecker/src/updatechecker.c Modified: updatechecker/src/updatechecker.c 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -47,7 +47,7 @@ enum { UPDATECHECK_STARTUP }; -#define UPDATE_CHECK_URL "
https://geany.org/service/version.php
" +#define UPDATE_CHECK_URL "
https://geany.org/service/version/
" static GtkWidget *main_menu_item = NULL; static void update_check_result_cb(SoupSession *session, -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
[geany/geany-plugins] 70c6aa: treebrowser: fixed deprecated gtk calls for gtk3
by LarsGit223
02 Jul '19
02 Jul '19
Branch: refs/heads/master Author: LarsGit223 <lars_paulsen(a)web.de> Committer: LarsGit223 <lars_paulsen(a)web.de> Date: Fri, 07 Jun 2019 16:46:57 UTC Commit: 70c6aa02f205f61b8a466a4a09573383ea5ef729
https://github.com/geany/geany-plugins/commit/70c6aa02f205f61b8a466a4a09573…
Log Message: ----------- treebrowser: fixed deprecated gtk calls for gtk3 Modified Paths: -------------- build/treebrowser.m4 treebrowser/src/Makefile.am treebrowser/src/treebrowser.c Modified: build/treebrowser.m4 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -1,6 +1,8 @@ AC_DEFUN([GP_CHECK_TREEBROWSER], [ GP_ARG_DISABLE([Treebrowser], [auto]) + GP_CHECK_UTILSLIB([Treebrowser]) + if [[ "$enable_treebrowser" != no ]]; then AC_CHECK_FUNC([creat], [enable_treebrowser=yes], Modified: treebrowser/src/Makefile.am 6 lines changed, 4 insertions(+), 2 deletions(-) =================================================================== @@ -5,8 +5,10 @@ geanyplugins_LTLIBRARIES = treebrowser.la treebrowser_la_SOURCES = treebrowser.c treebrowser_la_CPPFLAGS = $(AM_CPPFLAGS) -DG_LOG_DOMAIN=\"TreeBrowser\" -treebrowser_la_CFLAGS = $(AM_CFLAGS) $(GIO_CFLAGS) -treebrowser_la_LIBADD = $(COMMONLIBS) $(GIO_LIBS) +treebrowser_la_CFLAGS = $(AM_CFLAGS) $(GIO_CFLAGS) \ + -I$(top_srcdir)/utils/src +treebrowser_la_LIBADD = $(COMMONLIBS) $(GIO_LIBS) \ + $(top_builddir)/utils/src/libgeanypluginutils.la AM_CPPCHECKFLAGS = --suppress='deallocDealloc:$(srcdir)/treebrowser.c' AM_CPPCHECKFLAGS += --suppress='doubleFree:$(srcdir)/treebrowser.c' Modified: treebrowser/src/treebrowser.c 236 lines changed, 235 insertions(+), 1 deletions(-) =================================================================== @@ -18,6 +18,7 @@ #include "geany.h" #include "geanyplugin.h" +#include <gp_gtkcompat.h> #include <gio/gio.h> @@ -179,6 +180,27 @@ tree_view_row_expanded_iter(GtkTreeView *tree_view, GtkTreeIter *iter) return expanded; } +#if GTK_CHECK_VERSION(3, 10, 0) +static GdkPixbuf * +utils_pixbuf_from_name(const gchar *icon_name) +{ + GError *error = NULL; + GtkIconTheme *icon_theme; + GdkPixbuf *pixbuf; + + icon_theme = gtk_icon_theme_get_default (); + pixbuf = gtk_icon_theme_load_icon(icon_theme, icon_name, 16, 0, &error); + + if (!pixbuf) + { + g_warning("Couldn't load icon: %s", error->message); + g_error_free(error); + return NULL; + } + + return pixbuf; +} +#else static GdkPixbuf * utils_pixbuf_from_stock(const gchar *stock_id) { @@ -192,6 +214,7 @@ utils_pixbuf_from_stock(const gchar *stock_id) GTK_STATE_NORMAL, GTK_ICON_SIZE_MENU, NULL, NULL); return NULL; } +#endif static GdkPixbuf * utils_pixbuf_from_path(gchar *path) @@ -405,16 +428,31 @@ static gboolean treebrowser_checkdir(gchar *directory) { gboolean is_dir; + static gboolean old_value = TRUE; +#if !GTK_CHECK_VERSION(3, 0, 0) static const GdkColor red = {0, 0xffff, 0x6666, 0x6666}; static const GdkColor white = {0, 0xffff, 0xffff, 0xffff}; - static gboolean old_value = TRUE; +#endif is_dir = g_file_test(directory, G_FILE_TEST_IS_DIR); if (old_value != is_dir) { +#if GTK_CHECK_VERSION(3, 0, 0) + GtkStyleContext *context; + context = gtk_widget_get_style_context(GTK_WIDGET(addressbar)); + if (is_dir) + { + gtk_style_context_remove_class(context, "invalid"); + } + else + { + gtk_style_context_add_class(context, "invalid"); + } +#else gtk_widget_modify_base(GTK_WIDGET(addressbar), GTK_STATE_NORMAL, is_dir ? NULL : &red); gtk_widget_modify_text(GTK_WIDGET(addressbar), GTK_STATE_NORMAL, is_dir ? NULL : &white); +#endif old_value = is_dir; } @@ -516,7 +554,11 @@ treebrowser_browse(gchar *directory, gpointer parent) gtk_tree_iter_free(last_dir_iter); } last_dir_iter = gtk_tree_iter_copy(&iter); +#if GTK_CHECK_VERSION(3, 10, 0) + icon = CONFIG_SHOW_ICONS ? utils_pixbuf_from_name("folder") : NULL; +#else icon = CONFIG_SHOW_ICONS ? utils_pixbuf_from_stock(GTK_STOCK_DIRECTORY) : NULL; +#endif gtk_tree_store_set(treestore, &iter, TREEBROWSER_COLUMN_ICON, icon, TREEBROWSER_COLUMN_NAME, fname, @@ -536,7 +578,11 @@ treebrowser_browse(gchar *directory, gpointer parent) icon = CONFIG_SHOW_ICONS == 2 ? utils_pixbuf_from_path(uri) : CONFIG_SHOW_ICONS +#if GTK_CHECK_VERSION(3, 10, 0) + ? utils_pixbuf_from_name("text-x-generic") +#else ? utils_pixbuf_from_stock(GTK_STOCK_FILE) +#endif : NULL; gtk_tree_store_append(treestore, &iter, parent); gtk_tree_store_set(treestore, &iter, @@ -610,7 +656,11 @@ treebrowser_load_bookmarks(void) else { gtk_tree_store_prepend(treestore, &bookmarks_iter, NULL); +#if GTK_CHECK_VERSION(3, 10, 0) + icon = CONFIG_SHOW_ICONS ? utils_pixbuf_from_name("go-home") : NULL; +#else icon = CONFIG_SHOW_ICONS ? utils_pixbuf_from_stock(GTK_STOCK_HOME) : NULL; +#endif gtk_tree_store_set(treestore, &bookmarks_iter, TREEBROWSER_COLUMN_ICON, icon, TREEBROWSER_COLUMN_NAME, _("Bookmarks"), @@ -646,7 +696,11 @@ treebrowser_load_bookmarks(void) gchar *file_name = g_path_get_basename(path_full); gtk_tree_store_append(treestore, &iter, &bookmarks_iter); +#if GTK_CHECK_VERSION(3, 10, 0) + icon = CONFIG_SHOW_ICONS ? utils_pixbuf_from_name("folder") : NULL; +#else icon = CONFIG_SHOW_ICONS ? utils_pixbuf_from_stock(GTK_STOCK_DIRECTORY) : NULL; +#endif gtk_tree_store_set(treestore, &iter, TREEBROWSER_COLUMN_ICON, icon, TREEBROWSER_COLUMN_NAME, file_name, @@ -1197,15 +1251,27 @@ create_popup_menu(const gchar *name, const gchar *uri) gboolean is_dir = is_exists ? g_file_test(uri, G_FILE_TEST_IS_DIR) : FALSE; gboolean is_document = document_find_by_filename(uri) != NULL ? TRUE : FALSE; +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("go-up", _("Go _Up")); +#else item = ui_image_menu_item_new(GTK_STOCK_GO_UP, _("Go _Up")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_go_up), NULL); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("go-up", _("Set _Path From Document")); +#else item = ui_image_menu_item_new(GTK_STOCK_GO_UP, _("Set _Path From Document")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_current_path), NULL); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("document-open", _("_Open Externally")); +#else item = ui_image_menu_item_new(GTK_STOCK_OPEN, _("_Open Externally")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect_data(item, "activate", G_CALLBACK(on_menu_open_externally), g_strdup(uri), (GClosureNotify)g_free, 0); gtk_widget_set_sensitive(item, is_exists); @@ -1214,55 +1280,95 @@ create_popup_menu(const gchar *name, const gchar *uri) gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect_data(item, "activate", G_CALLBACK(on_menu_open_terminal), g_strdup(uri), (GClosureNotify)g_free, 0); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("go-top", _("Set as _Root")); +#else item = ui_image_menu_item_new(GTK_STOCK_GOTO_TOP, _("Set as _Root")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect_data(item, "activate", G_CALLBACK(on_menu_set_as_root), g_strdup(uri), (GClosureNotify)g_free, 0); gtk_widget_set_sensitive(item, is_dir); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("view-refresh", _("Refres_h")); +#else item = ui_image_menu_item_new(GTK_STOCK_REFRESH, _("Refres_h")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_refresh), NULL); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("edit-find", _("_Find in Files")); +#else item = ui_image_menu_item_new(GTK_STOCK_FIND, _("_Find in Files")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect_data(item, "activate", G_CALLBACK(on_menu_find_in_files), g_strdup(uri), (GClosureNotify)g_free, 0); gtk_widget_set_sensitive(item, is_dir); item = gtk_separator_menu_item_new(); gtk_container_add(GTK_CONTAINER(menu), item); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("list-add", _("N_ew Folder")); +#else item = ui_image_menu_item_new(GTK_STOCK_ADD, _("N_ew Folder")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_create_new_object), (gpointer)"directory"); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("document-new", _("_New File")); +#else item = ui_image_menu_item_new(GTK_STOCK_NEW, _("_New File")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_create_new_object), (gpointer)"file"); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("document-save-as", _("Rena_me")); +#else item = ui_image_menu_item_new(GTK_STOCK_SAVE_AS, _("Rena_me")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_rename), NULL); gtk_widget_set_sensitive(item, is_exists); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("edit-delete", _("_Delete")); +#else item = ui_image_menu_item_new(GTK_STOCK_DELETE, _("_Delete")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_delete), NULL); gtk_widget_set_sensitive(item, is_exists); item = gtk_separator_menu_item_new(); gtk_container_add(GTK_CONTAINER(menu), item); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("window-close", g_strdup_printf(_("Close: %s"), name)); +#else item = ui_image_menu_item_new(GTK_STOCK_CLOSE, g_strdup_printf(_("Close: %s"), name)); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect_data(item, "activate", G_CALLBACK(on_menu_close), g_strdup(uri), (GClosureNotify)g_free, 0); gtk_widget_set_sensitive(item, is_document); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("window-close", g_strdup_printf(_("Clo_se Child Documents "))); +#else item = ui_image_menu_item_new(GTK_STOCK_CLOSE, g_strdup_printf(_("Clo_se Child Documents "))); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect_data(item, "activate", G_CALLBACK(on_menu_close_children), g_strdup(uri), (GClosureNotify)g_free, 0); gtk_widget_set_sensitive(item, is_dir); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("edit-copy", _("_Copy Full Path to Clipboard")); +#else item = ui_image_menu_item_new(GTK_STOCK_COPY, _("_Copy Full Path to Clipboard")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect_data(item, "activate", G_CALLBACK(on_menu_copy_uri), g_strdup(uri), (GClosureNotify)g_free, 0); gtk_widget_set_sensitive(item, is_exists); @@ -1271,11 +1377,19 @@ create_popup_menu(const gchar *name, const gchar *uri) gtk_container_add(GTK_CONTAINER(menu), item); gtk_widget_show(item); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("go-next", _("E_xpand All")); +#else item = ui_image_menu_item_new(GTK_STOCK_GO_FORWARD, _("E_xpand All")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_expand_all), NULL); +#if GTK_CHECK_VERSION(3, 10, 0) + item = ui_image_menu_item_new("go-previous", _("Coll_apse All")); +#else item = ui_image_menu_item_new(GTK_STOCK_GO_BACK, _("Coll_apse All")); +#endif gtk_container_add(GTK_CONTAINER(menu), item); g_signal_connect(item, "activate", G_CALLBACK(on_menu_collapse_all), NULL); @@ -1404,7 +1518,12 @@ on_treeview_mouseclick(GtkWidget *widget, GdkEventButton *event, GtkTreeSelectio -1); menu = create_popup_menu(name != NULL ? name : "", uri != NULL ? uri : ""); + +#if GTK_CHECK_VERSION(3, 22, 0) + gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *)event); +#else gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, event->button, event->time); +#endif g_free(name); g_free(uri); @@ -1452,7 +1571,11 @@ on_treeview_keypress(GtkWidget *widget, GdkEventKey *event) -1); menu = create_popup_menu(name != NULL ? name : "", uri != NULL ? uri : ""); +#if GTK_CHECK_VERSION(3, 22, 0) + gtk_menu_popup_at_pointer(GTK_MENU(menu), (GdkEvent *)event); +#else gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, 0, event->time); +#endif g_free(name); g_free(uri); @@ -1562,7 +1685,11 @@ on_treeview_row_expanded(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *path } if (CONFIG_SHOW_ICONS) { +#if GTK_CHECK_VERSION(3, 10, 0) + GdkPixbuf *icon = utils_pixbuf_from_name("document-open"); +#else GdkPixbuf *icon = utils_pixbuf_from_stock(GTK_STOCK_OPEN); +#endif gtk_tree_store_set(treestore, iter, TREEBROWSER_COLUMN_ICON, icon, -1); g_object_unref(icon); @@ -1580,7 +1707,11 @@ on_treeview_row_collapsed(GtkWidget *widget, GtkTreeIter *iter, GtkTreePath *pat return; if (CONFIG_SHOW_ICONS) { +#if GTK_CHECK_VERSION(3, 10, 0) + GdkPixbuf *icon = utils_pixbuf_from_name("folder"); +#else GdkPixbuf *icon = utils_pixbuf_from_stock(GTK_STOCK_DIRECTORY); +#endif gtk_tree_store_set(treestore, iter, TREEBROWSER_COLUMN_ICON, icon, -1); g_object_unref(icon); @@ -1712,11 +1843,29 @@ create_sidebar(void) GtkWidget *wid; GtkTreeSelection *selection; +#if GTK_CHECK_VERSION(3, 0, 0) + GtkCssProvider *provider; + GdkDisplay *display; + GdkScreen *screen; + + provider = gtk_css_provider_new (); + display = gdk_display_get_default (); + screen = gdk_display_get_default_screen (display); + gtk_style_context_add_provider_for_screen (screen, + GTK_STYLE_PROVIDER (provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); + gtk_css_provider_load_from_data (GTK_CSS_PROVIDER(provider), + "#addressbar.invalid {color: #ffffff; background: #ff6666;}", + -1, NULL); +#endif + treeview = create_view_and_model(); sidebar_vbox = gtk_vbox_new(FALSE, 0); sidebar_vbox_bars = gtk_vbox_new(FALSE, 0); selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); addressbar = gtk_entry_new(); +#if GTK_CHECK_VERSION(3, 10, 0) + gtk_widget_set_name(addressbar, "addressbar"); +#endif filter = gtk_entry_new(); scrollwin = gtk_scrolled_window_new(NULL, NULL); @@ -1726,32 +1875,62 @@ create_sidebar(void) gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), GTK_ICON_SIZE_MENU); gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_ICONS); +#if GTK_CHECK_VERSION(3, 10, 0) + wid = gtk_image_new_from_icon_name("go-up", GTK_ICON_SIZE_SMALL_TOOLBAR); + wid = GTK_WIDGET(gtk_tool_button_new(wid, NULL)); +#else wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_GO_UP)); +#endif gtk_widget_set_tooltip_text(wid, _("Go up")); g_signal_connect(wid, "clicked", G_CALLBACK(on_button_go_up), NULL); gtk_container_add(GTK_CONTAINER(toolbar), wid); +#if GTK_CHECK_VERSION(3, 10, 0) + wid = gtk_image_new_from_icon_name("view-refresh", GTK_ICON_SIZE_SMALL_TOOLBAR); + wid = GTK_WIDGET(gtk_tool_button_new(wid, NULL)); +#else wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_REFRESH)); +#endif gtk_widget_set_tooltip_text(wid, _("Refresh")); g_signal_connect(wid, "clicked", G_CALLBACK(on_button_refresh), NULL); gtk_container_add(GTK_CONTAINER(toolbar), wid); +#if GTK_CHECK_VERSION(3, 10, 0) + wid = gtk_image_new_from_icon_name("go-home", GTK_ICON_SIZE_SMALL_TOOLBAR); + wid = GTK_WIDGET(gtk_tool_button_new(wid, NULL)); +#else wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_HOME)); +#endif gtk_widget_set_tooltip_text(wid, _("Home")); g_signal_connect(wid, "clicked", G_CALLBACK(on_button_go_home), NULL); gtk_container_add(GTK_CONTAINER(toolbar), wid); +#if GTK_CHECK_VERSION(3, 10, 0) + wid = gtk_image_new_from_icon_name("go-jump", GTK_ICON_SIZE_SMALL_TOOLBAR); + wid = GTK_WIDGET(gtk_tool_button_new(wid, NULL)); +#else wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_JUMP_TO)); +#endif gtk_widget_set_tooltip_text(wid, _("Set path from document")); g_signal_connect(wid, "clicked", G_CALLBACK(on_button_current_path), NULL); gtk_container_add(GTK_CONTAINER(toolbar), wid); +#if GTK_CHECK_VERSION(3, 10, 0) + wid = gtk_image_new_from_icon_name("folder", GTK_ICON_SIZE_SMALL_TOOLBAR); + wid = GTK_WIDGET(gtk_tool_button_new(wid, NULL)); +#else wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_DIRECTORY)); +#endif gtk_widget_set_tooltip_text(wid, _("Track path")); g_signal_connect(wid, "clicked", G_CALLBACK(treebrowser_track_current), NULL); gtk_container_add(GTK_CONTAINER(toolbar), wid); +#if GTK_CHECK_VERSION(3, 10, 0) + wid = gtk_image_new_from_icon_name("window-close", GTK_ICON_SIZE_SMALL_TOOLBAR); + wid = GTK_WIDGET(gtk_tool_button_new(wid, NULL)); +#else wid = GTK_WIDGET(gtk_tool_button_new_from_stock(GTK_STOCK_CLOSE)); +#endif gtk_widget_set_tooltip_text(wid, _("Hide bars")); g_signal_connect(wid, "clicked", G_CALLBACK(on_button_hide_bars), NULL); gtk_container_add(GTK_CONTAINER(toolbar), wid); @@ -1936,7 +2115,12 @@ plugin_configure(GtkDialog *dialog) label = gtk_label_new(_("External open command")); configure_widgets.OPEN_EXTERNAL_CMD = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(configure_widgets.OPEN_EXTERNAL_CMD), CONFIG_OPEN_EXTERNAL_CMD); +#if GTK_CHECK_VERSION(3, 14, 0) + gtk_widget_set_halign(label, 0); + gtk_widget_set_valign(label, 0.5); +#else gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); +#endif gtk_widget_set_tooltip_text(configure_widgets.OPEN_EXTERNAL_CMD, _("The command to execute when using \"Open with\". You can use %f and %d wildcards.\n" "%f will be replaced with the filename including full path\n" @@ -1949,7 +2133,13 @@ plugin_configure(GtkDialog *dialog) label = gtk_label_new(_("Terminal")); configure_widgets.OPEN_TERMINAL = gtk_entry_new(); gtk_entry_set_text(GTK_ENTRY(configure_widgets.OPEN_TERMINAL), CONFIG_OPEN_TERMINAL); + +#if GTK_CHECK_VERSION(3, 14, 0) + gtk_widget_set_halign(label, 0); + gtk_widget_set_valign(label, 0.5); +#else gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); +#endif gtk_widget_set_tooltip_text(configure_widgets.OPEN_TERMINAL, _("The terminal to use with the command \"Open Terminal\"")); gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 6); @@ -1981,61 +2171,105 @@ plugin_configure(GtkDialog *dialog) gtk_combo_box_set_active(GTK_COMBO_BOX(configure_widgets.SHOW_ICONS), CONFIG_SHOW_ICONS); configure_widgets.SHOW_HIDDEN_FILES = gtk_check_button_new_with_label(_("Show hidden files")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.SHOW_HIDDEN_FILES, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.SHOW_HIDDEN_FILES), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.SHOW_HIDDEN_FILES), CONFIG_SHOW_HIDDEN_FILES); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.SHOW_HIDDEN_FILES, FALSE, FALSE, 0); gtk_widget_set_tooltip_text(configure_widgets.SHOW_HIDDEN_FILES, _("On Windows, this just hide files that are prefixed with '.' (dot)")); configure_widgets.HIDE_OBJECT_FILES = gtk_check_button_new_with_label(_("Hide object files")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.HIDE_OBJECT_FILES, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.HIDE_OBJECT_FILES), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.HIDE_OBJECT_FILES), CONFIG_HIDE_OBJECT_FILES); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.HIDE_OBJECT_FILES, FALSE, FALSE, 0); gtk_widget_set_tooltip_text(configure_widgets.HIDE_OBJECT_FILES, _("Don't show generated object files in the file browser, this includes *.o, *.obj. *.so, *.dll, *.a, *.lib")); configure_widgets.REVERSE_FILTER = gtk_check_button_new_with_label(_("Reverse filter")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.REVERSE_FILTER, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.REVERSE_FILTER), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.REVERSE_FILTER), CONFIG_REVERSE_FILTER); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.REVERSE_FILTER, FALSE, FALSE, 0); configure_widgets.FOLLOW_CURRENT_DOC = gtk_check_button_new_with_label(_("Follow current document")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.FOLLOW_CURRENT_DOC, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.FOLLOW_CURRENT_DOC), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.FOLLOW_CURRENT_DOC), CONFIG_FOLLOW_CURRENT_DOC); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.FOLLOW_CURRENT_DOC, FALSE, FALSE, 0); configure_widgets.ONE_CLICK_CHDOC = gtk_check_button_new_with_label(_("Single click, open document and focus it")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.ONE_CLICK_CHDOC, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.ONE_CLICK_CHDOC), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.ONE_CLICK_CHDOC), CONFIG_ONE_CLICK_CHDOC); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.ONE_CLICK_CHDOC, FALSE, FALSE, 0); configure_widgets.CHROOT_ON_DCLICK = gtk_check_button_new_with_label(_("Double click open directory")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.ONE_CLICK_CHDOC, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.CHROOT_ON_DCLICK), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.CHROOT_ON_DCLICK), CONFIG_CHROOT_ON_DCLICK); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.CHROOT_ON_DCLICK, FALSE, FALSE, 0); configure_widgets.ON_DELETE_CLOSE_FILE = gtk_check_button_new_with_label(_("On delete file, close it if is opened")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.ON_DELETE_CLOSE_FILE, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.ON_DELETE_CLOSE_FILE), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.ON_DELETE_CLOSE_FILE), CONFIG_ON_DELETE_CLOSE_FILE); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.ON_DELETE_CLOSE_FILE, FALSE, FALSE, 0); configure_widgets.ON_OPEN_FOCUS_EDITOR = gtk_check_button_new_with_label(_("Focus editor on file open")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.ON_OPEN_FOCUS_EDITOR, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.ON_OPEN_FOCUS_EDITOR), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.ON_OPEN_FOCUS_EDITOR), CONFIG_ON_OPEN_FOCUS_EDITOR); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.ON_OPEN_FOCUS_EDITOR, FALSE, FALSE, 0); configure_widgets.SHOW_TREE_LINES = gtk_check_button_new_with_label(_("Show tree lines")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.SHOW_TREE_LINES, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.SHOW_TREE_LINES), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.SHOW_TREE_LINES), CONFIG_SHOW_TREE_LINES); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.SHOW_TREE_LINES, FALSE, FALSE, 0); configure_widgets.SHOW_BOOKMARKS = gtk_check_button_new_with_label(_("Show bookmarks")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.SHOW_BOOKMARKS, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.SHOW_BOOKMARKS), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.SHOW_BOOKMARKS), CONFIG_SHOW_BOOKMARKS); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.SHOW_BOOKMARKS, FALSE, FALSE, 0); configure_widgets.OPEN_NEW_FILES = gtk_check_button_new_with_label(_("Open new files")); +#if GTK_CHECK_VERSION(3, 20, 0) + gtk_widget_set_focus_on_click(configure_widgets.OPEN_NEW_FILES, FALSE); +#else gtk_button_set_focus_on_click(GTK_BUTTON(configure_widgets.OPEN_NEW_FILES ), FALSE); +#endif gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(configure_widgets.OPEN_NEW_FILES ), CONFIG_OPEN_NEW_FILES); gtk_box_pack_start(GTK_BOX(vbox), configure_widgets.OPEN_NEW_FILES , FALSE, FALSE, 0); -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
← Newer
1
2
3
4
Older →
Jump to page:
1
2
3
4
Results per page:
10
25
50
100
200