summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Makefile.am2
-rw-r--r--include/dialogs/dialogs.h1
-rw-r--r--include/dialogs/filebrowser.h44
-rw-r--r--include/keyb.h1
-rw-r--r--include/mode.h2
-rw-r--r--meson.build2
-rw-r--r--source/dialogs/drun.c5
-rw-r--r--source/dialogs/filebrowser.c403
-rw-r--r--source/dialogs/run.c212
-rw-r--r--source/keyb.c1
-rw-r--r--source/rofi.c11
-rw-r--r--source/view.c11
12 files changed, 655 insertions, 40 deletions
diff --git a/Makefile.am b/Makefile.am
index 97a6f387..de224b7e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -88,6 +88,7 @@ SOURCES=\
source/dialogs/combi.c\
source/dialogs/window.c\
source/dialogs/script.c\
+ source/dialogs/filebrowser.c\
source/dialogs/help-keys.c\
include/display.h\
include/xcb.h\
@@ -119,6 +120,7 @@ SOURCES=\
include/dialogs/ssh.h\
include/dialogs/run.h\
include/dialogs/drun.h\
+ include/dialogs/filebrowser.h\
include/dialogs/dmenu.h\
include/dialogs/combi.h\
include/dialogs/script.h\
diff --git a/include/dialogs/dialogs.h b/include/dialogs/dialogs.h
index f9a543f0..6084711c 100644
--- a/include/dialogs/dialogs.h
+++ b/include/dialogs/dialogs.h
@@ -43,4 +43,5 @@
#include "dialogs/window.h"
#include "dialogs/combi.h"
#include "dialogs/help-keys.h"
+#include "dialogs/filebrowser.h"
#endif // ROFI_DIALOGS_DIALOGS_H
diff --git a/include/dialogs/filebrowser.h b/include/dialogs/filebrowser.h
new file mode 100644
index 00000000..f57bd4a7
--- /dev/null
+++ b/include/dialogs/filebrowser.h
@@ -0,0 +1,44 @@
+/*
+ * rofi
+ *
+ * MIT/X11 License
+ * Copyright © 2013-2020 Qball Cow <qball@gmpclient.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef ROFI_DIALOG_FILE_BROWSER_H
+#define ROFI_DIALOG_FILE_BROWSER_H
+
+/**
+ * @defgroup FileBrowserMode FileBrowser
+ * @ingroup MODES
+ *
+ *
+ * @{
+ */
+/** #Mode object representing the run dialog. */
+extern Mode file_browser_mode;
+
+Mode *create_new_file_browser (void);
+ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path );
+/*@}*/
+#endif // ROFI_DIALOG_FILE_BROWSER_H
diff --git a/include/keyb.h b/include/keyb.h
index 911bdbc2..d6fb4c66 100644
--- a/include/keyb.h
+++ b/include/keyb.h
@@ -92,6 +92,7 @@ typedef enum
ACCEPT_ALT,
ACCEPT_CUSTOM,
MODE_NEXT,
+ MODE_COMPLETE,
MODE_PREVIOUS,
TOGGLE_CASE_SENSITIVITY,
DELETE_ENTRY,
diff --git a/include/mode.h b/include/mode.h
index ab3c6095..30a9021a 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -79,6 +79,8 @@ typedef enum
MENU_QUICK_SWITCH = 0x00200000,
/** Go to the previous menu. */
MENU_PREVIOUS = 0x00400000,
+ /** Go to the complete. */
+ MENU_COMPLETE = 0x00800000,
/** Bindings specifics */
MENU_CUSTOM_ACTION = 0x10000000,
/** Mask */
diff --git a/meson.build b/meson.build
index bec08967..de41e81f 100644
--- a/meson.build
+++ b/meson.build
@@ -162,6 +162,7 @@ rofi_sources = files(
'source/dialogs/combi.c',
'source/dialogs/window.c',
'source/dialogs/script.c',
+ 'source/dialogs/filebrowser.c',
'source/dialogs/help-keys.c',
'include/display.h',
'include/xcb.h',
@@ -193,6 +194,7 @@ rofi_sources = files(
'include/dialogs/ssh.h',
'include/dialogs/run.h',
'include/dialogs/drun.h',
+ 'include/dialogs/filebrowser.h',
'include/dialogs/dmenu.h',
'include/dialogs/combi.h',
'include/dialogs/script.h',
diff --git a/source/dialogs/drun.c b/source/dialogs/drun.c
index afc19ba6..d44c10e9 100644
--- a/source/dialogs/drun.c
+++ b/source/dialogs/drun.c
@@ -80,10 +80,6 @@ typedef struct
char *desktop_id;
/* Icon stuff */
char *icon_name;
- /* Icon size is used to indicate what size is requested by the gui.
- * secondary it indicates if the request for a lookup has been issued (0 not issued )
- */
- int icon_size;
/* Surface holding the icon. */
cairo_surface_t *icon;
/* Executable */
@@ -459,7 +455,6 @@ static void read_desktop_file ( DRunModePrivateData *pd, const char *root, const
else {
pd->entry_list[pd->cmd_list_length].sort_index = -nl;
}
- pd->entry_list[pd->cmd_list_length].icon_size = 0;
pd->entry_list[pd->cmd_list_length].icon_fetch_uid = 0;
pd->entry_list[pd->cmd_list_length].root = g_strdup ( root );
pd->entry_list[pd->cmd_list_length].path = g_strdup ( path );
diff --git a/source/dialogs/filebrowser.c b/source/dialogs/filebrowser.c
new file mode 100644
index 00000000..c9a3bbf3
--- /dev/null
+++ b/source/dialogs/filebrowser.c
@@ -0,0 +1,403 @@
+/**
+ * rofi-file_browser
+ *
+ * MIT/X11 License
+ * Copyright (c) 2017 Qball Cow <qball@gmpclient.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+#include <stdlib.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <gmodule.h>
+#include <gio/gio.h>
+
+#include "mode.h"
+#include "helper.h"
+#include "mode-private.h"
+#include "dialogs/filebrowser.h"
+
+#include <stdint.h>
+
+#include "rofi-icon-fetcher.h"
+/**
+ * The internal data structure holding the private data of the TEST Mode.
+ */
+enum FBFileType {
+ UP,
+ DIRECTORY,
+ RFILE,
+ NUM_FILE_TYPES,
+};
+const char *icon_name[NUM_FILE_TYPES] =
+{
+ "go-up",
+ "folder",
+ "gtk-file"
+};
+typedef struct {
+ char *name;
+ char *path;
+ enum FBFileType type;
+ uint32_t icon_fetch_uid;
+} FBFile;
+
+typedef struct
+{
+ GFile *current_dir;
+ FBFile *array;
+ unsigned int array_length;
+} FileBrowserModePrivateData;
+
+static void free_list ( FileBrowserModePrivateData *pd )
+{
+ for ( unsigned int i = 0; i < pd->array_length; i++ ) {
+ FBFile *fb = & ( pd->array[i] );
+ g_free ( fb->name );
+ g_free ( fb->path );
+ }
+ g_free (pd->array);
+ pd->array = NULL;
+ pd->array_length = 0;
+}
+#include <sys/types.h>
+#include <dirent.h>
+
+static gint compare ( gconstpointer a, gconstpointer b, gpointer data )
+{
+ FBFile *fa = (FBFile*)a;
+ FBFile *fb = (FBFile*)b;
+ if ( fa->type != fb->type ){
+ return (fa->type - fb->type);
+ }
+
+ return g_strcmp0 ( fa->name, fb->name );
+}
+
+static void get_file_browser ( Mode *sw )
+{
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+ /**
+ * Get the entries to display.
+ * this gets called on plugin initialization.
+ */
+ char *cdir = g_file_get_path ( pd->current_dir );
+ DIR *dir = opendir ( cdir );
+ if ( dir ) {
+ struct dirent *rd = NULL;
+ while ((rd = readdir (dir)) != NULL )
+ {
+ if ( g_strcmp0 ( rd->d_name, ".." ) == 0 ){
+ pd->array = g_realloc ( pd->array, (pd->array_length+1)*sizeof(FBFile));
+ // Rofi expects utf-8, so lets convert the filename.
+ pd->array[pd->array_length].name = g_strdup ( ".." );
+ pd->array[pd->array_length].path = NULL;
+ pd->array[pd->array_length].type = UP;
+ pd->array[pd->array_length].icon_fetch_uid = 0;
+ pd->array_length++;
+ continue;
+
+ } else if ( rd->d_name[0] == '.' ) {
+ continue;
+ }
+
+ switch ( rd->d_type )
+ {
+ case DT_BLK:
+ case DT_CHR:
+ case DT_FIFO:
+ case DT_UNKNOWN:
+ case DT_SOCK:
+ break;
+ case DT_REG:
+ case DT_DIR:
+ pd->array = g_realloc ( pd->array, (pd->array_length+1)*sizeof(FBFile));
+ // Rofi expects utf-8, so lets convert the filename.
+ pd->array[pd->array_length].name = g_filename_to_utf8 ( rd->d_name, -1, NULL, NULL, NULL);
+ pd->array[pd->array_length].path = g_build_filename ( cdir, rd->d_name, NULL );
+ pd->array[pd->array_length].type = (rd->d_type == DT_DIR)? DIRECTORY: RFILE;
+ pd->array[pd->array_length].icon_fetch_uid = 0;
+ pd->array_length++;
+ }
+ }
+ closedir ( dir );
+ }
+ g_qsort_with_data ( pd->array, pd->array_length, sizeof (FBFile ), compare, NULL );
+}
+
+
+static int file_browser_mode_init ( Mode *sw )
+{
+ /**
+ * Called on startup when enabled (in modi list)
+ */
+ if ( mode_get_private_data ( sw ) == NULL ) {
+ FileBrowserModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
+ mode_set_private_data ( sw, (void *) pd );
+ pd->current_dir = g_file_new_for_path(g_get_home_dir () );
+ // Load content.
+ get_file_browser ( sw );
+ }
+ return TRUE;
+}
+static unsigned int file_browser_mode_get_num_entries ( const Mode *sw )
+{
+ const FileBrowserModePrivateData *pd = (const FileBrowserModePrivateData *) mode_get_private_data ( sw );
+ return pd->array_length;
+}
+
+static ModeMode file_browser_mode_result ( Mode *sw, int mretv, char **input, unsigned int selected_line )
+{
+ ModeMode retv = MODE_EXIT;
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+ if ( mretv & MENU_NEXT ) {
+ retv = NEXT_DIALOG;
+ } else if ( mretv & MENU_PREVIOUS ) {
+ retv = PREVIOUS_DIALOG;
+ } else if ( mretv & MENU_QUICK_SWITCH ) {
+ retv = ( mretv & MENU_LOWER_MASK );
+ } else if ( ( mretv & MENU_OK ) ) {
+ if ( selected_line < pd->array_length )
+ {
+ if ( pd->array[selected_line].type == UP ) {
+ GFile *new = g_file_get_parent ( pd->current_dir );
+ if ( new ){
+ g_object_unref ( pd->current_dir );
+ pd->current_dir = new;
+ free_list (pd);
+ get_file_browser ( sw );
+ return RESET_DIALOG;
+ }
+ } else if ( pd->array[selected_line].type == DIRECTORY ) {
+ GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
+ g_object_unref ( pd->current_dir );
+ pd->current_dir = new;
+ free_list (pd);
+ get_file_browser ( sw );
+ return RESET_DIALOG;
+ } else if ( pd->array[selected_line].type == RFILE ) {
+ char *d = g_strescape ( pd->array[selected_line].path,NULL );
+ char *cmd = g_strdup_printf("xdg-open '%s'", d );
+ g_free(d);
+ char *cdir = g_file_get_path ( pd->current_dir );
+ helper_execute_command ( cdir,cmd, FALSE,NULL );
+ g_free ( cdir );
+ g_free ( cmd );
+ return MODE_EXIT;
+ }
+ }
+ retv = RELOAD_DIALOG;
+ } else if ( (mretv&MENU_CUSTOM_INPUT) && *input ) {
+ char *p = rofi_expand_path ( *input );
+ char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
+ g_free (p);
+ if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) )
+ {
+ if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ){
+ g_object_unref ( pd->current_dir );
+ pd->current_dir = g_file_new_for_path ( dir );
+ g_free ( dir );
+ free_list (pd);
+ get_file_browser ( sw );
+ return RESET_DIALOG;
+ }
+
+ }
+ g_free ( dir );
+ retv = RELOAD_DIALOG;
+ } else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
+ retv = RELOAD_DIALOG;
+ }
+ return retv;
+}
+
+
+static void file_browser_mode_destroy ( Mode *sw )
+{
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+ if ( pd != NULL ) {
+ g_object_unref ( pd->current_dir );
+ free_list ( pd );
+ g_free ( pd );
+ mode_set_private_data ( sw, NULL );
+ }
+}
+
+static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **attr_list, int get_entry )
+{
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+
+ // Only return the string if requested, otherwise only set state.
+ if ( !get_entry ) return NULL;
+ if ( pd->array[selected_line].type == DIRECTORY ){
+ return g_strdup ( pd->array[selected_line].name);
+ } else if ( pd->array[selected_line].type == UP ){
+ return g_strdup( " ..");
+ } else {
+ return g_strdup ( pd->array[selected_line].name);
+ }
+ return g_strdup("n/a");
+}
+
+/**
+ * @param sw The mode object.
+ * @param tokens The tokens to match against.
+ * @param index The index in this plugin to match against.
+ *
+ * Match the entry.
+ *
+ * @param returns try when a match.
+ */
+static int file_browser_token_match ( const Mode *sw, rofi_int_matcher **tokens, unsigned int index )
+{
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+
+ // Call default matching function.
+ return helper_token_match ( tokens, pd->array[index].name);
+}
+
+static cairo_surface_t *_get_icon ( const Mode *sw, unsigned int selected_line, int height )
+{
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+ g_return_val_if_fail ( pd->array != NULL, NULL );
+ FBFile *dr = &( pd->array[selected_line] );
+ if ( dr->icon_fetch_uid > 0 ) {
+ return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
+ }
+ if ( dr->path && (g_str_has_suffix(dr->path, ".png") || g_str_has_suffix(dr->path, "jpeg") || g_str_has_suffix(dr->path, "jpg") )){
+ dr->icon_fetch_uid = rofi_icon_fetcher_query ( dr->path, height );
+ } else {
+ dr->icon_fetch_uid = rofi_icon_fetcher_query ( icon_name[dr->type], height );
+ }
+ return rofi_icon_fetcher_get ( dr->icon_fetch_uid );
+}
+
+static char * _get_message ( const Mode *sw )
+{
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+ if ( pd->current_dir ) {
+ char *dirname = g_file_get_parse_name ( pd->current_dir );
+ char *str = g_markup_printf_escaped("<b>Current directory:</b> %s", dirname);
+ g_free ( dirname );
+ return str;
+ }
+ return "n/a";
+}
+
+
+static char *_get_completion ( const Mode *sw, unsigned int index )
+{
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+
+ char *d = g_strescape ( pd->array[index].path,NULL );
+ return d;
+}
+
+Mode file_browser_mode =
+{
+ .display_name = NULL,
+ .abi_version = ABI_VERSION,
+ .name = "file-browser",
+ .cfg_name_key = "display-file_browser",
+ ._init = file_browser_mode_init,
+ ._get_num_entries = file_browser_mode_get_num_entries,
+ ._result = file_browser_mode_result,
+ ._destroy = file_browser_mode_destroy,
+ ._token_match = file_browser_token_match,
+ ._get_display_value = _get_display_value,
+ ._get_icon = _get_icon,
+ ._get_message = _get_message,
+ ._get_completion = _get_completion,
+ ._preprocess_input = NULL,
+ .private_data = NULL,
+ .free = NULL,
+};
+
+Mode *create_new_file_browser (void )
+{
+ Mode *sw = g_malloc0(sizeof(Mode));
+
+ *sw = file_browser_mode;
+
+ sw->private_data = NULL;
+ return sw;
+}
+
+
+ModeMode file_browser_mode_completer ( Mode *sw, int mretv, char **input, unsigned int selected_line, char **path )
+{
+ ModeMode retv = MODE_EXIT;
+ FileBrowserModePrivateData *pd = (FileBrowserModePrivateData *) mode_get_private_data ( sw );
+ if ( mretv & MENU_NEXT ) {
+ retv = NEXT_DIALOG;
+ } else if ( mretv & MENU_PREVIOUS ) {
+ retv = PREVIOUS_DIALOG;
+ } else if ( mretv & MENU_QUICK_SWITCH ) {
+ retv = ( mretv & MENU_LOWER_MASK );
+ } else if ( ( mretv & MENU_OK ) ) {
+ if ( selected_line < pd->array_length )
+ {
+ if ( pd->array[selected_line].type == UP ) {
+ GFile *new = g_file_get_parent ( pd->current_dir );
+ if ( new ){
+ g_object_unref ( pd->current_dir );
+ pd->current_dir = new;
+ free_list (pd);
+ get_file_browser ( sw );
+ return RESET_DIALOG;
+ }
+ } else if ( pd->array[selected_line].type == DIRECTORY ) {
+ GFile *new = g_file_new_for_path ( pd->array[selected_line].path );
+ g_object_unref ( pd->current_dir );
+ pd->current_dir = new;
+ free_list (pd);
+ get_file_browser ( sw );
+ return RESET_DIALOG;
+ } else if ( pd->array[selected_line].type == RFILE ) {
+ *path = g_strescape ( pd->array[selected_line].path,NULL );
+ return MODE_EXIT;
+ }
+ }
+ retv = RELOAD_DIALOG;
+ } else if ( (mretv&MENU_CUSTOM_INPUT) && *input ) {
+ char *p = rofi_expand_path ( *input );
+ char *dir = g_filename_from_utf8 ( p, -1, NULL, NULL, NULL );
+ g_free (p);
+ if ( g_file_test ( dir, G_FILE_TEST_EXISTS ) )
+ {
+ if ( g_file_test ( dir, G_FILE_TEST_IS_DIR ) ){
+ g_object_unref ( pd->current_dir );
+ pd->current_dir = g_file_new_for_path ( dir );
+ g_free ( dir );
+ free_list (pd);
+ get_file_browser ( sw );
+ return RESET_DIALOG;
+ }
+
+ }
+ g_free ( dir );
+ retv = RELOAD_DIALOG;
+ } else if ( ( mretv & MENU_ENTRY_DELETE ) == MENU_ENTRY_DELETE ) {
+ retv = RELOAD_DIALOG;
+ }
+ return retv;
+}
diff --git a/source/dialogs/run.c b/source/dialogs/run.c
index 30caa8c2..f8df9a5d 100644
--- a/source/dialogs/run.c
+++ b/source/dialogs/run.c
@@ -51,6 +51,7 @@
#include "helper.h"
#include "history.h"
#include "dialogs/run.h"
+#include "dialogs/filebrowser.h"
#include "mode-private.h"
@@ -61,15 +62,31 @@
*/
#define RUN_CACHE_FILE "rofi-3.runcache"
+
+typedef struct
+{
+ char *entry;
+ uint32_t icon_fetch_uid;
+ /* Surface holding the icon. */
+ cairo_surface_t *icon;
+} RunEntry;
+
/**
* The internal data structure holding the private data of the Run Mode.
*/
typedef struct
{
/** list of available commands. */
- char **cmd_list;
+ RunEntry *cmd_list;
/** Length of the #cmd_list. */
unsigned int cmd_list_length;
+ /** Current mode. */
+ gboolean file_complete;
+ uint32_t selected_line;
+ char *old_input;
+
+ Mode *completer;
+ char *old_completer_input;
} RunModePrivateData;
/**
@@ -115,11 +132,11 @@ static void exec_cmd ( const char *cmd, int run_in_term )
*
* Remove command from history.
*/
-static void delete_entry ( const char *cmd )
+static void delete_entry ( const RunEntry *cmd )
{
char *path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
- history_remove ( path, cmd );
+ history_remove ( path, cmd->entry );
g_free ( path );
}
@@ -135,25 +152,25 @@ static void delete_entry ( const char *cmd )
*/
static int sort_func ( const void *a, const void *b, G_GNUC_UNUSED void *data )
{
- const char *astr = *( const char * const * ) a;
- const char *bstr = *( const char * const * ) b;
+ const RunEntry *astr = ( const RunEntry * ) a;
+ const RunEntry *bstr = ( const RunEntry * ) b;
- if ( astr == NULL && bstr == NULL ) {
+ if ( astr->entry == NULL && bstr->entry == NULL ) {
return 0;
}
- else if ( astr == NULL ) {
+ else if ( astr->entry == NULL ) {
return 1;
}
- else if ( bstr == NULL ) {
+ else if ( bstr->entry == NULL ) {
return -1;
}
- return g_strcmp0 ( astr, bstr );
+ return g_strcmp0 ( astr->entry , bstr->entry );
}
/**
* External spider to get list of executables.
*/
-static char ** get_apps_external ( char **retv, unsigned int *length, unsigned int num_favorites )
+static RunEntry * get_apps_external ( RunEntry *retv, unsigned int *length, unsigned int num_favorites )
{
int fd = execute_generator ( config.run_list_command );
if ( fd >= 0 ) {
@@ -172,7 +189,7 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
// This is a nice little penalty, but doable? time will tell.
// given num_favorites is max 25.
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
- if ( strcasecmp ( buffer, retv[j] ) == 0 ) {
+ if ( strcasecmp ( buffer, retv[j].entry ) == 0 ) {
found = 1;
}
}
@@ -182,8 +199,10 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
}
// No duplicate, add it.
- retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
- retv[( *length )] = g_strdup ( buffer );
+ retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( RunEntry ) );
+ retv[( *length )].entry = g_strdup ( buffer );
+ retv[( *length )].icon = NULL;
+ retv[( *length )].icon_fetch_uid = 0;
( *length )++;
}
@@ -196,17 +215,19 @@ static char ** get_apps_external ( char **retv, unsigned int *length, unsigned i
}
}
}
- retv[( *length ) ] = NULL;
+ retv[( *length ) ].entry = NULL;
+ retv[( *length ) ].icon = NULL;
+ retv[( *length ) ].icon_fetch_uid = 0;
return retv;
}
/**
* Internal spider used to get list of executables.
*/
-static char ** get_apps ( unsigned int *length )
+static RunEntry * get_apps ( unsigned int *length )
{
GError *error = NULL;
- char **retv = NULL;
+ RunEntry *retv = NULL;
unsigned int num_favorites = 0;
char *path;
@@ -215,7 +236,12 @@ static char ** get_apps ( unsigned int *length )
}
TICK_N ( "start" );
path = g_build_filename ( cache_dir, RUN_CACHE_FILE, NULL );
- retv = history_get_list ( path, length );
+ char **hretv = history_get_list ( path, length );
+ retv = (RunEntry*)g_malloc0((*length+1)*sizeof(RunEntry));
+ for(unsigned int i =0; i < *length; i++ ){
+ retv[i].entry = hretv[i];
+ }
+ g_free(hretv);
g_free ( path );
// Keep track of how many where loaded as favorite.
num_favorites = ( *length );
@@ -281,7 +307,7 @@ static char ** get_apps ( unsigned int *length )
// given num_favorites is max 25.
int found = 0;
for ( unsigned int j = 0; found == 0 && j < num_favorites; j++ ) {
- if ( g_strcmp0 ( name, retv[j] ) == 0 ) {
+ if ( g_strcmp0 ( name, retv[j].entry ) == 0 ) {
found = 1;
}
}
@@ -291,9 +317,13 @@ static char ** get_apps ( unsigned int *length )
continue;
}
- retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( char* ) );
- retv[( *length )] = name;
- retv[( *length ) + 1] = NULL;
+ retv = g_realloc ( retv, ( ( *length ) + 2 ) * sizeof ( RunEntry ) );
+ retv[( *length )].entry = name;
+ retv[( *length )].icon = NULL;
+ retv[( *length )].icon_fetch_uid = 0;
+ retv[( *length ) + 1].entry = NULL;
+ retv[( *length ) + 1].icon = NULL;
+ retv[( *length ) + 1].icon_fetch_uid = 0;
( *length )++;
}
@@ -312,21 +342,21 @@ static char ** get_apps ( unsigned int *length )
}
// TODO: check this is still fast enough. (takes 1ms on laptop.)
if ( ( *length ) > num_favorites ) {
- g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ), sort_func, NULL );
+ g_qsort_with_data ( &(retv[num_favorites]), ( *length ) - num_favorites, sizeof ( RunEntry ), sort_func, NULL );
}
g_free ( path );
unsigned int removed = 0;
for ( unsigned int index = num_favorites; index < ( ( *length ) - 1 ); index++ ) {
- if ( g_strcmp0 ( retv[index], retv[index + 1] ) == 0 ) {
- g_free ( retv[index] );
- retv[index] = NULL;
+ if ( g_strcmp0 ( retv[index].entry , retv[index + 1].entry ) == 0 ) {
+ g_free ( retv[index].entry );
+ retv[index].entry = NULL;
removed++;
}
}
if ( ( *length ) > num_favorites ) {
- g_qsort_with_data ( &retv[num_favorites], ( *length ) - num_favorites, sizeof ( char* ),
+ g_qsort_with_data ( &(retv[num_favorites]), ( *length ) - num_favorites, sizeof ( RunEntry ),
sort_func,
NULL );
}
@@ -343,6 +373,8 @@ static int run_mode_init ( Mode *sw )
RunModePrivateData *pd = g_malloc0 ( sizeof ( *pd ) );
sw->private_data = (void *) pd;
pd->cmd_list = get_apps ( &( pd->cmd_list_length ) );
+ pd->completer = create_new_file_browser ();
+ mode_init ( pd->completer );
}
return TRUE;
@@ -351,7 +383,16 @@ static void run_mode_destroy ( Mode *sw )
{
RunModePrivateData *rmpd = (RunModePrivateData *) sw->private_data;
if ( rmpd != NULL ) {
- g_strfreev ( rmpd->cmd_list );
+ for ( unsigned int i = 0; i < rmpd->cmd_list_length; i++ ){
+ g_free ( rmpd->cmd_list[i].entry );
+ if ( rmpd->cmd_list[i].icon != NULL ) {
+ cairo_surface_destroy ( rmpd->cmd_list[i].icon );
+ }
+ }
+ g_free ( rmpd->cmd_list );
+ g_free ( rmpd->old_input );
+ g_free ( rmpd->old_completer_input );
+ mode_destroy ( rmpd->completer );
g_free ( rmpd );
sw->private_data = NULL;
}
@@ -360,6 +401,12 @@ static void run_mode_destroy ( Mode *sw )
static unsigned int run_mode_get_num_entries ( const Mode *sw )
{
const RunModePrivateData *rmpd = (const RunModePrivateData *) sw->private_data;
+
+ if ( rmpd->file_complete ){
+ return rmpd->completer->_get_num_entries( rmpd->completer );
+ }
+
+
return rmpd->cmd_list_length;
}
@@ -369,6 +416,39 @@ static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned in
ModeMode retv = MODE_EXIT;
gboolean run_in_term = ( ( mretv & MENU_CUSTOM_ACTION ) == MENU_CUSTOM_ACTION );
+ if ( rmpd->file_complete == TRUE ) {
+
+ retv = RELOAD_DIALOG;
+
+ if ( ( mretv& (MENU_COMPLETE)) ) {
+ g_free ( rmpd->old_completer_input );
+ rmpd->old_completer_input = *input;
+ *input = NULL;
+ if ( rmpd->selected_line < rmpd->cmd_list_length ) {
+ (*input) = g_strdup ( rmpd->old_input );
+ }
+ rmpd->file_complete = FALSE;
+ } else if ( (mretv&MENU_CANCEL) ) {
+ retv = MODE_EXIT;
+ } else {
+ char *path = NULL;
+ retv = file_browser_mode_completer ( rmpd->completer, mretv, input, selected_line, &path );
+ if ( retv == MODE_EXIT ) {
+ if ( path == NULL )
+ {
+ exec_cmd ( rmpd->cmd_list[rmpd->selected_line].entry, run_in_term );
+ } else {
+ char *arg= g_strdup_printf ( "%s '%s'", rmpd->cmd_list[rmpd->selected_line].entry, path);
+ printf("Comnad: %s\r\n", arg);
+ exec_cmd ( arg, run_in_term );
+ g_free(arg);
+ }
+
+ }
+ g_free (path);
+ }
+ return retv;
+ }
if ( mretv & MENU_NEXT ) {
retv = NEXT_DIALOG;
@@ -379,33 +459,94 @@ static ModeMode run_mode_result ( Mode *sw, int mretv, char **input, unsigned in
else if ( mretv & MENU_QUICK_SWITCH ) {
retv = ( mretv & MENU_LOWER_MASK );
}
- else if ( ( mretv & MENU_OK ) && rmpd->cmd_list[selected_line] != NULL ) {
- exec_cmd ( rmpd->cmd_list[selected_line], run_in_term );
+ else if ( ( mretv & MENU_OK ) && selected_line < rmpd->cmd_list_length ) {
+ exec_cmd ( rmpd->cmd_list[selected_line].entry, run_in_term );
}
else if ( ( mretv & MENU_CUSTOM_INPUT ) && *input != NULL && *input[0] != '\0' ) {
exec_cmd ( *input, run_in_term );
}
- else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line] ) {
- delete_entry ( rmpd->cmd_list[selected_line] );
+ else if ( ( mretv & MENU_ENTRY_DELETE ) && rmpd->cmd_list[selected_line].entry ) {
+ delete_entry ( &(rmpd->cmd_list[selected_line]) );
// Clear the list.
retv = RELOAD_DIALOG;
run_mode_destroy ( sw );
run_mode_init ( sw );
}
+ else if ( ( mretv& MENU_COMPLETE) ) {
+ retv = RELOAD_DIALOG;
+ if ( selected_line < rmpd->cmd_list_length ) {
+ rmpd->selected_line = selected_line;
+
+ g_free ( rmpd->old_input );
+ rmpd->old_input = g_strdup ( *input );
+
+ if ( *input ) g_free (*input);
+ *input = g_strdup ( rmpd->old_completer_input );
+
+ rmpd->file_complete = TRUE;
+ }
+ }
return retv;
}
-static char *_get_display_value ( const Mode *sw, unsigned int selected_line, G_GNUC_UNUSED int *state, G_GNUC_UNUSED GList **list, int get_entry )
+static char *_get_display_value ( const Mode *sw, unsigned int selected