* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#include <string.h>
-#include <sys/types.h>
+#include <cstring>
#include <dirent.h>
+#include <sys/types.h>
#include "main.h"
#include "ui-tabcomp.h"
#include "history-list.h"
#include "misc.h" /* expand_tilde() */
#include "ui-fileops.h"
-#include "ui-spinner.h"
#include "ui-utildlg.h"
/* define this to enable a pop-up menu that shows possible matches
* ----------------------------------------------------------------
* Tab completion routines, can be connected to any gtkentry widget
* using the tab_completion_add_to_entry() function.
- *
+ *
* Use remove_trailing_slash() to strip the trailing G_DIR_SEPARATOR.
- *
+ *
* ----------------------------------------------------------------
*/
-typedef struct _TabCompData TabCompData;
-struct _TabCompData
+struct TabCompData
{
GtkWidget *entry;
gchar *dir_path;
static void tab_completion_free_list(TabCompData *td)
{
- GList *list;
-
g_free(td->dir_path);
- td->dir_path = NULL;
-
- list = td->file_list;
+ td->dir_path = nullptr;
- while (list)
- {
- g_free(list->data);
- list = list->next;
- }
-
- g_list_free(td->file_list);
- td->file_list = NULL;
+ g_list_free_full(td->file_list, g_free);
+ td->file_list = nullptr;
}
static void tab_completion_read_dir(TabCompData *td, const gchar *path)
{
DIR *dp;
struct dirent *dir;
- GList *list = NULL;
+ GList *list = nullptr;
gchar *pathl;
tab_completion_free_list(td);
g_free(pathl);
return;
}
- while ((dir = readdir(dp)) != NULL)
+ while ((dir = readdir(dp)) != nullptr)
{
gchar *name = dir->d_name;
if (strcmp(name, ".") != 0 && strcmp(name, "..") != 0 &&
g_free(pathl);
}
-static void tab_completion_destroy(GtkWidget *UNUSED(widget), gpointer data)
+static void tab_completion_destroy(GtkWidget *, gpointer data)
{
auto td = static_cast<TabCompData *>(data);
{
gchar *text;
- text = g_strdup(gtk_entry_get_text(GTK_ENTRY(td->entry)));
+ text = g_strdup(gq_gtk_entry_get_text(GTK_ENTRY(td->entry)));
if (text[0] == '~')
{
child = gtk_bin_get_child(GTK_BIN(widget));
if (GTK_IS_LABEL(child)) {
const gchar *text = gtk_label_get_text(GTK_LABEL(child));
- const gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(td->entry));
+ const gchar *entry_text = gq_gtk_entry_get_text(GTK_ENTRY(td->entry));
const gchar *prefix = filename_from_path(entry_text);
guint prefix_len = strlen(prefix);
/* Reduce the number of entries in the menu */
td->choices = 0;
- gtk_container_foreach(GTK_CONTAINER(widget), tab_completion_iter_menu_items, (gpointer) td);
+ gtk_container_foreach(GTK_CONTAINER(widget), tab_completion_iter_menu_items, td);
if (td->choices > 1) return TRUE; /* multiple choices */
if (td->choices > 0) tab_completion_do(td); /* one choice */
}
if (!td) return;
buf = g_build_filename(td->dir_path, name, NULL);
- gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
g_free(buf);
g_signal_connect(G_OBJECT(menu), "key_press_event",
G_CALLBACK(tab_completion_popup_key_press), td);
- gtk_menu_popup_at_widget(GTK_MENU(menu), td->entry, GDK_GRAVITY_NORTH_EAST, GDK_GRAVITY_NORTH, NULL);
+ gtk_menu_popup_at_widget(GTK_MENU(menu), td->entry, GDK_GRAVITY_NORTH_EAST, GDK_GRAVITY_NORTH, nullptr);
}
#ifndef CASE_SORT
static gboolean tab_completion_do(TabCompData *td)
{
- const gchar *entry_text = gtk_entry_get_text(GTK_ENTRY(td->entry));
+ const gchar *entry_text = gq_gtk_entry_get_text(GTK_ENTRY(td->entry));
const gchar *entry_file;
gchar *entry_dir;
gchar *ptr;
if (entry_text[0] == '\0')
{
entry_dir = g_strdup(G_DIR_SEPARATOR_S); /** @FIXME root directory win32 */
- gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(entry_dir));
g_free(entry_dir);
return FALSE;
{
if (home_exp)
{
- gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(entry_dir));
}
g_free(entry_dir);
{
if (home_exp)
{
- gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), entry_dir);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(entry_dir));
}
g_free(buf);
buf = tmp;
}
- gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
g_free(buf);
}
else
{
gchar *buf = g_strconcat(entry_dir, G_DIR_SEPARATOR_S, NULL);
- gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
g_free(buf);
g_free(entry_dir);
if (isdir(entry_dir))
{
GList *list;
- GList *poss = NULL;
+ GList *poss = nullptr;
gint l = strlen(entry_file);
if (!td->dir_path || !td->file_list || strcmp(td->dir_path, entry_dir) != 0)
gchar *buf;
buf = g_build_filename(entry_dir, file, NULL);
- gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
g_free(buf);
g_list_free(poss);
file = g_strdup(test_file);
file[c] = '\0';
buf = g_build_filename(entry_dir, file, NULL);
- gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
gtk_editable_set_position(GTK_EDITABLE(td->entry), strlen(buf));
#ifdef TAB_COMPLETION_ENABLE_POPUP_MENU
return (stop_signal);
}
-static void tab_completion_button_pressed(GtkWidget *UNUSED(widget), gpointer data)
+static void tab_completion_button_pressed(GtkWidget *, gpointer data)
{
TabCompData *td;
auto entry = static_cast<GtkWidget *>(data);
static GtkWidget *tab_completion_create_complete_button(GtkWidget *entry, GtkWidget *parent)
{
GtkWidget *button;
- GtkWidget *icon;
- GdkPixbuf *pixbuf;
- button = gtk_button_new();
+ button = gtk_button_new_from_icon_name(GQ_ICON_GO_LAST, GTK_ICON_SIZE_BUTTON);
gtk_widget_set_can_focus(button, FALSE);
g_signal_connect(G_OBJECT(button), "size_allocate",
G_CALLBACK(tab_completion_button_size_allocate), parent);
g_signal_connect(G_OBJECT(button), "clicked",
G_CALLBACK(tab_completion_button_pressed), entry);
- pixbuf = gdk_pixbuf_new_from_inline(-1, icon_tabcomp, FALSE, NULL);
- icon = gtk_image_new_from_pixbuf(pixbuf);
- g_object_unref(pixbuf);
-
- gtk_container_add(GTK_CONTAINER(button), icon);
- gtk_widget_show(icon);
-
return button;
}
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
combo = gtk_combo_box_text_new_with_entry();
- gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
gtk_widget_show(combo);
combo_entry = gtk_bin_get_child(GTK_BIN(combo));
button = tab_completion_create_complete_button(combo_entry, combo);
- gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
gtk_widget_show(button);
- tab_completion_add_to_entry(combo_entry, enter_func, NULL, NULL, data);
+ tab_completion_add_to_entry(combo_entry, enter_func, nullptr, nullptr, data);
td = static_cast<TabCompData *>(g_object_get_data(G_OBJECT(combo_entry), "tab_completion_data"));
- if (!td) return NULL; /* this should never happen! */
+ if (!td) return nullptr; /* this should never happen! */
td->combo = combo;
td->has_history = TRUE;
if (text)
{
- gtk_entry_set_text(GTK_ENTRY(combo_entry), text);
+ gq_gtk_entry_set_text(GTK_ENTRY(combo_entry), text);
}
else if (n > 0)
{
auto td = static_cast<TabCompData *>(g_object_get_data(G_OBJECT(entry), "tab_completion_data"));
const gchar *buf;
- if (!td || !td->has_history) return NULL;
+ if (!td || !td->has_history) return nullptr;
buf = history_list_find_last_path_by_key(td->history_key);
if (buf)
{
- gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), buf);
}
return buf;
hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
newentry = gtk_entry_new();
- if (text) gtk_entry_set_text(GTK_ENTRY(newentry), text);
- gtk_box_pack_start(GTK_BOX(hbox), newentry, TRUE, TRUE, 0);
+ if (text) gq_gtk_entry_set_text(GTK_ENTRY(newentry), text);
+ gq_gtk_box_pack_start(GTK_BOX(hbox), newentry, TRUE, TRUE, 0);
gtk_widget_show(newentry);
button = tab_completion_create_complete_button(newentry, newentry);
- gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0);
gtk_widget_show(button);
tab_completion_add_to_entry(newentry, enter_func, filter, filter_desc, data);
{
gint l;
- if (!path) return NULL;
+ if (!path) return nullptr;
l = strlen(path);
while (l > 1 && path[l - 1] == G_DIR_SEPARATOR) l--;
{
auto td = static_cast<TabCompData *>(data);
- td->fd = NULL;
+ td->fd = nullptr;
file_dialog_close(fd);
}
{
auto td = static_cast<TabCompData *>(data);
- gtk_entry_set_text(GTK_ENTRY(td->entry), gtk_entry_get_text(GTK_ENTRY(fd->entry)));
+ gq_gtk_entry_set_text(GTK_ENTRY(td->entry), gq_gtk_entry_get_text(GTK_ENTRY(fd->entry)));
tab_completion_select_cancel_cb(fd, data);
{
const gchar *title;
const gchar *path;
- const gchar *filter = NULL;
- gchar *filter_desc = NULL;
+ const gchar *filter = nullptr;
+ gchar *filter_desc = nullptr;
if (td->fd)
{
title = (td->fd_title) ? td->fd_title : _("Select path");
td->fd = file_dialog_new(title, "select_path", td->entry,
tab_completion_select_cancel_cb, td);
- file_dialog_add_button(td->fd, GTK_STOCK_OK, NULL,
+ file_dialog_add_button(td->fd, GQ_ICON_OK, "OK",
tab_completion_select_ok_cb, TRUE);
- generic_dialog_add_message(GENERIC_DIALOG(td->fd), NULL, title, NULL, FALSE);
+ generic_dialog_add_message(GENERIC_DIALOG(td->fd), nullptr, title, nullptr, FALSE);
if (td->filter)
{
filter_desc = _("All files");
}
- path = gtk_entry_get_text(GTK_ENTRY(td->entry));
- if (strlen(path) == 0) path = NULL;
+ path = gq_gtk_entry_get_text(GTK_ENTRY(td->entry));
+ if (strlen(path) == 0) path = nullptr;
if (td->fd_folders_only)
{
- file_dialog_add_path_widgets(td->fd, NULL, path, td->history_key, NULL, NULL);
+ file_dialog_add_path_widgets(td->fd, nullptr, path, td->history_key, nullptr, nullptr);
}
else
{
- file_dialog_add_path_widgets(td->fd, NULL, path, td->history_key, filter, filter_desc);
+ file_dialog_add_path_widgets(td->fd, nullptr, path, td->history_key, filter, filter_desc);
}
gtk_widget_show(GENERIC_DIALOG(td->fd)->dialog);
}
-static void tab_completion_select_pressed(GtkWidget *UNUSED(widget), gpointer data)
+static void tab_completion_select_pressed(GtkWidget *, gpointer data)
{
auto td = static_cast<TabCompData *>(data);
g_signal_connect(G_OBJECT(td->fd_button), "clicked",
G_CALLBACK(tab_completion_select_pressed), td);
- gtk_box_pack_start(GTK_BOX(hbox), td->fd_button, FALSE, FALSE, 0);
+ gq_gtk_box_pack_start(GTK_BOX(hbox), td->fd_button, FALSE, FALSE, 0);
gtk_widget_show(td->fd_button);
}