-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] File extension column #3086
base: master
Are you sure you want to change the base?
Conversation
<row> | ||
<row> | ||
<col id="0" translatable="yes">By Extension</col> | ||
<row> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tags are wrong - this causes nemo to crash.
Each column needs to open with <row>
and close with </row>
if (nemo_file_is_broken_symbolic_link (file)) { | ||
return g_strdup (_("link (broken)")); | ||
} | ||
|
||
char *str, *token, *result; | ||
str = g_strdup (eel_ref_str_peek(file->details->name));//strdup() | ||
|
||
while ((token = strsep(&str, "."))) {result = g_strdup(token);} | ||
if (result == NULL) {result = "";} | ||
g_free(str); | ||
g_free(token); | ||
|
||
return result; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a few problems here:
Remember you're not returning a new string (const char*
), since you're 'peeking' at the value:
- link broken string should just be a static string (no g_strdup).
- The remaining code either returns a new string, or a static empty one, and leaks memory (you never free
token
while running thestrsep
loop, and if there are multiple separators the intermediate ones leak).
I would suggest using g_strrstr
as it works from the end of the string and returns a pointer or NULL
, and no new strings need to be created:
const char *str, *ptr;
str = eel_ref_str_peek (file->details->name);
if ((ptr = g_strrstr (str, "."))) {
return ptr + 1;
}
return "";
We usually try to stick with glib functions, as they're generally more convenient (and often safer).
nemo_file_get_extension_name (NemoFile *file) | ||
{ | ||
return nemo_file_peek_extension_name (file); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here you're returning a new string (char *
return), so you would need to g_strdup the peeked extension name.
This pull request integrates the File extension column into nemo. You can use the column in list view, and you can sort the files in any views according to file extensions. This is useful in case someone works with Latex and has 10+ .tex files, 10+ .sty files and 10+ .aux files in a directory, and would like to sort them such that:
1.aux
2.aux
3.aux
a.sty
b.sty
1.tex
2.tex
3.tex
will be the sort behavior. This is not possible with the current "Type", "Detailed type" and "MIME type" methods. This feature was already requested in the issues, and dolphin recently added the same "Extension" column.