File: widget_saver.cpp

package info (click to toggle)
mysql-workbench 6.3.8%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 113,932 kB
  • ctags: 87,814
  • sloc: ansic: 955,521; cpp: 427,465; python: 59,728; yacc: 59,129; xml: 54,204; sql: 7,091; objc: 965; makefile: 638; sh: 613; java: 237; perl: 30; ruby: 6; php: 1
file content (78 lines) | stat: -rw-r--r-- 2,238 bytes parent folder | download | duplicates (2)
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
#include "base/log.h"
#include "widget_saver.h"
#include <gtkmm/paned.h>
#include "grt/grt_manager.h"
#include "mforms/toolbar.h"

DEFAULT_LOG_DOMAIN("gtk.utils")

//------------------------------------------------------------------------------
void utils::gtk::save_settings(bec::GRTManager* m, Gtk::Paned* paned, const bool right_side)
{
  const std::string name = paned->get_name();
  if (!name.empty() && paned->get_data("allow_save"))
  {
    long pos = paned->get_position();
    if (right_side)
      pos = paned->get_width() - pos;
    m->set_app_option(name + ".position", grt::IntegerRef(pos));
  }
}

//------------------------------------------------------------------------------
static bool set_paned_position(Gtk::Paned *paned, const long pos, const bool right, const int min_size)
{
  if (right)
  {
    int size;
    if (dynamic_cast<Gtk::HPaned*>(paned))
      size = paned->get_width() - pos;
    else
      size = paned->get_height() - pos;
    if (min_size > 0 && size < min_size)
      size = min_size;
    else if (min_size < 0 && size > abs(min_size))
      size = abs(min_size);
    paned->set_position(size);
  }
  else
  {
    int npos = pos;
    if (min_size > 0 && npos < min_size)
      npos = min_size;
    else if (min_size < 0 && npos > abs(min_size))
      npos = abs(min_size);
    paned->set_position(npos);
  }
  paned->set_data("allow_save", (void*)1);

  return false;
}


//------------------------------------------------------------------------------
sigc::connection utils::gtk::load_settings(bec::GRTManager* m, Gtk::Paned* paned, const sigc::slot<void> defaults_slot, const bool right_side, const int min_size)
{
  const std::string name = paned->get_name();
  long pos = -1;
  try
  {
    pos = m->get_app_option_int(name + ".position");
  }
  catch (const grt::type_error& e)
  {
    log_error("Can not restore paned position for name '%s', error '%s'\n", name.c_str(), e.what());
  }
  sigc::connection con;
  if (pos > 0)
  {
    paned->set_data("allow_save", NULL);
    con = Glib::signal_idle().connect(sigc::bind(sigc::ptr_fun(&set_paned_position), paned, pos, right_side, min_size));
  }
  else
  {
    defaults_slot();
    paned->set_data("allow_save", (void*)1);
  }
  return con;
}