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
----- 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
5470 discussions
Start a n
N
ew thread
[geany/geany-plugins] cec202: vimode: Refactor motion-word.c so the motion commands can be reused
by Jiřà Techet
08 May '23
08 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: Jiřà Techet <techet(a)gmail.com> Date: Fri, 10 Mar 2023 19:58:20 UTC Commit: cec20265a32d9db837914320317ae0ad9533d461
https://github.com/geany/geany-plugins/commit/cec20265a32d9db837914320317ae…
Log Message: ----------- vimode: Refactor motion-word.c so the motion commands can be reused This is a preparation for implementation of "iw", "ow", "iW" and "oW" text objects. Modified Paths: -------------- vimode/src/cmds/motion-word.c Modified: vimode/src/cmds/motion-word.c 233 lines changed, 133 insertions(+), 100 deletions(-) =================================================================== @@ -21,13 +21,6 @@ typedef gboolean (*CharacterPredicate)(gchar c); -static void get_current(ScintillaObject *sci, gchar *ch, gint *pos) -{ - *pos = SSM(sci, SCI_GETCURRENTPOS, 0, 0); - *ch = SSM(sci, SCI_GETCHARAT, *pos, 0); -} - - static void move_left(ScintillaObject *sci, gchar *ch, gint *pos) { *pos = PREV(sci, *pos); @@ -90,177 +83,217 @@ static gboolean skip_to_right(CharacterPredicate is_in_group, ScintillaObject *s } -void cmd_goto_next_word(CmdContext *c, CmdParams *p) +static gint find_next_word(ScintillaObject *sci, gint pos, gint num) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + if (!skip_to_right(is_wordchar, sci, &ch, &pos, len)) + skip_to_right(is_nonwordchar, sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + } + return pos; +} - if (!skip_to_right(is_wordchar, p->sci, &ch, &pos, len)) - skip_to_right(is_nonwordchar, p->sci, &ch, &pos, len); - skip_to_right(is_space, p->sci, &ch, &pos, len); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); - } +void cmd_goto_next_word(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); } -void cmd_goto_previous_word(CmdContext *c, CmdParams *p) +static gint find_previous_word(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_left(p->sci, &ch, &pos); + move_left(sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - if (!skip_to_left(is_wordchar, p->sci, &ch, &pos)) - skip_to_left(is_nonwordchar, p->sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + if (!skip_to_left(is_wordchar, sci, &ch, &pos)) + skip_to_left(is_nonwordchar, sci, &ch, &pos); if (pos != 0 || is_space(ch)) - move_right(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + move_right(sci, &ch, &pos); } + return pos; } -void cmd_goto_next_word_end(CmdContext *c, CmdParams *p) +void cmd_goto_previous_word(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_next_word_end(ScintillaObject *sci, gint pos, gint num, gboolean include_last) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_right(p->sci, &ch, &pos); + move_right(sci, &ch, &pos); - skip_to_right(is_space, p->sci, &ch, &pos, len); - if (!skip_to_right(is_wordchar, p->sci, &ch, &pos, len)) - skip_to_right(is_nonwordchar, p->sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + if (!skip_to_right(is_wordchar, sci, &ch, &pos, len)) + skip_to_right(is_nonwordchar, sci, &ch, &pos, len); - if (pos < len - 1 || is_space(ch)) - move_left(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + if (!include_last) + { + if (pos < len - 1 || is_space(ch)) + move_left(sci, &ch, &pos); + } } + return pos; } -void cmd_goto_previous_word_end(CmdContext *c, CmdParams *p) +void cmd_goto_next_word_end(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word_end(p->sci, pos, p->num, FALSE); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_previous_word_end(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + if (!skip_to_left(is_wordchar, sci, &ch, &pos)) + skip_to_left(is_nonwordchar, sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + } + return pos; +} - if (!skip_to_left(is_wordchar, p->sci, &ch, &pos)) - skip_to_left(is_nonwordchar, p->sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); - } +void cmd_goto_previous_word_end(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word_end(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); } -void cmd_goto_next_word_space(CmdContext *c, CmdParams *p) +static gint find_next_word_space(ScintillaObject *sci, gint pos, gint num) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + skip_to_right(is_nonspace, sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + } + return pos; +} - skip_to_right(is_nonspace, p->sci, &ch, &pos, len); - skip_to_right(is_space, p->sci, &ch, &pos, len); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); - } +void cmd_goto_next_word_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word_space(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); } -void cmd_goto_previous_word_space(CmdContext *c, CmdParams *p) +static gint find_previous_word_space(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_left(p->sci, &ch, &pos); + move_left(sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - skip_to_left(is_nonspace, p->sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + skip_to_left(is_nonspace, sci, &ch, &pos); if (pos != 0 || is_space(ch)) - move_right(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + move_right(sci, &ch, &pos); } + return pos; } -void cmd_goto_next_word_end_space(CmdContext *c, CmdParams *p) +void cmd_goto_previous_word_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word_space(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_next_word_end_space(ScintillaObject *sci, gint pos, gint num, gboolean include_last) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_right(p->sci, &ch, &pos); + move_right(sci, &ch, &pos); - skip_to_right(is_space, p->sci, &ch, &pos, len); - skip_to_right(is_nonspace, p->sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + skip_to_right(is_nonspace, sci, &ch, &pos, len); - if (pos < len - 1 || is_space(ch)) - move_left(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + if (!include_last) + { + if (pos < len - 1 || is_space(ch)) + move_left(sci, &ch, &pos); + } } + return pos; } -void cmd_goto_previous_word_end_space(CmdContext *c, CmdParams *p) +void cmd_goto_next_word_end_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word_end_space(p->sci, pos, p->num, FALSE); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_previous_word_end_space(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + skip_to_left(is_nonspace, sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + } + return pos; +} - skip_to_left(is_nonspace, p->sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); +void cmd_goto_previous_word_end_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word_end_space(p->sci, pos, p->num); + SET_POS(p->sci, pos, 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] e045c7: vimode: implement "iw", "ow", "iW" and "oW" text objects
by Jiřà Techet
08 May '23
08 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: Jiřà Techet <techet(a)gmail.com> Date: Fri, 10 Mar 2023 20:41:52 UTC Commit: e045c740f50a278fa3a8621ac139273e5d8c26c9
https://github.com/geany/geany-plugins/commit/e045c740f50a278fa3a8621ac1392…
Log Message: ----------- vimode: implement "iw", "ow", "iW" and "oW" text objects This enables a family of word-related text object commands such as: "ciw", "diw", "viw" etc. Fixes #1155. Modified Paths: -------------- vimode/README vimode/src/cmd-runner.c vimode/src/cmds/motion-word.c vimode/src/cmds/motion-word.h vimode/src/cmds/txtobjs.c vimode/src/cmds/txtobjs.h Modified: vimode/README 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -448,10 +448,12 @@ a new command, please do not forget to update the table below.:: v_a< a< "a <>" from '<' to the matching '>' v_a> a> same as a< v_aB aB "a Block" from "[{" to "]}" (with brackets) + v_aW aW "a WORD" (with white space) v_a[ a[ "a []" from '[' to the matching ']' v_a] a] same as a[ v_a` a` string in backticks v_ab ab "a block" from "[(" to "])" (with braces) + v_aw aw "a word" (with white space) v_a{ a{ same as aB v_a} a} same as aB v_iquote i" double quoted string without the quotes @@ -461,10 +463,12 @@ a new command, please do not forget to update the table below.:: v_i< i< "inner <>" from '<' to the matching '>' v_i> i> same as i< v_iB iB "inner Block" from "[{" and "]}" + v_iW iW "inner WORD" v_i[ i[ "inner []" from '[' to the matching ']' v_i] i] same as i[ v_i` i` string in backticks without the backticks v_ib ib "inner block" from "[(" to "])" + v_iw iw "inner word" v_i{ i{ same as iB v_i} i} same as iB Modified: vimode/src/cmd-runner.c 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -222,6 +222,8 @@ CmdDef operator_cmds[] = { {cmd_select_less, GDK_KEY_a, GDK_KEY_greater, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket, GDK_KEY_a, GDK_KEY_bracketleft, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket, GDK_KEY_a, GDK_KEY_bracketright, 0, 0, FALSE, FALSE}, \ + {cmd_select_word, GDK_KEY_a, GDK_KEY_w, 0, 0, FALSE, FALSE}, \ + {cmd_select_word_space, GDK_KEY_a, GDK_KEY_W, 0, 0, FALSE, FALSE}, \ /* inner */ \ {cmd_select_quotedbl_inner, GDK_KEY_i, GDK_KEY_quotedbl, 0, 0, FALSE, FALSE}, \ {cmd_select_quoteleft_inner, GDK_KEY_i, GDK_KEY_quoteleft, 0, 0, FALSE, FALSE}, \ @@ -236,6 +238,8 @@ CmdDef operator_cmds[] = { {cmd_select_less_inner, GDK_KEY_i, GDK_KEY_greater, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket_inner, GDK_KEY_i, GDK_KEY_bracketleft, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket_inner, GDK_KEY_i, GDK_KEY_bracketright, 0, 0, FALSE, FALSE}, \ + {cmd_select_word_inner, GDK_KEY_i, GDK_KEY_w, 0, 0, FALSE, FALSE}, \ + {cmd_select_word_space_inner, GDK_KEY_i, GDK_KEY_W, 0, 0, FALSE, FALSE}, \ /* END */ Modified: vimode/src/cmds/motion-word.c 90 lines changed, 90 insertions(+), 0 deletions(-) =================================================================== @@ -295,5 +295,95 @@ void cmd_goto_previous_word_end_space(CmdContext *c, CmdParams *p) pos = find_previous_word_end_space(p->sci, pos, p->num); SET_POS(p->sci, pos, TRUE); } + + +void get_word_range(ScintillaObject *sci, gboolean word_space, gboolean inner, + gint pos, gint num, gint *sel_start, gint *sel_len) +{ + guint i; + gint start_pos = pos; + gint end_pos; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); + gchar prev_ch = SSM(sci, SCI_GETCHARAT, PREV(sci, pos), 0); + gchar next_ch = SSM(sci, SCI_GETCHARAT, NEXT(sci, pos), 0); + + if (word_space) + { + if (is_space(prev_ch) && !is_space(ch)) + ; // already there + else if (is_space(ch) && !is_space(prev_ch)) + ; // already there + else if (is_space(ch)) + start_pos = NEXT(sci, find_previous_word_end_space(sci, pos, 1)); + else if (!is_space(ch)) + start_pos = find_previous_word_space(sci, pos, 1); + + if (inner && !is_space(ch) && is_space(next_ch)) + { + num--; // already there once + pos = NEXT(sci, pos); + } + + for (i = 0; i < num; i++) + { + if (is_space(ch)) + { + if (inner) + pos = find_next_word_space(sci, pos, 1); + else + pos = find_next_word_end_space(sci, pos, 1, TRUE); + } + else if (!is_space(ch)) + { + if (inner) + pos = find_next_word_end_space(sci, pos, 1, TRUE); + else + pos = find_next_word_space(sci, pos, 1); + } + } + + end_pos = pos; } + else + { + if ((is_space(prev_ch) || is_nonwordchar(prev_ch)) && is_wordchar(ch)) + ; // already there + else if ((is_wordchar(prev_ch) || is_nonwordchar(prev_ch)) && is_space(ch)) + ; // already there + else if ((is_space(prev_ch) || is_wordchar(prev_ch)) && is_nonwordchar(ch)) + ; // already there + else if (is_space(ch) || is_nonwordchar(ch)) + start_pos = NEXT(sci, find_previous_word_end(sci, pos, 1)); + else if (is_wordchar(ch)) + start_pos = find_previous_word(sci, pos, 1); + + if (inner && (is_space(next_ch) || is_nonwordchar(next_ch)) && is_wordchar(ch)) + { + num--; // already there once + pos = NEXT(sci, pos); + } + + for (i = 0; i < num; i++) + { + if (is_space(ch) || is_nonwordchar(ch)) + { + if (inner) + pos = find_next_word(sci, pos, 1); + else + pos = find_next_word_end(sci, pos, 1, TRUE); + } + else if (is_wordchar(ch)) + { + if (inner) + pos = find_next_word_end(sci, pos, 1, TRUE); + else + pos = find_next_word(sci, pos, 1); + } + } + + end_pos = pos; + } + + *sel_start = start_pos; + *sel_len = end_pos - start_pos; } Modified: vimode/src/cmds/motion-word.h 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -31,4 +31,7 @@ void cmd_goto_previous_word_space(CmdContext *c, CmdParams *p); void cmd_goto_next_word_end_space(CmdContext *c, CmdParams *p); void cmd_goto_previous_word_end_space(CmdContext *c, CmdParams *p); +void get_word_range(ScintillaObject *sci, gboolean word_space, gboolean inner, + gint pos, gint num, gint *sel_start, gint *sel_len); + #endif Modified: vimode/src/cmds/txtobjs.c 44 lines changed, 44 insertions(+), 0 deletions(-) =================================================================== @@ -17,6 +17,7 @@ */ #include "cmds/txtobjs.h" +#include "cmds/motion-word.h" static gint find_upper_level_brace(ScintillaObject *sci, gint pos, gint open_brace, gint close_brace) @@ -188,3 +189,46 @@ void cmd_select_bracket_inner(CmdContext *c, CmdParams *p) { select_brace(c, p, '[', ']', TRUE); } + + +static void select_word(CmdContext *c, CmdParams *p, gboolean word_space, gboolean inner) +{ + gint sel_start, sel_len; + + get_word_range(p->sci, word_space, inner, p->pos, p->num, &sel_start, &sel_len); + + if (VI_IS_VISUAL(vi_get_mode())) + { + c->sel_anchor = sel_start; + SET_POS(p->sci, sel_start + sel_len, TRUE); + } + else + { + p->sel_start = sel_start; + p->sel_len = sel_len; + } +} + + +void cmd_select_word(CmdContext *c, CmdParams *p) +{ + select_word(c, p, FALSE, FALSE); +} + + +void cmd_select_word_space(CmdContext *c, CmdParams *p) +{ + select_word(c, p, TRUE, FALSE); +} + + +void cmd_select_word_inner(CmdContext *c, CmdParams *p) +{ + select_word(c, p, FALSE, TRUE); +} + + +void cmd_select_word_space_inner(CmdContext *c, CmdParams *p) +{ + select_word(c, p, TRUE, TRUE); +} Modified: vimode/src/cmds/txtobjs.h 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -29,6 +29,8 @@ void cmd_select_brace(CmdContext *c, CmdParams *p); void cmd_select_paren(CmdContext *c, CmdParams *p); void cmd_select_less(CmdContext *c, CmdParams *p); void cmd_select_bracket(CmdContext *c, CmdParams *p); +void cmd_select_word(CmdContext *c, CmdParams *p); +void cmd_select_word_space(CmdContext *c, CmdParams *p); void cmd_select_quotedbl_inner(CmdContext *c, CmdParams *p); void cmd_select_quoteleft_inner(CmdContext *c, CmdParams *p); @@ -37,5 +39,7 @@ void cmd_select_brace_inner(CmdContext *c, CmdParams *p); void cmd_select_paren_inner(CmdContext *c, CmdParams *p); void cmd_select_less_inner(CmdContext *c, CmdParams *p); void cmd_select_bracket_inner(CmdContext *c, CmdParams *p); +void cmd_select_word_inner(CmdContext *c, CmdParams *p); +void cmd_select_word_space_inner(CmdContext *c, CmdParams *p); #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] 9c06cc: Merge pull request #1240 from techee/vim_iw
by Jiřà Techet
08 May '23
08 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: GitHub <noreply(a)github.com> Date: Mon, 08 May 2023 12:24:05 UTC Commit: 9c06cc5ed79618b15673f6f0b0a4bf1df8eafce8
https://github.com/geany/geany-plugins/commit/9c06cc5ed79618b15673f6f0b0a4b…
Log Message: ----------- Merge pull request #1240 from techee/vim_iw vimode: implement "iw", "ow", "iW" and "oW" text objects Modified Paths: -------------- vimode/README vimode/src/cmd-runner.c vimode/src/cmds/motion-word.c vimode/src/cmds/motion-word.h vimode/src/cmds/txtobjs.c vimode/src/cmds/txtobjs.h Modified: vimode/README 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -448,10 +448,12 @@ a new command, please do not forget to update the table below.:: v_a< a< "a <>" from '<' to the matching '>' v_a> a> same as a< v_aB aB "a Block" from "[{" to "]}" (with brackets) + v_aW aW "a WORD" (with white space) v_a[ a[ "a []" from '[' to the matching ']' v_a] a] same as a[ v_a` a` string in backticks v_ab ab "a block" from "[(" to "])" (with braces) + v_aw aw "a word" (with white space) v_a{ a{ same as aB v_a} a} same as aB v_iquote i" double quoted string without the quotes @@ -461,10 +463,12 @@ a new command, please do not forget to update the table below.:: v_i< i< "inner <>" from '<' to the matching '>' v_i> i> same as i< v_iB iB "inner Block" from "[{" and "]}" + v_iW iW "inner WORD" v_i[ i[ "inner []" from '[' to the matching ']' v_i] i] same as i[ v_i` i` string in backticks without the backticks v_ib ib "inner block" from "[(" to "])" + v_iw iw "inner word" v_i{ i{ same as iB v_i} i} same as iB Modified: vimode/src/cmd-runner.c 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -222,6 +222,8 @@ CmdDef operator_cmds[] = { {cmd_select_less, GDK_KEY_a, GDK_KEY_greater, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket, GDK_KEY_a, GDK_KEY_bracketleft, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket, GDK_KEY_a, GDK_KEY_bracketright, 0, 0, FALSE, FALSE}, \ + {cmd_select_word, GDK_KEY_a, GDK_KEY_w, 0, 0, FALSE, FALSE}, \ + {cmd_select_word_space, GDK_KEY_a, GDK_KEY_W, 0, 0, FALSE, FALSE}, \ /* inner */ \ {cmd_select_quotedbl_inner, GDK_KEY_i, GDK_KEY_quotedbl, 0, 0, FALSE, FALSE}, \ {cmd_select_quoteleft_inner, GDK_KEY_i, GDK_KEY_quoteleft, 0, 0, FALSE, FALSE}, \ @@ -236,6 +238,8 @@ CmdDef operator_cmds[] = { {cmd_select_less_inner, GDK_KEY_i, GDK_KEY_greater, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket_inner, GDK_KEY_i, GDK_KEY_bracketleft, 0, 0, FALSE, FALSE}, \ {cmd_select_bracket_inner, GDK_KEY_i, GDK_KEY_bracketright, 0, 0, FALSE, FALSE}, \ + {cmd_select_word_inner, GDK_KEY_i, GDK_KEY_w, 0, 0, FALSE, FALSE}, \ + {cmd_select_word_space_inner, GDK_KEY_i, GDK_KEY_W, 0, 0, FALSE, FALSE}, \ /* END */ Modified: vimode/src/cmds/motion-word.c 323 lines changed, 223 insertions(+), 100 deletions(-) =================================================================== @@ -21,13 +21,6 @@ typedef gboolean (*CharacterPredicate)(gchar c); -static void get_current(ScintillaObject *sci, gchar *ch, gint *pos) -{ - *pos = SSM(sci, SCI_GETCURRENTPOS, 0, 0); - *ch = SSM(sci, SCI_GETCHARAT, *pos, 0); -} - - static void move_left(ScintillaObject *sci, gchar *ch, gint *pos) { *pos = PREV(sci, *pos); @@ -90,177 +83,307 @@ static gboolean skip_to_right(CharacterPredicate is_in_group, ScintillaObject *s } -void cmd_goto_next_word(CmdContext *c, CmdParams *p) +static gint find_next_word(ScintillaObject *sci, gint pos, gint num) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + if (!skip_to_right(is_wordchar, sci, &ch, &pos, len)) + skip_to_right(is_nonwordchar, sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + } + return pos; +} - if (!skip_to_right(is_wordchar, p->sci, &ch, &pos, len)) - skip_to_right(is_nonwordchar, p->sci, &ch, &pos, len); - skip_to_right(is_space, p->sci, &ch, &pos, len); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); - } +void cmd_goto_next_word(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); } -void cmd_goto_previous_word(CmdContext *c, CmdParams *p) +static gint find_previous_word(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_left(p->sci, &ch, &pos); + move_left(sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - if (!skip_to_left(is_wordchar, p->sci, &ch, &pos)) - skip_to_left(is_nonwordchar, p->sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + if (!skip_to_left(is_wordchar, sci, &ch, &pos)) + skip_to_left(is_nonwordchar, sci, &ch, &pos); if (pos != 0 || is_space(ch)) - move_right(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + move_right(sci, &ch, &pos); } + return pos; } -void cmd_goto_next_word_end(CmdContext *c, CmdParams *p) +void cmd_goto_previous_word(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_next_word_end(ScintillaObject *sci, gint pos, gint num, gboolean include_last) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_right(p->sci, &ch, &pos); + move_right(sci, &ch, &pos); - skip_to_right(is_space, p->sci, &ch, &pos, len); - if (!skip_to_right(is_wordchar, p->sci, &ch, &pos, len)) - skip_to_right(is_nonwordchar, p->sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + if (!skip_to_right(is_wordchar, sci, &ch, &pos, len)) + skip_to_right(is_nonwordchar, sci, &ch, &pos, len); - if (pos < len - 1 || is_space(ch)) - move_left(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + if (!include_last) + { + if (pos < len - 1 || is_space(ch)) + move_left(sci, &ch, &pos); + } } + return pos; } -void cmd_goto_previous_word_end(CmdContext *c, CmdParams *p) +void cmd_goto_next_word_end(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word_end(p->sci, pos, p->num, FALSE); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_previous_word_end(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + if (!skip_to_left(is_wordchar, sci, &ch, &pos)) + skip_to_left(is_nonwordchar, sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + } + return pos; +} - if (!skip_to_left(is_wordchar, p->sci, &ch, &pos)) - skip_to_left(is_nonwordchar, p->sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); - } +void cmd_goto_previous_word_end(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word_end(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); } -void cmd_goto_next_word_space(CmdContext *c, CmdParams *p) +static gint find_next_word_space(ScintillaObject *sci, gint pos, gint num) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + skip_to_right(is_nonspace, sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + } + return pos; +} - skip_to_right(is_nonspace, p->sci, &ch, &pos, len); - skip_to_right(is_space, p->sci, &ch, &pos, len); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); - } +void cmd_goto_next_word_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word_space(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); } -void cmd_goto_previous_word_space(CmdContext *c, CmdParams *p) +static gint find_previous_word_space(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_left(p->sci, &ch, &pos); + move_left(sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - skip_to_left(is_nonspace, p->sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + skip_to_left(is_nonspace, sci, &ch, &pos); if (pos != 0 || is_space(ch)) - move_right(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + move_right(sci, &ch, &pos); } + return pos; } -void cmd_goto_next_word_end_space(CmdContext *c, CmdParams *p) +void cmd_goto_previous_word_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word_space(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_next_word_end_space(ScintillaObject *sci, gint pos, gint num, gboolean include_last) { gint i; - gint len = SSM(p->sci, SCI_GETLENGTH, 0, 0); + gint len = SSM(sci, SCI_GETLENGTH, 0, 0); - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); - move_right(p->sci, &ch, &pos); + move_right(sci, &ch, &pos); - skip_to_right(is_space, p->sci, &ch, &pos, len); - skip_to_right(is_nonspace, p->sci, &ch, &pos, len); + skip_to_right(is_space, sci, &ch, &pos, len); + skip_to_right(is_nonspace, sci, &ch, &pos, len); - if (pos < len - 1 || is_space(ch)) - move_left(p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); + if (!include_last) + { + if (pos < len - 1 || is_space(ch)) + move_left(sci, &ch, &pos); + } } + return pos; } -void cmd_goto_previous_word_end_space(CmdContext *c, CmdParams *p) +void cmd_goto_next_word_end_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_next_word_end_space(p->sci, pos, p->num, FALSE); + SET_POS(p->sci, pos, TRUE); +} + + +static gint find_previous_word_end_space(ScintillaObject *sci, gint pos, gint num) { gint i; - for (i = 0; i < p->num; i++) + for (i = 0; i < num; i++) { - gint pos; - gchar ch; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); - get_current(p->sci, &ch, &pos); + skip_to_left(is_nonspace, sci, &ch, &pos); + skip_to_left(is_space, sci, &ch, &pos); + } + return pos; +} - skip_to_left(is_nonspace, p->sci, &ch, &pos); - skip_to_left(is_space, p->sci, &ch, &pos); - if (!is_space(ch)) - SET_POS(p->sci, pos, TRUE); +void cmd_goto_previous_word_end_space(CmdContext *c, CmdParams *p) +{ + gint pos = SSM(p->sci, SCI_GETCURRENTPOS, 0, 0); + pos = find_previous_word_end_space(p->sci, pos, p->num); + SET_POS(p->sci, pos, TRUE); +} + + +void get_word_range(ScintillaObject *sci, gboolean word_space, gboolean inner, + gint pos, gint num, gint *sel_start, gint *sel_len) +{ + guint i; + gint start_pos = pos; + gint end_pos; + gchar ch = SSM(sci, SCI_GETCHARAT, pos, 0); + gchar prev_ch = SSM(sci, SCI_GETCHARAT, PREV(sci, pos), 0); + gchar next_ch = SSM(sci, SCI_GETCHARAT, NEXT(sci, pos), 0); + + if (word_space) + { + if (is_space(prev_ch) && !is_space(ch)) + ; // already there + else if (is_space(ch) && !is_space(prev_ch)) + ; // already there + else if (is_space(ch)) + start_pos = NEXT(sci, find_previous_word_end_space(sci, pos, 1)); + else if (!is_space(ch)) + start_pos = find_previous_word_space(sci, pos, 1); + + if (inner && !is_space(ch) && is_space(next_ch)) + { + num--; // already there once + pos = NEXT(sci, pos); + } + + for (i = 0; i < num; i++) + { + if (is_space(ch)) + { + if (inner) + pos = find_next_word_space(sci, pos, 1); + else + pos = find_next_word_end_space(sci, pos, 1, TRUE); + } + else if (!is_space(ch)) + { + if (inner) + pos = find_next_word_end_space(sci, pos, 1, TRUE); + else + pos = find_next_word_space(sci, pos, 1); + } + } + + end_pos = pos; } + else + { + if ((is_space(prev_ch) || is_nonwordchar(prev_ch)) && is_wordchar(ch)) + ; // already there + else if ((is_wordchar(prev_ch) || is_nonwordchar(prev_ch)) && is_space(ch)) + ; // already there + else if ((is_space(prev_ch) || is_wordchar(prev_ch)) && is_nonwordchar(ch)) + ; // already there + else if (is_space(ch) || is_nonwordchar(ch)) + start_pos = NEXT(sci, find_previous_word_end(sci, pos, 1)); + else if (is_wordchar(ch)) + start_pos = find_previous_word(sci, pos, 1); + + if (inner && (is_space(next_ch) || is_nonwordchar(next_ch)) && is_wordchar(ch)) + { + num--; // already there once + pos = NEXT(sci, pos); + } + + for (i = 0; i < num; i++) + { + if (is_space(ch) || is_nonwordchar(ch)) + { + if (inner) + pos = find_next_word(sci, pos, 1); + else + pos = find_next_word_end(sci, pos, 1, TRUE); + } + else if (is_wordchar(ch)) + { + if (inner) + pos = find_next_word_end(sci, pos, 1, TRUE); + else + pos = find_next_word(sci, pos, 1); + } + } + + end_pos = pos; + } + + *sel_start = start_pos; + *sel_len = end_pos - start_pos; } Modified: vimode/src/cmds/motion-word.h 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -31,4 +31,7 @@ void cmd_goto_previous_word_space(CmdContext *c, CmdParams *p); void cmd_goto_next_word_end_space(CmdContext *c, CmdParams *p); void cmd_goto_previous_word_end_space(CmdContext *c, CmdParams *p); +void get_word_range(ScintillaObject *sci, gboolean word_space, gboolean inner, + gint pos, gint num, gint *sel_start, gint *sel_len); + #endif Modified: vimode/src/cmds/txtobjs.c 44 lines changed, 44 insertions(+), 0 deletions(-) =================================================================== @@ -17,6 +17,7 @@ */ #include "cmds/txtobjs.h" +#include "cmds/motion-word.h" static gint find_upper_level_brace(ScintillaObject *sci, gint pos, gint open_brace, gint close_brace) @@ -188,3 +189,46 @@ void cmd_select_bracket_inner(CmdContext *c, CmdParams *p) { select_brace(c, p, '[', ']', TRUE); } + + +static void select_word(CmdContext *c, CmdParams *p, gboolean word_space, gboolean inner) +{ + gint sel_start, sel_len; + + get_word_range(p->sci, word_space, inner, p->pos, p->num, &sel_start, &sel_len); + + if (VI_IS_VISUAL(vi_get_mode())) + { + c->sel_anchor = sel_start; + SET_POS(p->sci, sel_start + sel_len, TRUE); + } + else + { + p->sel_start = sel_start; + p->sel_len = sel_len; + } +} + + +void cmd_select_word(CmdContext *c, CmdParams *p) +{ + select_word(c, p, FALSE, FALSE); +} + + +void cmd_select_word_space(CmdContext *c, CmdParams *p) +{ + select_word(c, p, TRUE, FALSE); +} + + +void cmd_select_word_inner(CmdContext *c, CmdParams *p) +{ + select_word(c, p, FALSE, TRUE); +} + + +void cmd_select_word_space_inner(CmdContext *c, CmdParams *p) +{ + select_word(c, p, TRUE, TRUE); +} Modified: vimode/src/cmds/txtobjs.h 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -29,6 +29,8 @@ void cmd_select_brace(CmdContext *c, CmdParams *p); void cmd_select_paren(CmdContext *c, CmdParams *p); void cmd_select_less(CmdContext *c, CmdParams *p); void cmd_select_bracket(CmdContext *c, CmdParams *p); +void cmd_select_word(CmdContext *c, CmdParams *p); +void cmd_select_word_space(CmdContext *c, CmdParams *p); void cmd_select_quotedbl_inner(CmdContext *c, CmdParams *p); void cmd_select_quoteleft_inner(CmdContext *c, CmdParams *p); @@ -37,5 +39,7 @@ void cmd_select_brace_inner(CmdContext *c, CmdParams *p); void cmd_select_paren_inner(CmdContext *c, CmdParams *p); void cmd_select_less_inner(CmdContext *c, CmdParams *p); void cmd_select_bracket_inner(CmdContext *c, CmdParams *p); +void cmd_select_word_inner(CmdContext *c, CmdParams *p); +void cmd_select_word_space_inner(CmdContext *c, CmdParams *p); #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] 64a68a: Merge pull request #1144 from techee/expand_remember
by Jiřà Techet
07 May '23
07 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: GitHub <noreply(a)github.com> Date: Sun, 07 May 2023 21:38:38 UTC Commit: 64a68aff27e9df388389ba8e0c7fb0d42be20de1
https://github.com/geany/geany-plugins/commit/64a68aff27e9df388389ba8e0c7fb…
Log Message: ----------- Merge pull request #1144 from techee/expand_remember projectorganizer: Restore tree state in the sidebar Modified Paths: -------------- projectorganizer/src/prjorg-main.c projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-sidebar.h Modified: projectorganizer/src/prjorg-main.c 4 lines changed, 3 insertions(+), 1 deletions(-) =================================================================== @@ -130,8 +130,10 @@ static void on_project_open(G_GNUC_UNUSED GObject * obj, GKeyFile * config, { if (!prj_org) { + gchar **arr = prjorg_project_load_expanded_paths(config); + prjorg_project_open(config); - prjorg_sidebar_update(TRUE); + prjorg_sidebar_update_full(TRUE, arr); prjorg_sidebar_activate(TRUE); prjorg_menu_activate_menu_items(TRUE); } Modified: projectorganizer/src/prjorg-project.c 19 lines changed, 19 insertions(+), 0 deletions(-) =================================================================== @@ -27,6 +27,7 @@ #include "prjorg-utils.h" #include "prjorg-project.h" +#include "prjorg-sidebar.h" extern GeanyPlugin *geany_plugin; extern GeanyData *geany_data; @@ -377,6 +378,16 @@ static void update_project( } +static void save_expanded_paths(GKeyFile * key_file) +{ + gchar **expanded_paths = prjorg_sidebar_get_expanded_paths(); + + g_key_file_set_string_list(key_file, "prjorg", "expanded_paths", + (const gchar**) expanded_paths, g_strv_length(expanded_paths)); + g_strfreev(expanded_paths); +} + + void prjorg_project_save(GKeyFile * key_file) { GPtrArray *array; @@ -385,6 +396,8 @@ void prjorg_project_save(GKeyFile * key_file) if (!prj_org) return; + save_expanded_paths(key_file); + g_key_file_set_string_list(key_file, "prjorg", "source_patterns", (const gchar**) prj_org->source_patterns, g_strv_length(prj_org->source_patterns)); g_key_file_set_string_list(key_file, "prjorg", "header_patterns", @@ -478,6 +491,12 @@ void prjorg_project_remove_external_dir(const gchar *utf8_dirname) } +gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file) +{ + return g_key_file_get_string_list(key_file, "prjorg", "expanded_paths", NULL, NULL); +} + + void prjorg_project_open(GKeyFile * key_file) { gchar **source_patterns, **header_patterns, **ignored_dirs_patterns, **ignored_file_patterns, **external_dirs, **dir_ptr, *last_name; Modified: projectorganizer/src/prjorg-project.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -52,6 +52,7 @@ typedef struct extern PrjOrg *prj_org; void prjorg_project_open(GKeyFile * key_file); +gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file); GtkWidget *prjorg_project_add_properties_tab(GtkWidget *notebook); Modified: projectorganizer/src/prjorg-sidebar.c 56 lines changed, 44 insertions(+), 12 deletions(-) =================================================================== @@ -51,7 +51,8 @@ typedef enum typedef struct { GeanyProject *project; - GPtrArray *expanded_paths; + gchar **expanded_paths; + gchar *selected_path; } ExpandData; @@ -1487,24 +1488,30 @@ static gboolean expand_path(gchar *utf8_expanded_path, gboolean select) static gboolean expand_on_idle(ExpandData *expand_data) { GeanyDocument *doc = document_get_current(); + gboolean selected = FALSE; if (!prj_org) return FALSE; if (geany_data->app->project == expand_data->project && expand_data->expanded_paths) { - gchar *item; - guint i; + gchar **item; + foreach_strv(item, expand_data->expanded_paths) + expand_path(*item, FALSE); + g_strfreev(expand_data->expanded_paths); + } - foreach_ptr_array(item, i, expand_data->expanded_paths) - expand_path(item, FALSE); - g_ptr_array_free(expand_data->expanded_paths, TRUE); + if (expand_data->selected_path) + { + expand_path(expand_data->selected_path, TRUE); + g_free(expand_data->selected_path); + selected = TRUE; } g_free(expand_data); - if (!s_follow_editor || !doc || !doc->file_name) + if (selected || !s_follow_editor || !doc || !doc->file_name) return FALSE; expand_path(doc->file_name, TRUE); @@ -1547,26 +1554,45 @@ static void on_map_expanded(GtkTreeView *tree_view, GtkTreePath *tree_path, GPtr } -static GPtrArray *get_expanded_paths(void) +gchar **prjorg_sidebar_get_expanded_paths(void) { - GPtrArray *expanded_paths = g_ptr_array_new_with_free_func(g_free); + GPtrArray *expanded_paths = g_ptr_array_new(); gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(s_file_view), (GtkTreeViewMappingFunc)on_map_expanded, expanded_paths); + g_ptr_array_add(expanded_paths, NULL); - return expanded_paths; + return g_ptr_array_free(expanded_paths, FALSE); } -void prjorg_sidebar_update(gboolean reload) +static gchar *get_selected_path(void) +{ + GtkTreeSelection *treesel; + GtkTreeIter iter; + GtkTreeModel *model; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) + return build_path(&iter); + return NULL; +} + + +void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths) { ExpandData *expand_data = g_new0(ExpandData, 1); expand_data->project = geany_data->app->project; if (reload) { - expand_data->expanded_paths = get_expanded_paths(); + GtkTreeSelection *treesel; + GtkTreeIter iter; + GtkTreeModel *model; + + expand_data->expanded_paths = expanded_paths != NULL ? expanded_paths : prjorg_sidebar_get_expanded_paths(); + expand_data->selected_path = get_selected_path(); load_project(); /* we get color information only after the sidebar is realized - @@ -1580,6 +1606,12 @@ void prjorg_sidebar_update(gboolean reload) } +void prjorg_sidebar_update(gboolean reload) +{ + prjorg_sidebar_update_full(reload, NULL); +} + + void prjorg_sidebar_find_file_in_active(void) { find_file(NULL); Modified: projectorganizer/src/prjorg-sidebar.h 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -28,9 +28,12 @@ void prjorg_sidebar_find_file_in_active(void); void prjorg_sidebar_find_tag_in_active(void); void prjorg_sidebar_update(gboolean reload); +void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths); void prjorg_sidebar_focus_project_tab(void); +gchar **prjorg_sidebar_get_expanded_paths(void); + void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); -------------- 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] f822e6: projectorganizer: Use gchar** instead of GPtrArray to simplify code
by Jiřà Techet
07 May '23
07 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: Jiřà Techet <techet(a)gmail.com> Date: Sun, 07 May 2023 21:27:13 UTC Commit: f822e69395f88a9c7df7139e2ced19d8486011ca
https://github.com/geany/geany-plugins/commit/f822e69395f88a9c7df7139e2ced1…
Log Message: ----------- projectorganizer: Use gchar** instead of GPtrArray to simplify code Modified Paths: -------------- projectorganizer/src/prjorg-main.c projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-sidebar.h Modified: projectorganizer/src/prjorg-main.c 1 lines changed, 0 insertions(+), 1 deletions(-) =================================================================== @@ -136,7 +136,6 @@ static void on_project_open(G_GNUC_UNUSED GObject * obj, GKeyFile * config, prjorg_sidebar_update_full(TRUE, arr); prjorg_sidebar_activate(TRUE); prjorg_menu_activate_menu_items(TRUE); - g_strfreev(arr); } } Modified: projectorganizer/src/prjorg-project.c 12 lines changed, 3 insertions(+), 9 deletions(-) =================================================================== @@ -380,17 +380,11 @@ static void update_project( static void save_expanded_paths(GKeyFile * key_file) { - GPtrArray *expanded_paths = prjorg_sidebar_get_expanded_paths(); - gchar **expanded_paths_v = g_new (gchar *, expanded_paths->len + 1); - guint i; + gchar **expanded_paths = prjorg_sidebar_get_expanded_paths(); - for (i = 0; i < expanded_paths->len; i++) - expanded_paths_v[i] = expanded_paths->pdata[i]; - expanded_paths_v[expanded_paths->len] = NULL; g_key_file_set_string_list(key_file, "prjorg", "expanded_paths", - (const gchar**) expanded_paths_v, g_strv_length(expanded_paths_v)); - g_free(expanded_paths_v); - g_ptr_array_free(expanded_paths, TRUE); + (const gchar**) expanded_paths, g_strv_length(expanded_paths)); + g_strfreev(expanded_paths); } Modified: projectorganizer/src/prjorg-sidebar.c 28 lines changed, 10 insertions(+), 18 deletions(-) =================================================================== @@ -51,7 +51,7 @@ typedef enum typedef struct { GeanyProject *project; - GPtrArray *expanded_paths; + gchar **expanded_paths; gchar *selected_path; } ExpandData; @@ -1496,12 +1496,10 @@ static gboolean expand_on_idle(ExpandData *expand_data) if (geany_data->app->project == expand_data->project && expand_data->expanded_paths) { - gchar *item; - guint i; - - foreach_ptr_array(item, i, expand_data->expanded_paths) - expand_path(item, FALSE); - g_ptr_array_free(expand_data->expanded_paths, TRUE); + gchar **item; + foreach_strv(item, expand_data->expanded_paths) + expand_path(*item, FALSE); + g_strfreev(expand_data->expanded_paths); } if (expand_data->selected_path) @@ -1556,14 +1554,15 @@ static void on_map_expanded(GtkTreeView *tree_view, GtkTreePath *tree_path, GPtr } -GPtrArray *prjorg_sidebar_get_expanded_paths(void) +gchar **prjorg_sidebar_get_expanded_paths(void) { - GPtrArray *expanded_paths = g_ptr_array_new_with_free_func(g_free); + GPtrArray *expanded_paths = g_ptr_array_new(); gtk_tree_view_map_expanded_rows(GTK_TREE_VIEW(s_file_view), (GtkTreeViewMappingFunc)on_map_expanded, expanded_paths); + g_ptr_array_add(expanded_paths, NULL); - return expanded_paths; + return g_ptr_array_free(expanded_paths, FALSE); } @@ -1591,15 +1590,8 @@ void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths) GtkTreeSelection *treesel; GtkTreeIter iter; GtkTreeModel *model; - gchar **path; - GPtrArray *exp_paths_arr = g_ptr_array_new(); - - foreach_strv (path, expanded_paths) - { - g_ptr_array_add(exp_paths_arr, g_strdup(*path)); - } - expand_data->expanded_paths = expanded_paths != NULL ? exp_paths_arr : prjorg_sidebar_get_expanded_paths(); + expand_data->expanded_paths = expanded_paths != NULL ? expanded_paths : prjorg_sidebar_get_expanded_paths(); expand_data->selected_path = get_selected_path(); load_project(); Modified: projectorganizer/src/prjorg-sidebar.h 2 lines changed, 1 insertions(+), 1 deletions(-) =================================================================== @@ -32,7 +32,7 @@ void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths); void prjorg_sidebar_focus_project_tab(void); -GPtrArray *prjorg_sidebar_get_expanded_paths(void); +gchar **prjorg_sidebar_get_expanded_paths(void); void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); -------------- 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] 6130bb: projectorganizer: Store/load expanded paths in the sidebar to project file
by Jiřà Techet
07 May '23
07 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: Jiřà Techet <techet(a)gmail.com> Date: Sun, 07 May 2023 21:27:00 UTC Commit: 6130bbe379e645b1a142bbcb67577db25568e422
https://github.com/geany/geany-plugins/commit/6130bbe379e645b1a142bbcb67577…
Log Message: ----------- projectorganizer: Store/load expanded paths in the sidebar to project file This allows us to restore expansion points on project open. Modified Paths: -------------- projectorganizer/src/prjorg-main.c projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-sidebar.h Modified: projectorganizer/src/prjorg-main.c 5 lines changed, 4 insertions(+), 1 deletions(-) =================================================================== @@ -130,10 +130,13 @@ static void on_project_open(G_GNUC_UNUSED GObject * obj, GKeyFile * config, { if (!prj_org) { + gchar **arr = prjorg_project_load_expanded_paths(config); + prjorg_project_open(config); - prjorg_sidebar_update(TRUE); + prjorg_sidebar_update_full(TRUE, arr); prjorg_sidebar_activate(TRUE); prjorg_menu_activate_menu_items(TRUE); + g_strfreev(arr); } } Modified: projectorganizer/src/prjorg-project.c 25 lines changed, 25 insertions(+), 0 deletions(-) =================================================================== @@ -27,6 +27,7 @@ #include "prjorg-utils.h" #include "prjorg-project.h" +#include "prjorg-sidebar.h" extern GeanyPlugin *geany_plugin; extern GeanyData *geany_data; @@ -377,6 +378,22 @@ static void update_project( } +static void save_expanded_paths(GKeyFile * key_file) +{ + GPtrArray *expanded_paths = prjorg_sidebar_get_expanded_paths(); + gchar **expanded_paths_v = g_new (gchar *, expanded_paths->len + 1); + guint i; + + for (i = 0; i < expanded_paths->len; i++) + expanded_paths_v[i] = expanded_paths->pdata[i]; + expanded_paths_v[expanded_paths->len] = NULL; + g_key_file_set_string_list(key_file, "prjorg", "expanded_paths", + (const gchar**) expanded_paths_v, g_strv_length(expanded_paths_v)); + g_free(expanded_paths_v); + g_ptr_array_free(expanded_paths, TRUE); +} + + void prjorg_project_save(GKeyFile * key_file) { GPtrArray *array; @@ -385,6 +402,8 @@ void prjorg_project_save(GKeyFile * key_file) if (!prj_org) return; + save_expanded_paths(key_file); + g_key_file_set_string_list(key_file, "prjorg", "source_patterns", (const gchar**) prj_org->source_patterns, g_strv_length(prj_org->source_patterns)); g_key_file_set_string_list(key_file, "prjorg", "header_patterns", @@ -478,6 +497,12 @@ void prjorg_project_remove_external_dir(const gchar *utf8_dirname) } +gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file) +{ + return g_key_file_get_string_list(key_file, "prjorg", "expanded_paths", NULL, NULL); +} + + void prjorg_project_open(GKeyFile * key_file) { gchar **source_patterns, **header_patterns, **ignored_dirs_patterns, **ignored_file_patterns, **external_dirs, **dir_ptr, *last_name; Modified: projectorganizer/src/prjorg-project.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -52,6 +52,7 @@ typedef struct extern PrjOrg *prj_org; void prjorg_project_open(GKeyFile * key_file); +gchar **prjorg_project_load_expanded_paths(GKeyFile * key_file); GtkWidget *prjorg_project_add_properties_tab(GtkWidget *notebook); Modified: projectorganizer/src/prjorg-sidebar.c 19 lines changed, 16 insertions(+), 3 deletions(-) =================================================================== @@ -1556,7 +1556,7 @@ static void on_map_expanded(GtkTreeView *tree_view, GtkTreePath *tree_path, GPtr } -static GPtrArray *get_expanded_paths(void) +GPtrArray *prjorg_sidebar_get_expanded_paths(void) { GPtrArray *expanded_paths = g_ptr_array_new_with_free_func(g_free); @@ -1580,7 +1580,7 @@ static gchar *get_selected_path(void) } -void prjorg_sidebar_update(gboolean reload) +void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths) { ExpandData *expand_data = g_new0(ExpandData, 1); @@ -1591,8 +1591,15 @@ void prjorg_sidebar_update(gboolean reload) GtkTreeSelection *treesel; GtkTreeIter iter; GtkTreeModel *model; + gchar **path; + GPtrArray *exp_paths_arr = g_ptr_array_new(); - expand_data->expanded_paths = get_expanded_paths(); + foreach_strv (path, expanded_paths) + { + g_ptr_array_add(exp_paths_arr, g_strdup(*path)); + } + + expand_data->expanded_paths = expanded_paths != NULL ? exp_paths_arr : prjorg_sidebar_get_expanded_paths(); expand_data->selected_path = get_selected_path(); load_project(); @@ -1607,6 +1614,12 @@ void prjorg_sidebar_update(gboolean reload) } +void prjorg_sidebar_update(gboolean reload) +{ + prjorg_sidebar_update_full(reload, NULL); +} + + void prjorg_sidebar_find_file_in_active(void) { find_file(NULL); Modified: projectorganizer/src/prjorg-sidebar.h 3 lines changed, 3 insertions(+), 0 deletions(-) =================================================================== @@ -28,9 +28,12 @@ void prjorg_sidebar_find_file_in_active(void); void prjorg_sidebar_find_tag_in_active(void); void prjorg_sidebar_update(gboolean reload); +void prjorg_sidebar_update_full(gboolean reload, gchar **expanded_paths); void prjorg_sidebar_focus_project_tab(void); +GPtrArray *prjorg_sidebar_get_expanded_paths(void); + void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); -------------- 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] a17d51: projectorganizer: Remember selected row in sidebar when reloading
by Jiřà Techet
07 May '23
07 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: Jiřà Techet <techet(a)gmail.com> Date: Sun, 07 May 2023 21:22:31 UTC Commit: a17d5128f777a679b97234d706886cda59ef977e
https://github.com/geany/geany-plugins/commit/a17d5128f777a679b97234d706886…
Log Message: ----------- projectorganizer: Remember selected row in sidebar when reloading In addition to remembering which paths are expanded, this patch also remembers which item in the tree is selected so when the project gets reloaded, the selection gets restored. Modified Paths: -------------- projectorganizer/src/prjorg-sidebar.c Modified: projectorganizer/src/prjorg-sidebar.c 29 lines changed, 28 insertions(+), 1 deletions(-) =================================================================== @@ -52,6 +52,7 @@ typedef struct { GeanyProject *project; GPtrArray *expanded_paths; + gchar *selected_path; } ExpandData; @@ -1487,6 +1488,7 @@ static gboolean expand_path(gchar *utf8_expanded_path, gboolean select) static gboolean expand_on_idle(ExpandData *expand_data) { GeanyDocument *doc = document_get_current(); + gboolean selected = FALSE; if (!prj_org) return FALSE; @@ -1502,9 +1504,16 @@ static gboolean expand_on_idle(ExpandData *expand_data) g_ptr_array_free(expand_data->expanded_paths, TRUE); } + if (expand_data->selected_path) + { + expand_path(expand_data->selected_path, TRUE); + g_free(expand_data->selected_path); + selected = TRUE; + } + g_free(expand_data); - if (!s_follow_editor || !doc || !doc->file_name) + if (selected || !s_follow_editor || !doc || !doc->file_name) return FALSE; expand_path(doc->file_name, TRUE); @@ -1558,6 +1567,19 @@ static GPtrArray *get_expanded_paths(void) } +static gchar *get_selected_path(void) +{ + GtkTreeSelection *treesel; + GtkTreeIter iter; + GtkTreeModel *model; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) + return build_path(&iter); + return NULL; +} + + void prjorg_sidebar_update(gboolean reload) { ExpandData *expand_data = g_new0(ExpandData, 1); @@ -1566,7 +1588,12 @@ void prjorg_sidebar_update(gboolean reload) if (reload) { + GtkTreeSelection *treesel; + GtkTreeIter iter; + GtkTreeModel *model; + expand_data->expanded_paths = get_expanded_paths(); + expand_data->selected_path = get_selected_path(); load_project(); /* we get color information only after the sidebar is realized - -------------- 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] 7e8682: Project Organizer: Add ability to open file manager and terminal
by xiota
07 May '23
07 May '23
Branch: refs/heads/master Author: xiota <github(a)mentalfossa.com> Committer: xiota <github(a)mentalfossa.com> Date: Tue, 07 Mar 2023 05:03:25 UTC Commit: 7e86828684c07622f2c2387db1785c73a2b04c50
https://github.com/geany/geany-plugins/commit/7e86828684c07622f2c2387db1785…
Log Message: ----------- Project Organizer: Add ability to open file manager and terminal File manager/terminal are opened at the location of the selected file in the tree view. If nothing is selected, the location of the current document is used. If the current document does not have a path, the project directory is used. If the project directory cannot be located, the current directory is used. The file manager is opened with the path as the first argument. The terminal path is set using the PWD. Modified Paths: -------------- projectorganizer/src/prjorg-menu.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-sidebar.h Modified: projectorganizer/src/prjorg-menu.c 8 lines changed, 8 insertions(+), 0 deletions(-) =================================================================== @@ -43,6 +43,8 @@ enum KB_FIND_FILE, KB_FIND_TAG, KB_FOCUS_SIDEBAR, + KB_OPEN_FILE_MANAGER, + KB_OPEN_TERMINAL, KB_COUNT }; @@ -408,6 +410,12 @@ void prjorg_menu_init(void) keybindings_set_item(key_group, KB_FOCUS_SIDEBAR, (GeanyKeyCallback)prjorg_sidebar_focus_project_tab, 0, 0, "focus_project_sidebar", _("Focus Project Sidebar"), NULL); + keybindings_set_item(key_group, KB_OPEN_FILE_MANAGER, (GeanyKeyCallback)on_open_file_manager, + 0, 0, "open_file_manager", _("Open File Manager at file location"), NULL); + + keybindings_set_item(key_group, KB_OPEN_TERMINAL, (GeanyKeyCallback)on_open_terminal, + 0, 0, "open_terminal", _("Open Terminal at file location"), NULL); + s_context_sep_item = gtk_separator_menu_item_new(); gtk_widget_show(s_context_sep_item); gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_sep_item); Modified: projectorganizer/src/prjorg-project.h 16 lines changed, 16 insertions(+), 0 deletions(-) =================================================================== @@ -64,6 +64,22 @@ void prjorg_project_remove_single_tm_file(gchar *utf8_filename); gboolean prjorg_project_is_in_project(const gchar *utf8_filename); + +/* set open command based on OS */ +#if defined(_WIN32) || defined(G_OS_WIN32) +#define PRJORG_COMMAND_OPEN "start" +#define PRJORG_COMMAND_TERMINAL "PowerShell" +#define PRJORG_COMMAND_TERMINAL_ALT "" +#elif defined(__APPLE__) +#define PRJORG_COMMAND_OPEN "open" +#define PRJORG_COMMAND_TERMINAL "open -b com.apple.terminal" +#define PRJORG_COMMAND_TERMINAL_ALT "" +#else +#define PRJORG_COMMAND_OPEN "xdg-open" +#define PRJORG_COMMAND_TERMINAL "xterm" +#define PRJORG_COMMAND_TERMINAL_ALT "/usr/bin/x-terminal-emulator" +#endif + /* In the code we create a list of all files but we want to keep empty directories * in the list for which we create a fake file name with the PROJORG_DIR_ENTRY * value. */ Modified: projectorganizer/src/prjorg-sidebar.c 172 lines changed, 143 insertions(+), 29 deletions(-) =================================================================== @@ -300,6 +300,129 @@ static void on_follow_active(GtkToggleToolButton *button, G_GNUC_UNUSED gpointer } +// returns path to selection if dir +// otherwise returns parent +// returned string must be freed +static gchar* get_dir_of_selection() +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter, parent; + gchar *path = NULL; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) + { + path = build_path(&iter); + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + { + g_free(path); + path = NULL; + if (gtk_tree_model_iter_parent(model, &parent, &iter)) + path = build_path(&parent); + } + } + return path; +} + + +/* if get_dir_of_selection() fails, + * returns parent of current document, project folder, or home folder */ +static gchar *get_fallback_dir_of_selection(void) +{ + gchar *locale_path; + + /* get path from treeview selection */ + locale_path = get_dir_of_selection(); + + /* get path from current document */ + if (!locale_path) + { + GeanyDocument *doc; + + doc = document_get_current(); + if (DOC_VALID(doc) && doc->real_path) + { + locale_path = g_path_get_dirname(doc->real_path); + + if (locale_path && locale_path == '.') + { + g_free(locale_path); + locale_path = NULL; + } + } + } + + /* get path from project */ + if (!locale_path && geany_data->app->project) + { + gchar *utf8_path = NULL; + utf8_path = get_project_base_path(); + locale_path = utils_get_locale_from_utf8(utf8_path); + g_free(utf8_path); + } + + /* get current directory */ + if (!locale_path || !g_file_test(locale_path, G_FILE_TEST_IS_DIR)) + locale_path = g_strdup(g_get_current_dir()); + + /* get user home directory */ + if (!locale_path || !g_file_test(locale_path, G_FILE_TEST_IS_DIR)) + locale_path = g_strdup(g_get_home_dir()); + + return locale_path; +} + + +void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *locale_path; + locale_path = get_fallback_dir_of_selection(); + + if (locale_path) + { + gchar *command, *open_command; + + open_command = PRJORG_COMMAND_OPEN; + command = g_strconcat (open_command, " \"", locale_path, "\"", NULL); + if (!spawn_async(locale_path, command, NULL, NULL, NULL, NULL)) + msgwin_status_add(_("Unable to open folder. Command unavailable: %s"), open_command); + + g_free(command); + g_free(locale_path); + } + else + { + msgwin_status_add(_("Unable to find folder.")); + } +} + + +void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *locale_path, *open_command; + + if (g_file_test(PRJORG_COMMAND_TERMINAL_ALT, G_FILE_TEST_EXISTS)) + { + gchar *alt_command; + alt_command = utils_get_real_path(PRJORG_COMMAND_TERMINAL_ALT); + open_command = g_path_get_basename(alt_command); + g_free(alt_command); + } + else + { + open_command = g_strdup(PRJORG_COMMAND_TERMINAL); + } + + locale_path = get_fallback_dir_of_selection(); + if (!spawn_async(locale_path, open_command, NULL, NULL, NULL, NULL)) + msgwin_status_add(_("Unable to open terminal: %s"), open_command); + + g_free(locale_path); + g_free(open_command); +} + + static void on_add_external(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { gchar *utf8_base_path = get_project_base_path(); @@ -355,35 +478,11 @@ static void on_remove_external_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_U } -// returned string must be freed -static gchar* parent_dir_for_create() -{ - GtkTreeSelection *treesel; - GtkTreeModel *model; - GtkTreeIter iter, parent; - gchar *path = NULL; - - treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); - if (gtk_tree_selection_get_selected(treesel, &model, &iter)) - { - path = build_path(&iter); - if (!g_file_test(path, G_FILE_TEST_IS_DIR)) - { - g_free(path); - path = NULL; - if (gtk_tree_model_iter_parent(model, &parent, &iter)) - path = build_path(&parent); - } - } - return path; -} - - static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) { gchar *dir, *name; - dir = parent_dir_for_create(); + dir = get_dir_of_selection(); if (dir == NULL) return; @@ -414,7 +513,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo { gchar *dir, *name; - dir = parent_dir_for_create(); + dir = get_dir_of_selection(); if (dir == NULL) return; @@ -1543,9 +1642,6 @@ void prjorg_sidebar_init(void) g_signal_connect(item, "clicked", G_CALLBACK(on_reload_project), NULL); gtk_container_add(GTK_CONTAINER(s_toolbar), item); - item = GTK_WIDGET(gtk_separator_tool_item_new()); - gtk_container_add(GTK_CONTAINER(s_toolbar), item); - image = gtk_image_new_from_icon_name("folder-new", GTK_ICON_SIZE_SMALL_TOOLBAR); item = GTK_WIDGET(gtk_tool_button_new(image, NULL)); gtk_widget_set_tooltip_text(item, _("Add external directory")); @@ -1634,6 +1730,10 @@ void prjorg_sidebar_init(void) g_signal_connect((gpointer) item, "activate", G_CALLBACK(expand_all), NULL); s_popup_menu.expand = item; + item = gtk_separator_menu_item_new(); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + item = menu_item_new("edit-find", _("Find in Files...")); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_find_in_files), NULL); @@ -1653,6 +1753,20 @@ void prjorg_sidebar_init(void) gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + item = menu_item_new("folder-open", _("Open File Manager")); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_open_file_manager), NULL); + s_popup_menu.find_in_directory = item; + + item = menu_item_new("terminal", _("Open Terminal")); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_open_terminal), NULL); + s_popup_menu.find_in_directory = item; + + item = gtk_separator_menu_item_new(); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + item = menu_item_new("list-remove", _("Remove External Directory")); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_remove_external_dir), NULL); Modified: projectorganizer/src/prjorg-sidebar.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -31,5 +31,7 @@ void prjorg_sidebar_update(gboolean reload); void prjorg_sidebar_focus_project_tab(void); +void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); +void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); #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] 24bbc8: Merge pull request #1126 from xiota/pr-prjorg-open-folder
by Jiřà Techet
07 May '23
07 May '23
Branch: refs/heads/master Author: Jiřà Techet <techet(a)gmail.com> Committer: GitHub <noreply(a)github.com> Date: Sun, 07 May 2023 20:47:58 UTC Commit: 24bbc88821fd58654202b8154bebb77a56643c20
https://github.com/geany/geany-plugins/commit/24bbc88821fd58654202b8154bebb…
Log Message: ----------- Merge pull request #1126 from xiota/pr-prjorg-open-folder Project Organizer: Add option to open current folder in file manager and terminal Modified Paths: -------------- projectorganizer/src/prjorg-menu.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-sidebar.c projectorganizer/src/prjorg-sidebar.h Modified: projectorganizer/src/prjorg-menu.c 8 lines changed, 8 insertions(+), 0 deletions(-) =================================================================== @@ -43,6 +43,8 @@ enum KB_FIND_FILE, KB_FIND_TAG, KB_FOCUS_SIDEBAR, + KB_OPEN_FILE_MANAGER, + KB_OPEN_TERMINAL, KB_COUNT }; @@ -283,6 +285,12 @@ void prjorg_menu_init(void) keybindings_set_item(key_group, KB_FOCUS_SIDEBAR, (GeanyKeyCallback)prjorg_sidebar_focus_project_tab, 0, 0, "focus_project_sidebar", _("Focus Project Sidebar"), NULL); + keybindings_set_item(key_group, KB_OPEN_FILE_MANAGER, (GeanyKeyCallback)on_open_file_manager, + 0, 0, "open_file_manager", _("Open File Manager at file location"), NULL); + + keybindings_set_item(key_group, KB_OPEN_TERMINAL, (GeanyKeyCallback)on_open_terminal, + 0, 0, "open_terminal", _("Open Terminal at file location"), NULL); + s_context_sep_item = gtk_separator_menu_item_new(); gtk_widget_show(s_context_sep_item); gtk_menu_shell_prepend(GTK_MENU_SHELL(geany->main_widgets->editor_menu), s_context_sep_item); Modified: projectorganizer/src/prjorg-project.h 16 lines changed, 16 insertions(+), 0 deletions(-) =================================================================== @@ -69,6 +69,22 @@ void prjorg_project_remove_single_tm_file(gchar *utf8_filename); gboolean prjorg_project_is_in_project(const gchar *utf8_filename); + +/* set open command based on OS */ +#if defined(_WIN32) || defined(G_OS_WIN32) +#define PRJORG_COMMAND_OPEN "start" +#define PRJORG_COMMAND_TERMINAL "PowerShell" +#define PRJORG_COMMAND_TERMINAL_ALT "" +#elif defined(__APPLE__) +#define PRJORG_COMMAND_OPEN "open" +#define PRJORG_COMMAND_TERMINAL "open -b com.apple.terminal" +#define PRJORG_COMMAND_TERMINAL_ALT "" +#else +#define PRJORG_COMMAND_OPEN "xdg-open" +#define PRJORG_COMMAND_TERMINAL "xterm" +#define PRJORG_COMMAND_TERMINAL_ALT "/usr/bin/x-terminal-emulator" +#endif + /* In the code we create a list of all files but we want to keep empty directories * in the list for which we create a fake file name with the PROJORG_DIR_ENTRY * value. */ Modified: projectorganizer/src/prjorg-sidebar.c 172 lines changed, 143 insertions(+), 29 deletions(-) =================================================================== @@ -300,6 +300,129 @@ static void on_follow_active(GtkToggleToolButton *button, G_GNUC_UNUSED gpointer } +// returns path to selection if dir +// otherwise returns parent +// returned string must be freed +static gchar* get_dir_of_selection() +{ + GtkTreeSelection *treesel; + GtkTreeModel *model; + GtkTreeIter iter, parent; + gchar *path = NULL; + + treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); + if (gtk_tree_selection_get_selected(treesel, &model, &iter)) + { + path = build_path(&iter); + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + { + g_free(path); + path = NULL; + if (gtk_tree_model_iter_parent(model, &parent, &iter)) + path = build_path(&parent); + } + } + return path; +} + + +/* if get_dir_of_selection() fails, + * returns parent of current document, project folder, or home folder */ +static gchar *get_fallback_dir_of_selection(void) +{ + gchar *locale_path; + + /* get path from treeview selection */ + locale_path = get_dir_of_selection(); + + /* get path from current document */ + if (!locale_path) + { + GeanyDocument *doc; + + doc = document_get_current(); + if (DOC_VALID(doc) && doc->real_path) + { + locale_path = g_path_get_dirname(doc->real_path); + + if (locale_path && locale_path == '.') + { + g_free(locale_path); + locale_path = NULL; + } + } + } + + /* get path from project */ + if (!locale_path && geany_data->app->project) + { + gchar *utf8_path = NULL; + utf8_path = get_project_base_path(); + locale_path = utils_get_locale_from_utf8(utf8_path); + g_free(utf8_path); + } + + /* get current directory */ + if (!locale_path || !g_file_test(locale_path, G_FILE_TEST_IS_DIR)) + locale_path = g_strdup(g_get_current_dir()); + + /* get user home directory */ + if (!locale_path || !g_file_test(locale_path, G_FILE_TEST_IS_DIR)) + locale_path = g_strdup(g_get_home_dir()); + + return locale_path; +} + + +void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *locale_path; + locale_path = get_fallback_dir_of_selection(); + + if (locale_path) + { + gchar *command, *open_command; + + open_command = PRJORG_COMMAND_OPEN; + command = g_strconcat (open_command, " \"", locale_path, "\"", NULL); + if (!spawn_async(locale_path, command, NULL, NULL, NULL, NULL)) + msgwin_status_add(_("Unable to open folder. Command unavailable: %s"), open_command); + + g_free(command); + g_free(locale_path); + } + else + { + msgwin_status_add(_("Unable to find folder.")); + } +} + + +void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) +{ + gchar *locale_path, *open_command; + + if (g_file_test(PRJORG_COMMAND_TERMINAL_ALT, G_FILE_TEST_EXISTS)) + { + gchar *alt_command; + alt_command = utils_get_real_path(PRJORG_COMMAND_TERMINAL_ALT); + open_command = g_path_get_basename(alt_command); + g_free(alt_command); + } + else + { + open_command = g_strdup(PRJORG_COMMAND_TERMINAL); + } + + locale_path = get_fallback_dir_of_selection(); + if (!spawn_async(locale_path, open_command, NULL, NULL, NULL, NULL)) + msgwin_status_add(_("Unable to open terminal: %s"), open_command); + + g_free(locale_path); + g_free(open_command); +} + + static void on_add_external(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { gchar *utf8_base_path = get_project_base_path(); @@ -355,35 +478,11 @@ static void on_remove_external_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_U } -// returned string must be freed -static gchar* parent_dir_for_create() -{ - GtkTreeSelection *treesel; - GtkTreeModel *model; - GtkTreeIter iter, parent; - gchar *path = NULL; - - treesel = gtk_tree_view_get_selection(GTK_TREE_VIEW(s_file_view)); - if (gtk_tree_selection_get_selected(treesel, &model, &iter)) - { - path = build_path(&iter); - if (!g_file_test(path, G_FILE_TEST_IS_DIR)) - { - g_free(path); - path = NULL; - if (gtk_tree_model_iter_parent(model, &parent, &iter)) - path = build_path(&parent); - } - } - return path; -} - - static void on_create_file(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpointer user_data) { gchar *dir, *name; - dir = parent_dir_for_create(); + dir = get_dir_of_selection(); if (dir == NULL) return; @@ -414,7 +513,7 @@ static void on_create_dir(G_GNUC_UNUSED GtkMenuItem *menuitem, G_GNUC_UNUSED gpo { gchar *dir, *name; - dir = parent_dir_for_create(); + dir = get_dir_of_selection(); if (dir == NULL) return; @@ -1543,9 +1642,6 @@ void prjorg_sidebar_init(void) g_signal_connect(item, "clicked", G_CALLBACK(on_reload_project), NULL); gtk_container_add(GTK_CONTAINER(s_toolbar), item); - item = GTK_WIDGET(gtk_separator_tool_item_new()); - gtk_container_add(GTK_CONTAINER(s_toolbar), item); - image = gtk_image_new_from_icon_name("folder-new", GTK_ICON_SIZE_SMALL_TOOLBAR); item = GTK_WIDGET(gtk_tool_button_new(image, NULL)); gtk_widget_set_tooltip_text(item, _("Add external directory")); @@ -1634,6 +1730,10 @@ void prjorg_sidebar_init(void) g_signal_connect((gpointer) item, "activate", G_CALLBACK(expand_all), NULL); s_popup_menu.expand = item; + item = gtk_separator_menu_item_new(); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + item = menu_item_new("edit-find", _("Find in Files...")); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_find_in_files), NULL); @@ -1653,6 +1753,20 @@ void prjorg_sidebar_init(void) gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + item = menu_item_new("folder-open", _("Open File Manager")); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_open_file_manager), NULL); + s_popup_menu.find_in_directory = item; + + item = menu_item_new("terminal", _("Open Terminal")); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_open_terminal), NULL); + s_popup_menu.find_in_directory = item; + + item = gtk_separator_menu_item_new(); + gtk_widget_show(item); + gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); + item = menu_item_new("list-remove", _("Remove External Directory")); gtk_container_add(GTK_CONTAINER(s_popup_menu.widget), item); g_signal_connect((gpointer) item, "activate", G_CALLBACK(on_remove_external_dir), NULL); Modified: projectorganizer/src/prjorg-sidebar.h 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -31,5 +31,7 @@ void prjorg_sidebar_update(gboolean reload); void prjorg_sidebar_focus_project_tab(void); +void on_open_file_manager(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); +void on_open_terminal(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data); #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] 18f9e1: Project Organizer: Set header filetype to match source filetype
by xiota
07 May '23
07 May '23
Branch: refs/heads/master Author: xiota <github(a)mentalfossa.com> Committer: xiota <github(a)mentalfossa.com> Date: Wed, 10 Nov 2021 18:09:47 UTC Commit: 18f9e1d1be413227c4989da1b5fc5d2e5db3ee79
https://github.com/geany/geany-plugins/commit/18f9e1d1be413227c4989da1b5fc5…
Log Message: ----------- Project Organizer: Set header filetype to match source filetype When opened, the filetype of header files is changed to match the source filetype. This is particularly useful for *.h files, which may be C or C++. Out of project files are matched with files in the same directory. Common code between swap header/source and change header filetypes are combined. When a project is not loaded, default file extensions are used. Modified Paths: -------------- projectorganizer/src/prjorg-main.c projectorganizer/src/prjorg-menu.c projectorganizer/src/prjorg-project.c projectorganizer/src/prjorg-project.h projectorganizer/src/prjorg-utils.c projectorganizer/src/prjorg-utils.h Modified: projectorganizer/src/prjorg-main.c 2 lines changed, 2 insertions(+), 0 deletions(-) =================================================================== @@ -28,6 +28,7 @@ #include "prjorg-project.h" #include "prjorg-sidebar.h" #include "prjorg-menu.h" +#include "prjorg-utils.h" GeanyPlugin *geany_plugin; @@ -54,6 +55,7 @@ static void on_doc_open(G_GNUC_UNUSED GObject * obj, G_GNUC_UNUSED GeanyDocument prjorg_project_remove_single_tm_file(doc->file_name); prjorg_sidebar_update(FALSE); + set_header_filetype(doc); } Modified: projectorganizer/src/prjorg-menu.c 134 lines changed, 4 insertions(+), 130 deletions(-) =================================================================== @@ -50,137 +50,12 @@ enum static GtkWidget *s_fif_item, *s_ff_item, *s_ft_item, *s_shs_item, *s_sep_item, *s_context_osf_item, *s_context_sep_item; -static gboolean try_swap_header_source(gchar *utf8_file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns) -{ - gchar *name_pattern; - GSList *elem = NULL; - GPatternSpec *pattern; - gboolean found = FALSE; - - name_pattern = g_path_get_basename(utf8_file_name); - SETPTR(name_pattern, utils_remove_ext_from_filename(name_pattern)); - SETPTR(name_pattern, g_strconcat(name_pattern, ".*", NULL)); - pattern = g_pattern_spec_new(name_pattern); - g_free(name_pattern); - - foreach_slist (elem, file_list) - { - gchar *full_name = elem->data; - gchar *base_name = g_path_get_basename(full_name); - - if (g_pattern_match_string(pattern, base_name) && - prjorg_project_is_in_project(full_name)) - { - if ((is_header && patterns_match(source_patterns, base_name)) || - (!is_header && patterns_match(header_patterns, base_name))) - { - open_file(full_name); - found = TRUE; - g_free(base_name); - break; - } - } - g_free(base_name); - } - - g_pattern_spec_free(pattern); - return found; -} - - static void on_swap_header_source(G_GNUC_UNUSED GtkMenuItem * menuitem, G_GNUC_UNUSED gpointer user_data) { - GSList *header_patterns, *source_patterns; - GeanyDocument *doc; - gboolean known_type = TRUE; - gboolean is_header; - gchar *doc_basename; - doc = document_get_current(); - - if (!prj_org || !geany_data->app->project || !doc || !doc->file_name) - return; - - header_patterns = get_precompiled_patterns(prj_org->header_patterns); - source_patterns = get_precompiled_patterns(prj_org->source_patterns); - - doc_basename = g_path_get_basename(doc->file_name); - - if (patterns_match(header_patterns, doc_basename)) - is_header = TRUE; - else if (patterns_match(source_patterns, doc_basename)) - is_header = FALSE; - else - known_type = FALSE; - - if (known_type) - { - gboolean swapped; - GSList *elem = NULL, *list = NULL; - guint i = 0; - - foreach_document(i) - { - gchar *filename; - - filename = document_index(i)->file_name; - if (prjorg_project_is_in_project(filename)) - list = g_slist_prepend(list, filename); - } - swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); - g_slist_free(list); - list = NULL; - - if (!swapped) - { - gchar *utf8_doc_dir; - gchar *locale_doc_dir; - - utf8_doc_dir = g_path_get_dirname(doc->file_name); - locale_doc_dir = utils_get_locale_from_utf8(utf8_doc_dir); - - list = utils_get_file_list(locale_doc_dir, NULL, NULL); - foreach_list (elem, list) - { - gchar *full_name; - - full_name = g_build_filename(locale_doc_dir, elem->data, NULL); - SETPTR(full_name, utils_get_utf8_from_locale(full_name)); - SETPTR(elem->data, full_name); - } - swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); - g_slist_foreach(list, (GFunc) g_free, NULL); - g_slist_free(list); - g_free(utf8_doc_dir); - g_free(locale_doc_dir); - list = NULL; - } - - if (!swapped) - { - foreach_slist(elem, prj_org->roots) - { - GHashTableIter iter; - gpointer key, value; - PrjOrgRoot *root = elem->data; - - list = NULL; - g_hash_table_iter_init(&iter, root->file_table); - while (g_hash_table_iter_next(&iter, &key, &value)) - list = g_slist_prepend(list, key); - swapped = try_swap_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); - g_slist_free(list); - if (swapped) - break; - } - } - } - - g_free(doc_basename); - - g_slist_foreach(header_patterns, (GFunc) g_pattern_spec_free, NULL); - g_slist_free(header_patterns); - g_slist_foreach(source_patterns, (GFunc) g_pattern_spec_free, NULL); - g_slist_free(source_patterns); + GeanyDocument *doc = document_get_current(); + gchar *full_name = find_header_source(doc); + open_file(full_name); + g_free(full_name); } @@ -424,7 +299,6 @@ void prjorg_menu_init(void) void prjorg_menu_activate_menu_items(gboolean activate) { gtk_widget_set_sensitive(s_context_osf_item, activate); - gtk_widget_set_sensitive(s_shs_item, activate); gtk_widget_set_sensitive(s_ff_item, activate); gtk_widget_set_sensitive(s_ft_item, activate); gtk_widget_set_sensitive(s_fif_item, activate); Modified: projectorganizer/src/prjorg-project.c 8 lines changed, 4 insertions(+), 4 deletions(-) =================================================================== @@ -500,16 +500,16 @@ void prjorg_project_open(GKeyFile * key_file) source_patterns = g_key_file_get_string_list(key_file, "prjorg", "source_patterns", NULL, NULL); if (!source_patterns) - source_patterns = g_strsplit("*.c *.C *.cpp *.cxx *.c++ *.cc *.m", " ", -1); + source_patterns = g_strsplit(PRJORG_PATTERNS_SOURCE, " ", -1); header_patterns = g_key_file_get_string_list(key_file, "prjorg", "header_patterns", NULL, NULL); if (!header_patterns) - header_patterns = g_strsplit("*.h *.H *.hpp *.hxx *.h++ *.hh", " ", -1); + header_patterns = g_strsplit(PRJORG_PATTERNS_HEADER, " ", -1); ignored_dirs_patterns = g_key_file_get_string_list(key_file, "prjorg", "ignored_dirs_patterns", NULL, NULL); if (!ignored_dirs_patterns) - ignored_dirs_patterns = g_strsplit(".* CVS", " ", -1); + ignored_dirs_patterns = g_strsplit(PRJORG_PATTERNS_IGNORED_DIRS, " ", -1); ignored_file_patterns = g_key_file_get_string_list(key_file, "prjorg", "ignored_file_patterns", NULL, NULL); if (!ignored_file_patterns) - ignored_file_patterns = g_strsplit("*.o *.obj *.a *.lib *.so *.dll *.lo *.la *.class *.jar *.pyc *.mo *.gmo", " ", -1); + ignored_file_patterns = g_strsplit(PRJORG_PATTERNS_IGNORED_FILE, " ", -1); generate_tag_prefs = utils_get_setting_integer(key_file, "prjorg", "generate_tag_prefs", PrjOrgTagAuto); show_empty_dirs = utils_get_setting_boolean(key_file, "prjorg", "show_empty_dirs", TRUE); Modified: projectorganizer/src/prjorg-project.h 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -19,6 +19,11 @@ #ifndef __PRJORG_PROJECT_H__ #define __PRJORG_PROJECT_H__ +#define PRJORG_PATTERNS_SOURCE "*.c *.C *.cpp *.cxx *.c++ *.cc *.m" +#define PRJORG_PATTERNS_HEADER "*.h *.H *.hpp *.hxx *.h++ *.hh" +#define PRJORG_PATTERNS_IGNORED_DIRS ".* CVS" +#define PRJORG_PATTERNS_IGNORED_FILE "*.o *.obj *.a *.lib *.so *.dll *.lo *.la *.class *.jar *.pyc *.mo *.gmo" + typedef struct { gchar *base_dir; Modified: projectorganizer/src/prjorg-utils.c 194 lines changed, 194 insertions(+), 0 deletions(-) =================================================================== @@ -26,6 +26,7 @@ #include <geanyplugin.h> +#include "prjorg-project.h" #include "prjorg-utils.h" extern GeanyData *geany_data; @@ -241,3 +242,196 @@ GtkWidget *menu_item_new(const gchar *icon_name, const gchar *label) gtk_widget_show(item); return item; } + +gchar *try_find_header_source(gchar *utf8_file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns) +{ + gchar *full_name; + gchar *name_pattern; + GSList *elem = NULL; + GPatternSpec *pattern; + gboolean found = FALSE; + + name_pattern = g_path_get_basename(utf8_file_name); + SETPTR(name_pattern, utils_remove_ext_from_filename(name_pattern)); + SETPTR(name_pattern, g_strconcat(name_pattern, ".*", NULL)); + pattern = g_pattern_spec_new(name_pattern); + g_free(name_pattern); + + foreach_slist (elem, file_list) + { + full_name = elem->data; + gchar *base_name = g_path_get_basename(full_name); + + if (g_pattern_match_string(pattern, base_name)) + { + if ((is_header && patterns_match(source_patterns, base_name)) || + (!is_header && patterns_match(header_patterns, base_name))) + { + g_free(base_name); + found = TRUE; + break; + } + } + g_free(base_name); + } + + g_pattern_spec_free(pattern); + + if(found) + return g_strdup(full_name); + + return NULL; +} + +gchar *find_header_source(GeanyDocument *doc) +{ + GSList *header_patterns, *source_patterns; + gboolean known_type = TRUE; + gboolean is_header; + gchar *found_name = NULL; + + if (!doc || !doc->file_name) + return NULL; + + if (prj_org) + { + header_patterns = get_precompiled_patterns(prj_org->header_patterns); + source_patterns = get_precompiled_patterns(prj_org->source_patterns); + } + else + { + // use default header/source patterns if project isn't open + gchar **headers, **source; + headers = g_strsplit(PRJORG_PATTERNS_HEADER, " ", -1); + source = g_strsplit(PRJORG_PATTERNS_SOURCE, " ", -1); + + header_patterns = get_precompiled_patterns(headers); + source_patterns = get_precompiled_patterns(source); + + g_strfreev(headers); + g_strfreev(source); + } + + // check if file matches patterns + { + gchar *doc_basename; + doc_basename = g_path_get_basename(doc->file_name); + + if (patterns_match(header_patterns, doc_basename)) + is_header = TRUE; + else if (patterns_match(source_patterns, doc_basename)) + is_header = FALSE; + else + known_type = FALSE; + + g_free(doc_basename); + } + + if (known_type) + { + GSList *elem = NULL, *list = NULL; + guint i = 0; + + /* check open documents */ + foreach_document(i) + { + gchar *filename; + filename = document_index(i)->file_name; + list = g_slist_prepend(list, filename); + } + found_name = try_find_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); + g_slist_free(list); + list = NULL; + + /* check document directory */ + if (!found_name) + { + gchar *utf8_doc_dir; + gchar *locale_doc_dir; + + utf8_doc_dir = g_path_get_dirname(doc->file_name); + locale_doc_dir = utils_get_locale_from_utf8(utf8_doc_dir); + + list = utils_get_file_list(locale_doc_dir, NULL, NULL); + foreach_list (elem, list) + { + gchar *full_name; + full_name = g_build_filename(locale_doc_dir, elem->data, NULL); + SETPTR(full_name, utils_get_utf8_from_locale(full_name)); + SETPTR(elem->data, full_name); + } + found_name = try_find_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); + g_slist_foreach(list, (GFunc) g_free, NULL); + g_slist_free(list); + g_free(utf8_doc_dir); + g_free(locale_doc_dir); + list = NULL; + } + + /* check project files */ + if (!found_name && prj_org) + { + foreach_slist(elem, prj_org->roots) + { + GHashTableIter iter; + gpointer key, value; + PrjOrgRoot *root = elem->data; + + list = NULL; + g_hash_table_iter_init(&iter, root->file_table); + while (g_hash_table_iter_next(&iter, &key, &value)) + list = g_slist_prepend(list, key); + found_name = try_find_header_source(doc->file_name, is_header, list, header_patterns, source_patterns); + g_slist_free(list); + if (found_name) + break; + } + } + } + + g_slist_foreach(header_patterns, (GFunc) g_pattern_spec_free, NULL); + g_slist_free(header_patterns); + g_slist_foreach(source_patterns, (GFunc) g_pattern_spec_free, NULL); + g_slist_free(source_patterns); + + return found_name; +} + + +/* sets filetype of header to match source + * changes filetype only if document is a header */ +void set_header_filetype(GeanyDocument * doc) +{ + gchar *doc_basename, *full_name; + gboolean is_header; + GSList * header_patterns; + + if (!doc || !doc->file_name) + return; + + if (prj_org) + { + header_patterns = get_precompiled_patterns(prj_org->header_patterns); + } + else + { + /* use default patterns when project isn't open */ + gchar ** patterns = g_strsplit(PRJORG_PATTERNS_HEADER, " ", -1); + header_patterns = get_precompiled_patterns(patterns); + g_strfreev(patterns); + } + + doc_basename = g_path_get_basename(doc->file_name); + is_header = patterns_match(header_patterns, doc_basename); + full_name = is_header ? find_header_source(doc) : NULL; + + if (full_name) + { + GeanyFiletype * source_filetype = filetypes_detect_from_file(full_name); + document_set_filetype(doc, source_filetype); + g_free(full_name); + } + + g_free(doc_basename); + g_slist_free(header_patterns); +} Modified: projectorganizer/src/prjorg-utils.h 4 lines changed, 4 insertions(+), 0 deletions(-) =================================================================== @@ -37,4 +37,8 @@ gchar *get_project_base_path(void); GtkWidget *menu_item_new(const gchar *icon_name, const gchar *label); +gchar *try_find_header_source(gchar *utf8_file_name, gboolean is_header, GSList *file_list, GSList *header_patterns, GSList *source_patterns); +gchar *find_header_source(GeanyDocument *doc); +void set_header_filetype(GeanyDocument * doc); + #endif -------------- This E-Mail was brought to you by github_commit_mail.py (Source:
https://github.com/geany/infrastructure
).
1
0
0
0
← Newer
1
...
17
18
19
20
21
22
23
...
547
Older →
Jump to page:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
Results per page:
10
25
50
100
200