Commit 27f54a9a authored by Sébastien Wilmet's avatar Sébastien Wilmet
Browse files

replace-open-button: remove OpenDocumentSelector

This will be replaced by the previous UI: two buttons, "Open" to open
the dialog, and an arrow to open the recent menu.

It's a pragmatic decision to simplify the gedit code, because there are
not enough developers, and too many bugs. Do you prefer a rock-solid
text editor? Or a text editor with some shiny and non-essential features
that complexifies the code, at the expense of more bugs? The gedit core
should have a much smaller code size, with all the essential features
implemented in libraries.

The OpenDocumentSelector showed only 5 items, while the normal menu can
show more (10 by default).

The search inside the popover duplicated the search in the file chooser
dialog. To open a file, one search entry is enough, it avoids a possible
confusion.

The OpenDocumentSelector showed all recent text files, not just those
previously opened in gedit. Again, this duplicates the feature present
in the file chooser dialog. The new simple menu will show only files
previously opened in gedit, which is IMHO more logical.

There is also the fact that the OpenDocumentSelector used GtkTreeView.
It is planned at some point in the future that GtkTreeView will be
removed from GTK. Porting to GtkListBox would be a lot of work.

The full file paths will also be visible with the new simple menu, in
the statusbar.

GeditOpenDocumentSelector was never adopted by other GNOME apps. gedit
was the only app with such an open file popover. It takes almost 3000
lines of code to do so. While the simple menu takes less than 100's (in
gedit). So the OpenDocumentSelector complicated a lot the code of gedit.
parent 74e0be7e
......@@ -51,9 +51,6 @@ libgedit_reference_ignored_h = [
'gedit-notebook-popup-menu.h',
'gedit-notebook-stack-switcher.h',
'gedit-notebook.h',
'gedit-open-document-selector-helper.h',
'gedit-open-document-selector-store.h',
'gedit-open-document-selector.h',
'gedit-open-menu-button.h',
'gedit-pango.h',
'gedit-plugins-engine.h',
......
/*
* gedit-open-document-selector-helper.c
* This file is part of gedit
*
* Copyright (C) 2015 - Sébastien Lafargue
*
* gedit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gedit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
#include "gedit-open-document-selector-helper.h"
void
gedit_open_document_selector_debug_print_list (const gchar *title,
GList *fileitem_list)
{
FileItem *item;
GList *l;
glong time_sec;
glong time_usec;
g_print ("%s\n", title);
for (l = fileitem_list; l != NULL; l = l->next)
{
item = (FileItem *)l->data;
time_sec = item->access_time.tv_sec;
time_usec = item->access_time.tv_usec;
g_print ("%ld:%ld uri:%s (%s %s)\n",
time_sec,
time_usec,
item->uri,
item->name,
item->path);
}
}
FileItem *
gedit_open_document_selector_create_fileitem_item (void)
{
FileItem *item;
item = g_slice_new0 (FileItem);
return item;
}
void
gedit_open_document_selector_free_fileitem_item (FileItem *item)
{
g_free (item->uri);
g_free (item->name);
g_free (item->path);
g_slice_free (FileItem, item);
}
FileItem *
gedit_open_document_selector_copy_fileitem_item (FileItem *item)
{
FileItem *new_item;
new_item = gedit_open_document_selector_create_fileitem_item ();
new_item->uri = g_strdup (item->uri);
new_item->name = g_strdup (item->name);
new_item->path = g_strdup (item->path);
new_item->access_time = item->access_time;
return new_item;
}
inline GList *
gedit_open_document_selector_copy_file_items_list (const GList *file_items_list)
{
GList *new_file_items_list;
new_file_items_list = g_list_copy_deep ((GList *)file_items_list,
(GCopyFunc)gedit_open_document_selector_copy_fileitem_item,
NULL);
return new_file_items_list;
}
inline void
gedit_open_document_selector_free_file_items_list (GList *file_items_list)
{
g_list_free_full (file_items_list,
(GDestroyNotify)gedit_open_document_selector_free_fileitem_item);
}
/* ex:set ts=8 noet: */
/*
* gedit-open-document-selector-helper.h
* This file is part of gedit
*
* Copyright (C) 2015 - Sébastien Lafargue
*
* gedit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gedit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GEDIT_OPEN_DOCUMENT_SELECTOR_HELPER_H
#define GEDIT_OPEN_DOCUMENT_SELECTOR_HELPER_H
#include "gedit-open-document-selector.h"
#include <glib-object.h>
G_BEGIN_DECLS
typedef struct
{
gchar *uri;
gchar *name;
gchar *path;
GTimeVal access_time;
} FileItem;
typedef enum
{
GEDIT_OPEN_DOCUMENT_SELECTOR_RECENT_FILES_LIST = 0,
GEDIT_OPEN_DOCUMENT_SELECTOR_HOME_DIR_LIST,
GEDIT_OPEN_DOCUMENT_SELECTOR_DESKTOP_DIR_LIST,
GEDIT_OPEN_DOCUMENT_SELECTOR_LOCAL_BOOKMARKS_DIR_LIST,
GEDIT_OPEN_DOCUMENT_SELECTOR_FILE_BROWSER_ROOT_DIR_LIST,
GEDIT_OPEN_DOCUMENT_SELECTOR_ACTIVE_DOC_DIR_LIST,
GEDIT_OPEN_DOCUMENT_SELECTOR_CURRENT_DOCS_LIST,
GEDIT_OPEN_DOCUMENT_SELECTOR_LIST_TYPE_NUM_OF_LISTS
} ListType;
/* Use #if 1 and rebuild to activate selector debugging and timing */
#if 0
#define DEBUG_OPEN_DOCUMENT_SELECTOR
#endif
#ifdef DEBUG_OPEN_DOCUMENT_SELECTOR
G_GNUC_UNUSED static const gchar *list_type_string[] =
{
"RECENT_FILES_LIST",
"HOME_DIR_LIST",
"DESKTOP_DIR_LIST",
"LOCAL_BOOKMARKS_DIR_LIST",
"FILE_BROWSER_ROOT_DIR_LIST",
"ACTIVE_DOC_DIR_LIST",
"CURRENT_DOCS_LIST"
};
#define DEBUG_SELECTOR(x) do { x; } while (0)
#define DEBUG_SELECTOR_TIMER_DECL G_GNUC_UNUSED GTimer *debug_timer;
#define DEBUG_SELECTOR_TIMER_NEW debug_timer = g_timer_new ();
#define DEBUG_SELECTOR_TIMER_DESTROY g_timer_destroy (debug_timer);
#define DEBUG_SELECTOR_TIMER_GET g_timer_elapsed (debug_timer, NULL)
#else
#define DEBUG_SELECTOR(x)
#define DEBUG_SELECTOR_TIMER_DECL
#define DEBUG_SELECTOR_TIMER_NEW
#define DEBUG_SELECTOR_TIMER_DESTROY
#define DEBUG_SELECTOR_TIMER_GET
#endif
typedef struct
{
GeditOpenDocumentSelector *selector;
ListType type;
} PushMessage;
void gedit_open_document_selector_debug_print_list (const gchar *title,
GList *fileitem_list);
GList *gedit_open_document_selector_copy_file_items_list (const GList *file_items_list);
void gedit_open_document_selector_free_file_items_list (GList *file_items_list);
FileItem *gedit_open_document_selector_create_fileitem_item (void);
void gedit_open_document_selector_free_fileitem_item (FileItem *item);
FileItem *gedit_open_document_selector_copy_fileitem_item (FileItem *item);
G_END_DECLS
#endif /* GEDIT_OPEN_DOCUMENT_SELECTOR_HELPER_H */
/* ex:set ts=8 noet: */
This diff is collapsed.
/*
* gedit-open-document-selector-store.h
* This file is part of gedit
*
* Copyright (C) 2015 - Sébastien Lafargue
*
* gedit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gedit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GEDIT_OPEN_DOCUMENT_SELECTOR_STORE_H
#define GEDIT_OPEN_DOCUMENT_SELECTOR_STORE_H
#include "gedit-open-document-selector-helper.h"
#include "gedit-open-document-selector.h"
#include <glib-object.h>
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GEDIT_TYPE_OPEN_DOCUMENT_SELECTOR_STORE (gedit_open_document_selector_store_get_type ())
G_DECLARE_FINAL_TYPE (GeditOpenDocumentSelectorStore, gedit_open_document_selector_store, GEDIT, OPEN_DOCUMENT_SELECTOR_STORE, GObject)
#define GEDIT_OPEN_DOCUMENT_SELECTOR_STORE_ERROR gedit_open_document_selector_store_error_quark ()
typedef enum
{
TYPE_OUT_OF_RANGE
} GeditOpenDocumentSelectorStoreError;
GQuark gedit_open_document_selector_store_error_quark (void);
gint gedit_open_document_selector_store_get_recent_limit (GeditOpenDocumentSelectorStore *store);
void gedit_open_document_selector_store_set_filter (GeditOpenDocumentSelectorStore *store,
const gchar *filter);
gchar *gedit_open_document_selector_store_get_filter (GeditOpenDocumentSelectorStore *store);
GList *gedit_open_document_selector_store_update_list_finish (GeditOpenDocumentSelectorStore *open_document_selector_store,
GAsyncResult *res,
GError **error);
void gedit_open_document_selector_store_update_list_async (GeditOpenDocumentSelectorStore *open_document_selector_store,
GeditOpenDocumentSelector *open_document_selector,
GCancellable *cancellable,
GAsyncReadyCallback callback,
ListType type,
gpointer user_data);
GeditOpenDocumentSelectorStore *gedit_open_document_selector_store_get_default (void);
G_END_DECLS
#endif /* GEDIT_OPEN_DOCUMENT_SELECTOR_STORE_H */
/* ex:set ts=8 noet: */
This diff is collapsed.
/*
* gedit-open-document-selector.h
* This file is part of gedit
*
* Copyright (C) 2014 - Sébastien Lafargue
*
* gedit is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* gedit is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with gedit. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GEDIT_OPEN_DOCUMENT_SELECTOR_H
#define GEDIT_OPEN_DOCUMENT_SELECTOR_H
#include <glib-object.h>
#include "gedit-window.h"
#include <gtk/gtk.h>
G_BEGIN_DECLS
#define GEDIT_TYPE_OPEN_DOCUMENT_SELECTOR (gedit_open_document_selector_get_type ())
G_DECLARE_FINAL_TYPE (GeditOpenDocumentSelector, gedit_open_document_selector, GEDIT, OPEN_DOCUMENT_SELECTOR, GtkBox)
GeditOpenDocumentSelector *gedit_open_document_selector_new (GeditWindow *window);
GeditWindow *gedit_open_document_selector_get_window (GeditOpenDocumentSelector *selector);
GtkWidget *gedit_open_document_selector_get_search_entry (GeditOpenDocumentSelector *selector);
G_END_DECLS
#endif /* GEDIT_OPEN_DOCUMENT_SELECTOR_H */
/* ex:set ts=8 noet: */
......@@ -27,7 +27,6 @@
#include "gedit-message-bus.h"
#include "gedit-settings.h"
#include "gedit-multi-notebook.h"
#include "gedit-open-document-selector.h"
G_BEGIN_DECLS
......@@ -63,7 +62,6 @@ struct _GeditWindowPrivate
GtkWidget *fullscreen_new_button;
GtkWidget *fullscreen_open_button;
GtkWidget *fullscreen_open_document_popover;
GeditOpenDocumentSelector *fullscreen_open_document_selector;
/* statusbar and context ids for statusbar messages */
GtkWidget *statusbar;
......@@ -87,7 +85,6 @@ struct _GeditWindowPrivate
GtkWidget *open_document_popover;
GtkWidget *new_button;
GtkWidget *open_button;
GeditOpenDocumentSelector *open_document_selector;
GtkMenuButton *gear_button;
......
......@@ -56,7 +56,6 @@
#include "gedit-settings.h"
#include "gedit-menu-stack-switcher.h"
#include "gedit-highlight-mode-selector.h"
#include "gedit-open-document-selector.h"
#define TAB_WIDTH_DATA "GeditWindowTabWidthData"
#define FULLSCREEN_ANIMATION_SPEED 500
......@@ -782,46 +781,6 @@ update_actions_sensitivity (GeditWindow *window)
window);
}
static void
on_recent_chooser_item_activated (GeditOpenDocumentSelector *open_document_selector,
gchar *uri,
GeditWindow *window)
{
GFile *location;
GeditView *active_view;
g_return_if_fail (GEDIT_WINDOW (window));
g_return_if_fail (GEDIT_OPEN_DOCUMENT_SELECTOR (open_document_selector));
/* TODO: get_current_file when exists */
location = g_file_new_for_uri (uri);
if (location)
{
GSList *locations = NULL;
GSList *loaded = NULL;
locations = g_slist_prepend (locations, (gpointer) location);
loaded = gedit_commands_load_locations (window, locations, NULL, 0, 0);
/* if it doesn't contain just 1 element */
if (!loaded || loaded->next)
{
gedit_recent_remove_if_local (location);
}
g_slist_free (locations);
g_slist_free (loaded);
g_object_unref (location);
}
/* Needed to close the popover when activating the same
* document as the current one */
active_view = gedit_window_get_active_view (window);
gtk_widget_grab_focus (GTK_WIDGET (active_view));
}
static void
on_language_selector_shown (GeditHighlightModeSelector *sel,
GeditWindow *window)
......@@ -1835,18 +1794,6 @@ fullscreen_controls_setup (GeditWindow *window)
priv->fullscreen_open_document_popover = gtk_popover_new (priv->fullscreen_open_button);
gtk_menu_button_set_popover (GTK_MENU_BUTTON (priv->fullscreen_open_button),
priv->fullscreen_open_document_popover);
window->priv->fullscreen_open_document_selector = gedit_open_document_selector_new (window);
gtk_container_add (GTK_CONTAINER (priv->fullscreen_open_document_popover),
GTK_WIDGET (priv->fullscreen_open_document_selector));
gtk_widget_show_all (GTK_WIDGET (priv->fullscreen_open_document_selector));
g_signal_connect (window->priv->fullscreen_open_document_selector,
"file-activated",
G_CALLBACK (on_recent_chooser_item_activated),
window);
}
static void
......@@ -2757,27 +2704,9 @@ gedit_window_init (GeditWindow *window)
gtk_menu_button_set_popover (GTK_MENU_BUTTON (window->priv->open_button),
window->priv->open_document_popover);
window->priv->open_document_selector = gedit_open_document_selector_new (window);
gtk_container_add (GTK_CONTAINER (window->priv->open_document_popover),
GTK_WIDGET (window->priv->open_document_selector));
gtk_widget_show_all (GTK_WIDGET (window->priv->open_document_selector));
g_signal_connect (window->priv->open_document_selector,
"file-activated",
G_CALLBACK (on_recent_chooser_item_activated),
window);
fullscreen_controls_setup (window);
sync_fullscreen_actions (window, FALSE);
g_object_bind_property (gedit_open_document_selector_get_search_entry (window->priv->open_document_selector),
"text",
gedit_open_document_selector_get_search_entry (window->priv->fullscreen_open_document_selector),
"text",
G_BINDING_BIDIRECTIONAL | G_BINDING_SYNC_CREATE);
hamburger_menu = _gedit_app_get_hamburger_menu (GEDIT_APP (g_application_get_default ()));
if (hamburger_menu)
{
......
......@@ -38,9 +38,6 @@ libgedit_private_h = files(
'gedit-notebook.h',
'gedit-notebook-popup-menu.h',
'gedit-notebook-stack-switcher.h',
'gedit-open-document-selector.h',
'gedit-open-document-selector-helper.h',
'gedit-open-document-selector-store.h',
'gedit-pango.h',
'gedit-plugins-engine.h',
'gedit-preferences-dialog.h',
......@@ -88,9 +85,6 @@ libgedit_sources = files(
'gedit-notebook.c',
'gedit-notebook-popup-menu.c',
'gedit-notebook-stack-switcher.c',
'gedit-open-document-selector.c',
'gedit-open-document-selector-helper.c',
'gedit-open-document-selector-store.c',
'gedit-pango.c',
'gedit-plugins-engine.c',
'gedit-preferences-dialog.c',
......
......@@ -14,10 +14,6 @@
padding: 12px;
}
.open-document-selector-treeview {
padding: 3px 6px 3px 6px;
}
statusbar frame {
border: none;
padding-left: 6px;
......
.open-document-selector-treeview:hover {
background-color: alpha(@theme_fg_color, 0.05);
}
.open-document-selector-treeview:selected:hover {
background-color: @theme_selected_bg_color;
}
/* Only normal state is handle */
.open-document-selector-name-label {
color: @theme_fg_color;
}
/* Only normal state is handle */
.open-document-selector-path-label {
color: @theme_unfocused_fg_color;
font-size: smaller;
}
/* Only normal state is handle */
.open-document-selector-match {
color: shade (@theme_fg_color, 0.6);
background-color: alpha(@warning_color, 0.4);
}
.gedit-document-panel {
background-color: @sidebar_bg;
}
......@@ -84,4 +59,3 @@ statusbar {
margin: 2px;
padding: 2px;
}
......@@ -16,7 +16,6 @@
<file preprocess="xml-stripblanks">ui/gedit-highlight-mode-dialog.ui</file>
<file preprocess="xml-stripblanks">ui/gedit-highlight-mode-selector.ui</file>
<file preprocess="xml-stripblanks">ui/gedit-window.ui</file>
<file preprocess="xml-stripblanks">ui/gedit-open-document-selector.ui</file>
<file preprocess="xml-stripblanks">ui/gedit-shortcuts.ui</file>
<file preprocess="xml-stripblanks">ui/gedit-statusbar.ui</file>
<file>css/gedit-style.css</file>
......
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="3.10"/>
<template class="GeditOpenDocumentSelector" parent="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">9</property>
<property name="orientation">vertical</property>
<property name="spacing">6</property>
<child>
<object class="GtkSearchEntry" id="search_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="primary_icon_name">edit-find-symbolic</property>
<property name="primary_icon_activatable">False</property>
<property name="primary_icon_sensitive">False</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="position">0</property>
</packing>
</child>
<child>
<object class="GtkFrame" id="placeholder_box">
<property name="visible">False</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkBox" id="placeholder_inner_box">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="halign">center</property>
<property name="valign">center</property>
<child>
<object class="GtkImage" id="placeholder_image">
<property name="visible">True</property>
<property name="icon_name">edit-find-symbolic</property>
<property name="pixel_size">64</property>
<property name="can_focus">False</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
<child>
<object class="GtkLabel" id="placeholder_label">
<property name="visible">True</property>
<property name="sensitive">False</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">No results</property>
<style>
<class name="dim-label"/>
</style>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">True</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow" id="scrolled_window">
<property name="visible">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="hscrollbar_policy">never</property>
<property name="shadow_type">in</property>
<child>
<object class="GtkTreeView" id="treeview">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="hexpand">True</property>
<property name="vexpand">True</property>
<property name="headers_visible">False</property>