@@ -104,6 +104,27 @@ goto_file_cleanup(void)
104
104
gtk_widget_destroy (menu_item );
105
105
}
106
106
107
+ /**
108
+ * @brief Replace any special characters present in path_name
109
+ * @param gchar** path_name
110
+ * @return void
111
+ *
112
+ */
113
+ static void
114
+ path_name_replace_special (gchar * * path_name )
115
+ {
116
+ GString * str ;
117
+
118
+ if (* path_name [0 ] == '~' )
119
+ {
120
+ str = g_string_new (* path_name );
121
+ utils_string_replace_first (str , "~" , g_get_home_dir ());
122
+
123
+ free (* path_name );
124
+ * path_name = g_string_free (str , FALSE);
125
+ }
126
+ }
127
+
107
128
/**
108
129
* @brief Populate the file list with file list of directory
109
130
* @param const char* dirname the directory where to find files
@@ -157,7 +178,7 @@ static void
157
178
directory_check (GtkEntry * entry , GtkEntryCompletion * completion )
158
179
{
159
180
GtkTreeModel * completion_list ;
160
- gchar * text , * new_dir , * new_dir_path ;
181
+ gchar * text , * new_dir , * new_dir_exp , * new_dir_path ;
161
182
162
183
/* We need to discern between text written by the user and text filled by the
163
184
* autocomplete, and to only use what the user wrote for the completion model.
@@ -188,15 +209,20 @@ directory_check(GtkEntry* entry, GtkEntryCompletion* completion)
188
209
g_free (curr_dir );
189
210
curr_dir = new_dir ;
190
211
212
+ /* Replace special chars here (e.g. '~') */
213
+ new_dir_exp = g_strdup (new_dir );
214
+ path_name_replace_special (& new_dir_exp );
215
+
191
216
/* Assemble full path to the entered directory */
192
- new_dir_path = (g_path_is_absolute (new_dir ) ? g_strdup (new_dir )
193
- : g_build_filename (ref_dir , new_dir , NULL ));
217
+ new_dir_path = (g_path_is_absolute (new_dir_exp ) ? g_strdup (new_dir_exp )
218
+ : g_build_filename (ref_dir , new_dir_exp , NULL ));
194
219
195
220
/* Build the new file list for completion */
196
221
completion_list = build_file_list (new_dir_path , new_dir );
197
222
gtk_entry_completion_set_model (completion , completion_list );
198
223
g_object_unref (completion_list );
199
224
225
+ g_free (new_dir_exp );
200
226
g_free (new_dir_path );
201
227
}
202
228
@@ -368,8 +394,8 @@ menu_item_activate(guint key_id)
368
394
GtkWidget * dialog_new = NULL ;
369
395
GtkWidget * dialog_entry ;
370
396
GeanyDocument * current_doc = document_get_current ();
371
- gchar * chosen_path ;
372
397
const gchar * chosen_file ;
398
+ gchar * chosen_file_exp , * chosen_path ;
373
399
gint response ;
374
400
375
401
log_func ();
@@ -386,8 +412,12 @@ menu_item_activate(guint key_id)
386
412
response = gtk_dialog_run (GTK_DIALOG (dialog ));
387
413
388
414
chosen_file = gtk_entry_get_text (GTK_ENTRY (dialog_entry ));
389
- chosen_path = (g_path_is_absolute (chosen_file ) ? g_strdup (chosen_file )
390
- : g_build_filename (ref_dir , chosen_file , NULL ));
415
+
416
+ chosen_file_exp = g_strdup (chosen_file );
417
+ path_name_replace_special (& chosen_file_exp );
418
+
419
+ chosen_path = (g_path_is_absolute (chosen_file_exp ) ? g_strdup (chosen_file_exp )
420
+ : g_build_filename (ref_dir , chosen_file_exp , NULL ));
391
421
392
422
if ( response == GTK_RESPONSE_ACCEPT )
393
423
{
@@ -444,6 +474,8 @@ menu_item_activate(guint key_id)
444
474
/* Freeing memory */
445
475
446
476
gtk_widget_destroy (dialog );
477
+
478
+ g_free (chosen_file_exp );
447
479
g_free (chosen_path );
448
480
449
481
g_free (ref_dir );
0 commit comments