Skip to content

Commit

Permalink
In {file,dir}browsers, redraw heading on RESIZE
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisschagt committed Oct 24, 2020
1 parent 9f34adf commit 1dd2194
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions include/view.h
Expand Up @@ -150,6 +150,7 @@ class View {
void cancel_input(std::shared_ptr<FormAction> fa);
void delete_word(std::shared_ptr<FormAction> fa);
bool handle_qna_event(const std::string& event, std::shared_ptr<FormAction> fa);
void handle_resize();

Controller* ctrl;

Expand Down
7 changes: 3 additions & 4 deletions src/dirbrowserformaction.cpp
Expand Up @@ -265,6 +265,9 @@ void DirBrowserFormAction::prepare()
* in the current directory.
*/
if (do_redraw) {
const std::string cwdtmp = utils::getcwd();
update_title(cwdtmp);

std::vector<std::string> directories = get_sorted_dirlist();

ListFormatter listfmt;
Expand Down Expand Up @@ -305,15 +308,11 @@ void DirBrowserFormAction::init()
int status = ::chdir(dir.c_str());
LOG(Level::DEBUG, "view::dirbrowser: chdir(%s) = %i", dir, status);

const std::string cwdtmp = utils::getcwd();

f.set("filenametext", dir);

// Set position to 0 and back to ensure that the text is visible
f.run(-1);
f.set("filenametext_pos", std::to_string(dir.length()));

update_title(cwdtmp);
}

KeyMapHintEntry* DirBrowserFormAction::get_keymap_hint()
Expand Down
7 changes: 3 additions & 4 deletions src/filebrowserformaction.cpp
Expand Up @@ -257,6 +257,9 @@ void FileBrowserFormAction::prepare()
* in the current directory.
*/
if (do_redraw) {
const std::string cwdtmp = utils::getcwd();
update_title(cwdtmp);

std::vector<std::string> files = get_sorted_filelist();

ListFormatter listfmt;
Expand Down Expand Up @@ -297,15 +300,11 @@ void FileBrowserFormAction::init()
int status = ::chdir(dir.c_str());
LOG(Level::DEBUG, "view::filebrowser: chdir(%s) = %i", dir, status);

const std::string cwdtmp = utils::getcwd();

f.set("filenametext", default_filename);

// Set position to 0 and back to ensure that the text is visible
f.run(-1);
f.set("filenametext_pos", std::to_string(default_filename.length()));

update_title(cwdtmp);
}

KeyMapHintEntry* FileBrowserFormAction::get_keymap_hint()
Expand Down
24 changes: 17 additions & 7 deletions src/view.cpp
Expand Up @@ -189,13 +189,7 @@ int View::run()
}

if (strcmp(event, "RESIZE") == 0) {
for (const auto& form : formaction_stack) {
if (form != nullptr) {
// Recalculate width and height of stfl widgets
form->get_form().run(-3);
form->set_redraw(true);
}
}
handle_resize();
continue;
}

Expand Down Expand Up @@ -257,6 +251,11 @@ std::string View::run_modal(std::shared_ptr<FormAction> f,
continue;
}

if (strcmp(event, "RESIZE") == 0) {
handle_resize();
continue;
}

if (handle_qna_event(event, fa)) {
continue;
}
Expand Down Expand Up @@ -1122,6 +1121,17 @@ bool View::handle_qna_event(const std::string& event,
return false;
}

void View::handle_resize()
{
for (const auto& form : formaction_stack) {
if (form != nullptr) {
// Recalculate width and height of stfl widgets
form->get_form().run(-3);
form->set_redraw(true);
}
}
}

void View::handle_cmdline_completion(std::shared_ptr<FormAction> fa)
{
std::string fragment = fa->get_form().get("qna_value");
Expand Down

0 comments on commit 1dd2194

Please sign in to comment.