public inbox for insight@sourceware.org
 help / color / mirror / Atom feed
From: Fernando Nasser <fnasser@redhat.com>
To: Insight List <insight@sources.redhat.com>
Subject: PluginWindow class and a revamped plug-in sample code
Date: Wed, 31 Jan 2001 21:04:00 -0000	[thread overview]
Message-ID: <3A78EDCA.512E7905@redhat.com> (raw)

I found an old Jim Ingham's definition of a PluginWindow class (at least 
someone told me that he wrote it) saying that it should have menu and
tollbar facilities and a running and a stopped methods.  This class
would
be inherited by plug-ins making it easier for the developer.

I added some automatic control of the menus and toolbar buttons (so they
will
be disabled and enabled automatically according to their category) with
code
stolen from the Source Window and here is the result.  

I also revamped the sample code to use this class.


	* library/pluginwin.itcl: New file.  Implements the PluginWindow
	class that provides some basic functionality for plug-ins.
	* library/plugins/rhabout/rhabout.itcl: Inherit from the new
	PluginWindow class.  Remove code dependent on ModalDlg.
	(constructor): Creates menus and a toolbar to show how these
	PluginWindow components are used.
	* library/tclIndex: Regenerate.


-- 
Fernando Nasser
Red Hat Canada Ltd.                     E-Mail:  fnasser@redhat.com
2323 Yonge Street, Suite #300
Toronto, Ontario   M4P 2C9
# PluginWindow
# Copyright 2001 Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License (GPL) as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# 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.

# ----------------------------------------------------------------------
# Implements a menu and a toolbar that are attached to a source window.
#
#   PUBLIC ATTRIBUTES:
#
#
#   METHODS:
#
#     configure ....... used to change public attributes
#
#   PRIVATE METHODS
#
#   X11 OPTION DATABASE ATTRIBUTES
#
#
# ----------------------------------------------------------------------

class PluginWindow {
  inherit ManagedWin

  # ------------------------------------------------------------------
  #  CONSTRUCTOR - create widget
  # ------------------------------------------------------------------
  constructor {args} {

    # Create a menu widget for the plug-in window
    set menubar [GDBMenuBar $itk_interior.menubar]

    # Create a toolbar widget for the plug-in window
    set toolbar [GDBToolBar $itk_interior.toolbar]

    # Pack the toolbar
    pack $toolbar -expand 1 -fill both

    # Create a frame for the subclass to use
    set child [frame $itk_interior.child]

    # Pack the childsite
    pack $child -expand 1 -fill both

    eval itk_initialize $args
    add_hook gdb_idle_hook "$this stopped"
    add_hook gdb_busy_hook "$this running"
    add_hook gdb_no_inferior_hook "$this no_inferior"
  }

  # ------------------------------------------------------------------
  #  DESTRUCTOR - destroy window containing widget
  # ------------------------------------------------------------------
  destructor {
    remove_hook gdb_idle_hook "$this stopped"
    remove_hook gdb_busy_hook "$this running"
    remove_hook gdb_no_inferior_hook "$this no_inferior"

    #destroy $this
  }

  # ------------------------------------------------------------------
  #  ACCESSOR METHOD - Retrieve childsite
  # ------------------------------------------------------------------
  method childsite {} {
    return $child
  }

  ####################################################################
  #
  # State control methods used by both the menu and the toolbar
  # 
  ####################################################################

  # ------------------------------------------------------------------
  #  METHOD:  stopped
  #             Invoked when there is an inferior and it has stopped
  # ------------------------------------------------------------------
  method stopped {} {
    debug 
    enable_ui 1
  }

  # ------------------------------------------------------------------
  #  METHOD:  running
  #             Invoked when gdb is going to run the inferior
  # ------------------------------------------------------------------
  method running {} {
    debug 
    enable_ui 0
  }

  # ------------------------------------------------------------------
  #  METHOD:  no_inferior
  #             Invoked when gdb detects the inferior is gone 
  # ------------------------------------------------------------------
  method no_inferior {} {
    debug 
    enable_ui 2
  }

  ####################################################################
  # The following method enables/disables both menus and buttons.
  ####################################################################

  # ------------------------------------------------------------------
  # METHOD:  enable_ui - enable/disable the appropriate buttons and menus
  # Called from the busy, idle, and no_inferior hooks.
  #
  # on must be:
  # value      Control    Other     State
  #   0          off       off      gdb is busy
  #   1          on        on       gdb has inferior, and is idle
  #   2          off       on       gdb has no inferior, and is idle
  # ------------------------------------------------------------------
  public method enable_ui {on} {
    global tcl_platform
    debug "$on"

    # Do the enabling so that all the disabling happens first, this way if a
    # button belongs to two groups, enabling takes precedence, which is
    #  probably right.

    switch $on {
      0 {
        # Busy
	set enable_list {Control disabled \
			   Other disabled}
      }
      1 {
        # Idle, with inferior
	set enable_list {Control normal \
			   Other normal}
      }
      2 {
        # Idle, no inferior
	set enable_list {Control disabled \
			   Other normal}
      }
      default {
	debug "Unknown type: $on in enable_ui"
	return
      }
    }

    $menubar set_class_state $enable_list
    $toolbar set_class_state $enable_list
  }

  ####################################################################
  #
  #  PRIVATE DATA
  #
  ####################################################################

  # The childsite
  private variable child

  ####################################################################
  #
  #  PROTECTED DATA
  #
  ####################################################################

  # The GdbMenuBar component
  protected variable menubar

  # The GdbToolBar component
  protected variable toolbar

  ####################################################################
  #
  #  PUBLIC DATA
  #
  ####################################################################

  # None.
}

             reply	other threads:[~2001-01-31 21:04 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-01-31 21:04 Fernando Nasser [this message]
2001-02-02 13:47 ` Tom Tromey
2001-02-02 13:58   ` Fernando Nasser
     [not found] <981320309.29300.ezmlm@sources.redhat.com>
2001-02-05 10:21 ` Jim Ingham
2001-02-05 10:30   ` Fernando Nasser
2001-02-05 10:26 ` Jim Ingham

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3A78EDCA.512E7905@redhat.com \
    --to=fnasser@redhat.com \
    --cc=insight@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).