This is the mail archive of the insight@sources.redhat.com mailing list for the Insight project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

PluginWindow class and a revamped plug-in sample code


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.
}
class RHAbout {
#  inherit PluginWindow ModalDialog
  inherit PluginWindow
  constructor {args} {
    global gdb_ImageDir

    # What about a menu?
    $menubar menubar_new_menu file "File" 0
    $menubar menubar_add_menu_command None "Close" \
      [code $this destroy_toplevel] \
      -underline 1
    $menubar menubar_new_menu help "Help" 0
    $menubar menubar_add_menu_command Other "Help Topics" \
      {HtmlViewer::open_help index.html} \
      -underline 0
    $menubar menubar_add_menu_separator
    $menubar menubar_add_menu_command Other "About GDB..." \
      {ManagedWin::open About -transient} \
      -underline 0

    # The menu only shows up if you do this:
    $menubar menubar_show

    # Do you want a toolbar?
    $toolbar toolbar_add_button con Other {ManagedWin::open Console} \
                           "Console (Ctrl+N)" -image console_img

    # The toolbar will only show up if you do this:
    $toolbar toolbar_show

    # Now, fill the childsite with some graphics and text

    # Remember to use the childsite, do not pack in the widget hull
    set f [childsite]

    # Put in some graphics
    label $f.image1 -bg white -image \
      [image create photo -file [file join $gdb_ImageDir insight.gif]]

    # Here we call an interface function provided by GDBTCL
    set text [gdb_cmd {show version}]

    # Here we call a command procedure that we created, if it exists
    catch {append text [rhabout_extra_text]}

    message $f.m -bg white -fg black -text $text -aspect 500 -relief flat
    pack $f.image1 $f.m -fill both -expand yes
    pack  $itk_interior
    window_name "About Red Hat Insight"
  }

  # Don't quit if this is the last window.  The only way that this can
  # happen is if we are the splash screen. 

  method quit_if_last {} { 
    return 0
  }

}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]