Skip to content
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

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft

Conversation

VitanovG
Copy link

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.

@ghost
Copy link

ghost commented Sep 30, 2022

Guess this option has never been considered before by the official developers because "Linux is not Windows" - which is the default motivation for everything that looks and/or works in an abnormal way as seen by former Windows users (or people that have some logic in their thinking).

What needs done next is adding an option for displaying file size in bytes only, with thousand separators, because both current options are either uninformative or space wasting.

Then it desperately needs a "common-sense" sorting order, which is based on the old ANSI character set and has always been the default in Windows. Some call it natural sorting. Back when I was still struggling to use Nemo it was making me crawl up the walls when subfolders named as _test or __work (note the underscores!) were always found aligned towards the bottom of the list with T-named or W-named subfolders, respectively, instead of being at the very top of the current folder/partition where I had always expected them to be for the past 20+ years.
Apparently others do have enough common-sense to provide choices for this, for example Double Commander:
Screenshot from 2022-09-30 16-09-06

@Jeremy7701
Copy link
Contributor

Jeremy7701 commented Sep 30, 2022 via email

<row>
<row>
<col id="0" translatable="yes">By Extension</col>
<row>
Copy link
Member

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>

Comment on lines +4075 to +4088
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;
}
Copy link
Member

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 the strsep 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);
}
Copy link
Member

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.

@clefebvre clefebvre changed the title File extension column [WIP] File extension column Nov 17, 2022
@rcalixte rcalixte marked this pull request as draft January 18, 2024 09:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants