Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
GNOME
gtk
Commits
6056f185
Commit
6056f185
authored
Dec 03, 2012
by
Federico Mena Quintero
Browse files
Merge branch 'bgo658280-filechooser-recently-used-2-24' into gtk-2-24
parents
1eb0d98d
f52befa7
Changes
4
Hide whitespace changes
Inline
Side-by-side
gtk/gtkfilechooserdefault.c
View file @
6056f185
...
...
@@ -235,6 +235,7 @@ enum {
typedef
enum
{
SHORTCUTS_SEARCH
,
SHORTCUTS_RECENT
,
SHORTCUTS_CWD
,
SHORTCUTS_RECENT_SEPARATOR
,
SHORTCUTS_HOME
,
SHORTCUTS_DESKTOP
,
...
...
@@ -1387,6 +1388,13 @@ shortcuts_update_count (GtkFileChooserDefault *impl,
{
switch
(
type
)
{
case
SHORTCUTS_CWD
:
if
(
value
<
0
)
impl
->
has_cwd
=
FALSE
;
else
impl
->
has_cwd
=
TRUE
;
break
;
case
SHORTCUTS_HOME
:
if
(
value
<
0
)
impl
->
has_home
=
FALSE
;
...
...
@@ -1444,7 +1452,6 @@ get_file_info_finished (GCancellable *cancellable,
const
GError
*
error
,
gpointer
data
)
{
gint
pos
=
-
1
;
gboolean
cancelled
=
g_cancellable_is_cancelled
(
cancellable
);
GdkPixbuf
*
pixbuf
;
GtkTreePath
*
path
;
...
...
@@ -1457,7 +1464,6 @@ get_file_info_finished (GCancellable *cancellable,
/* Handle doesn't exist anymore in the model */
goto
out
;
pos
=
gtk_tree_path_get_indices
(
path
)[
0
];
gtk_tree_model_get_iter
(
GTK_TREE_MODEL
(
request
->
impl
->
shortcuts_model
),
&
iter
,
path
);
gtk_tree_path_free
(
path
);
...
...
@@ -1754,6 +1760,45 @@ shortcuts_append_recent (GtkFileChooserDefault *impl)
g_object_unref
(
pixbuf
);
}
/* Appends the current working directory to the shortuts panel, but only if it is not equal to $HOME.
* This is so that the user can actually use the $CWD, for example, if running an application
* from the shell.
*/
static
void
shortcuts_append_cwd
(
GtkFileChooserDefault
*
impl
)
{
char
*
cwd
;
const
char
*
home
;
GFile
*
cwd_file
;
GFile
*
home_file
;
impl
->
has_cwd
=
FALSE
;
cwd
=
g_get_current_dir
();
if
(
cwd
==
NULL
)
return
;
home
=
g_get_home_dir
();
if
(
home
==
NULL
)
{
g_free
(
cwd
);
return
;
}
cwd_file
=
g_file_new_for_path
(
cwd
);
home_file
=
g_file_new_for_path
(
home
);
if
(
!
g_file_equal
(
cwd_file
,
home_file
))
{
shortcuts_insert_file
(
impl
,
-
1
,
SHORTCUT_TYPE_FILE
,
NULL
,
cwd_file
,
NULL
,
FALSE
,
SHORTCUTS_CWD
);
impl
->
has_cwd
=
TRUE
;
}
g_object_unref
(
cwd_file
);
g_object_unref
(
home_file
);
g_free
(
cwd
);
}
/* Appends an item for the user's home directory to the shortcuts model */
static
void
shortcuts_append_home
(
GtkFileChooserDefault
*
impl
)
...
...
@@ -1869,6 +1914,11 @@ shortcuts_get_index (GtkFileChooserDefault *impl,
n
+=
1
;
/* we always have the recently-used item */
if
(
where
==
SHORTCUTS_CWD
)
goto
out
;
n
+=
impl
->
has_cwd
?
1
:
0
;
if
(
where
==
SHORTCUTS_RECENT_SEPARATOR
)
goto
out
;
...
...
@@ -2170,6 +2220,7 @@ shortcuts_model_create (GtkFileChooserDefault *impl)
if
(
impl
->
file_system
)
{
shortcuts_append_cwd
(
impl
);
shortcuts_append_home
(
impl
);
shortcuts_append_desktop
(
impl
);
shortcuts_add_volumes
(
impl
);
...
...
@@ -3359,6 +3410,10 @@ shortcuts_build_popup_menu (GtkFileChooserDefault *impl)
G_CALLBACK
(
rename_shortcut_cb
),
impl
);
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
impl
->
browse_shortcuts_popup_menu
),
item
);
item
=
gtk_separator_menu_item_new
();
gtk_widget_show
(
item
);
gtk_menu_shell_append
(
GTK_MENU_SHELL
(
impl
->
browse_shortcuts_popup_menu
),
item
);
}
static
void
...
...
@@ -5865,6 +5920,7 @@ settings_load (GtkFileChooserDefault *impl)
gboolean
show_size_column
;
gint
sort_column
;
GtkSortType
sort_order
;
StartupMode
startup_mode
;
settings
=
_gtk_file_chooser_settings_new
();
...
...
@@ -5873,6 +5929,7 @@ settings_load (GtkFileChooserDefault *impl)
show_size_column
=
_gtk_file_chooser_settings_get_show_size_column
(
settings
);
sort_column
=
_gtk_file_chooser_settings_get_sort_column
(
settings
);
sort_order
=
_gtk_file_chooser_settings_get_sort_order
(
settings
);
startup_mode
=
_gtk_file_chooser_settings_get_startup_mode
(
settings
);
g_object_unref
(
settings
);
...
...
@@ -5889,6 +5946,8 @@ settings_load (GtkFileChooserDefault *impl)
* created yet. The individual functions that create and set the models will
* call set_sort_column() themselves.
*/
impl
->
startup_mode
=
startup_mode
;
}
static
void
...
...
@@ -5935,6 +5994,7 @@ settings_save (GtkFileChooserDefault *impl)
_gtk_file_chooser_settings_set_show_size_column
(
settings
,
impl
->
show_size_column
);
_gtk_file_chooser_settings_set_sort_column
(
settings
,
impl
->
sort_column
);
_gtk_file_chooser_settings_set_sort_order
(
settings
,
impl
->
sort_order
);
_gtk_file_chooser_settings_set_startup_mode
(
settings
,
impl
->
startup_mode
);
save_dialog_geometry
(
impl
,
settings
);
...
...
@@ -5981,6 +6041,38 @@ get_file_for_last_folder_opened (GtkFileChooserDefault *impl)
return
file
;
}
/* Changes the current folder to $CWD */
static
void
switch_to_cwd
(
GtkFileChooserDefault
*
impl
)
{
char
*
current_working_dir
;
current_working_dir
=
g_get_current_dir
();
gtk_file_chooser_set_current_folder
(
GTK_FILE_CHOOSER
(
impl
),
current_working_dir
);
g_free
(
current_working_dir
);
}
/* Sets the file chooser to showing Recent Files or $CWD, depending on the
* user's settings.
*/
static
void
set_startup_mode
(
GtkFileChooserDefault
*
impl
)
{
switch
(
impl
->
startup_mode
)
{
case
STARTUP_MODE_RECENT
:
recent_shortcut_handler
(
impl
);
break
;
case
STARTUP_MODE_CWD
:
switch_to_cwd
(
impl
);
break
;
default:
g_assert_not_reached
();
}
}
/* GtkWidget::map method */
static
void
gtk_file_chooser_default_map
(
GtkWidget
*
widget
)
...
...
@@ -5993,12 +6085,14 @@ gtk_file_chooser_default_map (GtkWidget *widget)
GTK_WIDGET_CLASS
(
_gtk_file_chooser_default_parent_class
)
->
map
(
widget
);
settings_load
(
impl
);
if
(
impl
->
operation_mode
==
OPERATION_MODE_BROWSE
)
{
switch
(
impl
->
reload_state
)
{
case
RELOAD_EMPTY
:
recent_shortcut_handler
(
impl
);
set_startup_mode
(
impl
);
break
;
case
RELOAD_HAS_FOLDER
:
...
...
@@ -6014,8 +6108,6 @@ gtk_file_chooser_default_map (GtkWidget *widget)
volumes_bookmarks_changed_cb
(
impl
->
file_system
,
impl
);
settings_load
(
impl
);
profile_end
(
"end"
,
NULL
);
}
...
...
gtk/gtkfilechooserprivate.h
View file @
6056f185
...
...
@@ -152,6 +152,11 @@ typedef enum {
OPERATION_MODE_RECENT
}
OperationMode
;
typedef
enum
{
STARTUP_MODE_RECENT
,
STARTUP_MODE_CWD
}
StartupMode
;
struct
_GtkFileChooserDefault
{
GtkVBox
parent_instance
;
...
...
@@ -195,6 +200,8 @@ struct _GtkFileChooserDefault
GtkFileSystemModel
*
browse_files_model
;
char
*
browse_files_last_selected_name
;
StartupMode
startup_mode
;
/* OPERATION_MODE_SEARCH */
GtkWidget
*
search_hbox
;
GtkWidget
*
search_entry
;
...
...
@@ -297,6 +304,7 @@ struct _GtkFileChooserDefault
guint
list_sort_ascending
:
1
;
guint
changing_folder
:
1
;
guint
shortcuts_current_folder_active
:
1
;
guint
has_cwd
:
1
;
guint
has_home
:
1
;
guint
has_desktop
:
1
;
guint
has_search
:
1
;
...
...
gtk/gtkfilechoosersettings.c
View file @
6056f185
...
...
@@ -48,6 +48,7 @@
#define GEOMETRY_HEIGHT_KEY "GeometryHeight"
#define SORT_COLUMN_KEY "SortColumn"
#define SORT_ORDER_KEY "SortOrder"
#define STARTUP_MODE_KEY "StartupMode"
#define COLUMN_NAME_STRING "name"
#define COLUMN_MTIME_STRING "modified"
...
...
@@ -55,6 +56,9 @@
#define SORT_ASCENDING_STRING "ascending"
#define SORT_DESCENDING_STRING "descending"
#define STARTUP_MODE_RECENT_STRING "recent"
#define STARTUP_MODE_CWD_STRING "cwd"
#define MODE_PATH_BAR "path-bar"
#define MODE_FILENAME_ENTRY "filename-entry"
...
...
@@ -113,6 +117,7 @@ ensure_settings_read (GtkFileChooserSettings *settings)
GKeyFile
*
key_file
;
gchar
*
location_mode_str
,
*
filename
;
gchar
*
sort_column
,
*
sort_order
;
gchar
*
startup_mode
;
gboolean
value
;
if
(
settings
->
settings_read
)
...
...
@@ -220,6 +225,23 @@ ensure_settings_read (GtkFileChooserSettings *settings)
g_free
(
sort_order
);
}
/* Startup mode */
startup_mode
=
g_key_file_get_string
(
key_file
,
SETTINGS_GROUP
,
STARTUP_MODE_KEY
,
NULL
);
if
(
startup_mode
)
{
if
(
EQ
(
STARTUP_MODE_RECENT_STRING
,
startup_mode
))
settings
->
startup_mode
=
STARTUP_MODE_RECENT
;
else
if
(
EQ
(
STARTUP_MODE_CWD_STRING
,
startup_mode
))
settings
->
startup_mode
=
STARTUP_MODE_CWD
;
else
g_warning
(
"Unknown startup mode '%s' encountered in filechooser settings"
,
startup_mode
);
g_free
(
startup_mode
);
}
out:
g_key_file_free
(
key_file
);
...
...
@@ -248,6 +270,7 @@ _gtk_file_chooser_settings_init (GtkFileChooserSettings *settings)
settings
->
geometry_y
=
-
1
;
settings
->
geometry_width
=
-
1
;
settings
->
geometry_height
=
-
1
;
settings
->
startup_mode
=
STARTUP_MODE_RECENT
;
}
GtkFileChooserSettings
*
...
...
@@ -367,6 +390,20 @@ _gtk_file_chooser_settings_set_sort_order (GtkFileChooserSettings *settings,
settings
->
sort_order
=
sort_order
;
}
void
_gtk_file_chooser_settings_set_startup_mode
(
GtkFileChooserSettings
*
settings
,
StartupMode
startup_mode
)
{
settings
->
startup_mode
=
startup_mode
;
}
StartupMode
_gtk_file_chooser_settings_get_startup_mode
(
GtkFileChooserSettings
*
settings
)
{
ensure_settings_read
(
settings
);
return
settings
->
startup_mode
;
}
gboolean
_gtk_file_chooser_settings_save
(
GtkFileChooserSettings
*
settings
,
GError
**
error
)
...
...
@@ -377,6 +414,7 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
gchar
*
contents
;
gchar
*
sort_column
;
gchar
*
sort_order
;
gchar
*
startup_mode
;
gsize
len
;
gboolean
retval
;
GKeyFile
*
key_file
;
...
...
@@ -432,6 +470,21 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
sort_order
=
NULL
;
}
switch
(
settings
->
startup_mode
)
{
case
STARTUP_MODE_RECENT
:
startup_mode
=
STARTUP_MODE_RECENT_STRING
;
break
;
case
STARTUP_MODE_CWD
:
startup_mode
=
STARTUP_MODE_CWD_STRING
;
break
;
default:
g_assert_not_reached
();
startup_mode
=
NULL
;
}
key_file
=
g_key_file_new
();
/* Initialise with the on-disk keyfile, so we keep unknown options */
...
...
@@ -457,6 +510,8 @@ _gtk_file_chooser_settings_save (GtkFileChooserSettings *settings,
SORT_COLUMN_KEY
,
sort_column
);
g_key_file_set_string
(
key_file
,
SETTINGS_GROUP
,
SORT_ORDER_KEY
,
sort_order
);
g_key_file_set_string
(
key_file
,
SETTINGS_GROUP
,
STARTUP_MODE_KEY
,
startup_mode
);
contents
=
g_key_file_to_data
(
key_file
,
&
len
,
error
);
g_key_file_free
(
key_file
);
...
...
gtk/gtkfilechoosersettings.h
View file @
6056f185
...
...
@@ -50,6 +50,7 @@ struct _GtkFileChooserSettings
GtkSortType
sort_order
;
gint
sort_column
;
StartupMode
startup_mode
;
int
geometry_x
;
int
geometry_y
;
...
...
@@ -104,6 +105,10 @@ void _gtk_file_chooser_settings_set_geometry (GtkFileChooserSettings *settings,
int
width
,
int
heigth
);
void
_gtk_file_chooser_settings_set_startup_mode
(
GtkFileChooserSettings
*
settings
,
StartupMode
startup_mode
);
StartupMode
_gtk_file_chooser_settings_get_startup_mode
(
GtkFileChooserSettings
*
settings
);
gboolean
_gtk_file_chooser_settings_save
(
GtkFileChooserSettings
*
settings
,
GError
**
error
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment