mirror of
https://github.com/eried/portapack-mayhem.git
synced 2024-10-01 01:26:06 -04:00
add Refactor in fileman app
This commit is contained in:
parent
c5738c46d5
commit
4ff71dcfca
@ -256,12 +256,38 @@ void FileManagerView::on_rename(NavigationView& nav) {
|
|||||||
if (destination_path.back() != '/')
|
if (destination_path.back() != '/')
|
||||||
destination_path += '/';
|
destination_path += '/';
|
||||||
destination_path = destination_path + buffer;
|
destination_path = destination_path + buffer;
|
||||||
|
|
||||||
rename_file(get_selected_path(), destination_path);
|
rename_file(get_selected_path(), destination_path);
|
||||||
load_directory_contents(current_path);
|
load_directory_contents(current_path);
|
||||||
refresh_list();
|
refresh_list();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FileManagerView::on_refactor(NavigationView& nav) {
|
||||||
|
text_prompt(nav, name_buffer, max_filename_length, [this](std::string& buffer) {
|
||||||
|
std::string destination_path = current_path.string();
|
||||||
|
if (destination_path.back() != '/')
|
||||||
|
destination_path += '/';
|
||||||
|
destination_path = destination_path + buffer;
|
||||||
|
rename_file(get_selected_path(), destination_path); //rename the selected file
|
||||||
|
|
||||||
|
if (get_selected_path().extension().string().substr(1) == "C16") {//rename it's partner ( C16 <-> TXT ) file.
|
||||||
|
auto selected_path = get_selected_path();
|
||||||
|
auto partner_file_path = selected_path.string().substr(0, selected_path.string().size()-4) + ".TXT";
|
||||||
|
destination_path = destination_path.substr(0, destination_path.size()-4) + ".TXT";
|
||||||
|
rename_file(partner_file_path, destination_path);
|
||||||
|
}else if (get_selected_path().extension().string().substr(1) == "TXT") {//If the file user choose is a TXT file
|
||||||
|
auto selected_path = get_selected_path();
|
||||||
|
auto partner_file_path = selected_path.string().substr(0, selected_path.string().size()-4) + ".C16";
|
||||||
|
destination_path = destination_path.substr(0, destination_path.size()-4) + ".C16";
|
||||||
|
rename_file(partner_file_path, destination_path);
|
||||||
|
}
|
||||||
|
|
||||||
|
load_directory_contents(current_path);
|
||||||
|
refresh_list();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
void FileManagerView::on_delete() {
|
void FileManagerView::on_delete() {
|
||||||
delete_file(get_selected_path());
|
delete_file(get_selected_path());
|
||||||
load_directory_contents(current_path);
|
load_directory_contents(current_path);
|
||||||
@ -271,6 +297,7 @@ void FileManagerView::on_delete() {
|
|||||||
void FileManagerView::refresh_widgets(const bool v) {
|
void FileManagerView::refresh_widgets(const bool v) {
|
||||||
button_rename.hidden(v);
|
button_rename.hidden(v);
|
||||||
button_new_dir.hidden(v);
|
button_new_dir.hidden(v);
|
||||||
|
button_refactor.hidden(v);
|
||||||
button_delete.hidden(v);
|
button_delete.hidden(v);
|
||||||
set_dirty();
|
set_dirty();
|
||||||
}
|
}
|
||||||
@ -293,6 +320,7 @@ FileManagerView::FileManagerView(
|
|||||||
&labels,
|
&labels,
|
||||||
&text_date,
|
&text_date,
|
||||||
&button_rename,
|
&button_rename,
|
||||||
|
&button_refactor,
|
||||||
&button_new_dir,
|
&button_new_dir,
|
||||||
&button_delete
|
&button_delete
|
||||||
});
|
});
|
||||||
@ -326,6 +354,11 @@ FileManagerView::FileManagerView(
|
|||||||
on_rename(nav);
|
on_rename(nav);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
button_refactor.on_select = [this, &nav](Button&) {
|
||||||
|
name_buffer = entry_list[menu_view.highlighted_index()].entry_path.filename().string().substr(0, max_filename_length);
|
||||||
|
on_refactor(nav);
|
||||||
|
};
|
||||||
|
|
||||||
button_delete.on_select = [this, &nav](Button&) {
|
button_delete.on_select = [this, &nav](Button&) {
|
||||||
// Use display_modal ?
|
// Use display_modal ?
|
||||||
nav.push<ModalMessageView>("Delete", "Delete " + entry_list[menu_view.highlighted_index()].entry_path.filename().string() + "\nAre you sure?", YESNO,
|
nav.push<ModalMessageView>("Delete", "Delete " + entry_list[menu_view.highlighted_index()].entry_path.filename().string() + "\nAre you sure?", YESNO,
|
||||||
|
@ -146,6 +146,7 @@ private:
|
|||||||
|
|
||||||
void refresh_widgets(const bool v);
|
void refresh_widgets(const bool v);
|
||||||
void on_rename(NavigationView& nav);
|
void on_rename(NavigationView& nav);
|
||||||
|
void on_refactor(NavigationView& nav);
|
||||||
void on_delete();
|
void on_delete();
|
||||||
|
|
||||||
Labels labels {
|
Labels labels {
|
||||||
@ -158,11 +159,17 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
Button button_rename {
|
Button button_rename {
|
||||||
{ 0 * 8, 29 * 8, 14 * 8, 32 },
|
{ 0 * 8, 29 * 8, 10 * 8, 32 },
|
||||||
"Rename"
|
"Rename"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Button button_refactor{
|
||||||
|
{ 10 * 8, 29 * 8, 10 * 8, 32 },
|
||||||
|
"Refactor"
|
||||||
|
};
|
||||||
|
|
||||||
Button button_delete {
|
Button button_delete {
|
||||||
{ 16 * 8, 29 * 8, 14 * 8, 32 },
|
{ 20 * 8, 29 * 8, 10 * 8, 32 },
|
||||||
"Delete"
|
"Delete"
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user