1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250
|
/*
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
*
* This program 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; version 2 of the
* License.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "form_view_base.h"
#include "plugin_editor_base.h"
#include <gtkmm/box.h>
#include <gtkmm/label.h>
#include <gtkmm/eventbox.h>
#include <gtkmm/window.h>
#include "active_label.h"
#include "grt/grt_manager.h"
#include "mforms/toolbar.h"
bool FormViewBase::close_plugin_tab(PluginEditorBase *editor)
{
if (editor->can_close())
{
_close_editor(editor);
remove_plugin_tab(editor);
}
else
return false;
bool has_visible_tabs = false;
for (int c= _editor_note->get_n_pages(), i= 0; i < c; i++)
{
if (_editor_note->get_nth_page(i)->is_visible())
{
has_visible_tabs = true;
break;
}
}
if (!has_visible_tabs)
_editor_note->hide();
return true;
}
void FormViewBase::set_close_editor_callback(const sigc::slot<void, PluginEditorBase*> &handler)
{
_close_editor = handler;
}
void FormViewBase::add_plugin_tab(PluginEditorBase *plugin)
{
if (_editor_note)
{
ActiveLabel* label = Gtk::manage(new ActiveLabel(plugin->get_title(), sigc::hide_return(sigc::bind(sigc::mem_fun(this, &FormViewBase::close_plugin_tab), plugin))));
int page_num = _editor_note->append_page(*plugin, *label);
plugin->signal_title_changed().connect(sigc::mem_fun(label, &ActiveLabel::set_text));
if (!_editor_note->is_visible())
{
_editor_note->show();
reset_layout();
}
plugin_tab_added(plugin);
Glib::signal_idle().connect_once(sigc::bind(sigc::mem_fun(_editor_note, &Gtk::Notebook::set_current_page), page_num));
}
else
g_warning("active form doesn't support editor tabs");
}
void FormViewBase::remove_plugin_tab(PluginEditorBase *plugin)
{
if (_editor_note)
{
_editor_note->remove_page(*plugin);
// Make the plugin manager forget about this plugin
GUIPluginBase *base = dynamic_cast<GUIPluginBase *>(plugin);
_grtm->get_plugin_manager()->close_and_forget_gui_plugin(reinterpret_cast<NativeHandle>(base));
if (_editor_note->get_n_pages() == 0)
_editor_note->hide();
}
}
bool FormViewBase::close_editors_for_object(const std::string &id)
{
for (int i= _editor_note->get_n_pages()-1; i >= 0; --i)
{
Gtk::Widget *panel= _editor_note->get_nth_page(i);
PluginEditorBase* editor;
if ((editor= dynamic_cast<PluginEditorBase*>(panel))
&& (id.empty() || editor->should_close_on_delete_of(id)))
{
remove_plugin_tab(editor);
return true;
}
}
return false;
}
PluginEditorBase *FormViewBase::get_focused_plugin_tab()
{
if (_editor_note)
{
Gtk::Widget *focused= dynamic_cast<Gtk::Window*>(_editor_note->get_toplevel())->get_focus();
// go up the hierarchy to see if the focused widget is inside _editor_note
while (focused && focused != _editor_note)
focused= focused->get_parent();
if (focused)
{
int page= _editor_note->get_current_page();
if (page >= 0)
{
Gtk::Widget *tab= _editor_note->get_nth_page(page);
return dynamic_cast<PluginEditorBase*>(tab);
}
}
}
return 0;
}
bool FormViewBase::close_focused_tab()
{
PluginEditorBase *active = get_focused_plugin_tab();
if (active)
{
close_plugin_tab(active);
return true;
}
return false;
}
void FormViewBase::restore_sidebar_layout()
{
if (_sidebar1_pane)
{
int w = _grtm->get_app_option_int(_panel_savename+":SidebarWidth", 200);
_sidebar1_pane->set_position(w);
if (_grtm->get_app_option_int(_panel_savename+":SidebarHidden", 0))
{
_toolbar->set_item_checked("wb.toggleSidebar", false);
_sidebar1_pane->get_child1()->hide();
}
else
_toolbar->set_item_checked("wb.toggleSidebar", true);
_sidebar1_pane->property_position().signal_changed().connect(sigc::bind(sigc::mem_fun(this, &FormViewBase::sidebar_resized), true));
}
if (_sidebar2_pane)
{
int w = _grtm->get_app_option_int(_panel_savename+":SecondarySidebarWidth", 200);
_sidebar2_pane->set_position(_sidebar2_pane->get_width()-w);
if (_grtm->get_app_option_int(_panel_savename+":SecondarySidebarHidden", 0))
{
_toolbar->set_item_checked("wb.toggleSecondarySidebar", false);
_sidebar2_pane->get_child2()->hide();
}
else
_toolbar->set_item_checked("wb.toggleSecondarySidebar", true);
_sidebar2_pane->property_position().signal_changed().connect(sigc::bind(sigc::mem_fun(this, &FormViewBase::sidebar_resized), false));
}
}
void FormViewBase::toggle_sidebar(bool show)
{
if (_sidebar1_pane)
{
Gtk::Widget *w = _sidebar1_pane->get_child1();
if (show)
w->show();
else
w->hide();
}
}
void FormViewBase::toggle_secondary_sidebar(bool show)
{
if (_sidebar2_pane)
{
Gtk::Widget *w = _sidebar2_pane->get_child2();
if (show)
w->show();
else
w->hide();
}
}
void FormViewBase::sidebar_resized(bool primary)
{
if (primary)
_grtm->set_app_option(_panel_savename+":SidebarWidth", grt::IntegerRef(_sidebar1_pane->get_position()));
else
_grtm->set_app_option(_panel_savename+":SecondarySidebarWidth", grt::IntegerRef(_sidebar2_pane->get_width() - _sidebar2_pane->get_position()));
}
bool FormViewBase::perform_command(const std::string &cmd)
{
if (cmd == "wb.toggleSidebar")
{
bool hidden = !_toolbar->get_item_checked(cmd);
_grtm->set_app_option(_panel_savename+":SidebarHidden", grt::IntegerRef(hidden));
toggle_sidebar(!hidden);
return true;
}
else if (cmd == "wb.toggleSecondarySidebar")
{
bool hidden = !_toolbar->get_item_checked(cmd);
_grtm->set_app_option(_panel_savename+":SecondarySidebarHidden", grt::IntegerRef(hidden));
toggle_secondary_sidebar(!hidden);
return true;
}
return false;
}
|