@@ -7,6 +7,7 @@ public class AppWindow : Gtk.Window {
77 public File file { get ; set ; }
88 private Gtk . TextBuffer buf;
99 private Gtk . EditableLabel header_label;
10+ public string file_name;
1011
1112 // Add a debounce so we aren't writing the entire buffer every character input
1213 public int interval = 500 ; // ms
@@ -100,8 +101,8 @@ public class AppWindow : Gtk.Window {
100101 // Window title, and header label, are file name
101102 // We dont want to rename files with no save location yet
102103 //
103- file.bind_property ("basename ", this , "title ");
104- file.bind_property ("basename ", header_label , "text ");
104+ file.bind_property ("file_name ", this , "title ");
105+ file.bind_property ("file_name ", header_label , "text ");
105106 bind_property ("is_unsaved_doc ", header_label , "sensitive ", Glib .BindingFlags .INVERT_BOOLEANS );
106107
107108 debug ("Success !");
@@ -133,15 +134,17 @@ public class AppWindow : Gtk.Window {
133134
134135 /* ---------------- FILE OPERATIONS ---------------- */
135136 public void open_file (File file = this .file ) {
136- this . file = file;
137+
137138 debug (" Attempting to open file %s " , file. get_basename ());
138139 try {
139140 var distream = new DataInputStream (file. read (null ));
140141 var contents = distream. read_upto (" " , - 1 , null );
141142
142143 buf. set_text (contents);
143- is_unsaved_doc = (Environment . get_user_data_dir () in this . file. get_path ());
144- header_label. tooltip_markup. text = this . file. get_path ();
144+ this . file = file;
145+ this . is_unsaved_doc = (Environment . get_user_data_dir () in this . file. get_path ());
146+ this . header_label. tooltip_markup. text = this . file. get_path ();
147+ this . file_name = file. get_basename ();
145148
146149 } catch (Error err) {
147150 warning (" Couldn't open file: %s " , err. message);
@@ -180,7 +183,6 @@ public class AppWindow : Gtk.Window {
180183 debug (" Save event!" );
181184 var save_dialog = new Gtk .FileDialog () { initial_name = this.file.basename () };
182185 File oldfile = this . file;
183- bool delete_after = (Environment . get_user_data_dir () in this . file. get_path ());
184186
185187 save_dialog.save.begin (this , null , (obj , res ) => {
186188 try {
@@ -190,18 +192,20 @@ public class AppWindow : Gtk.Window {
190192
191193 // Only do after the operation, so we do not set this.file to something fucky
192194 this . file = file;
195+ this . file_name = file. get_basename ();
193196
194- if ((delete_after ) && (oldfile != file)) {
197+ if ((unsaved_doc ) && (oldfile != file)) {
195198 oldfile. delete ();
196199 }
200+ this . is_unsaved_doc = (Environment . get_user_data_dir () in this . file. get_path ());
201+
197202
198203 } catch (Error err) {
199204 warning (" Failed to save file: %s " , err. message);
200205 }
201206 });
202207
203- is_unsaved_doc = (Environment . get_user_data_dir () in this . file. get_path ());
204- header_label. tooltip_markup. text = this.file.get_path ();
208+
205209 }
206210
207211 private void on_buffer_changed () {
@@ -224,8 +228,6 @@ public class AppWindow : Gtk.Window {
224228 private bool on_close () {
225229 debug (" Close event!" );
226230
227- bool is_unsaved_doc = (Environment . get_user_data_dir () in this . file. get_path ());
228-
229231 // We want to delete empty unsaved documents
230232 if ((is_unsaved_doc) && (buf. text == " " )) {
231233
@@ -243,12 +245,11 @@ public class AppWindow : Gtk.Window {
243245 }
244246
245247 private void on_title_changed () {
246- debug (" Close event!" );
248+ debug (" Renaming event!" );
247249
248250 try {
249251 this . file. move (header_label, File . CopyFlags . None );
250- header_label. text = this . file. basename;
251- header_label. tooltip_markup. text = this . file. get_path ();
252+ this . file_name = this . file. get_basename ();
252253
253254 } catch (Error err) {
254255 warning (" Failed to rename: %s " , err. message);
0 commit comments