Commit ef49de68 authored by erg@google.com's avatar erg@google.com

Create a bookmark editor dialog interface and implement a GTK version.

The GTK version is currently limited to only editing the name/url of the
bookmark; I'm submitting this since it's getting big and I want a design
review.

Review URL: http://codereview.chromium.org/99131

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14763 0039d316-1c4b-4281-b951-d872f2087c98
parent b938c4cd
......@@ -5,6 +5,7 @@
#include "chrome/browser/bookmarks/bookmark_context_menu.h"
#include "base/compiler_specific.h"
#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/browser.h"
......@@ -21,7 +22,6 @@
// TODO(port): Port these files.
#if defined(OS_WIN)
#include "chrome/browser/tab_contents/tab_contents.h"
#include "chrome/browser/views/bookmark_editor_view.h"
#include "chrome/browser/views/bookmark_manager_view.h"
#include "chrome/views/window/window.h"
#endif
......@@ -189,7 +189,7 @@ class EditFolderController : public InputWindowDialog::Delegate,
// Used when adding a new bookmark. If a new bookmark is created it is selected
// in the bookmark manager.
class SelectOnCreationHandler : public BookmarkEditorView::Handler {
class SelectOnCreationHandler : public BookmarkEditor::Handler {
public:
explicit SelectOnCreationHandler(Profile* profile) : profile_(profile) {
}
......@@ -336,17 +336,13 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
}
if (selection_[0]->is_url()) {
#if defined(OS_WIN)
BookmarkEditorView::Configuration editor_config;
BookmarkEditor::Configuration editor_config;
if (configuration_ == BOOKMARK_BAR)
editor_config = BookmarkEditorView::SHOW_TREE;
editor_config = BookmarkEditor::SHOW_TREE;
else
editor_config = BookmarkEditorView::NO_TREE;
BookmarkEditorView::Show(wnd_, profile_, NULL, selection_[0],
editor_config, NULL);
#else
NOTIMPLEMENTED() << "BookmarkEditorView unimplemented";
#endif
editor_config = BookmarkEditor::NO_TREE;
BookmarkEditor::Show(wnd_, profile_, NULL, selection_[0],
editor_config, NULL);
} else {
EditFolderController::Show(profile_, wnd_, selection_[0], false,
false);
......@@ -368,21 +364,21 @@ void BookmarkContextMenu::ExecuteCommand(int id) {
case IDS_BOOMARK_BAR_ADD_NEW_BOOKMARK: {
UserMetrics::RecordAction(L"BookmarkBar_ContextMenu_Add", profile_);
#if defined(OS_WIN)
BookmarkEditorView::Configuration editor_config;
BookmarkEditorView::Handler* handler = NULL;
BookmarkEditor::Configuration editor_config;
BookmarkEditor::Handler* handler = NULL;
if (configuration_ == BOOKMARK_BAR) {
editor_config = BookmarkEditorView::SHOW_TREE;
editor_config = BookmarkEditor::SHOW_TREE;
} else {
editor_config = BookmarkEditorView::NO_TREE;
editor_config = BookmarkEditor::NO_TREE;
#if defined(OS_WIN)
// This is owned by the BookmarkEditorView.
handler = new SelectOnCreationHandler(profile_);
}
BookmarkEditorView::Show(wnd_, profile_, GetParentForNewNodes(), NULL,
editor_config, handler);
#else
NOTIMPLEMENTED() << "Adding new bookmark not implemented";
NOTIMPLEMENTED() << "Custom SelectOnCreationHandler not implemented";
#endif
}
BookmarkEditor::Show(wnd_, profile_, GetParentForNewNodes(), NULL,
editor_config, handler);
break;
}
......
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
#define CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
#include "base/gfx/native_widget_types.h"
class BookmarkNode;
class Profile;
// Small, cross platform interface that shows the correct platform specific
// bookmark editor dialog.
class BookmarkEditor {
public:
// Handler is notified when the BookmarkEditor creates a new bookmark.
// Handler is owned by the BookmarkEditor and deleted when it is deleted.
class Handler {
public:
virtual ~Handler() {}
virtual void NodeCreated(BookmarkNode* new_node) = 0;
};
// An enumeration of the possible configurations offered.
enum Configuration {
SHOW_TREE,
NO_TREE
};
// Shows the platform specific BookmarkEditor subclass editing |node|. If
// |node| is NULL a new entry is created initially parented to |parent|. If
// |show_tree| is false the tree is not shown. BookmarkEditor takes
// ownership of |handler| and deletes it when done. |handler| may be
// null. See description of Handler for details.
static void Show(gfx::NativeWindow parent_window,
Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
Configuration configuration,
Handler* handler);
};
#endif // CHROME_BROWSER_BOOKMARKS_BOOKMARK_EDITOR_H_
......@@ -589,6 +589,10 @@
RelativePath=".\bookmarks\bookmark_drop_info.h"
>
</File>
<File
RelativePath=".\bookmarks\bookmark_editor.h"
>
</File>
<File
RelativePath=".\bookmarks\bookmark_folder_tree_model.cc"
>
......
This diff is collapsed.
// Copyright (c) 2009 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_GTK_BOOKMARK_EDITOR_GTK_H_
#define CHROME_BROWSER_GTK_BOOKMARK_EDITOR_GTK_H_
#include <gtk/gtk.h>
#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
// GTK version of the bookmark editor dialog.
class BookmarkEditorGtk : public BookmarkEditor,
public BookmarkModelObserver {
public:
BookmarkEditorGtk(GtkWindow* window,
Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler);
virtual ~BookmarkEditorGtk();
void Show();
void Close();
private:
void Init(GtkWindow* parent_window);
// BookmarkModel observer methods. Any structural change results in
// resetting the tree model.
virtual void Loaded(BookmarkModel* model) { }
virtual void BookmarkNodeMoved(BookmarkModel* model,
BookmarkNode* old_parent,
int old_index,
BookmarkNode* new_parent,
int new_index);
virtual void BookmarkNodeAdded(BookmarkModel* model,
BookmarkNode* parent,
int index);
virtual void BookmarkNodeRemoved(BookmarkModel* model,
BookmarkNode* parent,
int index,
BookmarkNode* node);
virtual void BookmarkNodeChanged(BookmarkModel* model,
BookmarkNode* node) {}
virtual void BookmarkNodeChildrenReordered(BookmarkModel* model,
BookmarkNode* node);
virtual void BookmarkNodeFavIconLoaded(BookmarkModel* model,
BookmarkNode* node) {}
// Resets the model of the tree and updates the various buttons appropriately.
void Reset();
// Returns the current url the user has input.
GURL GetInputURL() const;
// Returns the title the user has input.
std::wstring GetInputTitle() const;
void ApplyEdits();
static void OnResponse(GtkDialog* dialog, int response_id,
BookmarkEditorGtk* window);
static gboolean OnWindowDeleteEvent(GtkWidget* widget,
GdkEvent* event,
BookmarkEditorGtk* dialog);
static void OnWindowDestroy(GtkWidget* widget, BookmarkEditorGtk* dialog);
static void OnEntryChanged(GtkEditable* entry, BookmarkEditorGtk* dialog);
// Profile the entry is from.
Profile* profile_;
// The dialog to display on screen.
GtkWidget* dialog_;
GtkWidget* name_entry_;
GtkWidget* url_entry_;
GtkWidget* close_button_;
GtkWidget* ok_button_;
GtkWidget* folder_tree_;
// TODO(erg): BookmarkEditorView has an EditorTreeModel object here; convert
// that into a GObject that implements the interface GtkTreeModel.
// Initial parent to select. Is only used if node_ is NULL.
BookmarkNode* parent_;
// Node being edited. Is NULL if creating a new node.
BookmarkNode* node_;
// Mode used to create nodes from.
BookmarkModel* bb_model_;
// If true, we're running the menu for the bookmark bar or other bookmarks
// nodes.
bool running_menu_for_root_;
// Is the tree shown?
bool show_tree_;
scoped_ptr<BookmarkEditor::Handler> handler_;
DISALLOW_COPY_AND_ASSIGN(BookmarkEditorGtk);
};
#endif // CHROME_BROWSER_GTK_BOOKMARK_EDITOR_GTK_H_
......@@ -5,11 +5,11 @@
#include "chrome/browser/views/bookmark_bubble_view.h"
#include "chrome/app/chrome_dll_resource.h"
#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/metrics/user_metrics.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/views/bookmark_editor_view.h"
#include "chrome/browser/views/info_bubble.h"
#include "chrome/browser/views/standard_layout.h"
#include "chrome/common/gfx/chrome_canvas.h"
......@@ -373,9 +373,10 @@ void BookmarkBubbleView::ShowEditor() {
// the delete and all that.
Close();
if (node)
BookmarkEditorView::Show(parent, profile_, NULL, node,
BookmarkEditorView::SHOW_TREE, NULL);
if (node) {
BookmarkEditor::Show(parent, profile_, NULL, node,
BookmarkEditor::SHOW_TREE, NULL);
}
}
void BookmarkBubbleView::ApplyEdits() {
......
......@@ -42,11 +42,25 @@ static const int kTreeWidth = 300;
// ID for various children.
static const int kNewGroupButtonID = 1002;
BookmarkEditorView::BookmarkEditorView(Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
Configuration configuration,
Handler* handler)
// static
void BookmarkEditor::Show(HWND parent_hwnd,
Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
Configuration configuration,
Handler* handler) {
DCHECK(profile);
BookmarkEditorView* editor =
new BookmarkEditorView(profile, parent, node, configuration, handler);
editor->Show(parent_hwnd);
}
BookmarkEditorView::BookmarkEditorView(
Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler)
: profile_(profile),
tree_view_(NULL),
new_group_button_(NULL),
......@@ -67,19 +81,6 @@ BookmarkEditorView::~BookmarkEditorView() {
bb_model_->RemoveObserver(this);
}
// static
void BookmarkEditorView::Show(HWND parent_hwnd,
Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
Configuration configuration,
Handler* handler) {
DCHECK(profile);
BookmarkEditorView* editor =
new BookmarkEditorView(profile, parent, node, configuration, handler);
editor->Show(parent_hwnd);
}
bool BookmarkEditorView::IsDialogButtonEnabled(
MessageBoxFlags::DialogButton button) const {
if (button == MessageBoxFlags::DIALOGBUTTON_OK) {
......@@ -489,7 +490,7 @@ void BookmarkEditorView::ApplyEdits(EditorNode* parent) {
BookmarkNode* old_parent = node_ ? node_->GetParent() : NULL;
const int old_index = old_parent ? old_parent->IndexOfChild(node_) : -1;
if (!show_tree_ ) {
if (!show_tree_) {
if (!node_) {
BookmarkNode* node =
bb_model_->AddURL(parent_, parent_->GetChildCount(), new_title,
......
......@@ -7,6 +7,7 @@
#include <set>
#include "chrome/browser/bookmarks/bookmark_editor.h"
#include "chrome/browser/bookmarks/bookmark_model.h"
#include "chrome/views/controls/button/button.h"
#include "chrome/views/controls/menu/menu.h"
......@@ -32,7 +33,8 @@ class Profile;
//
// To use BookmarkEditorView invoke the static show method.
class BookmarkEditorView : public views::View,
class BookmarkEditorView : public BookmarkEditor,
public views::View,
public views::ButtonListener,
public views::TreeViewController,
public views::DialogDelegate,
......@@ -51,40 +53,14 @@ class BookmarkEditorView : public views::View,
FRIEND_TEST(BookmarkEditorViewTest, ChangeURLNoTree);
FRIEND_TEST(BookmarkEditorViewTest, ChangeTitleNoTree);
public:
// Handler is notified when the BookmarkEditorView creates a new bookmark.
// Handler is owned by the BookmarkEditorView and deleted when it is deleted.
class Handler {
public:
virtual ~Handler() {}
virtual void NodeCreated(BookmarkNode* new_node) = 0;
};
// An enumeration of the possible configurations offered.
enum Configuration {
SHOW_TREE,
NO_TREE
};
BookmarkEditorView(Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
Configuration configuration,
Handler* handler);
BookmarkEditor::Configuration configuration,
BookmarkEditor::Handler* handler);
virtual ~BookmarkEditorView();
// Shows the BookmarkEditorView editing |node|. If |node| is NULL a new entry
// is created initially parented to |parent|. If |show_tree| is false the
// tree is not shown. BookmarkEditorView takes ownership of |handler| and
// deletes it when done. |handler| may be null. See description of Handler
// for details.
static void Show(HWND parent_window,
Profile* profile,
BookmarkNode* parent,
BookmarkNode* node,
Configuration configuration,
Handler* handler);
// DialogDelegate methods:
virtual bool IsDialogButtonEnabled(
MessageBoxFlags::DialogButton button) const;
......@@ -280,7 +256,7 @@ class BookmarkEditorView : public views::View,
// Is the tree shown?
bool show_tree_;
scoped_ptr<Handler> handler_;
scoped_ptr<BookmarkEditor::Handler> handler_;
DISALLOW_COPY_AND_ASSIGN(BookmarkEditorView);
};
......
......@@ -458,6 +458,7 @@
'browser/bookmarks/bookmark_drag_data.h',
'browser/bookmarks/bookmark_drop_info.cc',
'browser/bookmarks/bookmark_drop_info.h',
'browser/bookmarks/bookmark_editor.h',
'browser/bookmarks/bookmark_folder_tree_model.cc',
'browser/bookmarks/bookmark_folder_tree_model.h',
'browser/bookmarks/bookmark_html_writer.cc',
......@@ -724,6 +725,8 @@
'browser/gtk/back_forward_menu_model_gtk.h',
'browser/gtk/bookmark_bar_gtk.cc',
'browser/gtk/bookmark_bar_gtk.h',
'browser/gtk/bookmark_editor_gtk.cc',
'browser/gtk/bookmark_editor_gtk.h',
'browser/gtk/browser_toolbar_gtk.cc',
'browser/gtk/browser_toolbar_gtk.h',
'browser/gtk/browser_window_factory_gtk.cc',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment