Skip to content

Commit

Permalink
editor: Make Recent Files limit customizable and increase default to 10
Browse files Browse the repository at this point in the history
  • Loading branch information
irydacea committed Oct 9, 2015
1 parent 744dd6c commit cb7b217
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
11 changes: 11 additions & 0 deletions data/advanced_preferences.cfg
Expand Up @@ -188,6 +188,17 @@
default=no
[/advanced_preference]

[advanced_preference]
field=editor_max_recent_files
name= _ "Editor recent files limit"
description= _ "The maximum number of items to display on the Recent Files menu in the editor"
type=int
default=10
min=1
max=64
step=1
[/advanced_preference]

#ifndef APPLE
[advanced_preference]
field=color_cursors
Expand Down
13 changes: 8 additions & 5 deletions src/editor/editor_preferences.cpp
Expand Up @@ -98,8 +98,11 @@ namespace editor {
}

namespace {
// TODO: make user-customizable in Advanced Preferences.
const size_t MAX_RECENT_FILES = 6;
size_t editor_mru_limit()
{
return std::max(size_t(1), lexical_cast_default<size_t>(
preferences::get("editor_max_recent_files"), 10));
}

//
// NOTE: The MRU read/save functions enforce the entry count limit in
Expand All @@ -124,7 +127,7 @@ namespace editor {
}
}

mru.resize(std::min(MAX_RECENT_FILES, mru.size()));
mru.resize(std::min(editor_mru_limit(), mru.size()));

return mru;
}
Expand All @@ -143,7 +146,7 @@ namespace editor {
config& child = cfg.add_child("entry");
child["path"] = entry;

if(++n >= MAX_RECENT_FILES) {
if(++n >= editor_mru_limit()) {
break;
}
}
Expand All @@ -170,7 +173,7 @@ namespace editor {
mru.erase(std::remove(mru.begin(), mru.end(), path), mru.end());

mru.insert(mru.begin(), path);
mru.resize(std::min(MAX_RECENT_FILES, mru.size()));
mru.resize(std::min(editor_mru_limit(), mru.size()));

do_commit_editor_mru(mru);
}
Expand Down

0 comments on commit cb7b217

Please sign in to comment.