nano: Add File Manager option to edit selected file

Change-Id: Ie7d940545569e6de976d2a51666b692f3fc23798
diff --git a/gui/Android.mk b/gui/Android.mk
index b9ff266..c4d938a 100755
--- a/gui/Android.mk
+++ b/gui/Android.mk
@@ -100,6 +100,9 @@
 ifeq ($(TW_SCREEN_BLANK_ON_BOOT), true)
     LOCAL_CFLAGS += -DTW_SCREEN_BLANK_ON_BOOT
 endif
+ifeq ($(TW_EXCLUDE_NANO), true)
+    LOCAL_CFLAGS += -DTW_EXCLUDE_NANO
+endif
 
 LOCAL_C_INCLUDES += \
     bionic \
diff --git a/gui/action.cpp b/gui/action.cpp
index 1ab4ee4..ecb035e 100755
--- a/gui/action.cpp
+++ b/gui/action.cpp
@@ -237,6 +237,9 @@
 		ADD_ACTION(uninstalltwrpsystemapp);
 		ADD_ACTION(repackimage);
 		ADD_ACTION(fixabrecoverybootloop);
+#ifndef TW_EXCLUDE_NANO
+		ADD_ACTION(editfile);
+#endif
 	}
 
 	// First, get the action
@@ -2253,3 +2256,15 @@
 		gui_changePage("terminalcommand");
 	return 0;
 }
+#ifndef TW_EXCLUDE_NANO
+int GUIAction::editfile(std::string arg) {
+	if (term != NULL) {
+		for (uint8_t iter = 0; iter < arg.size(); iter++)
+			term->NotifyCharInput(arg.at(iter));
+		term->NotifyCharInput(13);
+	}
+	else
+		LOGINFO("Unable to switch to Terminal\n");
+	return 0;
+}
+#endif
diff --git a/gui/objects.hpp b/gui/objects.hpp
index 9ef1b65..b3cd867 100644
--- a/gui/objects.hpp
+++ b/gui/objects.hpp
@@ -372,6 +372,9 @@
 	int repackimage(std::string arg);
 	int fixabrecoverybootloop(std::string arg);
 	int changeterminal(std::string arg);
+#ifndef TW_EXCLUDE_NANO
+	int editfile(std::string arg);
+#endif
 
 	int simulate;
 };
diff --git a/gui/theme/common/landscape.xml b/gui/theme/common/landscape.xml
index 17977e2..5ffa146 100755
--- a/gui/theme/common/landscape.xml
+++ b/gui/theme/common/landscape.xml
@@ -4086,6 +4086,19 @@
 			</button>
 
 			<button style="main_button_half_width">
+edi				<conditions>
+					<condition var1="tw_include_nano" var2="1"/>
+					<condition var1="tw_fm_isfolder" var2="0"/>
+				</conditions>
+				<placement x="%col1_x_left%" y="%row15a_y%"/>
+				<text>{@fm_edit_file=Edit File}</text>
+				<actions>
+					<action function="editfile">nano "%tw_filename1%"</action>
+					<action function="page">terminalcommand</action>
+				</actions>
+			</button>
+
+			<button style="main_button_half_width">
 				<placement x="%col2_x_left%" y="%row11_y%"/>
 				<text>{@fm_move_btn=Move}</text>
 				<actions>
diff --git a/gui/theme/common/languages/en.xml b/gui/theme/common/languages/en.xml
index 497d088..352bffa 100755
--- a/gui/theme/common/languages/en.xml
+++ b/gui/theme/common/languages/en.xml
@@ -460,6 +460,7 @@
 		<string name="fm_perms">Permissions:</string>
 		<string name="fm_complete">File Operation Complete</string>
 		<string name="fm_open_terminal_btn">Open Terminal Here</string>
+		<string name="fm_edit_file">Edit File</string>
 		<string name="decrypt_data_hdr">Decrypt Data</string>
 		<string name="decrypt_data_enter_pass">Enter Password.</string>
 		<string name="decrypt_data_failed">Password failed, please try again!</string>
diff --git a/gui/theme/common/portrait.xml b/gui/theme/common/portrait.xml
index ea52af8..3a11170 100755
--- a/gui/theme/common/portrait.xml
+++ b/gui/theme/common/portrait.xml
@@ -4188,6 +4188,19 @@
 			</text>
 
 			<button style="main_button_half_height">
+				<conditions>
+					<condition var1="tw_include_nano" var2="1"/>
+					<condition var1="tw_fm_isfolder" var2="0"/>
+				</conditions>
+				<placement x="%indent%" y="%row12a_y%"/>
+				<text>{@fm_edit_file=Edit File}</text>
+				<actions>
+					<action function="editfile">nano "%tw_filename1%"</action>
+					<action function="page">terminalcommand</action>
+				</actions>
+			</button>
+
+			<button style="main_button_half_height">
 				<condition var1="tw_fm_isfolder" var2="1"/>
 				<placement x="%center_x%" y="%row12a_y%"/>
 				<text>{@fm_open_terminal_btn=Open Terminal Here}</text>